leaflet-draw delete button remove quot;clear allquot; action(传单绘制删除按钮删除“全部清除行动)
问题描述
如何从 leaflet-draw 编辑工具栏?
How can I remove the "clear all" action from the delete button in the leaflet-draw edit toolbar?
我知道您可以删除整个 删除 按钮,但仍需要删除单个项目.基本上是在寻找一种方法来防止用户从地图中删除每个项目.
I know you can remove the whole delete button but still need to remove individual items. Basically looking for a way to prevent the user from deleting every item from the map.
推荐答案
编辑工具栏测试按钮处理程序上是否存在 removeAllLayers
成员.因此,禁用清除所有操作的一种简单但可能很笨拙的方法是在 L.EditToolbar.Delete
模块上使用 removeAllLayers
:
The edit toolbar tests the existence of a removeAllLayers
member on the button handler. So, a simple but probably heavy handed way to disable the clear all action is to nuke removeAllLayers
on the L.EditToolbar.Delete
module:
L.EditToolbar.Delete.include({
removeAllLayers: false
});
new L.Control.Draw({
edit: {
featureGroup: drawnItems
},
draw: {
}
}).addTo(map);
还有一个演示
var map = L.map(document.getElementById('map'), {zoomControl: false}).setView([48.8583736, 2.2922926], 15);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var drawnItems = new L.geoJson().addTo(map);
map.on(L.Draw.Event.CREATED, function (event) {
var layer = event.layer;
drawnItems.addLayer(layer);
});
L.EditToolbar.Delete.include({
removeAllLayers: false
});
new L.Control.Draw({
edit: {
featureGroup: drawnItems
},
draw: {
polygon: false,
rectangle: false,
circlemarker: false
}
}).addTo(map);
html, body {
height: 100%;
margin: 0;
}
#map {
width: 100%;
height: 100%;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css" integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js" integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log==" crossorigin=""></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.12/leaflet.draw.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.12/leaflet.draw.js"></script>
<div id='map'></div>
这篇关于传单绘制删除按钮删除“全部清除"行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:传单绘制删除按钮删除“全部清除"行动
基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01