Merge pull request #1471 from snkashis/drag_handling

handle drag listeners properly to avoid errors on marker removal
This commit is contained in:
Vladimir Agafonkin 2013-02-28 03:25:04 -08:00
commit b993f1fc4b
3 changed files with 38 additions and 0 deletions

View 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>

View File

@ -19,6 +19,11 @@ L.Handler.MarkerDrag = L.Handler.extend({
}, },
removeHooks: function () { removeHooks: function () {
this._draggable
.off('dragstart', this._onDragStart)
.off('drag', this._onDrag)
.off('dragend', this._onDragEnd);
this._draggable.disable(); this._draggable.disable();
}, },

View File

@ -41,6 +41,10 @@ L.Marker = L.Class.extend({
}, },
onRemove: function (map) { onRemove: function (map) {
if (this.dragging) {
this.dragging.disable();
}
this._removeIcon(); this._removeIcon();
this.fire('remove'); this.fire('remove');