1

在 HTML 中,我的地图被定义为

<leaflet bounds="map.spatial_bounds_card" layers="map.layers_card" height="200px" ></leaflet>

在控制器中,我扩展了角度范围,以定义边界和层。我不知道如何访问传单地图,以便向其中添加 OverlayItems。目前我已经创建了一个矩形,但它没有显示在地图上。

function Ctrl($scope, leafletBoundsHelpers, leafletDrawEvents) {
    var drawnItems2 = new L.FeatureGroup();
    angular.extend($scope, {
        map: {
            spatial_bounds_card: {},
            layers_card: {
                baselayers: {
                    osm: {
                        name: 'OpenStreetMap',
                        url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
                        type: 'xyz'
                    }
                }
            },
            drawOptions: {
                position: "bottomright",
                draw: {
                    polyline: false,
                    polygon: false,
                    circle: false,
                    rectangle: {
                        metric: false,
                        showArea: true,
                        shapeOptions: {
                            color: 'blue'
                        }
                    },
                    marker: false
                },
                edit: {
                    featureGroup: drawnItems2,
                    remove: false
                }
            },
            defaults: {
                scrollWheelZoom: false
            }
        }
    });
    var bb = L.latLngBounds($scope.filters.spatial.params.southwest, $scope.filters.spatial.params.northeast);
    console.log(bb);
    var selectedBoundingBox = new L.rectangle(bb,
            {
                color: 'blue'
            });
    selectedBoundingBox.addTo($scope.map); // <-- error here
}

运行代码时确实出现此错误:

angular.js:13920 TypeError: t.addLayer is not a function
    at e.addTo (leaflet.js:7)
    at new FilterSpatialCardCtrl (filter_spatial_card.controller.js:50)
    at Object.invoke (angular.js:4718)
    at $controllerInit (angular.js:10354)
    at nodeLinkFn (angular.js:9263)
    at angular.js:9673
    at processQueue (angular.js:16383)
    at angular.js:16399
    at Scope.$eval (angular.js:17682)
    at Scope.$digest (angular.js:17495)
4

1 回答 1

1

在您的代码中,还有额外的参数。让它尽可能简单。

喜欢:

angular.extend($scope, {
    center: {
            lat: 54.559322,
            lng: -5.767822,
            zoom: 14
    },
        defaults: {
            maxZoom: 25,
            minZoom: 1,
            path: {
                weight: 10,
                color: '#800000',
                opacity: 1
            }
        }
});

    var markersFeatureGroup = new L.FeatureGroup();
leafletData.getMap()
.then(function(map) {
    var latlang = L.latLng(50.5, 30.5);
    var circleobj = L.rectangle([[54.559322, -5.767822], [54.560900, -5.760000]],{
    color: 'blue'
        }).bindLabel("Hello World", { direction: 'bottom', clickable: "interactive" });//use left, left, auto, 
  markersFeatureGroup.addLayer(circleobj);
  map.addLayer(markersFeatureGroup);
});

有关更多信息,请参阅 Jsfiddle:http: //jsfiddle.net/nidhiarya1245/5hukx0g5/

于 2016-10-20T12:10:31.610 回答