当我使用带有angular-leaflet-directive的传单映射并尝试添加绘制控件时,这会导致错误。
控制器:
SomeApp.controller("mainMapController", function ($scope){
angular.extend($scope, {
defaults: {
tileLayer: "http://{s}.tile.osm.org/{z}/{x}/{y}.png"
},
controls: {
draw: {}
}
})
leafletData.getMap().then(function(map) {
var drawnItems = $scope.controls.edit.featureGroup;
})
});
HTML代码:
<div ng-controller="mainMapController">
<leaflet></leaflet>
</div>
Angular会出现此错误:
错误:ng:areq Bad Argument
参数mainMapController
不是。
你能给我一些帮助吗?
由于
答案 0 :(得分:0)
我猜您必须在控制器中包含leafletData,如下所示:
您的MainMapController.js:
SomeApp.controller("mainMapController", ['$scope', 'leafletData', function ($scope, leafletData){
angular.extend($scope, {
defaults: {
tileLayer: "http://{s}.tile.osm.org/{z}/{x}/{y}.png"
},
controls: {
draw: {}
}
})
leafletData.getMap().then(function(map) {
var drawnItems = $scope.controls.edit.featureGroup;
})
map.on('draw:created', function (e) {
var layer = e.layer;
drawnItems.addLayer(layer);
console.log(JSON.stringify(layer.toGeoJSON()));
});
}]);
HTML:
<div ng-controller="mainMapController">
<leaflet defaults="defaults" controls="controls" width="100%" height="480px"></leaflet>
</div>