Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(geomap): leave a base-map place standing inside a drawn shape to the shape
Elian Doran6518dbaa6477
diff --git a/apps/client/src/widgets/collections/geomap/Pois.spec.tsx b/apps/client/src/widgets/collections/geomap/Pois.spec.tsxindex 1241a103b9..40e0b27552 100644--- a/apps/client/src/widgets/collections/geomap/Pois.spec.tsx+++ b/apps/client/src/widgets/collections/geomap/Pois.spec.tsx@@ -54,6 +54,10 @@ function tooltipText() {type Listener = (e?: unknown) => void;+/** The layers a drawn shape offers to be pointed at by, named after its note (see ShapeLayer). */+const SHAPE_FILL_LAYER = "shape-fill-note1";+const SHAPE_HIT_LAYER = "shape-hit-note1";+/** A place as a tile carries one: named, classified by its OSM tags, standing at a point. */function poiFeature(properties: Record<string, unknown>, coordinates: [number, number] = [ 13.4, 52.5 ]) {return {@@ -257,6 +261,23 @@ describe("geo map Pois", () => {expect(picked).toEqual([]);});+ /**+ * A drawn shape is one of the map's own, and an area covers every place standing inside it. Left+ * out of the hit test, the click opened the place alongside the pane the shape had just opened.+ */+ it("leaves a click that landed inside a drawn shape to the shape", async () => {+ const map = fakeMap({ ownLayerIds: [ SHAPE_FILL_LAYER, SHAPE_HIT_LAYER ] });+ const { picked } = await renderPois(map);++ map.setUnderPointer({+ poi: [ poiFeature({ name: "Café Kranzler", amenity: "cafe" }) ],+ own: [ { properties: { id: "note1" } } ]+ });+ await act(async () => { map.click(); });++ expect(picked).toEqual([]);+ });+it("leaves a click that landed on the device's own dot to the dot", async () => {const map = fakeMap();const { picked } = await renderPois(map);@@ -361,6 +382,17 @@ describe("geo map Pois", () => {expect(map.cursor).toBe("pointer");});+ /** An area covers every place inside it, so its own name is what a rest there asks for. */+ it("leaves the pointer to a drawn shape the place stands inside", async () => {+ const map = fakeMap({ ownLayerIds: [ SHAPE_FILL_LAYER, SHAPE_HIT_LAYER ] });+ await renderPois(map);++ map.setUnderPointer({ own: [ { properties: { id: "note1" } } ] });+ map.hover(poiFeature({ name: "Café Kranzler", amenity: "cafe" }));++ expect(map.cursor).toBe("");+ });+it("puts the pointer back on the layers a style switch brought in", async () => {const map = fakeMap();await renderPois(map);diff --git a/apps/client/src/widgets/collections/geomap/Pois.tsx b/apps/client/src/widgets/collections/geomap/Pois.tsxindex 422b6bef19..dcacde56ad 100644--- a/apps/client/src/widgets/collections/geomap/Pois.tsx+++ b/apps/client/src/widgets/collections/geomap/Pois.tsx@@ -11,6 +11,7 @@ import { isLocationDot } from "./MapToolbar";import { MARKER_LAYER } from "./Markers";import { placeIcon } from "./osm_icons";import { PLACE_LAYER, PLACE_MARKER_COLOR } from "./PlaceMarker";+import { shapeHitLayers } from "./ShapeLayer";/** The source layer the vector styles draw shops, cafes and the rest of the base map's places from. */const POI_SOURCE_LAYER = "pois";@@ -341,11 +342,14 @@ export function poiLayers(map: MapLibreGLMap) {}/**- * Whether the map has something of its own under the pointer — a marker, a cluster, a track or the- * pin of a place already in hand. Those stand above the base map and answer for it.+ * Whether the map has something of its own under the pointer — a marker, a cluster, a track, a drawn+ * shape, or the pin of a place already in hand. Those stand above the base map and answer for it.+ *+ * A shape counts over its whole area rather than along its boundary, which is what `shapeHitLayers`+ * gives: the fill covers every place standing inside it, and those belong to the shape.*/function isOwnUnderPointer(map: MapLibreGLMap, point: MapMouseEvent["point"]) {- const own = [ MARKER_LAYER, PLACE_LAYER, ...CLUSTER_LAYERS, ...trackHitLayers(map) ]+ const own = [ MARKER_LAYER, PLACE_LAYER, ...CLUSTER_LAYERS, ...trackHitLayers(map), ...shapeHitLayers(map) ].filter((id) => map.getLayer(id));return own.length > 0 && map.queryRenderedFeatures(point, { layers: own }).length > 0;