php - 使用 VichGeographicalBundle 在 Symfony2 中单击时不显示 Google map 信息窗口

标签 php symfony google-maps-api-3 google-maps-markers symfony-2.1

我已经成功设置VichGeographicalBundle在谷歌地图中显示一堆地方。一切正常,除了点击时不显示的信息窗口。

$this->setShowInfoWindowsForMarkers(true); 已设置但似乎不起作用。

有什么想法吗?

编辑:

class allShopsMap extends Map
{
    /**
     * Constructs a new instance of LocationMap.
     */
    public function __construct(EntityManager $em)
    {
        parent::__construct();

        // configure your map in the constructor 
        // by setting the options

        $this->setShowZoomControl(true);
        $this->setZoom(13);
        $this->setAutoZoom(false);
        $this->setContainerId('map_canvas');
        $this->setWidth(980);
        $this->setHeight(360);
        $this->setShowInfoWindowsForMarkers(true);
        $this->setCenter(23.232323,23.232323);
        $this->setShowMapTypeControl(true);

        $query = $em->createQuery("SELECT st
                       FROM acme\ShopBundle\Entity\Shop sh 
                       WHERE sh.published = 1 ");
        $shops = $query->getResult();

        foreach ($shops as $shop) {
            $this->addMarker(new MapMarker($shop->getLatitude(), $shop->getLongitude(),$icon='images/map_marker.png'));
        }
    }
}

从 Twig 模板调用:

{{ vichgeo_map('allShops') }}

配置.yml

vich_geographical:
    db_driver: orm 
    query_service: vich_geographical.query_service.default
    map_renderer: vich_geographical.map_renderer.google
    templating:
        engine: twig
        info_window: msgrShopBundle:Map:infoWindow.html.twig

services:
    msgr.map.allShops:
        class: msgr\ShopBundle\Map\allShopsMap  
        tags:
           -  { name: vichgeo.map, alias: allShops }
        arguments: 
            entityManager: "@doctrine.orm.entity_manager" 

{{ vichgeo_map('allShops') }} 生成的 HTML 代码:http://pastebin.com/jqvzG67N

最佳答案

试试这个:

class allShopsMap extends Map
{
    /**
     * Constructs a new instance of LocationMap.
     */
    public function __construct(EntityManager $em, $infoWindowBuilder)
    {
        parent::__construct();

        // configure your map in the constructor 
        // by setting the options

        $this->setShowZoomControl(true);
        $this->setZoom(13);
        $this->setAutoZoom(false);
        $this->setContainerId('map_canvas');
        $this->setWidth(980);
        $this->setHeight(360);
        $this->setShowInfoWindowsForMarkers(true);
        $this->setCenter(23.232323,23.232323);
        $this->setShowMapTypeControl(true);

        $query = $em->createQuery("SELECT st
                       FROM acme\ShopBundle\Entity\Shop sh 
                       WHERE sh.published = 1 ");
        $shops = $query->getResult();

        foreach ($shops as $shop) {
            $marker = new MapMarker($shop->getLatitude(), $shop->getLongitude(),$icon='images/map_marker.png');
            $marker->setInfoWindow($infoWindowBuilder->build($marker)); 
            $this->addMarker($marker);
        }
    }
}

infoWindowBuilder 是容器中可用的 vich_geographical.info_window_builder 服务。

并修改你的配置:

services:
    msgr.map.allShops:
        class: msgr\ShopBundle\Map\allShopsMap  
        tags:
           -  { name: vichgeo.map, alias: allShops }
        arguments: 
            entityManager: "@doctrine.orm.entity_manager" 
            infoWindowBuilder: "@vich_geographical.info_window_builder"

关于php - 使用 VichGeographicalBundle 在 Symfony2 中单击时不显示 Google map 信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14044290/

相关文章:

包含的 PHP + MySQL 登录

symfony - 如何在 Symfony2 Twig 模板中获取配置参数

javascript - 防止标记在 MarkerClusterer 中聚类

android - 添加 ML Kit 后无法解析 : com. google.android.gms :play-services:15. 0.1

JavaScript/Angular - 尝试使用本地 JSON 文件设置 Google map 样式时出现问题

php - 我正在尝试用 PHP 为服务器/InFrame 支付编写自己的类

php - 带有 id 的 mysql && php 问题

symfony - 在没有 for 循环的情况下计算 Twig

java - Oracle/Mysql编辑记录量大,有推荐吗?

php - Symfony 3 应用程序的 Google Play Market 身份验证