/**
  * Renders the info window open flag.
  *
  * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window.
  * @param \Ivory\GoogleMap\Map                 $map        The map.
  * @param \Ivory\GoogleMap\Overlays\Marker     $marker     The marker.
  *
  * @return string The JS output.
  */
 public function renderOpen(InfoWindow $infoWindow, Map $map, Marker $marker = null)
 {
     if ($marker !== null) {
         return sprintf('%s.open(%s, %s);' . PHP_EOL, $infoWindow->getJavascriptVariable(), $map->getJavascriptVariable(), $marker->getJavascriptVariable());
     }
     return sprintf('%s.open(%s);' . PHP_EOL, $infoWindow->getJavascriptVariable(), $map->getJavascriptVariable());
 }
    /**
     * {@inheritdoc}
     */
    public function renderAfter(Map $map)
    {
        // Here, we can render js code just after the generated one.
        return '
                    var mapVariable = ' . $map->getJavascriptVariable() . ';
                    var geocoder;
                    var marker;
                    function initialize() {
                        if (mapVariable.addMarker === true){
                            geocoder = new google.maps.Geocoder();
                            google.maps.event.addListener(mapVariable, "click", function(event) {
                                placeMarker(event.latLng);
                            });
                        }
                    }
                    function placeMarker(location) {
                        if (marker == null){
                            marker = new google.maps.Marker({
                                position: location,
                                map: mapVariable,
                                markerID: 0
                            });
                            google.maps.event.addListener(marker, "click", markerClickEventListener);
                            marker.info = new google.maps.InfoWindow({
                                content: "<br>"
                            });
                            geocodePosition(marker.getPosition());
                            google.maps.event.addListener(marker, "click", function() {
                                marker.info.open(mapVariable, marker);
                            });
                        }else{
                            marker.setPosition(location);
                            geocodePosition(marker.getPosition());
                        }
                    }

                    function geocodePosition(pos) {
                        geocoder.geocode({
                            latLng: pos
                        }, function(responses) {
                            if (responses && responses.length > 0) {
                                var address = responses[0].address_components[1].long_name + " " +
                                              responses[0].address_components[0].long_name + ", " +
                                              responses[0].address_components[2].long_name;
                                updateMarkerAddress(address);
                            } else {
                                updateMarkerAddress("Cannot determine address at this location.");
                            }
                        });
                    }

                    function updateMarkerAddress(str) {
                        var contentText = str + "<br>";
                        marker.markerAddress = str;
                        marker.info.setContent(contentText);
                        new google.maps.event.trigger( marker, "click");
                    }
                    initialize();' . PHP_EOL;
    }
Ejemplo n.º 3
0
 /**
  * Renders a polygon.
  *
  * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon.
  * @param \Ivory\GoogleMapl\Map             $map     The map.
  *
  * @return string Ths JS output.
  */
 public function render(Polygon $polygon, Map $map)
 {
     $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValue('[paths]', array());
     foreach ($polygon->getCoordinates() as $index => $coordinate) {
         $this->jsonBuilder->setValue(sprintf('[paths][%d]', $index), $coordinate->getJavascriptVariable(), false);
     }
     $this->jsonBuilder->setValues($polygon->getOptions());
     return sprintf('%s = new google.maps.Polygon(%s);' . PHP_EOL, $polygon->getJavascriptVariable(), $this->jsonBuilder->build());
 }
