角度和传单库出错

时间:2015-03-25 20:06:47

标签: javascript angularjs leaflet angular-leaflet-directive

当我使用带有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不是。

你能给我一些帮助吗?

由于

1 个答案:

答案 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>

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