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

## Statements: 3.57% (1 / 28) Branches: 0% (0 / 21) Functions: 0% (0 / 6) Lines: 3.57% (1 / 28)

All files » src/layer/marker/ » Marker.Popup.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
    68
    69
    70
    71
    72
    73

    1

     /*
     * Popup extension to L.Marker, adding popup-related methods.
     */

    L.Marker.include({
    	openPopup: function () {
    		if (this._popup && this._map && !this._map.hasLayer(this._popup)) {
    			this._popup.setLatLng(this._latlng);
    			this._map.openPopup(this._popup);
    		}

    		return this;
    	},

    	closePopup: function () {
    		if (this._popup) {
    			this._popup._close();
    		}
    		return this;
    	},

    	bindPopup: function (content, options) {
    		var anchor = L.point(this.options.icon.options.popupAnchor) || new L.Point(0, 0);

    		anchor = anchor.add(L.Popup.prototype.options.offset);

    		if (options && options.offset) {
    			anchor = anchor.add(options.offset);
    		}

    		options = L.extend({offset: anchor}, options);

    		if (!this._popup) {
    			this
    			    .on('click', this.openPopup, this)
    			    .on('remove', this.closePopup, this)
    			    .on('move', this._movePopup, this);
    		}

    		if (content instanceof L.Popup) {
    			L.setOptions(content, options);
    			this._popup = content;
    		} else {
    			this._popup = new L.Popup(options, this)
    				.setContent(content);
    		}

    		return this;
    	},

    	setPopupContent: function (content) {
    		if (this._popup) {
    			this._popup.setContent(content);
    		}
    		return this;
    	},

    	unbindPopup: function () {
    		if (this._popup) {
    			this._popup = null;
    			this
    			    .off('click', this.openPopup)
    			    .off('remove', this.closePopup)
    			    .off('move', this._movePopup);
    		}
    		return this;
    	},

    	_movePopup: function (e) {
    		this._popup.setLatLng(e.latlng);
    	}
    });