@trackunit/react-map-adapter-google 0.0.191-alpha-2f5decf56c8.0 → 0.0.192
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 +98 -14
- package/index.esm.js +100 -16
- package/package.json +5 -5
- package/src/GoogleMapsLayerPort.d.ts +11 -0
package/index.cjs.js
CHANGED
|
@@ -56,6 +56,10 @@ const GoogleApiProvider = ({ apiKey, language, children }) => {
|
|
|
56
56
|
return (jsxRuntime.jsx(reactGoogleMaps.APIProvider, { apiKey: apiKey, language: language, libraries: libraries, version: GOOGLE_MAPS_API_VERSION, children: children }));
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
const findMapEventElement = (adapter) => {
|
|
60
|
+
const element = adapter.getMapEventElement();
|
|
61
|
+
return element;
|
|
62
|
+
};
|
|
59
63
|
/**
|
|
60
64
|
* Builds the Google Maps bridge for the shared drawing engine (ADR 0030).
|
|
61
65
|
*
|
|
@@ -67,15 +71,20 @@ const GoogleApiProvider = ({ apiKey, language, children }) => {
|
|
|
67
71
|
*/
|
|
68
72
|
const createGoogleDrawEngineLoader = (map) => async () => {
|
|
69
73
|
const { TerraDrawGoogleMapsAdapter } = await import('terra-draw-google-maps-adapter');
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
const adapter = new TerraDrawGoogleMapsAdapter({
|
|
75
|
+
lib: google.maps,
|
|
76
|
+
map,
|
|
77
|
+
// Keep drawn features in their own Data layer so nothing else on the map
|
|
78
|
+
// (or a future layer port feature) shares styling or click handling with them.
|
|
79
|
+
isolatedData: true,
|
|
80
|
+
coordinatePrecision: reactMapDraw.DRAW_COORDINATE_PRECISION,
|
|
81
|
+
});
|
|
82
|
+
const engine = await reactMapDraw.loadTerraDrawEngine({ adapter });
|
|
83
|
+
// The adapter finds Google's event layer by an inline style (SAGA-985) and types the
|
|
84
|
+
// result as never missing; the capture treats a miss as "nothing to capture".
|
|
85
|
+
return reactMapDraw.withPointerCapture(engine, {
|
|
86
|
+
resolveElement: () => findMapEventElement(adapter),
|
|
87
|
+
resolveBounds: () => map.getDiv().getBoundingClientRect(),
|
|
79
88
|
});
|
|
80
89
|
};
|
|
81
90
|
|
|
@@ -762,6 +771,51 @@ class GoogleMapsLayerPort {
|
|
|
762
771
|
}
|
|
763
772
|
// ---- Marker sources ----
|
|
764
773
|
syncMarkerSource(config) {
|
|
774
|
+
this.renderMarkerSource(config);
|
|
775
|
+
const tracked = this.markerSources.get(config.id);
|
|
776
|
+
if (tracked !== undefined)
|
|
777
|
+
this.applyMarkerHitTesting(tracked);
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Marker hit testing follows `config.interactive` (ADR 0030): while a drawing mode is
|
|
781
|
+
* active, markers, clusters and the symbol canvas stay visible but stop receiving
|
|
782
|
+
* pointer events, so every click and every drag release reaches the drawing engine
|
|
783
|
+
* instead of a marker. The suspension goes on the advanced marker host, which Google
|
|
784
|
+
* keeps at `pointer-events: auto`, and the shared rule covers the content inside it.
|
|
785
|
+
*/
|
|
786
|
+
applyMarkerHitTesting(tracked) {
|
|
787
|
+
const { config } = tracked;
|
|
788
|
+
if (config.kind !== "marker")
|
|
789
|
+
return;
|
|
790
|
+
const { interactive } = config;
|
|
791
|
+
for (const marker of tracked.markers) {
|
|
792
|
+
this.setMarkerHitTarget(marker, interactive);
|
|
793
|
+
}
|
|
794
|
+
if (tracked.clustererMarkers !== undefined) {
|
|
795
|
+
for (const marker of tracked.clustererMarkers) {
|
|
796
|
+
// The clusterer retires a bubble by clearing its map (at once on a reset, a frame
|
|
797
|
+
// later for a replaced group) and attaches a new one in the tick that minted it.
|
|
798
|
+
// The DOM mounts it later, so being disconnected says nothing about retirement:
|
|
799
|
+
// pruning on that would forget a bubble born this frame and leave it stuck in
|
|
800
|
+
// whichever state it was born with.
|
|
801
|
+
if (marker.map === null || marker.map === undefined) {
|
|
802
|
+
tracked.clustererMarkers.delete(marker);
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
this.setMarkerHitTarget(marker, interactive);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (tracked.canvasElement !== undefined) {
|
|
809
|
+
this.setHitTarget(tracked.canvasElement, interactive);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
setMarkerHitTarget(marker, interactive) {
|
|
813
|
+
this.setHitTarget(marker.element, interactive);
|
|
814
|
+
}
|
|
815
|
+
setHitTarget(element, interactive) {
|
|
816
|
+
reactMapAdapterShared.setHitTargetInert(element, !interactive);
|
|
817
|
+
}
|
|
818
|
+
renderMarkerSource(config) {
|
|
765
819
|
if (this.map === null)
|
|
766
820
|
return;
|
|
767
821
|
// Skip full rebuild if config reference hasn't changed (same data, nothing to do)
|
|
@@ -1041,7 +1095,7 @@ class GoogleMapsLayerPort {
|
|
|
1041
1095
|
}
|
|
1042
1096
|
else if (type === "Point") {
|
|
1043
1097
|
const [lng, lat] = geometry.coordinates;
|
|
1044
|
-
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap);
|
|
1098
|
+
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap, config.interactive !== "none");
|
|
1045
1099
|
tracked.pointMarkers.push(marker);
|
|
1046
1100
|
if (fid !== undefined) {
|
|
1047
1101
|
this.pushToFeatureMap(tracked.featureIdToPointMarkers, fid, marker);
|
|
@@ -1053,7 +1107,7 @@ class GoogleMapsLayerPort {
|
|
|
1053
1107
|
else if (type === "MultiPoint") {
|
|
1054
1108
|
for (const coords of geometry.coordinates) {
|
|
1055
1109
|
const [lng, lat] = coords;
|
|
1056
|
-
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap);
|
|
1110
|
+
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap, config.interactive !== "none");
|
|
1057
1111
|
tracked.pointMarkers.push(marker);
|
|
1058
1112
|
if (fid !== undefined) {
|
|
1059
1113
|
this.pushToFeatureMap(tracked.featureIdToPointMarkers, fid, marker);
|
|
@@ -1277,6 +1331,24 @@ class GoogleMapsLayerPort {
|
|
|
1277
1331
|
if (existing !== undefined && esToolkit.isEqual(existing.config, config)) {
|
|
1278
1332
|
return;
|
|
1279
1333
|
}
|
|
1334
|
+
// Only the hit-target flag changed (a drawing mode started or stopped): toggle the
|
|
1335
|
+
// polyline's clickability and its listeners in place instead of recreating it.
|
|
1336
|
+
if (existing !== undefined && esToolkit.isEqual({ ...existing.config, interactive: config.interactive }, config)) {
|
|
1337
|
+
for (const listener of existing.listeners) {
|
|
1338
|
+
google.maps.event.removeListener(listener);
|
|
1339
|
+
}
|
|
1340
|
+
existing.listeners = [];
|
|
1341
|
+
existing.polyline.setOptions({ clickable: config.interactive });
|
|
1342
|
+
if (config.interactive) {
|
|
1343
|
+
const feature = config.features.features.find(candidate => reactMapAdapterShared.extractLineCoordinates(candidate) !== null);
|
|
1344
|
+
const fid = feature?.id !== undefined ? String(feature.id) : undefined;
|
|
1345
|
+
if (feature !== undefined && fid !== undefined) {
|
|
1346
|
+
this.attachRouteInteractionListeners(existing.polyline, fid, feature, existing);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
existing.config = config;
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1280
1352
|
// Remove existing route for this source (update case)
|
|
1281
1353
|
this.removeRouteSourceInternal(config.id);
|
|
1282
1354
|
const currentMap = this.map;
|
|
@@ -1955,6 +2027,8 @@ class GoogleMapsLayerPort {
|
|
|
1955
2027
|
canvas.addEventListener("dblclick", this.handleDblClick);
|
|
1956
2028
|
canvas.addEventListener("mousemove", this.handleMouseMove);
|
|
1957
2029
|
canvas.addEventListener("mouseleave", this.handleMouseLeave);
|
|
2030
|
+
tracked.canvasElement = canvas;
|
|
2031
|
+
layerPort.applyMarkerHitTesting(tracked);
|
|
1958
2032
|
}
|
|
1959
2033
|
draw() {
|
|
1960
2034
|
const canvas = this.canvas;
|
|
@@ -2116,6 +2190,7 @@ class GoogleMapsLayerPort {
|
|
|
2116
2190
|
this.canvas.removeEventListener("mouseleave", this.handleMouseLeave);
|
|
2117
2191
|
this.canvas.remove();
|
|
2118
2192
|
this.canvas = null;
|
|
2193
|
+
tracked.canvasElement = undefined;
|
|
2119
2194
|
}
|
|
2120
2195
|
drawnMarkers = [];
|
|
2121
2196
|
}
|
|
@@ -2188,6 +2263,8 @@ class GoogleMapsLayerPort {
|
|
|
2188
2263
|
// Build the custom cluster renderer
|
|
2189
2264
|
const layerPort = this;
|
|
2190
2265
|
const sourceId = config.id;
|
|
2266
|
+
const clustererMarkers = new Set();
|
|
2267
|
+
tracked.clustererMarkers = clustererMarkers;
|
|
2191
2268
|
const renderer = {
|
|
2192
2269
|
render(cluster, _stats, _map) {
|
|
2193
2270
|
const count = cluster.count;
|
|
@@ -2235,6 +2312,9 @@ class GoogleMapsLayerPort {
|
|
|
2235
2312
|
content,
|
|
2236
2313
|
zIndex: 1000 + count,
|
|
2237
2314
|
});
|
|
2315
|
+
clustererMarkers.add(clusterMarker);
|
|
2316
|
+
// Clusters are re-rendered on every zoom, so a cluster born while drawing must start inert.
|
|
2317
|
+
layerPort.setMarkerHitTarget(clusterMarker, tracked.config.kind !== "marker" || tracked.config.interactive);
|
|
2238
2318
|
// Cluster interaction listeners
|
|
2239
2319
|
const entity = {
|
|
2240
2320
|
type: "cluster",
|
|
@@ -2506,11 +2586,12 @@ class GoogleMapsLayerPort {
|
|
|
2506
2586
|
}
|
|
2507
2587
|
return polylines;
|
|
2508
2588
|
}
|
|
2509
|
-
createShapePointMarker(position, style, map) {
|
|
2589
|
+
createShapePointMarker(position, style, map, interactive) {
|
|
2510
2590
|
const diameter = (style.pointRadius ?? this.shapeStyleDefaults.point.pointRadius) * 2;
|
|
2511
2591
|
const el = document.createElement("div");
|
|
2512
2592
|
el.style.boxSizing = "content-box";
|
|
2513
|
-
|
|
2593
|
+
// A non-interactive source (drawing in progress) must let clicks through to the map.
|
|
2594
|
+
el.style.pointerEvents = interactive ? "auto" : "none";
|
|
2514
2595
|
el.style.width = `${diameter}px`;
|
|
2515
2596
|
el.style.height = `${diameter}px`;
|
|
2516
2597
|
el.style.borderRadius = "50%";
|
|
@@ -2521,7 +2602,10 @@ class GoogleMapsLayerPort {
|
|
|
2521
2602
|
el.style.borderStyle = "solid";
|
|
2522
2603
|
el.style.borderColor = reactMapColorUtils.colorWithOpacity(style.stroke ?? "#000", strokeOpacity);
|
|
2523
2604
|
el.style.transform = reactMapAdapterShared.anchorFromBottomCenter("center");
|
|
2524
|
-
|
|
2605
|
+
const marker = new google.maps.marker.AdvancedMarkerElement({ map, position, content: el });
|
|
2606
|
+
if (!interactive)
|
|
2607
|
+
reactMapAdapterShared.setHitTargetInert(marker.element, true);
|
|
2608
|
+
return marker;
|
|
2525
2609
|
}
|
|
2526
2610
|
// ============================================================================
|
|
2527
2611
|
// Private: Route creation
|
package/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { canPatchAdaptiveMarker, canPatchAdaptiveViewport, canPatchMarkerInPlace, extractPointCoordinates, mergeAntimeridianFeatures, extractPolygonPaths, extractLineCoordinates, patchPortalDescriptors, collectFeatureIdSet, removeGoneIndexedMarkers, getAdaptiveDomFeatureIds, extractSourceData, buildAdaptiveDomRenderFn, resolveCircleSymbolDefaults, resolveSymbolDescriptor, buildAdaptiveSymbolStyleFn, createSymbolDotElement, anchorFromBottomCenter, createDefaultClusterElement, createClusterPinElement, fadeInElement, buildAdaptiveDomEntries, MAP_CURSORS, resolveSelectedStyle, resolveHoveredStyle, attachSafeAreaHoverListeners, INITIAL_MAP_STATE, DEFAULT_MAP_APPEARANCE, computeInitialState, getEffectiveRestrictBounds, TRAFFIC_MIN_ZOOM, cameraStateEquals, isEventOfType, DEFAULT_ZOOM, DEFAULT_CENTER, defineAdapter } from '@trackunit/react-map-adapter-shared';
|
|
1
|
+
import { setHitTargetInert, canPatchAdaptiveMarker, canPatchAdaptiveViewport, canPatchMarkerInPlace, extractPointCoordinates, mergeAntimeridianFeatures, extractPolygonPaths, extractLineCoordinates, patchPortalDescriptors, collectFeatureIdSet, removeGoneIndexedMarkers, getAdaptiveDomFeatureIds, extractSourceData, buildAdaptiveDomRenderFn, resolveCircleSymbolDefaults, resolveSymbolDescriptor, buildAdaptiveSymbolStyleFn, createSymbolDotElement, anchorFromBottomCenter, createDefaultClusterElement, createClusterPinElement, fadeInElement, buildAdaptiveDomEntries, MAP_CURSORS, resolveSelectedStyle, resolveHoveredStyle, attachSafeAreaHoverListeners, INITIAL_MAP_STATE, DEFAULT_MAP_APPEARANCE, computeInitialState, getEffectiveRestrictBounds, TRAFFIC_MIN_ZOOM, cameraStateEquals, isEventOfType, DEFAULT_ZOOM, DEFAULT_CENTER, defineAdapter } from '@trackunit/react-map-adapter-shared';
|
|
2
2
|
export { googleMapCspDirectives } from '@trackunit/react-map-adapter-shared';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { APIProvider, RenderingType, APIProviderContext, useMap, useApiLoadingStatus, APILoadingStatus, Map as Map$1 } from '@vis.gl/react-google-maps';
|
|
5
5
|
import { useMemo, useCallback, useSyncExternalStore, useId, useContext, useEffect } from 'react';
|
|
6
6
|
import { validateBbox, validatePosition } from '@trackunit/geo-json-utils';
|
|
7
|
-
import { loadTerraDrawEngine,
|
|
7
|
+
import { DRAW_COORDINATE_PRECISION, loadTerraDrawEngine, withPointerCapture, DrawController } from '@trackunit/react-map-draw';
|
|
8
8
|
import { MarkerClusterer, SuperClusterAlgorithm } from '@googlemaps/markerclusterer';
|
|
9
9
|
import { colorWithOpacity } from '@trackunit/react-map-color-utils';
|
|
10
10
|
import { isEqual } from 'es-toolkit';
|
|
@@ -55,6 +55,10 @@ const GoogleApiProvider = ({ apiKey, language, children }) => {
|
|
|
55
55
|
return (jsx(APIProvider, { apiKey: apiKey, language: language, libraries: libraries, version: GOOGLE_MAPS_API_VERSION, children: children }));
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
const findMapEventElement = (adapter) => {
|
|
59
|
+
const element = adapter.getMapEventElement();
|
|
60
|
+
return element;
|
|
61
|
+
};
|
|
58
62
|
/**
|
|
59
63
|
* Builds the Google Maps bridge for the shared drawing engine (ADR 0030).
|
|
60
64
|
*
|
|
@@ -66,15 +70,20 @@ const GoogleApiProvider = ({ apiKey, language, children }) => {
|
|
|
66
70
|
*/
|
|
67
71
|
const createGoogleDrawEngineLoader = (map) => async () => {
|
|
68
72
|
const { TerraDrawGoogleMapsAdapter } = await import('terra-draw-google-maps-adapter');
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
const adapter = new TerraDrawGoogleMapsAdapter({
|
|
74
|
+
lib: google.maps,
|
|
75
|
+
map,
|
|
76
|
+
// Keep drawn features in their own Data layer so nothing else on the map
|
|
77
|
+
// (or a future layer port feature) shares styling or click handling with them.
|
|
78
|
+
isolatedData: true,
|
|
79
|
+
coordinatePrecision: DRAW_COORDINATE_PRECISION,
|
|
80
|
+
});
|
|
81
|
+
const engine = await loadTerraDrawEngine({ adapter });
|
|
82
|
+
// The adapter finds Google's event layer by an inline style (SAGA-985) and types the
|
|
83
|
+
// result as never missing; the capture treats a miss as "nothing to capture".
|
|
84
|
+
return withPointerCapture(engine, {
|
|
85
|
+
resolveElement: () => findMapEventElement(adapter),
|
|
86
|
+
resolveBounds: () => map.getDiv().getBoundingClientRect(),
|
|
78
87
|
});
|
|
79
88
|
};
|
|
80
89
|
|
|
@@ -761,6 +770,51 @@ class GoogleMapsLayerPort {
|
|
|
761
770
|
}
|
|
762
771
|
// ---- Marker sources ----
|
|
763
772
|
syncMarkerSource(config) {
|
|
773
|
+
this.renderMarkerSource(config);
|
|
774
|
+
const tracked = this.markerSources.get(config.id);
|
|
775
|
+
if (tracked !== undefined)
|
|
776
|
+
this.applyMarkerHitTesting(tracked);
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Marker hit testing follows `config.interactive` (ADR 0030): while a drawing mode is
|
|
780
|
+
* active, markers, clusters and the symbol canvas stay visible but stop receiving
|
|
781
|
+
* pointer events, so every click and every drag release reaches the drawing engine
|
|
782
|
+
* instead of a marker. The suspension goes on the advanced marker host, which Google
|
|
783
|
+
* keeps at `pointer-events: auto`, and the shared rule covers the content inside it.
|
|
784
|
+
*/
|
|
785
|
+
applyMarkerHitTesting(tracked) {
|
|
786
|
+
const { config } = tracked;
|
|
787
|
+
if (config.kind !== "marker")
|
|
788
|
+
return;
|
|
789
|
+
const { interactive } = config;
|
|
790
|
+
for (const marker of tracked.markers) {
|
|
791
|
+
this.setMarkerHitTarget(marker, interactive);
|
|
792
|
+
}
|
|
793
|
+
if (tracked.clustererMarkers !== undefined) {
|
|
794
|
+
for (const marker of tracked.clustererMarkers) {
|
|
795
|
+
// The clusterer retires a bubble by clearing its map (at once on a reset, a frame
|
|
796
|
+
// later for a replaced group) and attaches a new one in the tick that minted it.
|
|
797
|
+
// The DOM mounts it later, so being disconnected says nothing about retirement:
|
|
798
|
+
// pruning on that would forget a bubble born this frame and leave it stuck in
|
|
799
|
+
// whichever state it was born with.
|
|
800
|
+
if (marker.map === null || marker.map === undefined) {
|
|
801
|
+
tracked.clustererMarkers.delete(marker);
|
|
802
|
+
continue;
|
|
803
|
+
}
|
|
804
|
+
this.setMarkerHitTarget(marker, interactive);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if (tracked.canvasElement !== undefined) {
|
|
808
|
+
this.setHitTarget(tracked.canvasElement, interactive);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
setMarkerHitTarget(marker, interactive) {
|
|
812
|
+
this.setHitTarget(marker.element, interactive);
|
|
813
|
+
}
|
|
814
|
+
setHitTarget(element, interactive) {
|
|
815
|
+
setHitTargetInert(element, !interactive);
|
|
816
|
+
}
|
|
817
|
+
renderMarkerSource(config) {
|
|
764
818
|
if (this.map === null)
|
|
765
819
|
return;
|
|
766
820
|
// Skip full rebuild if config reference hasn't changed (same data, nothing to do)
|
|
@@ -1040,7 +1094,7 @@ class GoogleMapsLayerPort {
|
|
|
1040
1094
|
}
|
|
1041
1095
|
else if (type === "Point") {
|
|
1042
1096
|
const [lng, lat] = geometry.coordinates;
|
|
1043
|
-
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap);
|
|
1097
|
+
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap, config.interactive !== "none");
|
|
1044
1098
|
tracked.pointMarkers.push(marker);
|
|
1045
1099
|
if (fid !== undefined) {
|
|
1046
1100
|
this.pushToFeatureMap(tracked.featureIdToPointMarkers, fid, marker);
|
|
@@ -1052,7 +1106,7 @@ class GoogleMapsLayerPort {
|
|
|
1052
1106
|
else if (type === "MultiPoint") {
|
|
1053
1107
|
for (const coords of geometry.coordinates) {
|
|
1054
1108
|
const [lng, lat] = coords;
|
|
1055
|
-
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap);
|
|
1109
|
+
const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap, config.interactive !== "none");
|
|
1056
1110
|
tracked.pointMarkers.push(marker);
|
|
1057
1111
|
if (fid !== undefined) {
|
|
1058
1112
|
this.pushToFeatureMap(tracked.featureIdToPointMarkers, fid, marker);
|
|
@@ -1276,6 +1330,24 @@ class GoogleMapsLayerPort {
|
|
|
1276
1330
|
if (existing !== undefined && isEqual(existing.config, config)) {
|
|
1277
1331
|
return;
|
|
1278
1332
|
}
|
|
1333
|
+
// Only the hit-target flag changed (a drawing mode started or stopped): toggle the
|
|
1334
|
+
// polyline's clickability and its listeners in place instead of recreating it.
|
|
1335
|
+
if (existing !== undefined && isEqual({ ...existing.config, interactive: config.interactive }, config)) {
|
|
1336
|
+
for (const listener of existing.listeners) {
|
|
1337
|
+
google.maps.event.removeListener(listener);
|
|
1338
|
+
}
|
|
1339
|
+
existing.listeners = [];
|
|
1340
|
+
existing.polyline.setOptions({ clickable: config.interactive });
|
|
1341
|
+
if (config.interactive) {
|
|
1342
|
+
const feature = config.features.features.find(candidate => extractLineCoordinates(candidate) !== null);
|
|
1343
|
+
const fid = feature?.id !== undefined ? String(feature.id) : undefined;
|
|
1344
|
+
if (feature !== undefined && fid !== undefined) {
|
|
1345
|
+
this.attachRouteInteractionListeners(existing.polyline, fid, feature, existing);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
existing.config = config;
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1279
1351
|
// Remove existing route for this source (update case)
|
|
1280
1352
|
this.removeRouteSourceInternal(config.id);
|
|
1281
1353
|
const currentMap = this.map;
|
|
@@ -1954,6 +2026,8 @@ class GoogleMapsLayerPort {
|
|
|
1954
2026
|
canvas.addEventListener("dblclick", this.handleDblClick);
|
|
1955
2027
|
canvas.addEventListener("mousemove", this.handleMouseMove);
|
|
1956
2028
|
canvas.addEventListener("mouseleave", this.handleMouseLeave);
|
|
2029
|
+
tracked.canvasElement = canvas;
|
|
2030
|
+
layerPort.applyMarkerHitTesting(tracked);
|
|
1957
2031
|
}
|
|
1958
2032
|
draw() {
|
|
1959
2033
|
const canvas = this.canvas;
|
|
@@ -2115,6 +2189,7 @@ class GoogleMapsLayerPort {
|
|
|
2115
2189
|
this.canvas.removeEventListener("mouseleave", this.handleMouseLeave);
|
|
2116
2190
|
this.canvas.remove();
|
|
2117
2191
|
this.canvas = null;
|
|
2192
|
+
tracked.canvasElement = undefined;
|
|
2118
2193
|
}
|
|
2119
2194
|
drawnMarkers = [];
|
|
2120
2195
|
}
|
|
@@ -2187,6 +2262,8 @@ class GoogleMapsLayerPort {
|
|
|
2187
2262
|
// Build the custom cluster renderer
|
|
2188
2263
|
const layerPort = this;
|
|
2189
2264
|
const sourceId = config.id;
|
|
2265
|
+
const clustererMarkers = new Set();
|
|
2266
|
+
tracked.clustererMarkers = clustererMarkers;
|
|
2190
2267
|
const renderer = {
|
|
2191
2268
|
render(cluster, _stats, _map) {
|
|
2192
2269
|
const count = cluster.count;
|
|
@@ -2234,6 +2311,9 @@ class GoogleMapsLayerPort {
|
|
|
2234
2311
|
content,
|
|
2235
2312
|
zIndex: 1000 + count,
|
|
2236
2313
|
});
|
|
2314
|
+
clustererMarkers.add(clusterMarker);
|
|
2315
|
+
// Clusters are re-rendered on every zoom, so a cluster born while drawing must start inert.
|
|
2316
|
+
layerPort.setMarkerHitTarget(clusterMarker, tracked.config.kind !== "marker" || tracked.config.interactive);
|
|
2237
2317
|
// Cluster interaction listeners
|
|
2238
2318
|
const entity = {
|
|
2239
2319
|
type: "cluster",
|
|
@@ -2505,11 +2585,12 @@ class GoogleMapsLayerPort {
|
|
|
2505
2585
|
}
|
|
2506
2586
|
return polylines;
|
|
2507
2587
|
}
|
|
2508
|
-
createShapePointMarker(position, style, map) {
|
|
2588
|
+
createShapePointMarker(position, style, map, interactive) {
|
|
2509
2589
|
const diameter = (style.pointRadius ?? this.shapeStyleDefaults.point.pointRadius) * 2;
|
|
2510
2590
|
const el = document.createElement("div");
|
|
2511
2591
|
el.style.boxSizing = "content-box";
|
|
2512
|
-
|
|
2592
|
+
// A non-interactive source (drawing in progress) must let clicks through to the map.
|
|
2593
|
+
el.style.pointerEvents = interactive ? "auto" : "none";
|
|
2513
2594
|
el.style.width = `${diameter}px`;
|
|
2514
2595
|
el.style.height = `${diameter}px`;
|
|
2515
2596
|
el.style.borderRadius = "50%";
|
|
@@ -2520,7 +2601,10 @@ class GoogleMapsLayerPort {
|
|
|
2520
2601
|
el.style.borderStyle = "solid";
|
|
2521
2602
|
el.style.borderColor = colorWithOpacity(style.stroke ?? "#000", strokeOpacity);
|
|
2522
2603
|
el.style.transform = anchorFromBottomCenter("center");
|
|
2523
|
-
|
|
2604
|
+
const marker = new google.maps.marker.AdvancedMarkerElement({ map, position, content: el });
|
|
2605
|
+
if (!interactive)
|
|
2606
|
+
setHitTargetInert(marker.element, true);
|
|
2607
|
+
return marker;
|
|
2524
2608
|
}
|
|
2525
2609
|
// ============================================================================
|
|
2526
2610
|
// Private: Route creation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-map-adapter-google",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.192",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"@loaders.gl/core": "~4.5.2",
|
|
15
15
|
"@luma.gl/core": "^9.4.1",
|
|
16
16
|
"@luma.gl/engine": "^9.4.1",
|
|
17
|
-
"@trackunit/react-map-adapter-shared": "0.0.
|
|
18
|
-
"@trackunit/react-map-color-utils": "0.0.
|
|
19
|
-
"@trackunit/geo-json-utils": "1.21.
|
|
17
|
+
"@trackunit/react-map-adapter-shared": "0.0.202",
|
|
18
|
+
"@trackunit/react-map-color-utils": "0.0.176",
|
|
19
|
+
"@trackunit/geo-json-utils": "1.21.35",
|
|
20
20
|
"@googlemaps/markerclusterer": "^2.6.2",
|
|
21
21
|
"@vis.gl/react-google-maps": "^1.7.1",
|
|
22
22
|
"es-toolkit": "^1.52.0",
|
|
23
23
|
"react-device-detect": "^2.2.3",
|
|
24
24
|
"zod": "^3.25.76",
|
|
25
|
-
"@trackunit/react-map-draw": "0.0.
|
|
25
|
+
"@trackunit/react-map-draw": "0.0.40",
|
|
26
26
|
"terra-draw-google-maps-adapter": "^1.6.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -107,6 +107,17 @@ export declare class GoogleMapsLayerPort implements LayerPort {
|
|
|
107
107
|
destroy(): void;
|
|
108
108
|
private applySnapshot;
|
|
109
109
|
private syncMarkerSource;
|
|
110
|
+
/**
|
|
111
|
+
* Marker hit testing follows `config.interactive` (ADR 0030): while a drawing mode is
|
|
112
|
+
* active, markers, clusters and the symbol canvas stay visible but stop receiving
|
|
113
|
+
* pointer events, so every click and every drag release reaches the drawing engine
|
|
114
|
+
* instead of a marker. The suspension goes on the advanced marker host, which Google
|
|
115
|
+
* keeps at `pointer-events: auto`, and the shared rule covers the content inside it.
|
|
116
|
+
*/
|
|
117
|
+
private applyMarkerHitTesting;
|
|
118
|
+
private setMarkerHitTarget;
|
|
119
|
+
private setHitTarget;
|
|
120
|
+
private renderMarkerSource;
|
|
110
121
|
private removeMarkerSourceInternal;
|
|
111
122
|
private syncShapeSource;
|
|
112
123
|
/** Deep equality for clipped fill overrides — map emissions create new Map refs every time. */
|