我有一个圆,当你点击一个特定的点(圆的质心将是该点所在的位置)时,我会添加到Map中,你可以编辑圆,这意味着你可以使用圆末端的夹爪调整它的大小:
调整大小工作正常,但我想做的是防止圆圈被拖动:
如何禁用拖动圆圈但仍保持调整大小?我正在使用leaflet-draw library和@types/leaflet-draw包。下面是我如何将圆添加到Map中:
onMapClick(leafletMouseEvent: LeafletMouseEvent) {
const drawControl = new L.Control.Draw({
draw: {
circle: true, // Enable circle drawing
},
edit: {
featureGroup: new L.FeatureGroup()
}
});
map.addControl(drawControl);
// Initialize the feature group for drawn items
drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
map.on(L.Draw.Event.CREATED, (e: any) => {
let layer = e.layer;
drawnItems.addLayer(layer); // Add shape to current drawing
});
map.on(L.Draw.Event.EDITED, (e: any) => {
let layers = e.layers;
layers.eachLayer((layer: any) => {
drawnItems.addLayer(layer);
});
});
const circle: any = new L.Circle(latLng, {
radius: 1609.34, // 1 mile in meters
});
drawnItems.addLayer(circle);
circle.editing.enable()
}
1条答案
按热度按时间j8ag8udp1#
我只找到了a hack来防止圆移动,也许你可以在上面扩展: