对于任何使用过传单或传单.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),您可以找到绘制其他元素以及编辑或删除它们的函数.
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:
这篇关于Leaflet.draw 映射:如何在没有工具栏的情况下启动绘图功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Browserify,Babel 6,Gulp - 传播运算符上的意外令牌Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 传播运算符上的意外令牌)
是否可以将标志传递给 Gulp 以使其以不同的方式Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以将标志传递给 Gulp 以使其以不同的方式运行任务
为什么我们需要在全局和本地安装 gulp?Why do we need to install gulp globally and locally?(为什么我们需要在全局和本地安装 gulp?)
如何一个接一个地依次运行 Gulp 任务How to run Gulp tasks sequentially one after the other(如何一个接一个地依次运行 Gulp 任务)
打开 Javascript 文件时 Visual Studio 2015 崩溃Visual Studio 2015 crashes when opening Javascript files(打开 Javascript 文件时 Visual Studio 2015 崩溃)
检测 FLASH 插件崩溃Detect FLASH plugin crashes(检测 FLASH 插件崩溃)