Leaflet.draw mapping:如何在没有工具栏的情况下启动绘图功能? [英] Leaflet.draw mapping: How to initiate the draw function without toolbar?

查看:2781
本文介绍了Leaflet.draw mapping:如何在没有工具栏的情况下启动绘图功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用传单或leaflet.draw插件的任何人:

For anyone experienced with leaflet or leaflet.draw plugin:

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

I want to initiate drawing a polygon without using the toolbar from leaflet.draw. I've managed to find the property that allows editing without using the toolbar (layer.editing.enable();) by searching online (it's not in the main documentation). I can't seem to find how to begin drawing a polygon without the toolbar button. Any help would be much appreciated!

谢谢:)

推荐答案

这个简单的代码适合我:

This simple code works for me:

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

只需将其放入自定义按钮的onclick处理程序(或任何您想要的位置)。

Just put it into the onclick handler of your custom button (or wherever you want).

变量 map drawControl 是对传单地图的引用,绘制控件。

The variables map and drawControl are references to your leaflet map and draw control.

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

Diving into the source code (leaflet.draw-src.js) you can find the functions to draw the other elements and to edit or delete them.

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.Edit L.EditToolbar.Delete 类公开以下有用的方法:

The L.EditToolbar.Edit and L.EditToolbar.Delete classes expose the following useful methods:


  • enable():开始编辑/删除模式

  • disable():返回标准模式

  • save():保存更改(触发绘制:编辑/绘制:删除事件)

  • revertLayers():撤消更改

  • enable(): to start edit/delete mode
  • disable(): to return to standard mode
  • save(): to save changes (it fires draw:edited / draw:deleted events)
  • revertLayers(): to undo changes

这篇关于Leaflet.draw mapping:如何在没有工具栏的情况下启动绘图功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