javascript - 使用angularjs过滤谷歌地图标记

标签 javascript google-maps angularjs

我正在使用 angular-google-maps directive当我尝试删除绑定(bind)到 Controller 的标记时遇到问题。我尝试过各种版本的 Angular,并尝试过 angular-google-maps 的 master 和 r1-dev 分支。

我不知道为什么,但它似乎陷入了 $digest 函数,而当我过滤掉列表项时,这不会发生。抛出的异常是这样的:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

可以在这里看到一个演示,我的代码从 JavaScript 的第 550 行开始。上面几行是 angular-google-maps 指令。

http://jsfiddle.net/ADukg/4127/

最佳答案

这对我有用,这是通过阅读 angular-google-maps 模块问题队列中的其他一些相关错误得到的。

重点是您需要在 watch 内创建一个变量并使用它传递给模型参数。

基础 JS:

controller('MainCtrl', function ($scope, $filter) {

   $scope.$watch("breweryFilter", function(breweryFilter){
      $scope.filteredMarkers = $filter("filter")($scope.breweries, breweryFilter);
      if (!$scope.filteredMarkers){
        return;
      }
   });
});

过滤输入:

<input name="brewery-filter" class="form-control" type="search" ng-model="breweryFilter" placeholder="filter locations" />

包含标记指令的 map 指令:

   <google-map
        center="map.center"
        zoom="map.zoom"
        draggable="true"
        control="map.control">

      <window
          show="breweryInfoWindow.showWindow"
          coords="breweryInfoWindow.coords"
          isIconVisibleOnClick="true"
          options="breweryInfoWindow.options"
          templateUrl="breweryInfoWindow.templateUrl"
          templateParameter="breweryInfoWindow.templateParams"
          data-ng-cloak>
        _
      </window>

      <markers
          models="filteredMarkers"
          idKey="'nid'"
          coords="'self'"
          icon="'icon'"
          doRebuildAll="true"
          fit='true'
          doCluster='true'
          control="map.markersControl"
          click="'onMarkerClicked'">
      </markers>

    </google-map>

希望对您有所帮助。

关于javascript - 使用angularjs过滤谷歌地图标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19412035/

相关文章:

javascript - 如何在 Angularjs $state.go 中发送参数?

javascript - 如何使用 AngularJs ui-router 添加可选的 $stateParams?

javascript - 在 ChartJS 散点图中显示图像而不是点

javascript - 谷歌地图 - 获取拖动标记的坐标

c# - 在移动设备中实现 Google map

android - 管理 MapView 的缓存

javascript - 在 Angular 服务中使用 Underscore 和 Google map 时出现 JsHint 错误

javascript - jQuery 是如何实现异步功能的?

javascript - Angular2 父子组件

javascript - Enyo MVC实现和粒 subview 渲染