为什么单张标记在取消版本后仍然被选中?
Why leaflet marker still selected after cancel edition?
我从传单和 leaflet.draw 开始,但我在尝试更改标记的图标时遇到了麻烦。
在这种特殊情况下,我试图在按下取消编辑按钮时更新所有标记的图标。我可以更改图标,但所有标记仍处于选中状态
这里是fiddleexample
重现步骤
- 按编辑按钮
- 按取消编辑
- 您会看到所有标记都已更改其图标,但同时所有标记仍处于选中状态
这是我必须模拟撤消图标更改的代码:
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.draw1.0.3
我做错了什么?
我快速查看了您的代码,但不确定是什么原因导致了此问题。但是,我从控制台深入研究了可编辑标记代码和样式,并意识到一旦您点击编辑按钮,.leaflet-edit-marker-selected
class 就会应用于从 leaflet.draw.css line 9.
因此,一个可能的解决方法是在调用 'draw:editstop' 事件后删除 .leaflet-edit-marker-selected
class:
map.on('draw:editstop',function(e) {
$(".leaflet-pane img").removeClass("leaflet-edit-marker-selected");
editing=false;
map.closePopup();
});
我从传单和 leaflet.draw 开始,但我在尝试更改标记的图标时遇到了麻烦。
在这种特殊情况下,我试图在按下取消编辑按钮时更新所有标记的图标。我可以更改图标,但所有标记仍处于选中状态
这里是fiddleexample
重现步骤
- 按编辑按钮
- 按取消编辑
- 您会看到所有标记都已更改其图标,但同时所有标记仍处于选中状态
这是我必须模拟撤消图标更改的代码:
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.draw1.0.3
我做错了什么?
我快速查看了您的代码,但不确定是什么原因导致了此问题。但是,我从控制台深入研究了可编辑标记代码和样式,并意识到一旦您点击编辑按钮,.leaflet-edit-marker-selected
class 就会应用于从 leaflet.draw.css line 9.
因此,一个可能的解决方法是在调用 'draw:editstop' 事件后删除 .leaflet-edit-marker-selected
class:
map.on('draw:editstop',function(e) {
$(".leaflet-pane img").removeClass("leaflet-edit-marker-selected");
editing=false;
map.closePopup();
});