javascript - Leaflet.draw映射: How to initiate the draw function without toolbar?

标签 javascript leaflet gis leaflet.draw

对于任何有 leaflet 或 leaflet.draw 插件经验的人:

我想在不使用 leaflet.draw 中的工具栏的情况下开始绘制多边形。通过在线搜索(它不在主文档中),我设法找到了允许不使用工具栏 (layer.editing.enable();) 进行编辑的属性。我似乎无法找到如何在没有工具栏按钮的情况下开始绘制多边形。任何帮助将不胜感激!

谢谢你:)

最佳答案

这个简单的代码对我有用:

new L.Draw.Polyline(map, drawControl.options.polyline).enable();

只需将它放入自定义按钮的 onclick 处理程序中(或任何您想要的地方)。

变量 mapdrawControl 是对传单 map 和绘图控件的引用。

深入研究源代码 (leaflet.draw-src.js),您可以找到绘制其他元素以及编辑或删除它们的函数。

new L.Draw.Polygon(map, drawControl.options.polygon).enable()
new L.Draw.Rectangle(map, drawControl.options.rectangle).enable()
new L.Draw.Circle(map, drawControl.options.circle).enable()
new L.Draw.Marker(map, drawControl.options.marker).enable()

new L.EditToolbar.Edit(map, {
                featureGroup: drawControl.options.featureGroup,
                selectedPathOptions: drawControl.options.edit.selectedPathOptions
            })
new L.EditToolbar.Delete(map, {
                featureGroup: drawControl.options.featureGroup
            })

我希望这对你也有用。

编辑: L.EditToolbar.EditL.EditToolbar.Delete 类公开了以下有用的方法:

  • enable(): 启动编辑/删除模式
  • disable(): 返回标准模式
  • save():保存更改(它触发 draw:edited/draw:deleted 事件)
  • revertLayers():撤消更改

关于javascript - Leaflet.draw映射: How to initiate the draw function without toolbar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15775103/

相关文章:

javascript - Angular传单指令问题: other parts besides the map does't show the second time entering the page

javascript - 单击(右键单击)使用传单 map 库获取图像叠加层的像素坐标

javascript - 如何在 AngularJS 中处理来自 REST Api 的日期字段?

javascript - PHPStorm 在编辑 Javascript 时异常缓慢

javascript - 如何使用 initSelection 附加 jquery select2 值

ruby-on-rails - 如何转换 Shapefile 的坐标?

gis - 如何过滤空间数据

javascript - 获取用户在 jwplayer 中观看视频的总时间

javascript - Leaflet popup.update() 调整大小解决方案 - 每次重新创建弹窗,无法点击嵌入的 URL

postgresql - 使用 Postgis 和 pgRouting 的行车路线