/**
  * Checks the render method
  */
 public function testRender()
 {
     $mapTest = new Map();
     $markerTest = new Overlays\Marker();
     $markerTest->setPosition(new Base\Coordinate(1.1, 2.1, true));
     $markerTest->setAnimation(Overlays\Animation::BOUNCE);
     $iconTest = new Overlays\MarkerImage();
     $iconTest->setUrl('url');
     $markerTest->setIcon($iconTest);
     $shadowTest = new Overlays\MarkerImage();
     $shadowTest->setUrl('url');
     $markerTest->setShadow($shadowTest);
     $shapeTest = new Overlays\MarkerShape();
     $shapeTest->setType('poly');
     $shapeTest->setCoordinates(array(1, 2, 3, 4));
     $markerTest->setShape($shapeTest);
     $infoWindowTest = new Overlays\InfoWindow();
     $infoWindowTest->setContent('content');
     $markerTest->setInfoWindow($infoWindowTest);
     $this->assertEquals(self::$markerHelper->render($markerTest, $mapTest), 'var ' . $markerTest->getIcon()->getJavascriptVariable() . ' = new google.maps.MarkerImage("url");' . PHP_EOL . 'var ' . $markerTest->getShadow()->getJavascriptVariable() . ' = new google.maps.MarkerImage("url");' . PHP_EOL . 'var ' . $markerTest->getShape()->getJavascriptVariable() . ' = new google.maps.MarkerShape({"type":"poly","coords":[1,2,3,4]});' . PHP_EOL . 'var ' . $markerTest->getJavascriptVariable() . ' = new google.maps.Marker({"map":' . $mapTest->getJavascriptVariable() . ',"position":new google.maps.LatLng(1.1, 2.1, true), "animation":google.maps.Animation.BOUNCE, "icon":' . $markerTest->getIcon()->getJavascriptVariable() . ', "shadow":' . $markerTest->getShadow()->getJavascriptVariable() . ', "shape":' . $markerTest->getShape()->getJavascriptVariable() . '});' . PHP_EOL . 'var ' . $markerTest->getInfoWindow()->getJavascriptVariable() . ' = new google.maps.InfoWindow({"content":"content"});' . PHP_EOL);
     $markerTest->setOptions(array('option1' => 'value1', 'option2' => 'value2'));
     $this->assertEquals(self::$markerHelper->render($markerTest, $mapTest), 'var ' . $markerTest->getIcon()->getJavascriptVariable() . ' = new google.maps.MarkerImage("url");' . PHP_EOL . 'var ' . $markerTest->getShadow()->getJavascriptVariable() . ' = new google.maps.MarkerImage("url");' . PHP_EOL . 'var ' . $markerTest->getShape()->getJavascriptVariable() . ' = new google.maps.MarkerShape({"type":"poly","coords":[1,2,3,4]});' . PHP_EOL . 'var ' . $markerTest->getJavascriptVariable() . ' = new google.maps.Marker({"map":' . $mapTest->getJavascriptVariable() . ',"position":new google.maps.LatLng(1.1, 2.1, true), "animation":google.maps.Animation.BOUNCE, "icon":' . $markerTest->getIcon()->getJavascriptVariable() . ', "shadow":' . $markerTest->getShadow()->getJavascriptVariable() . ', "shape":' . $markerTest->getShape()->getJavascriptVariable() . ',"option1":"value1","option2":"value2"});' . PHP_EOL . 'var ' . $markerTest->getInfoWindow()->getJavascriptVariable() . ' = new google.maps.InfoWindow({"content":"content"});' . PHP_EOL);
 }
 /**
  * Renders the marker
  *
  * @param Ivory\GoogleMapBundle\Model\Overlays\Marker $marker
  * @param Ivory\GoogleMapBundle\Model\Map $map
  * @return string HTML output
  */
 public function render(Marker $marker, Map $map)
 {
     $html = array();
     $markerJSONOptions = sprintf('{"map":%s,"position":%s', $map->getJavascriptVariable(), $this->coordinateHelper->render($marker->getPosition()));
     $markerOptions = $marker->getOptions();
     if ($marker->hasAnimation()) {
         $markerJSONOptions .= ', "animation":' . $this->animationHelper->render($marker->getAnimation());
     }
     if ($marker->hasIcon()) {
         $html[] = $this->markerImageHelper->render($marker->getIcon());
         $markerJSONOptions .= ', "icon":' . $marker->getIcon()->getJavascriptVariable();
     }
     if ($marker->hasShadow()) {
         $html[] = $this->markerImageHelper->render($marker->getShadow());
         $markerJSONOptions .= ', "shadow":' . $marker->getShadow()->getJavascriptVariable();
     }
     if ($marker->hasShape()) {
         $html[] = $this->markerShapeHelper->render($marker->getShape());
         $markerJSONOptions .= ', "shape":' . $marker->getShape()->getJavascriptVariable();
     }
     if (!empty($markerOptions)) {
         $markerJSONOptions .= ',' . substr(json_encode($markerOptions), 1);
     } else {
         $markerJSONOptions .= '}';
     }
     $html[] = sprintf('var %s = new google.maps.Marker(%s);' . PHP_EOL, $marker->getJavascriptVariable(), $markerJSONOptions);
     if ($marker->hasInfoWindow()) {
         $html[] = $this->infoWindowHelper->render($marker->getInfoWindow(), false);
         if ($marker->getInfoWindow()->isOpen()) {
             $html[] = $this->infoWindowHelper->renderOpen($marker->getInfoWindow(), $map, $marker);
         }
     }
     return implode('', $html);
 }
 /**
  * Checks the render markers method
  */
 public function testRenderMarkers()
 {
     $mapTest = new Model\Map();
     $markerTest = new Overlays\Marker();
     $markerTest->setPosition(new Base\Coordinate(1.1, 2.1, false));
     $mapTest->addMarker($markerTest);
     $this->assertEquals(self::$mapHelper->renderMarkers($mapTest), 'var ' . $markerTest->getJavascriptVariable() . ' = new google.maps.Marker({"map":' . $mapTest->getJavascriptVariable() . ',"position":new google.maps.LatLng(1.1, 2.1, false)});' . PHP_EOL);
 }
Ejemplo n.º 4
0
 /**
  * Create a marker
  */
 public function __construct()
 {
     parent::__construct();
 }