[Libreoffice-commits] online.git: loleaflet/build loleaflet/src
Henry Castro
hcastro at collabora.com
Wed Sep 14 23:21:58 UTC 2016
loleaflet/build/deps.js | 3 -
loleaflet/src/layer/vector/Path.Popup.js | 72 +++++++++++++++++++++++++++++++
loleaflet/src/layer/vector/SVG.js | 21 +++++++++
3 files changed, 95 insertions(+), 1 deletion(-)
New commits:
commit 44c3d5dfdec440164abbae9833fe9a7b6a96aa0f
Author: Henry Castro <hcastro at collabora.com>
Date: Wed Sep 14 19:22:31 2016 -0400
loleaflet: add Path.Popup
diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index cb83325..58a2ff1 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -119,7 +119,8 @@ var deps = {
Path: {
src: [
'layer/vector/Renderer.js',
- 'layer/vector/Path.js'
+ 'layer/vector/Path.js',
+ 'layer/vector/Path.Popup.js'
],
desc: 'Vector rendering core.',
heading: 'Vector layers'
diff --git a/loleaflet/src/layer/vector/Path.Popup.js b/loleaflet/src/layer/vector/Path.Popup.js
new file mode 100644
index 0000000..a3dcef5
--- /dev/null
+++ b/loleaflet/src/layer/vector/Path.Popup.js
@@ -0,0 +1,72 @@
+/*
+ * 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({
+ mouseover: this._openPopup,
+ mouseout: this._delayClose,
+ remove: this.closePopup,
+ add: this.firstPopup
+ });
+
+ this._popupHandlersAdded = true;
+ }
+
+ return this;
+ },
+
+ unbindPopup: function () {
+ if (this._popup) {
+ this._popup = null;
+ this.off({
+ mouseover: this._openPopup,
+ mouseout: this._delayClose,
+ remove: this.closePopup,
+ add: this.firstPopup
+ });
+
+ this._popupHandlersAdded = false;
+ }
+ return this;
+ },
+
+ firstPopup: function (e) {
+ if (this._popup) {
+ this._openPopup({latlng: this._bounds.getCenter()});
+ }
+ },
+
+ closePopup: function () {
+ if (this._popup) {
+ this._popup._close();
+ }
+ return this;
+ },
+
+ _delayClose: function () {
+ clearTimeout(this._timer);
+ this._timer = setTimeout(L.bind(this.closePopup, this), 3000);
+ },
+
+ _openPopup: function (e) {
+ if (!this._map.hasLayer(this._popup)) {
+ this._popup.setLatLng(e.latlng);
+ this._map.openPopup(this._popup);
+ this._delayClose();
+ }
+ }
+});
diff --git a/loleaflet/src/layer/vector/SVG.js b/loleaflet/src/layer/vector/SVG.js
index 3b203df..9d0affb 100644
--- a/loleaflet/src/layer/vector/SVG.js
+++ b/loleaflet/src/layer/vector/SVG.js
@@ -45,11 +45,32 @@ L.SVG = L.Renderer.extend({
if (layer.options.interactive) {
L.DomUtil.addClass(path, 'leaflet-interactive');
+
+ var events = ['mouseenter', 'mouseout'];
+ for (var i = 0; i < events.length; i++) {
+ L.DomEvent.on(path, events[i], this._fireMouseEvent, this);
+ }
}
this._updateStyle(layer);
},
+ _fireMouseEvent: function (e) {
+ if (!this._map || !this.hasEventListeners(e.type)) { return; }
+
+ var map = this._map,
+ containerPoint = map.mouseEventToContainerPoint(e),
+ layerPoint = map.containerPointToLayerPoint(containerPoint),
+ latlng = map.layerPointToLatLng(layerPoint);
+
+ this.fire(e.type, {
+ latlng: latlng,
+ layerPoint: layerPoint,
+ containerPoint: containerPoint,
+ originalEvent: e
+ });
+ },
+
_addPath: function (layer) {
this._container.appendChild(layer._path);
layer.addInteractiveTarget(layer._path);
More information about the Libreoffice-commits
mailing list