Javascript 如何向使用角度谷歌地图构建的地图添加自定义缩放控件
我目前正在使用angular google maps,并且已经构建了一个工作地图,显示了后端的一些标记。我想做的是向地图添加自定义缩放控件。所以我就这样做了。但它并没有像预期的那样发挥作用。如果以前有人做过或者知道怎么做,你能帮我吗 这是我的指导意见:Javascript 如何向使用角度谷歌地图构建的地图添加自定义缩放控件,javascript,angularjs,google-maps,angular-google-maps,Javascript,Angularjs,Google Maps,Angular Google Maps,我目前正在使用angular google maps,并且已经构建了一个工作地图,显示了后端的一些标记。我想做的是向地图添加自定义缩放控件。所以我就这样做了。但它并没有像预期的那样发挥作用。如果以前有人做过或者知道怎么做,你能帮我吗 这是我的指导意见: %ui-gmap-google-map(center='map.center' pan='map.pan' options='map.options' draggable='true' zoom='map.zoom') %ui-gmap-m
%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();
}