I’m building a project that makes use of clickable markers and shapes on a floor plan.
<leaflet layers="layers" markers="markers" ></leaflet>
The markers are going well and seem pretty straightforward…
$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];
});
But the layers don’t seem to work anything like this. I haven’t had any luck with code that adds layers to $scope.layers (a la typical Angular code). The only thing that works is this un-Angular mess…
$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]
},
}));
});
});
Is there a better/smarter way to add drawn items to a map? And how can I bind click events to layers? Or are shapes in Leaflet just dumb, non-interactive decorations?