0
我正在構建一個項目,利用可點擊的標記和形狀在平面圖上。Angular-Leaflet-Directive圖層
<leaflet layers="layers" markers="markers" ></leaflet>
的標誌進展順利,似乎很簡單...
$scope.markers = {};
lodash.each(data.markers, function(marker, i) {
$scope.markers[marker.name] = {
lat : device.map_location[0],
lng : device.map_location[1],
};
});
$scope.$on('leafletDirectiveMarker.click', function (e, args) {
$scope.selected_marker = $scope.markers[args.modelName];
});
但層似乎並不管用這樣的事。我沒有將代碼添加到$ scope.layers(一個典型的Angular代碼)中。唯一可行的是這種無角度的混亂...
$scope.layers = {
overlays: {
spaces: {
name: 'Spaces',
type: 'group',
},
}
};
leafletData.getLayers().then(function(layers) {
lodash.each(data.spaces, function(space, i) {
layers.overlays.spaces.addLayer(L.geoJson({
type: 'Feature',
geometry: {
type: "Polygon",
coordinates: [space.map_area]
},
}));
});
});
有更好/更聰明的方式添加繪製的項目到地圖嗎?如何將點擊事件綁定到圖層?或者是宣傳單中的形狀只是啞巴,非互動的裝飾品?