【问题标题】:Leaflet Draw how to trigger button events from outside the mapLeaflet Draw 如何从地图外部触发按钮事件
【发布时间】:2022-07-23 08:14:44
【问题描述】:

我有一个传单绘制实例,我需要地图外的按钮来启动/取消绘制动作。我已经成功触发了抽奖开始

map.Draw.Polyline(map, myDrawControlInstance.options.polyline).enable();

但我可以在 API 中的任何位置找到唯一提到取消绘制操作的操作:map.Draw.Polyline(map, myDrawControlInstance.options.polyline).disable(); 不会触发取消操作。

如何模仿Leaflet Draw界面在绘制、编辑、删除等时出现的所有按钮

非常感谢任何帮助

【问题讨论】:

    标签: leaflet leaflet-draw


    【解决方案1】:

    在大约 10 年前的某个地方找到了一个带有答案的帖子。

    您必须保留新的L.Draw. 方法返回的drawHandler 并在其上调用cancel()

    从外面开始抽签:

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

    从地图外取消抽奖:

    drawHandler.disable();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-31
      相关资源
      最近更新 更多