Sha256: 7c790a3c5cc36f4747a3ac2f970eec2ac4a4bdfe1ee10f01d917fd36e3fb710b

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 KB

Contents

/*
 * 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);
	}
});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
leaflet-js-0.7.9 vendor/assets/Leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.7.8 vendor/assets/Leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.7.7 vendor/assets/Leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.7.0.4 lib/leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.7.0.3 lib/leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.7.0.2 lib/leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.7.0.1 lib/leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.7.0 lib/leaflet/src/layer/vector/Path.Popup.js
leaflet-js-0.6.beta4 lib/leaflet/src/layer/vector/Path.Popup.js