/** * Renders the js container extra. * * @param \Ivory\GoogleMap\Map $map The map. * * @return string The JS output. */ public function renderJsContainerExtra(Map $map) { $output = array(); foreach ($map->getInfoWindows() as $infoWindow) { if ($infoWindow->isOpen()) { $output[] = $this->infoWindowHelper->renderOpen($infoWindow, $map); } } foreach ($map->getMarkers() as $marker) { if ($marker->hasInfoWindow() && $marker->getInfoWindow()->isOpen()) { $output[] = $this->infoWindowHelper->renderOpen($marker->getInfoWindow(), $map, $marker); } } foreach ($this->computeBounds($map) as $bound) { if ($bound->hasExtends()) { $output[] = $this->boundHelper->renderExtends($bound); } } if ($map->isAutoZoom()) { $output[] = $this->renderMapBound($map); } else { $output[] = $this->renderMapCenter($map); } return implode('', $output); }
/** * Renders the autocomplete javascripts. * * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. * * @throws \Ivory\GoogleMap\Exception\HelperException if the autocomplete bound does not have coordinates. * * @return string The HTML output. */ public function renderJavascripts(Autocomplete $autocomplete) { $output = array(); if (!$this->apiHelper->isLoaded() && !$autocomplete->isAsync()) { $output[] = $this->apiHelper->render($autocomplete->getLanguage(), array('places')); } $output[] = '<script type="text/javascript">' . PHP_EOL; if ($autocomplete->isAsync()) { $output[] = 'function load_ivory_google_place () {' . PHP_EOL; } if ($autocomplete->hasBound()) { if (!$autocomplete->getBound()->hasCoordinates()) { throw HelperException::invalidAutocompleteBound(); } $output[] = $this->coordinateHelper->render($autocomplete->getBound()->getSouthWest()); $output[] = $this->coordinateHelper->render($autocomplete->getBound()->getNorthEast()); $output[] = $this->boundHelper->render($autocomplete->getBound()); } $output[] = $this->renderAutocomplete($autocomplete); if ($autocomplete->isAsync()) { $output[] = '}' . PHP_EOL; } $output[] = '</script>' . PHP_EOL; if (!$this->apiHelper->isLoaded() && $autocomplete->isAsync()) { $output[] = $this->apiHelper->render($autocomplete->getLanguage(), array('places'), 'load_ivory_google_place'); } return implode('', $output); }
public function testRenderExtends() { $bound = new Bound(); $bound->setJavascriptVariable('bound'); $circle = $this->getMock('Ivory\\GoogleMap\\Overlays\\Circle'); $circle->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('circle')); $groundOverlayBound = $this->getMock('Ivory\\GoogleMap\\Base\\Bound'); $groundOverlayBound->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('groundOverlayBound')); $groundOverlay = $this->getMock('Ivory\\GoogleMap\\Overlays\\GroundOverlay'); $groundOverlay->expects($this->once())->method('getBound')->will($this->returnValue($groundOverlayBound)); $infoWindow = $this->getMock('Ivory\\GoogleMap\\Overlays\\InfoWindow'); $infoWindow->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('infoWindow')); $marker = $this->getMock('Ivory\\GoogleMap\\Overlays\\Marker'); $marker->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('marker')); $polygon = $this->getMock('Ivory\\GoogleMap\\Overlays\\Polygon'); $polygon->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('polygon')); $polyline = $this->getMock('Ivory\\GoogleMap\\Overlays\\Polyline'); $polyline->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('polyline')); $rectangleBound = $this->getMock('Ivory\\GoogleMap\\Base\\Bound'); $rectangleBound->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('rectangleBound')); $rectangle = $this->getMock('Ivory\\GoogleMap\\Overlays\\Rectangle'); $rectangle->expects($this->once())->method('getBound')->will($this->returnValue($rectangleBound)); $bound->extend($circle); $bound->extend($groundOverlay); $bound->extend($infoWindow); $bound->extend($marker); $bound->extend($polygon); $bound->extend($polyline); $bound->extend($rectangle); $expected = <<<EOF bound.union(circle.getBounds()); bound.union(groundOverlayBound); bound.extend(infoWindow.getPosition()); bound.extend(marker.getPosition()); polygon.getPath().forEach(function(element){bound.extend(element)}); polyline.getPath().forEach(function(element){bound.extend(element)}); bound.union(rectangleBound); EOF; $this->assertSame($expected, $this->boundHelper->renderExtends($bound)); }