【问题标题】:Hiding all info windows on click with angular-google-maps使用 angular-google-maps 隐藏所有点击信息窗口
【发布时间】:2014-11-25 14:01:18
【问题描述】:

我正在使用此处定义的 angular google maps api: https://angular-ui.github.io/angular-google-maps/#!/api

我有以下 DOM 结构

<ui-gmap-markers models="destinationMarkers" coords="'self'" idKey='self.idkey' >
    <div ui-gmap-windows models="destinationMarkers" control="infoWindows">
        <div ng-non-bindable>
            <!-- {{contents}} -->
        </div>
    </div>
</ui-gmap-markers>

我正在尝试使信息窗口在单击地图的任何其他部分或打开另一个窗口时关闭。我得到的最接近的是调用:scope.infoWindows.getChildWindows(),它可以访问标记对象,但是调用相关的 hideWindow 函数似乎什么都不做。有人知道怎么做吗?

【问题讨论】:

  • 请发布您目前所拥有的工作演示(最好在plnkr.co
  • 您可以在底部的“Windows”菜单项下的angular-ui.github.io/angular-google-maps/#!/api 看到一个。所有其他代码都运行良好 - 我只是不知道如何访问和删除这些信息窗口。

标签: javascript angularjs google-maps google-maps-api-3 angular-google-maps


【解决方案1】:

我刚刚遇到了完全相同的问题,经过一番折腾后,我有了一个解决方案(对不起,如果我玩游戏有点晚了)

您必须像这样在窗口上设置控制器属性...

<ui-gmap-window ng-if="m.response" control="googlemap" >

“googlemap”控件必须是 Scope 的成员,并且“控件”必须定义为地图对象上的空对象,如下所示...

$scope.googlemap = {};

$scope.map = {
    zoom: 5,
    center: getMapCenter(response),
    options: {
        // draggable: false
    },
    control: {}
};

现在我们可以将一个事件附加到标记上,这将使我们能够遍历窗口列表并像这样隐藏它们......

markers.push({
    id: i,
    ...
    ...
    events: {
        click: function(e){
            var windows = $scope.googlemap.getChildWindows();

            for (var i = 0; i < windows.length; i++){
                windows[i].hideWindow()
            }
        }
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-14
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 2013-01-09
    • 2011-08-08
    • 2011-11-20
    • 2012-06-03
    相关资源
    最近更新 更多