Ejemplo n.º 1
0
 public function testRenderWithBound()
 {
     $coordinate1 = new Coordinate(-1.1, -2.1, false);
     $coordinate1->setJavascriptVariable('foo');
     $coordinate2 = new Coordinate(1.1, 2.1, true);
     $coordinate2->setJavascriptVariable('bar');
     $bound = new Bound($coordinate1, $coordinate2);
     $bound->setJavascriptVariable('baz');
     $this->assertSame('baz = new google.maps.LatLngBounds(foo, bar);' . PHP_EOL, $this->boundHelper->render($bound));
 }
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * Renders the javascript container bounds.
  *
  * @param \Ivory\GoogleMap\Map $map The map.
  *
  * @return string The JS output.
  */
 public function renderJsContainerBounds(Map $map)
 {
     $output = array();
     foreach ($this->computeBounds($map) as $bound) {
         $output[] = sprintf('%s.bounds.%s = %s', $this->getJsContainerName($map), $bound->getJavascriptVariable(), $this->boundHelper->render($bound));
     }
     return implode('', $output);
 }