@trackunit/react-map-adapter-mapbox 0.0.189 → 0.0.191
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +95 -14
- package/index.esm.js +97 -16
- package/package.json +4 -4
- package/src/MapboxLayerPort.d.ts +16 -0
package/index.cjs.js
CHANGED
|
@@ -45,9 +45,14 @@ const getInitialStyleUrl = (theme) => MAPBOX_MAP_TYPE_STYLES.roadmap[theme];
|
|
|
45
45
|
*/
|
|
46
46
|
const createMapboxDrawEngineLoader = (map) => async () => {
|
|
47
47
|
const { TerraDrawMapboxGLAdapter } = await import('terra-draw-mapbox-gl-adapter');
|
|
48
|
-
|
|
48
|
+
const engine = await reactMapDraw.loadTerraDrawEngine({
|
|
49
49
|
adapter: new TerraDrawMapboxGLAdapter({ map, coordinatePrecision: reactMapDraw.DRAW_COORDINATE_PRECISION }),
|
|
50
50
|
});
|
|
51
|
+
// The Mapbox adapter listens on the canvas, which fills the container.
|
|
52
|
+
return reactMapDraw.withPointerCapture(engine, {
|
|
53
|
+
resolveElement: () => map.getCanvas(),
|
|
54
|
+
resolveBounds: () => map.getContainer().getBoundingClientRect(),
|
|
55
|
+
});
|
|
51
56
|
};
|
|
52
57
|
|
|
53
58
|
// ============================================================================
|
|
@@ -514,6 +519,63 @@ class MapboxLayerPort {
|
|
|
514
519
|
}
|
|
515
520
|
// ---- Marker sources ----
|
|
516
521
|
syncMarkerSource(config) {
|
|
522
|
+
this.renderMarkerSource(config);
|
|
523
|
+
const tracked = this.markerSources.get(config.id);
|
|
524
|
+
if (tracked !== undefined)
|
|
525
|
+
this.applyMarkerHitTesting(tracked);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* DOM marker hit testing follows `config.interactive` (ADR 0030): while a drawing mode
|
|
529
|
+
* is active, or when the consumer opts out, DOM markers and clusters stay visible but stop
|
|
530
|
+
* receiving pointer events, so every click reaches the map canvas. Circle layers draw
|
|
531
|
+
* inside the canvas; their handlers check the same flag at event time instead
|
|
532
|
+
* (`attachMarkerCircleLayerListeners`).
|
|
533
|
+
*
|
|
534
|
+
* mapbox-gl rewrites a marker element's inline `pointer-events` on every frame
|
|
535
|
+
* (`Marker._evaluateOpacity`), so the suspension is the shared class rule, never an
|
|
536
|
+
* inline value.
|
|
537
|
+
*/
|
|
538
|
+
applyMarkerHitTesting(tracked) {
|
|
539
|
+
const { config } = tracked;
|
|
540
|
+
if (config.kind !== "marker")
|
|
541
|
+
return;
|
|
542
|
+
const { interactive } = config;
|
|
543
|
+
for (const marker of tracked.markers) {
|
|
544
|
+
this.setHitTarget(marker.getElement(), interactive);
|
|
545
|
+
}
|
|
546
|
+
for (const marker of tracked.clusterMarkers ?? []) {
|
|
547
|
+
this.setHitTarget(marker.getElement(), interactive);
|
|
548
|
+
}
|
|
549
|
+
// A circle-layer hover that is live when the source goes non-interactive would
|
|
550
|
+
// otherwise stay recorded, and the next move over the same symbol after the flip
|
|
551
|
+
// back would look like no change and never restart the hover.
|
|
552
|
+
if (!interactive && this.map !== null && this.isCircleHoverOn(config)) {
|
|
553
|
+
this.endMarkerCircleHover(this.map);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
isCircleHoverOn(config) {
|
|
557
|
+
const hovered = this.lastHoveredMarkerFeatureId;
|
|
558
|
+
if (hovered === null)
|
|
559
|
+
return false;
|
|
560
|
+
return config.features.features.some(feature => String(feature.id) === hovered);
|
|
561
|
+
}
|
|
562
|
+
endMarkerCircleHover(map) {
|
|
563
|
+
map.getCanvas().style.cursor = reactMapAdapterShared.MAP_CURSORS.default;
|
|
564
|
+
map.getCanvasContainer().style.cursor = reactMapAdapterShared.MAP_CURSORS.default;
|
|
565
|
+
if (this.lastHoveredMarkerFeatureId !== null) {
|
|
566
|
+
this.emitEntityInteraction("hover-end", {
|
|
567
|
+
type: "marker",
|
|
568
|
+
id: this.lastHoveredMarkerFeatureId,
|
|
569
|
+
position: [0, 0],
|
|
570
|
+
clusterId: null,
|
|
571
|
+
});
|
|
572
|
+
this.lastHoveredMarkerFeatureId = null;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
setHitTarget(element, interactive) {
|
|
576
|
+
reactMapAdapterShared.setHitTargetInert(element, !interactive);
|
|
577
|
+
}
|
|
578
|
+
renderMarkerSource(config) {
|
|
517
579
|
if (this.map === null)
|
|
518
580
|
return;
|
|
519
581
|
// Skip full rebuild if config reference hasn't changed (same data, nothing to do)
|
|
@@ -621,7 +683,7 @@ class MapboxLayerPort {
|
|
|
621
683
|
tracked.sourceId = sourceId;
|
|
622
684
|
tracked.layerIds = [circleLayerId];
|
|
623
685
|
if (config.kind === "marker") {
|
|
624
|
-
this.attachMarkerCircleLayerListeners(currentMap, circleLayerId);
|
|
686
|
+
this.attachMarkerCircleLayerListeners(currentMap, circleLayerId, config.id);
|
|
625
687
|
}
|
|
626
688
|
if (markerRender.mode === "adaptive") {
|
|
627
689
|
this.createAdaptiveDomOverlays(config, currentMap, tracked);
|
|
@@ -906,6 +968,17 @@ class MapboxLayerPort {
|
|
|
906
968
|
if (existing !== undefined && esToolkit.isEqual(existing.config, config)) {
|
|
907
969
|
return;
|
|
908
970
|
}
|
|
971
|
+
// Only the hit-target flag changed (a drawing mode started or stopped): swap the
|
|
972
|
+
// listeners and keep the source and layers, so the route neither fades in again nor
|
|
973
|
+
// moves above the layers added since, the way shapes already handle it.
|
|
974
|
+
if (existing !== undefined && esToolkit.isEqual({ ...existing.config, interactive: config.interactive }, config)) {
|
|
975
|
+
this.detachRouteLayerInteractionListeners(this.map, existing.layerIds);
|
|
976
|
+
if (config.interactive) {
|
|
977
|
+
this.attachRouteLayerInteractionListeners(this.map, existing.layerIds, config.id);
|
|
978
|
+
}
|
|
979
|
+
existing.config = config;
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
909
982
|
// Remove existing route for this source (update case)
|
|
910
983
|
this.removeRouteSourceInternal(config.id);
|
|
911
984
|
const currentMap = this.map;
|
|
@@ -1734,6 +1807,8 @@ class MapboxLayerPort {
|
|
|
1734
1807
|
const markerIds = leaves.map(leaf => leaf.properties.featureId);
|
|
1735
1808
|
const clusterMarker = this.createClusterMarkerForViewport(config, coords, numericCount, markerIds, String(numericClusterId), map);
|
|
1736
1809
|
tracked.clusterMarkers.push(clusterMarker);
|
|
1810
|
+
// Clusters are re-rendered on every viewport change, so one born while drawing starts inert.
|
|
1811
|
+
this.setHitTarget(clusterMarker.getElement(), tracked.config.kind !== "marker" || tracked.config.interactive);
|
|
1737
1812
|
// Cluster interaction
|
|
1738
1813
|
const entity = {
|
|
1739
1814
|
type: "cluster",
|
|
@@ -1771,6 +1846,9 @@ class MapboxLayerPort {
|
|
|
1771
1846
|
const { originalFeature, featureId } = cluster.properties;
|
|
1772
1847
|
const marker = this.createMarkerForFeature(originalFeature, coords, config, map);
|
|
1773
1848
|
tracked.markers.push(marker);
|
|
1849
|
+
// Individual markers are rebuilt on every viewport change as well, so one born
|
|
1850
|
+
// while drawing starts inert instead of waiting for the next layer sync.
|
|
1851
|
+
this.setHitTarget(marker.getElement(), tracked.config.kind !== "marker" || tracked.config.interactive);
|
|
1774
1852
|
if (featureId !== "") {
|
|
1775
1853
|
this.attachMarkerInteractionListeners(marker, featureId, coords);
|
|
1776
1854
|
}
|
|
@@ -1912,8 +1990,17 @@ class MapboxLayerPort {
|
|
|
1912
1990
|
this.clusterEntitiesByMarker.set(marker, entity);
|
|
1913
1991
|
}
|
|
1914
1992
|
// ---- Marker circle layer interaction ----
|
|
1915
|
-
attachMarkerCircleLayerListeners(map, circleLayerId) {
|
|
1993
|
+
attachMarkerCircleLayerListeners(map, circleLayerId, sourceId) {
|
|
1994
|
+
// Circle layers draw inside the WebGL canvas, so `interactive: false` cannot be a DOM
|
|
1995
|
+
// property on them: the handlers consult the source's current config instead. It is read
|
|
1996
|
+
// at event time because an adaptive source keeps its layer and listeners across a patch.
|
|
1997
|
+
const isInteractive = () => {
|
|
1998
|
+
const config = this.markerSources.get(sourceId)?.config;
|
|
1999
|
+
return config?.kind === "marker" && config.interactive;
|
|
2000
|
+
};
|
|
1916
2001
|
const clickHandler = (e) => {
|
|
2002
|
+
if (!isInteractive())
|
|
2003
|
+
return;
|
|
1917
2004
|
// Mapbox fires a click for each of the two rapid clicks that precede a dblclick.
|
|
1918
2005
|
// Guard on detail >= 2 to suppress the spurious second click so consumers don't
|
|
1919
2006
|
// see a toggle before the dblclick fires.
|
|
@@ -1935,6 +2022,8 @@ class MapboxLayerPort {
|
|
|
1935
2022
|
this.emitEntityInteraction("click", entity);
|
|
1936
2023
|
};
|
|
1937
2024
|
const dblClickHandler = (e) => {
|
|
2025
|
+
if (!isInteractive())
|
|
2026
|
+
return;
|
|
1938
2027
|
this.suppressNativeZoom();
|
|
1939
2028
|
const feature = e.features?.[0];
|
|
1940
2029
|
if (feature === undefined)
|
|
@@ -1952,6 +2041,8 @@ class MapboxLayerPort {
|
|
|
1952
2041
|
this.emitEntityInteraction("dblclick", entity);
|
|
1953
2042
|
};
|
|
1954
2043
|
const mouseMoveHandler = (e) => {
|
|
2044
|
+
if (!isInteractive())
|
|
2045
|
+
return;
|
|
1955
2046
|
const feature = e.features?.[0];
|
|
1956
2047
|
if (feature === undefined)
|
|
1957
2048
|
return;
|
|
@@ -1981,17 +2072,7 @@ class MapboxLayerPort {
|
|
|
1981
2072
|
});
|
|
1982
2073
|
};
|
|
1983
2074
|
const mouseLeaveHandler = () => {
|
|
1984
|
-
|
|
1985
|
-
map.getCanvasContainer().style.cursor = reactMapAdapterShared.MAP_CURSORS.default;
|
|
1986
|
-
if (this.lastHoveredMarkerFeatureId !== null) {
|
|
1987
|
-
this.emitEntityInteraction("hover-end", {
|
|
1988
|
-
type: "marker",
|
|
1989
|
-
id: this.lastHoveredMarkerFeatureId,
|
|
1990
|
-
position: [0, 0],
|
|
1991
|
-
clusterId: null,
|
|
1992
|
-
});
|
|
1993
|
-
this.lastHoveredMarkerFeatureId = null;
|
|
1994
|
-
}
|
|
2075
|
+
this.endMarkerCircleHover(map);
|
|
1995
2076
|
};
|
|
1996
2077
|
map.on("click", circleLayerId, clickHandler);
|
|
1997
2078
|
map.on("dblclick", circleLayerId, dblClickHandler);
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { canPatchAdaptiveMarker, canPatchAdaptiveViewport, canPatchMarkerInPlace, getAdaptiveDomFeatureIds, buildAdaptiveSymbolStyleFn, extractPointCoordinates, resolveCircleSymbolDefaults, resolveSymbolDescriptor, mergeAntimeridianFeatures, densifyGeodesicFeatures, LAYER_FADE_DURATION_MS, patchPortalDescriptors, buildAdaptiveDomRenderFn, extractSourceData, collectFeatureIdSet, removeGoneIndexedMarkers, createSymbolDotElement, createDefaultClusterElement, createClusterPinElement, fadeInElement, buildAdaptiveDomEntries, attachSafeAreaHoverListeners, resolveSelectedStyle, resolveHoveredStyle,
|
|
1
|
+
import { MAP_CURSORS, setHitTargetInert, canPatchAdaptiveMarker, canPatchAdaptiveViewport, canPatchMarkerInPlace, getAdaptiveDomFeatureIds, buildAdaptiveSymbolStyleFn, extractPointCoordinates, resolveCircleSymbolDefaults, resolveSymbolDescriptor, mergeAntimeridianFeatures, densifyGeodesicFeatures, LAYER_FADE_DURATION_MS, patchPortalDescriptors, buildAdaptiveDomRenderFn, extractSourceData, collectFeatureIdSet, removeGoneIndexedMarkers, createSymbolDotElement, createDefaultClusterElement, createClusterPinElement, fadeInElement, buildAdaptiveDomEntries, attachSafeAreaHoverListeners, resolveSelectedStyle, resolveHoveredStyle, geometryTypeToShapeType, INITIAL_MAP_STATE, DEFAULT_MAP_APPEARANCE, computeInitialState, cameraStateEquals, isEventOfType, getEffectiveRestrictBounds, DEFAULT_ZOOM, DEFAULT_CENTER, defineAdapter } from '@trackunit/react-map-adapter-shared';
|
|
2
2
|
export { mapboxMapCspDirectives } from '@trackunit/react-map-adapter-shared';
|
|
3
3
|
import { validateBbox, validatePosition } from '@trackunit/geo-json-utils';
|
|
4
|
-
import { loadTerraDrawEngine, DRAW_COORDINATE_PRECISION, DrawController } from '@trackunit/react-map-draw';
|
|
4
|
+
import { loadTerraDrawEngine, DRAW_COORDINATE_PRECISION, withPointerCapture, DrawController } from '@trackunit/react-map-draw';
|
|
5
5
|
import { isEqual } from 'es-toolkit';
|
|
6
6
|
import mapboxgl from 'mapbox-gl';
|
|
7
7
|
import Supercluster from 'supercluster';
|
|
@@ -44,9 +44,14 @@ const getInitialStyleUrl = (theme) => MAPBOX_MAP_TYPE_STYLES.roadmap[theme];
|
|
|
44
44
|
*/
|
|
45
45
|
const createMapboxDrawEngineLoader = (map) => async () => {
|
|
46
46
|
const { TerraDrawMapboxGLAdapter } = await import('terra-draw-mapbox-gl-adapter');
|
|
47
|
-
|
|
47
|
+
const engine = await loadTerraDrawEngine({
|
|
48
48
|
adapter: new TerraDrawMapboxGLAdapter({ map, coordinatePrecision: DRAW_COORDINATE_PRECISION }),
|
|
49
49
|
});
|
|
50
|
+
// The Mapbox adapter listens on the canvas, which fills the container.
|
|
51
|
+
return withPointerCapture(engine, {
|
|
52
|
+
resolveElement: () => map.getCanvas(),
|
|
53
|
+
resolveBounds: () => map.getContainer().getBoundingClientRect(),
|
|
54
|
+
});
|
|
50
55
|
};
|
|
51
56
|
|
|
52
57
|
// ============================================================================
|
|
@@ -513,6 +518,63 @@ class MapboxLayerPort {
|
|
|
513
518
|
}
|
|
514
519
|
// ---- Marker sources ----
|
|
515
520
|
syncMarkerSource(config) {
|
|
521
|
+
this.renderMarkerSource(config);
|
|
522
|
+
const tracked = this.markerSources.get(config.id);
|
|
523
|
+
if (tracked !== undefined)
|
|
524
|
+
this.applyMarkerHitTesting(tracked);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* DOM marker hit testing follows `config.interactive` (ADR 0030): while a drawing mode
|
|
528
|
+
* is active, or when the consumer opts out, DOM markers and clusters stay visible but stop
|
|
529
|
+
* receiving pointer events, so every click reaches the map canvas. Circle layers draw
|
|
530
|
+
* inside the canvas; their handlers check the same flag at event time instead
|
|
531
|
+
* (`attachMarkerCircleLayerListeners`).
|
|
532
|
+
*
|
|
533
|
+
* mapbox-gl rewrites a marker element's inline `pointer-events` on every frame
|
|
534
|
+
* (`Marker._evaluateOpacity`), so the suspension is the shared class rule, never an
|
|
535
|
+
* inline value.
|
|
536
|
+
*/
|
|
537
|
+
applyMarkerHitTesting(tracked) {
|
|
538
|
+
const { config } = tracked;
|
|
539
|
+
if (config.kind !== "marker")
|
|
540
|
+
return;
|
|
541
|
+
const { interactive } = config;
|
|
542
|
+
for (const marker of tracked.markers) {
|
|
543
|
+
this.setHitTarget(marker.getElement(), interactive);
|
|
544
|
+
}
|
|
545
|
+
for (const marker of tracked.clusterMarkers ?? []) {
|
|
546
|
+
this.setHitTarget(marker.getElement(), interactive);
|
|
547
|
+
}
|
|
548
|
+
// A circle-layer hover that is live when the source goes non-interactive would
|
|
549
|
+
// otherwise stay recorded, and the next move over the same symbol after the flip
|
|
550
|
+
// back would look like no change and never restart the hover.
|
|
551
|
+
if (!interactive && this.map !== null && this.isCircleHoverOn(config)) {
|
|
552
|
+
this.endMarkerCircleHover(this.map);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
isCircleHoverOn(config) {
|
|
556
|
+
const hovered = this.lastHoveredMarkerFeatureId;
|
|
557
|
+
if (hovered === null)
|
|
558
|
+
return false;
|
|
559
|
+
return config.features.features.some(feature => String(feature.id) === hovered);
|
|
560
|
+
}
|
|
561
|
+
endMarkerCircleHover(map) {
|
|
562
|
+
map.getCanvas().style.cursor = MAP_CURSORS.default;
|
|
563
|
+
map.getCanvasContainer().style.cursor = MAP_CURSORS.default;
|
|
564
|
+
if (this.lastHoveredMarkerFeatureId !== null) {
|
|
565
|
+
this.emitEntityInteraction("hover-end", {
|
|
566
|
+
type: "marker",
|
|
567
|
+
id: this.lastHoveredMarkerFeatureId,
|
|
568
|
+
position: [0, 0],
|
|
569
|
+
clusterId: null,
|
|
570
|
+
});
|
|
571
|
+
this.lastHoveredMarkerFeatureId = null;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
setHitTarget(element, interactive) {
|
|
575
|
+
setHitTargetInert(element, !interactive);
|
|
576
|
+
}
|
|
577
|
+
renderMarkerSource(config) {
|
|
516
578
|
if (this.map === null)
|
|
517
579
|
return;
|
|
518
580
|
// Skip full rebuild if config reference hasn't changed (same data, nothing to do)
|
|
@@ -620,7 +682,7 @@ class MapboxLayerPort {
|
|
|
620
682
|
tracked.sourceId = sourceId;
|
|
621
683
|
tracked.layerIds = [circleLayerId];
|
|
622
684
|
if (config.kind === "marker") {
|
|
623
|
-
this.attachMarkerCircleLayerListeners(currentMap, circleLayerId);
|
|
685
|
+
this.attachMarkerCircleLayerListeners(currentMap, circleLayerId, config.id);
|
|
624
686
|
}
|
|
625
687
|
if (markerRender.mode === "adaptive") {
|
|
626
688
|
this.createAdaptiveDomOverlays(config, currentMap, tracked);
|
|
@@ -905,6 +967,17 @@ class MapboxLayerPort {
|
|
|
905
967
|
if (existing !== undefined && isEqual(existing.config, config)) {
|
|
906
968
|
return;
|
|
907
969
|
}
|
|
970
|
+
// Only the hit-target flag changed (a drawing mode started or stopped): swap the
|
|
971
|
+
// listeners and keep the source and layers, so the route neither fades in again nor
|
|
972
|
+
// moves above the layers added since, the way shapes already handle it.
|
|
973
|
+
if (existing !== undefined && isEqual({ ...existing.config, interactive: config.interactive }, config)) {
|
|
974
|
+
this.detachRouteLayerInteractionListeners(this.map, existing.layerIds);
|
|
975
|
+
if (config.interactive) {
|
|
976
|
+
this.attachRouteLayerInteractionListeners(this.map, existing.layerIds, config.id);
|
|
977
|
+
}
|
|
978
|
+
existing.config = config;
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
908
981
|
// Remove existing route for this source (update case)
|
|
909
982
|
this.removeRouteSourceInternal(config.id);
|
|
910
983
|
const currentMap = this.map;
|
|
@@ -1733,6 +1806,8 @@ class MapboxLayerPort {
|
|
|
1733
1806
|
const markerIds = leaves.map(leaf => leaf.properties.featureId);
|
|
1734
1807
|
const clusterMarker = this.createClusterMarkerForViewport(config, coords, numericCount, markerIds, String(numericClusterId), map);
|
|
1735
1808
|
tracked.clusterMarkers.push(clusterMarker);
|
|
1809
|
+
// Clusters are re-rendered on every viewport change, so one born while drawing starts inert.
|
|
1810
|
+
this.setHitTarget(clusterMarker.getElement(), tracked.config.kind !== "marker" || tracked.config.interactive);
|
|
1736
1811
|
// Cluster interaction
|
|
1737
1812
|
const entity = {
|
|
1738
1813
|
type: "cluster",
|
|
@@ -1770,6 +1845,9 @@ class MapboxLayerPort {
|
|
|
1770
1845
|
const { originalFeature, featureId } = cluster.properties;
|
|
1771
1846
|
const marker = this.createMarkerForFeature(originalFeature, coords, config, map);
|
|
1772
1847
|
tracked.markers.push(marker);
|
|
1848
|
+
// Individual markers are rebuilt on every viewport change as well, so one born
|
|
1849
|
+
// while drawing starts inert instead of waiting for the next layer sync.
|
|
1850
|
+
this.setHitTarget(marker.getElement(), tracked.config.kind !== "marker" || tracked.config.interactive);
|
|
1773
1851
|
if (featureId !== "") {
|
|
1774
1852
|
this.attachMarkerInteractionListeners(marker, featureId, coords);
|
|
1775
1853
|
}
|
|
@@ -1911,8 +1989,17 @@ class MapboxLayerPort {
|
|
|
1911
1989
|
this.clusterEntitiesByMarker.set(marker, entity);
|
|
1912
1990
|
}
|
|
1913
1991
|
// ---- Marker circle layer interaction ----
|
|
1914
|
-
attachMarkerCircleLayerListeners(map, circleLayerId) {
|
|
1992
|
+
attachMarkerCircleLayerListeners(map, circleLayerId, sourceId) {
|
|
1993
|
+
// Circle layers draw inside the WebGL canvas, so `interactive: false` cannot be a DOM
|
|
1994
|
+
// property on them: the handlers consult the source's current config instead. It is read
|
|
1995
|
+
// at event time because an adaptive source keeps its layer and listeners across a patch.
|
|
1996
|
+
const isInteractive = () => {
|
|
1997
|
+
const config = this.markerSources.get(sourceId)?.config;
|
|
1998
|
+
return config?.kind === "marker" && config.interactive;
|
|
1999
|
+
};
|
|
1915
2000
|
const clickHandler = (e) => {
|
|
2001
|
+
if (!isInteractive())
|
|
2002
|
+
return;
|
|
1916
2003
|
// Mapbox fires a click for each of the two rapid clicks that precede a dblclick.
|
|
1917
2004
|
// Guard on detail >= 2 to suppress the spurious second click so consumers don't
|
|
1918
2005
|
// see a toggle before the dblclick fires.
|
|
@@ -1934,6 +2021,8 @@ class MapboxLayerPort {
|
|
|
1934
2021
|
this.emitEntityInteraction("click", entity);
|
|
1935
2022
|
};
|
|
1936
2023
|
const dblClickHandler = (e) => {
|
|
2024
|
+
if (!isInteractive())
|
|
2025
|
+
return;
|
|
1937
2026
|
this.suppressNativeZoom();
|
|
1938
2027
|
const feature = e.features?.[0];
|
|
1939
2028
|
if (feature === undefined)
|
|
@@ -1951,6 +2040,8 @@ class MapboxLayerPort {
|
|
|
1951
2040
|
this.emitEntityInteraction("dblclick", entity);
|
|
1952
2041
|
};
|
|
1953
2042
|
const mouseMoveHandler = (e) => {
|
|
2043
|
+
if (!isInteractive())
|
|
2044
|
+
return;
|
|
1954
2045
|
const feature = e.features?.[0];
|
|
1955
2046
|
if (feature === undefined)
|
|
1956
2047
|
return;
|
|
@@ -1980,17 +2071,7 @@ class MapboxLayerPort {
|
|
|
1980
2071
|
});
|
|
1981
2072
|
};
|
|
1982
2073
|
const mouseLeaveHandler = () => {
|
|
1983
|
-
|
|
1984
|
-
map.getCanvasContainer().style.cursor = MAP_CURSORS.default;
|
|
1985
|
-
if (this.lastHoveredMarkerFeatureId !== null) {
|
|
1986
|
-
this.emitEntityInteraction("hover-end", {
|
|
1987
|
-
type: "marker",
|
|
1988
|
-
id: this.lastHoveredMarkerFeatureId,
|
|
1989
|
-
position: [0, 0],
|
|
1990
|
-
clusterId: null,
|
|
1991
|
-
});
|
|
1992
|
-
this.lastHoveredMarkerFeatureId = null;
|
|
1993
|
-
}
|
|
2074
|
+
this.endMarkerCircleHover(map);
|
|
1994
2075
|
};
|
|
1995
2076
|
map.on("click", circleLayerId, clickHandler);
|
|
1996
2077
|
map.on("dblclick", circleLayerId, dblClickHandler);
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-map-adapter-mapbox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.191",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/react-map-adapter-shared": "0.0.
|
|
11
|
-
"@trackunit/geo-json-utils": "1.21.
|
|
10
|
+
"@trackunit/react-map-adapter-shared": "0.0.203",
|
|
11
|
+
"@trackunit/geo-json-utils": "1.21.36",
|
|
12
12
|
"mapbox-gl": "^3.18.1",
|
|
13
13
|
"supercluster": "^8.0.1",
|
|
14
14
|
"es-toolkit": "^1.52.0",
|
|
15
15
|
"react-device-detect": "^2.2.3",
|
|
16
16
|
"zod": "^3.25.76",
|
|
17
|
-
"@trackunit/react-map-draw": "0.0.
|
|
17
|
+
"@trackunit/react-map-draw": "0.0.41",
|
|
18
18
|
"terra-draw-mapbox-gl-adapter": "^1.4.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
package/src/MapboxLayerPort.d.ts
CHANGED
|
@@ -100,6 +100,22 @@ export declare class MapboxLayerPort implements LayerPort {
|
|
|
100
100
|
/** @internal */
|
|
101
101
|
destroy(): void;
|
|
102
102
|
private syncMarkerSource;
|
|
103
|
+
/**
|
|
104
|
+
* DOM marker hit testing follows `config.interactive` (ADR 0030): while a drawing mode
|
|
105
|
+
* is active, or when the consumer opts out, DOM markers and clusters stay visible but stop
|
|
106
|
+
* receiving pointer events, so every click reaches the map canvas. Circle layers draw
|
|
107
|
+
* inside the canvas; their handlers check the same flag at event time instead
|
|
108
|
+
* (`attachMarkerCircleLayerListeners`).
|
|
109
|
+
*
|
|
110
|
+
* mapbox-gl rewrites a marker element's inline `pointer-events` on every frame
|
|
111
|
+
* (`Marker._evaluateOpacity`), so the suspension is the shared class rule, never an
|
|
112
|
+
* inline value.
|
|
113
|
+
*/
|
|
114
|
+
private applyMarkerHitTesting;
|
|
115
|
+
private isCircleHoverOn;
|
|
116
|
+
private endMarkerCircleHover;
|
|
117
|
+
private setHitTarget;
|
|
118
|
+
private renderMarkerSource;
|
|
103
119
|
private removeMarkerSourceInternal;
|
|
104
120
|
private syncShapeSource;
|
|
105
121
|
private removeShapeSourceInternal;
|