# Code coverage report for src/layer/marker/Marker.Drag.js

## Statements: 11.76% (2 / 17) Branches: 0% (0 / 6) Functions: 14.29% (1 / 7) Lines: 11.76% (2 / 17)

All files » src/layer/marker/ » Marker.Drag.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67

    1

    2

     /*
     * L.Handler.MarkerDrag is used internally by L.Marker to make the markers draggable.
     */

    L.Handler.MarkerDrag = L.Handler.extend({
    	initialize: function (marker) {
    		this._marker = marker;
    	},

    	addHooks: function () {
    		var icon = this._marker._icon;
    		if (!this._draggable) {
    			this._draggable = new L.Draggable(icon, icon);
    		}

    		this._draggable
    			.on('dragstart', this._onDragStart, this)
    			.on('drag', this._onDrag, this)
    			.on('dragend', this._onDragEnd, this);
    		this._draggable.enable();
    	},

    	removeHooks: function () {
    		this._draggable
    			.off('dragstart', this._onDragStart)
    			.off('drag', this._onDrag)
    			.off('dragend', this._onDragEnd);

    		this._draggable.disable();
    	},

    	moved: function () {
    		return this._draggable && this._draggable._moved;
    	},

    	_onDragStart: function () {
    		this._marker
    		    .closePopup()
    		    .fire('movestart')
    		    .fire('dragstart');
    	},

    	_onDrag: function () {
    		var marker = this._marker,
    		    shadow = marker._shadow,
    		    iconPos = L.DomUtil.getPosition(marker._icon),
    		    latlng = marker._map.layerPointToLatLng(iconPos);

    		// update shadow position
    		if (shadow) {
    			L.DomUtil.setPosition(shadow, iconPos);
    		}

    		marker._latlng = latlng;

    		marker
    		    .fire('move', {latlng: latlng})
    		    .fire('drag');
    	},

    	_onDragEnd: function () {
    		this._marker
    		    .fire('moveend')
    		    .fire('dragend');
    	}
    });