diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2021-03-01 12:16:23 +0530 |
---|---|---|
committer | Dennis Francis <dennisfrancis.in@gmail.com> | 2021-03-04 15:06:02 +0530 |
commit | cb1b5d4e64b91fe578470735fda9d475b7cd1b87 (patch) | |
tree | 7fde5e2b73b8ab1e21714497b40eb4a3a575067d /loleaflet | |
parent | overlay layer must be interactable for getting events (diff) | |
download | online-cb1b5d4e64b91fe578470735fda9d475b7cd1b87.tar.gz online-cb1b5d4e64b91fe578470735fda9d475b7cd1b87.zip |
CEventsHandler: pass an 'event-data' object to handlers
This can optionally contain corepixel position for now.
Signed-off-by: Dennis Francis <dennis.francis@collabora.com>
Change-Id: I3b9e369ee9c3b58070f2c16b0c6cf0dd8f0df87f
Diffstat (limited to 'loleaflet')
-rw-r--r-- | loleaflet/src/layer/vector/CEventsHandler.ts | 8 | ||||
-rw-r--r-- | loleaflet/src/layer/vector/CPath.ts | 26 |
2 files changed, 20 insertions, 14 deletions
diff --git a/loleaflet/src/layer/vector/CEventsHandler.ts b/loleaflet/src/layer/vector/CEventsHandler.ts index 9879e25122..b60dc2b434 100644 --- a/loleaflet/src/layer/vector/CEventsHandler.ts +++ b/loleaflet/src/layer/vector/CEventsHandler.ts @@ -1,5 +1,9 @@ /* eslint-disable */ +interface EventData { + position?: CPoint; +} + abstract class CEventsHandler { protected supportedEventNames = [ @@ -55,7 +59,7 @@ abstract class CEventsHandler { return true; } - fire(eventName: string): boolean { + fire(eventName: string, eventData: EventData): boolean { var handlerSet = this.handlers.get(eventName); if (handlerSet === undefined) { console.warn('Unknown event type: ' + eventName); @@ -64,7 +68,7 @@ abstract class CEventsHandler { var that = this; handlerSet.forEach(function (handler) { - handler.call(that); + handler.call(that, eventData); }); } }
\ No newline at end of file diff --git a/loleaflet/src/layer/vector/CPath.ts b/loleaflet/src/layer/vector/CPath.ts index d30151f47a..85750f85f6 100644 --- a/loleaflet/src/layer/vector/CPath.ts +++ b/loleaflet/src/layer/vector/CPath.ts @@ -80,7 +80,7 @@ abstract class CPath extends CEventsHandler { if (this.renderer) { this.addPathTestDiv(); } - this.fire('add'); + this.fire('add', {}); } // Adds a div for cypress-tests (if active) for this CPath if not already done. @@ -118,7 +118,7 @@ abstract class CPath extends CEventsHandler { } setDeleted() { - this.fire('remove'); + this.fire('remove', {}); this.isDeleted = true; if (this.testDiv) { this.testDiv.remove(); @@ -135,11 +135,11 @@ abstract class CPath extends CEventsHandler { } onMouseEnter(position: CPoint) { - this.fire('mouseenter'); + this.fire('mouseenter', {position: position}); } onMouseLeave(position: CPoint) { - this.fire('mouseleave'); + this.fire('mouseleave', {position: position}); } redraw(oldBounds: CBounds) { @@ -283,32 +283,34 @@ abstract class CPath extends CEventsHandler { return this; } - protected firstPopup() { + protected firstPopup(e: EventData) { if (this.popup) { - var center = this.getBounds().getCenter(); this.openPopup({ - latlng: this.toCompatUnits([center.x, center.y]) + position: this.getBounds().getCenter() }); } } - protected closePopup() { + protected closePopup(e: EventData) { if (this.popup) { this.popup._close(); } return this; } - protected delayClosePopup() { + protected delayClosePopup(e: EventData) { clearTimeout(this.popupTimer); this.popupTimer = setTimeout(this.closePopup.bind(this), 3000); } - protected openPopup(e: any) { + protected openPopup(e: EventData) { if (!this.getMap().hasLayer(this.popup)) { - this.popup.setLatLng(e.latlng); + if (!e.position) + e.position = this.getBounds().getCenter(); + var latlngPos = this.toCompatUnits([e.position.x, e.position.y]) + this.popup.setLatLng(latlngPos); this.getMap().openPopup(this.popup); - this.delayClosePopup(); + this.delayClosePopup({}); } } |