我目前正在使用 angular-google-maps 并构建了一个工作地图,显示来自后端的一些标记。我想做的是向地图添加自定义缩放控件。因此我这样做了。但它没有按预期工作。如果有人以前做过或知道如何做,那么您能帮帮我吗?
这是我的指令视图:
%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 已经在进行中并且更改的地图对象没有反映在范围中。:(