【问题标题】:Error with angular and leaflet libraries角度和传单库错误
【发布时间】:2015-05-29 16:55:04
【问题描述】:

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

你能给我一些帮助吗?

谢谢

【问题讨论】:

    标签: javascript angularjs leaflet angular-leaflet-directive


    【解决方案1】:

    我猜你必须在你的控制器中包含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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多