handle drag handlers properly to avoid errors if moving while removed.

This commit is contained in:
snkashis 2013-02-28 10:38:27 +00:00
parent bba4f2ae1b
commit 95c73a3d77
3 changed files with 37 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

@ -37,6 +37,10 @@ L.Draggable = L.Class.extend({
disable: function () { disable: function () {
if (!this._enabled) { return; } 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--) { for (var i = L.Draggable.START.length - 1; i >= 0; i--) {
L.DomEvent.off(this._dragStartTarget, L.Draggable.START[i], this._onDown, this); L.DomEvent.off(this._dragStartTarget, L.Draggable.START[i], this._onDown, this);

View File

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