コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 public function testRenderOpenWithMarker()
 {
     $map = $this->getMock('Ivory\\GoogleMap\\Map');
     $map->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('map'));
     $infoWindow = new InfoWindow();
     $infoWindow->setJavascriptVariable('infoWindow');
     $infoWindow->setPosition(1.1, 2.1, true);
     $infoWindow->setContent('content');
     $infoWindow->setOpen(true);
     $infoWindow->setOptions(array('option1' => 'value1', 'option2' => 'value2'));
     $marker = $this->getMock('Ivory\\GoogleMap\\Overlays\\Marker');
     $marker->expects($this->once())->method('getJavascriptVariable')->will($this->returnValue('marker'));
     $this->assertSame('infoWindow.open(map, marker);' . PHP_EOL, $this->infoWindowHelper->renderOpen($infoWindow, $map, $marker));
 }
コード例 #3
0
    /**
     * Registers the info window event (auto open).
     *
     * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker.
     * @param \Ivory\GoogleMap\Map             $map    The map.
     */
    protected function registerInfoWindowEvent(Marker $marker, Map $map)
    {
        $closableInfoWindows = sprintf('%s.closable_info_windows', $this->getJsContainerName($map));
        $handle = <<<EOF
function () {
    for (var info_window in {$closableInfoWindows}) {
        {$closableInfoWindows}[info_window].close();
    }
    {$this->infoWindowHelper->renderOpen($marker->getInfoWindow(), $map, $marker)}
}
EOF;
        $event = new Event();
        $event->setJavascriptVariable(sprintf('%s_%s', $marker->getJavascriptVariable(), 'info_window_event'));
        $event->setInstance($marker->getJavascriptVariable());
        $event->setEventName($marker->getInfoWindow()->getOpenEvent());
        $event->setHandle($handle);
        $map->getEventManager()->addEvent($event);
    }