/** * Generate map tiles * * @param array $maps [ id => map.png ] * @param array $zoomRange [ min, max] */ public function generate(array $maps, array $zoomRange) { foreach ($maps as $id => $mapImage) { // load map file $mapFilename = $this->mapsDirectory . '/' . $mapImage; if (!file_exists($mapFilename)) { $this->info("- map file '{$id}:{$mapFilename}' not found, skip\n"); continue; } // find out map coordinates for base zoom level $zoneBounds = $this->projWorld->getZoneBounds($id); $this->info("+ loading map {$mapFilename}\n"); $mapImage = $this->loadImage($mapFilename); $mapImageWidth = imagesx($mapImage); $mapImageHeight = imagesy($mapImage); // map image coords at base zoom $zoneLeft = $zoneBounds->left; $zoneBottom = $zoneBounds->bottom; $zoneRight = $zoneBounds->right; $zoneTop = $zoneBounds->top; $this->info(">> map size ({$mapImageWidth}, {$mapImageHeight}), position ({$zoneLeft}, {$zoneTop}, {$zoneRight}, {$zoneBottom})\n"); $mapImageWidth = imagesx($mapImage); $mapImageHeight = imagesy($mapImage); for ($zoom = $zoomRange[0]; $zoom <= $zoomRange[1]; $zoom++) { $this->mapCutter($mapImage, $zoom, $mapImageWidth, $mapImageHeight, $zoneBounds); } imagedestroy($mapImage); } }
public function testGetInnerZoneBounds() { $expected = $this->worldProj['place_pyr']; $inner = $this->proj->getZoneBounds('place_pyr'); $result = array(array($inner->left, $inner->bottom), array($inner->right, $inner->top)); $this->assertEquals($expected, $result); }
/** * @return resource * @throws \RuntimeException */ protected function _background() { $canvas = imagecreatetruecolor($this->width, $this->height); if ($canvas === false) { throw new \RuntimeException("Unable to create output image at size [{$this->width}x{$this->height}]"); } if ($this->center === null) { if ($this->bounds === null) { // no features on map, so take center point in world zone $world = $this->proj->getZoneBounds('world'); $this->bounds = clone $world; } $cx = ($this->bounds->left + $this->bounds->right) / 2; $cy = ($this->bounds->top + $this->bounds->bottom) / 2; $this->center = new Point($cx, $cy); } else { // this comes in handy with automatic zoom $this->extend($this->center); } if ($this->zoom === null) { $this->zoom = $this->getBoundsZoom(); } //calculate viewport $scale = $this->getZoomScale(); // calculate viewport $halfWidth = $this->width / 2; $halfHeight = $this->height / 2; // absolute coords for viewport $vpLeft = $this->center->x * $scale - $halfWidth; $vpTop = $this->center->y * $scale - $halfHeight; $vpRight = $vpLeft + $this->width; $vpBottom = $vpTop + $this->height; $this->viewport = new Bounds($vpLeft, $vpBottom, $vpRight, $vpTop); $this->draw($canvas); return $canvas; }