vue2-leaflet-draw
vue2-leaflet-draw copied to clipboard
Support options for disabling shape types and editing
Hi, thanks for this plugin, it is really useful.
I'd like to enable only rectangle shapes and disable other shape types. How is it possible ?
You could use the native leaflet draw ( npm i leaflet-draw -S
). You could use the vue2-leaflet wrapper and just use the leaflet-draw. Maybe someone with more knowledge could integrate the native way to handle the draw-options into this plugin.
<l-map id="map" ref="map">
<l-tile-layer :url=url></l-tile-layer>
</l-map>
.
.
.
import LDraw from 'leaflet-draw';
mounted() {
this.$nextTick(() => {
const map = this.$refs.map.mapObject;
const drawControl = new window.L.Control.Draw({
position: 'topright',
draw: {
polyline: {
allowIntersection: false,
showArea: true
},
polygon: false, // disable or enable with true/false
rectangle: false,
circle: false,
marker: false
}
});
map.addControl(drawControl);
const editableLayers = new window.L.FeatureGroup().addTo(map);
map.on(window.L.Draw.Event.CREATED, (e) => {
// const type = e.layerType;
const layer = e.layer;
// Do whatever else you need to. (save to db, add to map etc)
editableLayers.addLayer(layer);
});
});