为什么取消版本后仍选择传单标记?

时间:2018-09-22 19:40:31

标签: leaflet leaflet.draw

我从leaflet和leaflet.draw开始,尝试更改标记的图标时遇到了麻烦。

在这种情况下,我尝试按“取消编辑”按钮时更新所有标记的图标。我可以更改图标,但所有标记仍处于选中状态

这里是小提琴example

复制步骤

  1. 按下编辑按钮
  2. 按取消编辑
  3. 您将看到所有标记都已更改其图标,但同时所有标记仍处于选中状态

这是我模拟撤消图标更改的代码:

drawControl._toolbars.edit.disable =  function () {
  if (!this.enabled()) {
       /* If you need to do something right as the
       edit tool is enabled, do it here right
       before the return */
    return;
  }

  geojsonLayer.eachLayer(function(layer) {
     layer.setIcon(new  L.Icon.Default({}));
  });
  geojsonLayer2.eachLayer(function(layer) {
     layer.setIcon(new  L.Icon.Default({}));
  });

   this._activeMode.handler.revertLayers();

   L.Toolbar.prototype.disable.call(this);
};    

版本: 传单1.3.4 leaflet.draw 1.0.3

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

我快速浏览了您的代码,但不确定是什么原因导致此问题。但是,我从控制台深入研究了可编辑标记的代码和样式,并意识到,一旦按下编辑按钮,.leaflet-edit-marker-selected类将应用于从leaflet.draw.css line 9.派生的每个绘制或呈现的标记

因此,可能的解决方法是在调用'draw:editstop'事件后删除.leaflet-edit-marker-selected类:

map.on('draw:editstop',function(e) {
    $(".leaflet-pane img").removeClass("leaflet-edit-marker-selected");
    editing=false;
    map.closePopup();
});

Updated Demo