开发者

IvoryGoogleMap - can't display infoWindow

开发者 https://www.devze.com 2023-04-02 08:18 出处:网络
i\'m trying to use IvoryGoogleMap to display a simple map with markers and infoWindows using this code:

i'm trying to use IvoryGoogleMap to display a simple map with markers and infoWindows using this code:

$marker     ->setPosition($place->getLat(), $place->getLng());
$infoWindow ->setContent('<p>Default content</p>');
$marker     ->setInfoWindow($infoWindow);
$map        ->addMarker($marker);开发者_如何学Python

and all i'm getting is a map with marker(s) but when i click on one of them, nothing happens. Have you any idea what am i doing wrong ?


Ok, problem solved. Here is the solution from bundle's author egeloen (on github):

======================================================================

This functionality doesn't exist natively. If you want to open an info window with a click event on a marker, you need to use the ivory_google_map.event service. This service allow you to generate all events you want.

In your case, the event is :

$clickEvent = $this->get('ivory_google_map.event');
$clickEvent->setInstance($marker->getJavascriptVariable());
$clickEvent->setEventName('click');
$clickEvent->setHandle(sprintf('function(){%s.open(%s, %s);}',
    $infoWindow->getJavascriptVariable(),
    $map->getJavascriptVariable(),
    $marker->getJavascriptVariable()
);

$map->getEventManager()->addEvent($clickEvent);
0

精彩评论

暂无评论...
验证码 换一张
取 消