/** * 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); }
/** * Renders the javascript container coordinates. * * @param \Ivory\GoogleMap\Map $map The map. * * @return string The JS output. */ public function renderJsContainerCoordinates(Map $map) { $output = array(); foreach ($this->computeCoordinates($map) as $coordinate) { $output[] = sprintf('%s.coordinates.%s = %s', $this->getJsContainerName($map), $coordinate->getJavascriptVariable(), $this->coordinateHelper->render($coordinate)); } return implode('', $output); }
public function testRender() { $coordinate = new Coordinate(1.1, 2.1, true); $coordinate->setJavascriptVariable('foo'); $this->assertSame('foo = new google.maps.LatLng(1.1, 2.1, true);' . PHP_EOL, $this->coordinateHelper->render($coordinate)); }