Merge pull request #1471 from snkashis/drag_handling
handle drag listeners properly to avoid errors on marker removal
This commit is contained in:
commit
b993f1fc4b
29
debug/tests/remove_while_dragging.html
Normal file
29
debug/tests/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>
|
@ -19,6 +19,11 @@ L.Handler.MarkerDrag = L.Handler.extend({
|
||||
},
|
||||
|
||||
removeHooks: function () {
|
||||
this._draggable
|
||||
.off('dragstart', this._onDragStart)
|
||||
.off('drag', this._onDrag)
|
||||
.off('dragend', this._onDragEnd);
|
||||
|
||||
this._draggable.disable();
|
||||
},
|
||||
|
||||
|
@ -41,6 +41,10 @@ L.Marker = L.Class.extend({
|
||||
},
|
||||
|
||||
onRemove: function (map) {
|
||||
if (this.dragging) {
|
||||
this.dragging.disable();
|
||||
}
|
||||
|
||||
this._removeIcon();
|
||||
|
||||
this.fire('remove');
|
||||
|
Loading…
Reference in New Issue
Block a user