Ejemplo n.º 4
0
 /**
  * Renders a marker.
  *
  * @param Ivory\GoogleMap\Overlays\Marker $marker The marker.
  * @param Ivory\GoogleMap\Map             $map    The map.
  *
  * @return string The JS output.
  */
 public function render(Marker $marker, Map $map = null)
 {
     $this->jsonBuilder->reset()->setValue('[position]', $marker->getPosition()->getJavascriptVariable(), false);
     if ($map !== null) {
         $this->jsonBuilder->setValue('[map]', $map->getJavascriptVariable(), false);
     }
     if ($marker->hasAnimation()) {
         $this->jsonBuilder->setValue('[animation]', $this->animationHelper->render($marker->getAnimation()), false);
     }
     if ($marker->hasIcon()) {
         $this->jsonBuilder->setValue('[icon]', $marker->getIcon()->getJavascriptVariable(), false);
     }
     if ($marker->hasShadow()) {
         $this->jsonBuilder->setValue('[shadow]', $marker->getShadow()->getJavascriptVariable(), false);
     }
     if ($marker->hasShape()) {
         $this->jsonBuilder->setValue('[shape]', $marker->getShape()->getJavascriptVariable(), false);
     }
     $this->jsonBuilder->setValues($marker->getOptions());
     return sprintf('%s = new google.maps.Marker(%s);' . PHP_EOL, $marker->getJavascriptVariable(), $this->jsonBuilder->build());
 }
 /**
  * Renders an encoded polyline.
  *
  * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline.
  * @param \Ivory\GoogleMap\Map                      $map             The map.
  *
  * @return string The JS output.
  */
 public function render(EncodedPolyline $encodedPolyline, Map $map)
 {
     $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValue('[path]', $this->encodingHelper->renderDecodePath($encodedPolyline->getValue()), false)->setValues($encodedPolyline->getOptions());
     return sprintf('%s = new google.maps.Polyline(%s);' . PHP_EOL, $encodedPolyline->getJavascriptVariable(), $this->jsonBuilder->build());
 }
 /**
  * {@inheritdoc}
  */
 public function render(MarkerCluster $markerCluster, Map $map)
 {
     $this->jsonBuilder->reset()->setValues($markerCluster->getOptions());
     return sprintf('%s = new MarkerClusterer(%s, %s, %s);' . PHP_EOL, $markerCluster->getJavascriptVariable(), $map->getJavascriptVariable(), sprintf('%s.functions.to_array(%s.markers)', $this->getJsContainerName($map), $this->getJsContainerName($map)), $this->jsonBuilder->build());
 }
Ejemplo n.º 7
0
 /**
  * Renders the map bound.
  *
  * @param \Ivory\GoogleMap\Map $map The map.
  *
  * @return string The JS output.
  */
 public function renderMapBound(Map $map)
 {
     return sprintf('%s.fitBounds(%s);' . PHP_EOL, $map->getJavascriptVariable(), $map->getBound()->getJavascriptVariable());
 }
Ejemplo n.º 8
0
 /**
  * Gets the javascript container name according to the map.
  *
  * @param \Ivory\GoogleMap\Map $map The map.
  *
  * @return string The javascript container name.
  */
 protected function getJsContainerName(Map $map)
 {
     return $map->getJavascriptVariable() . '_container';
 }
Ejemplo n.º 9
0
 /**
  * Renders a rectangle.
  *
  * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle.
  * @param \Ivory\GoogleMap\Map                $map       The map.
  *
  * @return string The JS output.
  */
 public function render(Rectangle $rectangle, Map $map)
 {
     $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValue('[bounds]', $rectangle->getBound()->getJavascriptVariable(), false)->setValues($rectangle->getOptions());
     return sprintf('%s = new google.maps.Rectangle(%s);' . PHP_EOL, $rectangle->getJavascriptVariable(), $this->jsonBuilder->build());
 }
 /**
  * Renders a ground overlay.
  *
  * @param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay.
  * @param \Ivory\GoogleMap\Map                    $map           The map.
  *
  * @return string The JS output.
  */
 public function render(GroundOverlay $groundOverlay, Map $map)
 {
     $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValues($groundOverlay->getOptions());
     return sprintf('%s = new google.maps.GroundOverlay("%s", %s, %s);' . PHP_EOL, $groundOverlay->getJavascriptVariable(), $groundOverlay->getUrl(), $groundOverlay->getBound()->getJavascriptVariable(), $this->jsonBuilder->build());
 }
Ejemplo n.º 11
0
 /**
  * Renders a circle.
  *
  * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle.
  * @param \Ivory\GoogleMap\Map             $map    The map.
  *
  * @return string The JS output.
  */
 public function render(Circle $circle, Map $map)
 {
     $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValue('[center]', $circle->getCenter()->getJavascriptVariable(), false)->setValue('[radius]', $circle->getRadius())->setValues($circle->getOptions());
     return sprintf('%s = new google.maps.Circle(%s);' . PHP_EOL, $circle->getJavascriptVariable(), $this->jsonBuilder->build());
 }
Ejemplo n.º 12
0
 /**
  * Renders a kml layer.
  *
  * @param \Ivory\GoogleMap\Layers\KMLLayer $kmlLayer The KML layer.
  * @param \Ivory\GoogleMap\Map             $map      The map.
  *
  * @return string The JS output.
  */
 public function render(KMLLayer $kmlLayer, Map $map)
 {
     $this->jsonBuilder->reset()->setValue('[map]', $map->getJavascriptVariable(), false)->setValues($kmlLayer->getOptions());
     return sprintf('%s = new google.maps.KmlLayer("%s", %s);' . PHP_EOL, $kmlLayer->getJavascriptVariable(), $kmlLayer->getUrl(), $this->jsonBuilder->build());
 }