Created
September 22, 2023 22:07
-
-
Save gtramontina/ff58345cb9cc53398945fd25a4ddbd3c to your computer and use it in GitHub Desktop.
leaflet-dom-event-bridge.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L.Map.addInitHook(function () { | |
const dom = this.getContainer(); | |
const forward = (e) => | |
dom.dispatchEvent( | |
new CustomEvent(`map:${e.type}`, { | |
detail: { | |
originalEvent: e, | |
zoom: this.getZoom(), | |
center: this.getCenter(), | |
bounds: { | |
northEast: this.getBounds().getNorthEast(), | |
southWest: this.getBounds().getSouthWest(), | |
}, | |
}, | |
}), | |
); | |
dom._leaflet_map = this; | |
this.on("unload", () => { | |
dom._leaflet_map = undefined; | |
}); | |
this.on("baselayerchange", forward); | |
this.on("overlayadd", forward); | |
this.on("overlayremove", forward); | |
this.on("layerremove", forward); | |
this.on("zoomlevelschange", forward); | |
this.on("resize", forward); | |
this.on("unload", forward); | |
this.on("viewreset", forward); | |
this.on("load", forward); | |
this.on("zoomstart", forward); | |
this.on("movestart", forward); | |
this.on("zoom", forward); | |
this.on("move", forward); | |
this.on("zoomend", forward); | |
this.on("moveend", forward); | |
this.on("popupopen", forward); | |
this.on("popupclose", forward); | |
this.on("autopanstart", forward); | |
this.on("tooltipopen", forward); | |
this.on("tooltipclose", forward); | |
this.on("locationerror", forward); | |
this.on("locationfound", forward); | |
this.on("click", forward); | |
this.on("dblclick", forward); | |
this.on("mousedown", forward); | |
this.on("mouseup", forward); | |
this.on("mouseover", forward); | |
this.on("mouseout", forward); | |
this.on("mousemove", forward); | |
this.on("contextmenu", forward); | |
this.on("keypress", forward); | |
this.on("keydown", forward); | |
this.on("keyup", forward); | |
this.on("preclick", forward); | |
this.on("zoomanim", forward); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment