0

当我使用带有 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 错误参数

论据mainMapController不是。

你能给我一些帮助吗?

谢谢

4

1 回答 1

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>

欲了解更多信息:https ://tombatossals.github.io/angular-leaflet-directive/examples/0000-viewer.html#/controls/draw-example

于 2015-05-25T01:15:42.010 回答