public function testMarkerGroup()
 {
     $map = new StaticMap();
     $map->setCenter(new Coordinate(59.93863, 30.31413));
     $markerGroup = new MarkerGroup(new MarkerStyle());
     $markerGroup->addMarker(new Marker(new Coordinate(59.93863, 30.31413), new MarkerStyle()));
     $markerGroup->addMarker(new Marker(new Coordinate(59.93863, 30.31413), new MarkerStyle()));
     $map->addMarker(new Marker(new Coordinate(54.93863, 32.31413), new MarkerStyle()));
     $map->addMarker($markerGroup);
     $urlGenerator = new UrlGenerator();
     $url = $this->normalizeUrl($urlGenerator->generate($map));
     $urlInfo = parse_url($url);
     parse_str($urlInfo['query'], $queryParameters);
     $this->assertEquals('size:mid|54.93863000,32.31413000', $queryParameters['markers'][0]);
     $this->assertEquals('size:mid|59.93863000,30.31413000|59.93863000,30.31413000', $queryParameters['markers'][1]);
     $this->assertEquals('59.93863000,30.31413000', $queryParameters['center']);
     $this->assertEquals('8', $queryParameters['zoom']);
     $this->assertEquals('600x300', $queryParameters['size']);
     $this->assertEquals('roadmap', $queryParameters['maptype']);
 }
 public function generate(StaticMap $map)
 {
     $parameters = [];
     $parameters['markers'] = [];
     foreach ($map->getMarkers() as $marker) {
         if ($marker instanceof MarkerGroup) {
             $groupStyle = $this->buildMarkerStyleQuery($marker);
             $groupLocations = [];
             foreach ($marker->getMarkers() as $groupMarker) {
                 $groupLocations[] = $this->buildMarkerLocationQuery($groupMarker);
             }
             $parameters['markers'][] = $groupStyle . '|' . implode('|', $groupLocations);
         } else {
             $markerStyle = $this->buildMarkerStyleQuery($marker);
             $markerLocation = $this->buildMarkerLocationQuery($marker);
             $parameters['markers'][] = $markerStyle . '|' . $markerLocation;
         }
     }
     if (($center = $map->getCenter()) !== null) {
         $parameters['center'] = $center->getLatitude() . ',' . $center->getLongitude();
     }
     if ($map->isAutoScale()) {
         $parameters['autoscale'] = 1;
     } else {
         $parameters['zoom'] = $map->getZoom();
     }
     if (($scale = $map->getScale()) !== null) {
         $parameters['scale'] = $scale;
     }
     $parameters['size'] = $map->getSize()->getWidth() . 'x' . $map->getSize()->getHeight();
     $parameters['maptype'] = $map->getType();
     $parameters['key'] = $map->getKey();
     $query = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', http_build_query($parameters, '', '&'));
     $query = str_replace('%2F', '/', $query);
     $query = str_replace('%3A', ':', $query);
     $query = str_replace('%7C', '|', $query);
     $query = str_replace('%2C', ',', $query);
     return self::GOOGLE_MAP_URL . '?' . $query;
 }
Beispiel #3
0
 /**
  * Primary call to class that returns a google url to the custom static map
  * @param $lat
  * @param $lng
  * @param string $setting
  * @param array $override
  * @return string
  */
 public function getMap($lat, $lng, $setting = 'default', $override = array())
 {
     if ($setting == null) {
         $setting = 'default';
     }
     $this->setMapConfig($setting, $override);
     $map = new StaticMap();
     $map->setZoom($this->config["zoom"]);
     $map->setType($this->config["type"]);
     $map->setSize(new MapSize($this->config["width"], $this->config["height"]));
     $urlGenerator = new UrlGenerator();
     $map->addMarker(new Marker(new Coordinate($lat, $lng), new MarkerStyle()));
     return $urlGenerator->generate($map);
 }