如何将自定义缩放控件添加到使用角度谷歌地图构建的地图中



我目前正在使用角度谷歌地图,并构建了一个工作地图,显示了后端的一些标记。我希望做的是将自定义缩放控件添加到地图。因此,我这样做了。但它没有按预期工作。如果有人以前做过它或知道如何做,那么你能帮我吗?

这是我的指令观点:

 %ui-gmap-google-map(center='map.center' pan='map.pan' options='map.options' draggable='true' zoom='map.zoom')
  %ui-gmap-marker(ng-repeat='marker in map.markers' idKey="marker.id" coords='marker.coords' location='marker.location' icon="marker.icon" click="marker.click")
     %ui-gmap-window(show="marker.showWindow" isIconVisibleOnClick="marker.isIconVisibleOnClick" options="map.infoWindowCustomClass.options")
        .tooltip-container
          %p.paragraph-one {{marker.appName}}
          %ul
            %li {{marker.city}}, {{marker.country}}
            %li Users: {{marker.userName}}
.mapzoomControls
   %i.fa.fa-minus-square.zoom-icons(ng-click='increaseMapZoom()')
   %i.fa.fa-plus-square.zoom-icons(ng-click='decreaseMapZoom()')

这是我的指示:

'use strict'
 angular.module('protoV3App')
 .directive('dashboardMap',[ 'mapSettings',(mapSettings) ->
  templateUrl: 'views/dashboardmap.html'
  restrict: 'E'
  link: (scope, element, attrs) ->
    scope.increaseMapZoom = ()->
        mapSettings.increaseMapZoom()
        scope.$apply()
    scope.decreaseMapZoom = ()->
        mapSettings.decreaseMapZoom()
        scope.$apply()

   ])

服务中的相应功能:

increaseMapZoom: ()-> 
    currentMap.zoom =currentMap.zoom+1;
    currentMap;
decreaseMapZoom: ()-> 
    currentMap.zoom =currentMap.zoom-1;
    currentMap;

所以我得到的错误是应用已经在进行中,并且更改的地图对象没有反映在范围内。 :(

之所以

收到此错误,是因为您在现有的消化周期内调用$apply。

要解决此问题,请在代码中添加以下行:

if ($scope.$root.$$phase != '$apply' && $scope.$root.$$phase != '$digest') {
    $scope.$apply();
}

最新更新