public function init($args) { $this->baseURL = $args['BASE_URL']; $this->diskCache = new DiskCache(Kurogo::getSiteVar('WMS_CACHE', 'maps'), 86400 * 7, true); $this->diskCache->preserveFormat(); $filename = md5($this->baseURL); $metafile = $filename . '-meta.txt'; if (!$this->diskCache->isFresh($filename)) { $params = array('request' => 'GetCapabilities', 'service' => 'WMS'); $query = $this->baseURL . '?' . http_build_query($params); file_put_contents($this->diskCache->getFullPath($metafile), $query); $contents = file_get_contents($query); $this->diskCache->write($contents, $filename); } else { $contents = $this->diskCache->read($filename); } $this->wmsParser = new WMSDataParser(); $this->wmsParser->parseData($contents); $this->enableAllLayers(); // TODO make sure this projection is supported by the server $projections = $this->wmsParser->getProjections(); if (count($projections)) { // make sure this is a projection we can handle foreach ($projections as $proj) { $contents = MapProjector::getProjSpecs($proj); if ($contents) { $this->setMapProjection($proj); } } } else { $this->setMapProjection(GEOGRAPHIC_PROJECTION); } }
protected function getCurrentScale() { if ($this->unitsPerMeter === null) { $contents = MapProjector::getProjSpecs($this->mapProjection); if (preg_match('/to_meter=([\d\.]+)/', $contents, $matches)) { $this->unitsPerMeter = 1 / $matches[1]; } else { $this->unitsPerMeter = self::NO_PROJECTION; } } if ($this->unitsPerMeter != self::NO_PROJECTION) { $metersPerPixel = $this->getHorizontalRange() / $this->imageWidth / $this->unitsPerMeter; return $metersPerPixel / self::LIFE_SIZE_METERS_PER_PIXEL; } else { // TODO this isn't quite right, this won't allow us to use // maxScaleDenom and minScaleDenom in any layers return self::NO_PROJECTION; } }
public function __construct($projString) { $this->specs = $projString; if (preg_match('/^\\d+$/', $projString)) { $this->format = 'wkid'; } elseif (preg_match('/^\\w+\\[/', $projString)) { $this->format = 'wkt'; } elseif (preg_match('/^\\+/', $projString)) { $this->format = 'proj4'; } switch ($this->format) { case 'wkid': $projString = MapProjector::getProjSpecs($projString); $params = self::parseProj4String($projString); $this->initFromProj4Params($params); break; case 'wkt': $params = WKTParser::parseWKTString($projString); $this->initFromWKTParams($params); break; case 'proj4': default: $params = self::parseProj4String($projString); $this->initFromProj4Params($params); break; } }