Remove marker.dragging when not on the map (#5295)

* Add some tests for #5293

* Fix enabling marker dragging while markers aren't on the map by removing the dragging object when not on the map.

This is a change of behavior (.dragging is only defined when a marker is on the map).

* Docs for dragging change
This commit is contained in:
Dave Leaver 2017-02-02 22:14:39 +13:00 committed by Iván Sánchez Ortega
parent d10f3ca317
commit 5603a87c70
3 changed files with 13 additions and 2 deletions

View File

@ -108,8 +108,18 @@ describe("Marker", function () {
map.removeLayer(marker); map.removeLayer(marker);
// Dragging is still enabled, we should be able to disable it, // Dragging is still enabled, we should be able to disable it,
// even if marker is off the map. // even if marker is off the map.
marker.dragging.disable(); expect(marker.dragging).to.be(undefined);
marker.options.draggable = false;
map.addLayer(marker); map.addLayer(marker);
map.removeLayer(marker);
// We should also be able to enable dragging while off the map
expect(marker.dragging).to.be(undefined);
marker.options.draggable = true;
map.addLayer(marker);
expect(marker.dragging.enabled()).to.be(true);
}); });
it("changes the icon to another DivIcon", function () { it("changes the icon to another DivIcon", function () {

View File

@ -17,7 +17,7 @@ import {Draggable} from '../../dom/Draggable';
* ``` * ```
* *
* @property dragging: Handler * @property dragging: Handler
* Marker dragging handler (by both mouse and touch). * Marker dragging handler (by both mouse and touch). Only valid when the marker is on the map (Otherwise set [`marker.options.draggable`](#marker-draggable)).
*/ */
export var MarkerDrag = Handler.extend({ export var MarkerDrag = Handler.extend({

View File

@ -96,6 +96,7 @@ export var Marker = Layer.extend({
this.options.draggable = true; this.options.draggable = true;
this.dragging.removeHooks(); this.dragging.removeHooks();
} }
delete this.dragging;
if (this._zoomAnimated) { if (this._zoomAnimated) {
map.off('zoomanim', this._animateZoom, this); map.off('zoomanim', this._animateZoom, this);