Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Improve mouse pointer behaviour on zoom

Russ Garrett096843806937
diff --git a/web/src/click-router.ts b/web/src/click-router.ts
index db68324..fc3ab9a 100644
--- a/web/src/click-router.ts
+++ b/web/src/click-router.ts
@@ -24,8 +24,25 @@ export class ClickRouter {
this.layerPriorities[layer.id] = layer.zorder
}
- // Always reset the cursor on zoom
- map.on('zoom', () => this.clearCursor())
+ map.on('zoomend', () => {
+ if (this.map.getZoom() < this.minZoom) {
+ this.map.getCanvas().style.cursor = ''
+ return
+ }
+
+ // Reset the cursor on mouse move
+ this.map.once('mousemove', (e) => {
+ const features = this.map.queryRenderedFeatures(e.point, {
+ layers: this.getLayers()
+ })
+
+ if (features.length > 0) {
+ this.setCursor()
+ } else {
+ this.clearCursor()
+ }
+ })
+ })
}
registerHandler(layerIds: LayerId | LayerId[], handler: ClickHandler) {