Exemplo n.º 1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @throws \InvalidArgumentException
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->helper = $this->getHelper('resource');
     $mapmode = strtolower($input->getOption('mapmode'));
     if (!in_array($mapmode, array('world', 'server'))) {
         throw new \InvalidArgumentException("--mapmode must be 'world' or 'server'");
     }
     $mapname = $input->getOption('mapname');
     $this->mapdir = $input->getOption('mapdir');
     $lang = $input->getOption('lang');
     if ($this->mapdir[0] != '/') {
         $this->mapdir = $this->helper->get('app.path') . '/' . $this->mapdir;
     }
     $withMap = $input->hasParameterOption('--with-map');
     $withCity = $input->hasParameterOption('--with-city');
     $withRegionColor = $input->hasParameterOption('--with-region-color');
     $output->writeln("=======================");
     $output->writeln("mode = <info>{$mapmode}</info>");
     $output->writeln("mapdir = <info>{$this->mapdir}</info>");
     if (!$withMap && !$withCity && empty($lang)) {
         throw new \InvalidArgumentException("Use --with-map, --with-city, --lang options\n");
     }
     $config = $this->helper->get('map-config');
     $this->proj = new MapProjection();
     $this->proj->setServerZones($this->helper->get('server.json.array'));
     $maps = $config['maps'];
     if ($mapmode == 'world') {
         $this->proj->setWorldZones($this->helper->get('world.json.array'));
     } else {
         // include individual zone map
         $maps = array_merge($maps, $config['zones']);
         unset($maps['world']);
         $this->proj->setWorldZones(array('grid' => array(array(0, 47520), array(108000, 0))));
     }
     $this->mapmode = $mapmode;
     $this->mapname = $mapname;
     $this->tileStorage = $this->helper->get('tilestorage');
     // map tiles
     $minMapZoom = 1;
     $maxMapZoom = 11;
     // city map on world image
     $minCityZoom = 10;
     $maxCityZoom = 11;
     // text tiles
     $minTextZoom = 5;
     $maxTextZoom = 12;
     // generate tiles for world map zone placement
     if ($withMap) {
         $this->doMaps($maps, $minMapZoom, $maxMapZoom, $output);
     }
     if ($withCity) {
         $this->doMaps($config['cities'], $minCityZoom, $maxCityZoom, $output);
     }
     if (!empty($lang)) {
         $languages = explode(',', $lang);
         foreach ($languages as $l) {
             $this->doTextTiles($l, $minTextZoom, $maxTextZoom, $output);
         }
     }
 }
Exemplo n.º 2
0
 public function testSetWorldZones()
 {
     $wz = array('wz' => array(array(0, 1), array(1, 0)));
     $this->proj->setWorldZones($wz, 5);
     $scale = $this->proj->scale(5);
     $bounds = $this->proj->getZoneBounds('wz');
     $expected = new Bounds(0, 1, 1, 0);
     $this->assertEquals(1, $scale);
     $this->assertEquals($expected, $bounds);
 }
Exemplo n.º 3
0
<?php

use Bmsite\Maps\MapProjection;
use Bmsite\Maps\ResourceLoader;
use Bmsite\Maps\StaticMap;
require_once __DIR__ . '/../vendor/autoload.php';
$tiledir = '/srv/websites/maps/htdocs/webroot/api/tiles';
$params = array('maptype' => 'atys', 'size' => '512x300', 'maxzoom' => 10, 'markers' => array('icon:lm_marker|color:0xff5050|label:Glue|8749.71,-3163.33', 'icon:lm_marker|color:0xff5050|label:Zun|8812.64,-3243.71', 'icon:lm_marker|color:0xff5050|label:Koorin|8732.69,-3387.78', 'icon:lm_marker|color:0xff5050|label:Splinter|8909.87,-3028.54', 'icon:lm_marker|color:0xff5050|label:Oath|8991.02,-3053.90'));
$loader = new ResourceLoader();
$proj = new MapProjection();
$proj->setServerZones($loader->loadJson('server.json'));
$proj->setWorldZones($loader->loadJson('world.json'));
$map = new StaticMap($tiledir, $proj);
$map->configure($params);
$etag = $map->etag();
echo "etag:[{$etag}]\n";
$img = $map->render();
file_put_contents(__DIR__ . '/../static-map-result.png', $img);
$size = strlen($img);
echo "size:[{$size}]\n";