Code coverage report for src/layer/vector/Path.Popup.js

Statements: 4.17% (1 / 24)      Branches: 0% (0 / 17)      Functions: 0% (0 / 5)      Lines: 4.17% (1 / 24)     

All files » src/layer/vector/ » Path.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        1                                                                                                                          
/*
 * Popup extension to L.Path (polylines, polygons, circles), adding popup-related methods.
 */
 
L.Path.include({
 
	bindPopup: function (content, options) {
 
		if (content instanceof L.Popup) {
			this._popup = content;
		} else {
			if (!this._popup || options) {
				this._popup = new L.Popup(options, this);
			}
			this._popup.setContent(content);
		}
 
		if (!this._popupHandlersAdded) {
			this
			    .on('click', this._openPopup, this)
			    .on('remove', this.closePopup, this);
 
			this._popupHandlersAdded = true;
		}
 
		return this;
	},
 
	unbindPopup: function () {
		if (this._popup) {
			this._popup = null;
			this
			    .off('click', this._openPopup)
			    .off('remove', this.closePopup);
 
			this._popupHandlersAdded = false;
		}
		return this;
	},
 
	openPopup: function (latlng) {
 
		if (this._popup) {
			// open the popup from one of the path's points if not specified
			latlng = latlng || this._latlng ||
			         this._latlngs[Math.floor(this._latlngs.length / 2)];
 
			this._openPopup({latlng: latlng});
		}
 
		return this;
	},
 
	closePopup: function () {
		if (this._popup) {
			this._popup._close();
		}
		return this;
	},
 
	_openPopup: function (e) {
		this._popup.setLatLng(e.latlng);
		this._map.openPopup(this._popup);
	}
});