【问题标题】:How to change Google Maps marker's visibility dynamically如何动态更改谷歌地图标记的可见性
【发布时间】:2015-09-01 15:27:06
【问题描述】:

我在我的 Angular 项目中使用 this directive 用于 Google 地图。

<map center="50.4501, 30.5234" zoom="11" style="height: 100%" data-tap-disabled="true">
    <marker ng-repeat="item in items | limitTo: 50" icon="img/marker.png" position="{{item.coords}}" eventid={{item.id}} on-click="go()">
    </marker>
</map>

我需要使用返回 true / false 的函数更改标记的可见性。

我试图通过设置标记的属性 visible="isVisible()" 来使用 ng-if="isVisible()", ng-show="isVisible()" - 没有任何效果。

有什么想法吗?非常感谢。

【问题讨论】:

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


    【解决方案1】:

    利用专门为调用各种 UI 相关 API 而设计的 angularjs-google-maps 库。

    嵌入此库后,您可以像使用 Google 地图时一样调用所有 API。例如,要控制特定标记的可见性,请使用以下代码:

    <map center="[40.74, -74.18]">
      <marker
          position="[40.76, -74.16]"
          title="Hello Marker"
          animation="Animation.BOUNCE"
          draggable="true"
          visible="true"
          icon="beachflag.png"></marker>
    </map>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-20
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      • 2023-04-04
      • 1970-01-01
      相关资源
      最近更新 更多