handle drag handlers properly to avoid errors if moving while removed.
This commit is contained in:
parent
bba4f2ae1b
commit
95c73a3d77
29
debug/map/remove_while_dragging.html
Normal file
29
debug/map/remove_while_dragging.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Leaflet debug page</title>
|
||||
|
||||
<link rel="stylesheet" href="../../dist/leaflet.css" />
|
||||
<!--[if lte IE 8]><link rel="stylesheet" href="../../dist/leaflet.ie.css" /><![endif]-->
|
||||
|
||||
<link rel="stylesheet" href="../css/screen.css" />
|
||||
|
||||
<script type="text/javascript" src="../../build/deps.js"></script>
|
||||
<script src="../leaflet-include.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="map" style="width: 600px; height: 600px; border: 1px solid #ccc"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var map = L.map('map').setView( [50, 50], 10);
|
||||
var marker = L.marker([50, 50], {draggable: true}).addTo(map);
|
||||
|
||||
setTimeout(function() {
|
||||
map.removeLayer(marker);
|
||||
}, 3000);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -37,6 +37,10 @@ L.Draggable = L.Class.extend({
|
||||
|
||||
disable: function () {
|
||||
if (!this._enabled) { return; }
|
||||
|
||||
this.off('dragstart', this._onDragStart)
|
||||
.off('drag', this._onDrag)
|
||||
.off('dragend', this._onDragEnd);
|
||||
|
||||
for (var i = L.Draggable.START.length - 1; i >= 0; i--) {
|
||||
L.DomEvent.off(this._dragStartTarget, L.Draggable.START[i], this._onDown, this);
|
||||
|
@ -41,6 +41,10 @@ L.Marker = L.Class.extend({
|
||||
},
|
||||
|
||||
onRemove: function (map) {
|
||||
if (this.dragging) {
|
||||
this.dragging.removeHooks();
|
||||
}
|
||||
|
||||
this._removeIcon();
|
||||
|
||||
this.fire('remove');
|
||||
|
Loading…
Reference in New Issue
Block a user