/**
  * {@inheritdoc}
  */
 public function renderLibraries(Map $map)
 {
     if ($this->apiHelper->isLoaded()) {
         return;
     }
     $callback = null;
     if ($map->isAsync()) {
         $callback = 'load_ivory_google_map';
     }
     $output = array();
     $output[] = $this->apiHelper->render($map->getLanguage(), $this->getLibraries($map), $callback, $map->getApiKey());
     $output[] = $this->markerClusterHelper->renderLibraries($map->getMarkerCluster(), $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);
 }
Ejemplo n.º 3
0
    public function testRenderWithKey()
    {
        $expected = <<<EOF
<script type="text/javascript">
function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&key=ABQIAAAApsu_yVyPoWjn3yp6vDxlSg"}); };
</script>
<script type="text/javascript" src="//www.google.com/jsapi?callback=load_ivory_google_map_api"></script>

EOF;
        $this->assertSame($expected, $this->apiHelper->render('en', array(), null, 'ABQIAAAApsu_yVyPoWjn3yp6vDxlSg'));
    }
Ejemplo n.º 4
0
    public function testRenderWithSensor()
    {
        $expected = <<<EOF
<script type="text/javascript">
function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=true"}); };
</script>
<script type="text/javascript" src="//www.google.com/jsapi?callback=load_ivory_google_map_api"></script>

EOF;
        $this->assertSame($expected, $this->apiHelper->render('en', array(), null, true));
    }