@trackunit/react-map-adapter-google 0.0.197-alpha-375f337cfb9.0 → 0.0.198

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 CHANGED
@@ -29,6 +29,10 @@ const GOOGLE_MAP_IDS = {
29
29
  *
30
30
  * Temporary: Google deletes numbered versions after ~3 quarters. Remove the pin once
31
31
  * `HeatmapLayer` and `DrawingManager` usages are migrated to replacements.
32
+ *
33
+ * Checklist for every change of this version: draw a polygon on both the Create Site
34
+ * wizard map and the react-map Storybook `useDraw` story (why: ADR 0030, open items,
35
+ * SAGA-985).
32
36
  */
33
37
  const GOOGLE_MAPS_API_VERSION = "3.64";
34
38
 
@@ -56,18 +60,93 @@ const GoogleApiProvider = ({ apiKey, language, children }) => {
56
60
  return (jsxRuntime.jsx(reactGoogleMaps.APIProvider, { apiKey: apiKey, language: language, libraries: libraries, version: GOOGLE_MAPS_API_VERSION, children: children }));
57
61
  };
58
62
 
63
+ /**
64
+ * The engine could not be built because the element `terra-draw-google-maps-adapter`
65
+ * listens on is not in the map container. Surfaces as the `cause` of the
66
+ * `DrawController`'s `engine-load-failed` error (ADR 0030, open items, SAGA-985).
67
+ */
68
+ class GoogleDrawEventLayerMissingError extends Error {
69
+ constructor() {
70
+ super("Google Maps event layer not found after waiting for the map to render its panes (SAGA-985)");
71
+ this.name = "GoogleDrawEventLayerMissingError";
72
+ }
73
+ }
74
+ /**
75
+ * How long a map gets to render its panes after the probe first misses before the
76
+ * loader gives up. The loader runs once `GoogleMapsAdapterInstance` has connected it,
77
+ * on the map's first `idle` or after its own fallback timer; the observer below then
78
+ * resolves as soon as the panes appear, and on a hidden or zero-sized map they may never
79
+ * appear, so this bound is what keeps the loader promise settling and the controller's
80
+ * "loads again on the next mode or value change" true.
81
+ */
82
+ const PANES_RENDER_TIMEOUT_MS = 1000;
83
+ /**
84
+ * The adapter finds Google's event layer by an inline style (`z-index: 3`) that no Google
85
+ * Maps API documents, and types the lookup as never missing (SAGA-985). Callers treat a
86
+ * miss as "no element": the loader refuses to build an engine, the capture has nothing
87
+ * to capture.
88
+ */
59
89
  const findMapEventElement = (adapter) => {
60
90
  const element = adapter.getMapEventElement();
61
91
  return element;
62
92
  };
93
+ /**
94
+ * Resolves with the element as soon as a DOM change inside `container` makes `probe`
95
+ * find it, or with `probe`'s answer after `PANES_RENDER_TIMEOUT_MS`, whichever comes
96
+ * first. Inline `style` changes are observed too, because the adapter's selector
97
+ * matches a style, not an element. The observer is registered before the timer is
98
+ * armed, and whichever side settles first disconnects the other; `probe` runs the
99
+ * adapter's full-subtree selector, so a burst of mutations (Google inserting tiles) is
100
+ * checked once per animation frame.
101
+ */
102
+ const waitForEventLayer = (container, probe) => new Promise(resolve => {
103
+ let settled = false;
104
+ let frame = null;
105
+ const settle = (element) => {
106
+ if (settled)
107
+ return;
108
+ settled = true;
109
+ observer.disconnect();
110
+ clearTimeout(timer);
111
+ if (frame !== null)
112
+ cancelAnimationFrame(frame);
113
+ resolve(element);
114
+ };
115
+ const observer = new MutationObserver(() => {
116
+ if (frame !== null)
117
+ return;
118
+ frame = requestAnimationFrame(() => {
119
+ frame = null;
120
+ const element = probe();
121
+ if (element !== null)
122
+ settle(element);
123
+ });
124
+ });
125
+ observer.observe(container, { childList: true, subtree: true, attributes: true, attributeFilter: ["style"] });
126
+ const timer = setTimeout(() => settle(probe()), PANES_RENDER_TIMEOUT_MS);
127
+ });
63
128
  /**
64
129
  * Builds the Google Maps bridge for the shared drawing engine (ADR 0030).
65
130
  *
66
131
  * One loader per `google.maps.Map` instance: theme switches and traffic toggles
67
- * recreate the map, and `GoogleMapsAdapterInstance.connect` hands the controller a
68
- * fresh loader each time so the engine is rebuilt on the live map. Terra Draw and its
69
- * Google adapter are only downloaded when the loader runs, which the controller
70
- * defers until drawing is actually needed.
132
+ * recreate the map, and `GoogleMapsAdapterInstance` hands the controller a fresh loader
133
+ * on each map's first `idle`, or after its `DRAW_CONNECT_TIMEOUT_MS` fallback for a map
134
+ * that never goes idle, so the engine is rebuilt on the live map once Google has built
135
+ * it. Terra Draw and its Google adapter are only downloaded when the loader runs, which
136
+ * the controller defers until drawing is actually needed.
137
+ *
138
+ * Readiness probe, the second line after that gate: before the engine is built,
139
+ * the loader looks for the event layer the adapter will listen on. A miss watches the
140
+ * map container for the layer to appear, bounded by `PANES_RENDER_TIMEOUT_MS`, and
141
+ * probes once more; a miss after that rejects with `GoogleDrawEventLayerMissingError`,
142
+ * which the `DrawController` reports as `engine-load-failed`, and the controller loads
143
+ * again on the next connect, mode or value change. There is no retry loop. The wait is
144
+ * not cancelled by a disconnect: the observer goes with the layer or the timer, and an
145
+ * engine built for a map the controller has left is destroyed by its generation check,
146
+ * the same cost as a slow chunk download. The failure path downloads the adapter chunk
147
+ * and constructs an adapter only to run its selector; that is accepted, because the
148
+ * selector is the adapter's to own and a copy of it here would drift from it. History,
149
+ * the Maps JS version checklist and the upstream fix: ADR 0030, open items (SAGA-985).
71
150
  */
72
151
  const createGoogleDrawEngineLoader = (map) => async () => {
73
152
  const { TerraDrawGoogleMapsAdapter } = await import('terra-draw-google-maps-adapter');
@@ -79,11 +158,14 @@ const createGoogleDrawEngineLoader = (map) => async () => {
79
158
  isolatedData: true,
80
159
  coordinatePrecision: reactMapDraw.DRAW_COORDINATE_PRECISION,
81
160
  });
161
+ const probe = () => findMapEventElement(adapter);
162
+ const element = probe() ?? (await waitForEventLayer(map.getDiv(), probe));
163
+ if (element === null) {
164
+ throw new GoogleDrawEventLayerMissingError();
165
+ }
82
166
  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
167
  return reactMapDraw.withPointerCapture(engine, {
86
- resolveElement: () => findMapEventElement(adapter),
168
+ resolveElement: probe,
87
169
  resolveBounds: () => map.getDiv().getBoundingClientRect(),
88
170
  });
89
171
  };
@@ -2987,6 +3069,14 @@ class GoogleMapsLayerPort {
2987
3069
  }
2988
3070
  GoogleMapsLayerPort.DBLCLICK_THRESHOLD_MS = 400;
2989
3071
 
3072
+ /**
3073
+ * How long a connected map gets to fire its first `idle` before the draw loader is
3074
+ * connected anyway (ADR 0030, SAGA-985). A visible map goes idle within a frame or two
3075
+ * of its first render, so three seconds covers a slow tile fetch on a weak connection
3076
+ * without leaving a hidden or stalled map's drawing disconnected (no engine, no error,
3077
+ * no hint) for longer than that; past it the loader's own probe and bound decide.
3078
+ */
3079
+ const DRAW_CONNECT_TIMEOUT_MS = 3000;
2990
3080
  /**
2991
3081
  * Google Maps adapter instance implementation
2992
3082
  * Manages the connection between our abstract interface and Google Maps API
@@ -3014,6 +3104,14 @@ class GoogleMapsAdapterInstance {
3014
3104
  this.statusListeners = new Set();
3015
3105
  this.eventListeners = new Map();
3016
3106
  this.googleEventListeners = [];
3107
+ /**
3108
+ * The one-shot `idle` hook and its fallback timer that connect the draw loader once
3109
+ * Google has built the map, or after `DRAW_CONNECT_TIMEOUT_MS` if it never says so;
3110
+ * whichever fires first connects once, and both are cancelled with the other map
3111
+ * listeners so a map that is gone never connects a stale loader (ADR 0030, SAGA-985).
3112
+ */
3113
+ this.pendingDrawConnect = null;
3114
+ this.pendingDrawConnectTimer = null;
3017
3115
  /** Throttled pointermove channel shared by map mousemove and shape overlay mousemove. */
3018
3116
  this.pointerMoveRaf = null;
3019
3117
  this.lastPointerPosition = null;
@@ -3100,9 +3198,11 @@ class GoogleMapsAdapterInstance {
3100
3198
  this.updateStatusCache();
3101
3199
  this.layers.connect(map);
3102
3200
  // Theme changes recreate the google.maps.Map, so traffic and drawing must re-attach on every (re)connect.
3103
- // The draw controller rebuilds its engine from the committed value on the new map (ADR 0030).
3201
+ // The draw controller keeps mode and value while disconnected and rebuilds its engine from the
3202
+ // committed value on the new map once it first goes idle (ADR 0030): the loader is connected from
3203
+ // the one-shot idle hook in setupEventListeners, not here.
3104
3204
  this.syncTrafficLayer();
3105
- this.draw.connect(createGoogleDrawEngineLoader(map));
3205
+ this.draw.disconnect();
3106
3206
  this.setupEventListeners();
3107
3207
  this.layers.setPointerMoveReporter(position => {
3108
3208
  this.reportPointerMove(position);
@@ -3379,6 +3479,7 @@ class GoogleMapsAdapterInstance {
3379
3479
  google.maps.event.removeListener(listener);
3380
3480
  });
3381
3481
  this.googleEventListeners = [];
3482
+ this.cancelPendingDrawConnect();
3382
3483
  if (this.pointerMoveRaf !== null) {
3383
3484
  cancelAnimationFrame(this.pointerMoveRaf);
3384
3485
  this.pointerMoveRaf = null;
@@ -3405,6 +3506,16 @@ class GoogleMapsAdapterInstance {
3405
3506
  this.updateState(true);
3406
3507
  this.emitEvent({ type: "idle" });
3407
3508
  }));
3509
+ // Drawing connects on the map's first idle, once Google has built the map and its
3510
+ // panes exist for the engine to listen on, or after DRAW_CONNECT_TIMEOUT_MS for a map
3511
+ // that never says so (hidden, zero-sized, stalled); the loader's probe and bound then
3512
+ // decide between a live engine and engine-load-failed (ADR 0030, SAGA-985).
3513
+ const connectDraw = () => {
3514
+ this.cancelPendingDrawConnect();
3515
+ this.draw.connect(createGoogleDrawEngineLoader(currentMap));
3516
+ };
3517
+ this.pendingDrawConnect = currentMap.addListener("idle", connectDraw);
3518
+ this.pendingDrawConnectTimer = setTimeout(connectDraw, DRAW_CONNECT_TIMEOUT_MS);
3408
3519
  const markCameraActive = () => {
3409
3520
  if (this.state.isIdle) {
3410
3521
  this.state = { ...this.state, isIdle: false };
@@ -3448,6 +3559,14 @@ class GoogleMapsAdapterInstance {
3448
3559
  this.reportPointerMove(latLngToPosition(latLng));
3449
3560
  }));
3450
3561
  }
3562
+ cancelPendingDrawConnect() {
3563
+ this.pendingDrawConnect?.remove();
3564
+ this.pendingDrawConnect = null;
3565
+ if (this.pendingDrawConnectTimer !== null) {
3566
+ clearTimeout(this.pendingDrawConnectTimer);
3567
+ this.pendingDrawConnectTimer = null;
3568
+ }
3569
+ }
3451
3570
  updateState(isIdle) {
3452
3571
  const currentMap = this.map;
3453
3572
  if (currentMap === null)
package/index.esm.js CHANGED
@@ -28,6 +28,10 @@ const GOOGLE_MAP_IDS = {
28
28
  *
29
29
  * Temporary: Google deletes numbered versions after ~3 quarters. Remove the pin once
30
30
  * `HeatmapLayer` and `DrawingManager` usages are migrated to replacements.
31
+ *
32
+ * Checklist for every change of this version: draw a polygon on both the Create Site
33
+ * wizard map and the react-map Storybook `useDraw` story (why: ADR 0030, open items,
34
+ * SAGA-985).
31
35
  */
32
36
  const GOOGLE_MAPS_API_VERSION = "3.64";
33
37
 
@@ -55,18 +59,93 @@ const GoogleApiProvider = ({ apiKey, language, children }) => {
55
59
  return (jsx(APIProvider, { apiKey: apiKey, language: language, libraries: libraries, version: GOOGLE_MAPS_API_VERSION, children: children }));
56
60
  };
57
61
 
62
+ /**
63
+ * The engine could not be built because the element `terra-draw-google-maps-adapter`
64
+ * listens on is not in the map container. Surfaces as the `cause` of the
65
+ * `DrawController`'s `engine-load-failed` error (ADR 0030, open items, SAGA-985).
66
+ */
67
+ class GoogleDrawEventLayerMissingError extends Error {
68
+ constructor() {
69
+ super("Google Maps event layer not found after waiting for the map to render its panes (SAGA-985)");
70
+ this.name = "GoogleDrawEventLayerMissingError";
71
+ }
72
+ }
73
+ /**
74
+ * How long a map gets to render its panes after the probe first misses before the
75
+ * loader gives up. The loader runs once `GoogleMapsAdapterInstance` has connected it,
76
+ * on the map's first `idle` or after its own fallback timer; the observer below then
77
+ * resolves as soon as the panes appear, and on a hidden or zero-sized map they may never
78
+ * appear, so this bound is what keeps the loader promise settling and the controller's
79
+ * "loads again on the next mode or value change" true.
80
+ */
81
+ const PANES_RENDER_TIMEOUT_MS = 1000;
82
+ /**
83
+ * The adapter finds Google's event layer by an inline style (`z-index: 3`) that no Google
84
+ * Maps API documents, and types the lookup as never missing (SAGA-985). Callers treat a
85
+ * miss as "no element": the loader refuses to build an engine, the capture has nothing
86
+ * to capture.
87
+ */
58
88
  const findMapEventElement = (adapter) => {
59
89
  const element = adapter.getMapEventElement();
60
90
  return element;
61
91
  };
92
+ /**
93
+ * Resolves with the element as soon as a DOM change inside `container` makes `probe`
94
+ * find it, or with `probe`'s answer after `PANES_RENDER_TIMEOUT_MS`, whichever comes
95
+ * first. Inline `style` changes are observed too, because the adapter's selector
96
+ * matches a style, not an element. The observer is registered before the timer is
97
+ * armed, and whichever side settles first disconnects the other; `probe` runs the
98
+ * adapter's full-subtree selector, so a burst of mutations (Google inserting tiles) is
99
+ * checked once per animation frame.
100
+ */
101
+ const waitForEventLayer = (container, probe) => new Promise(resolve => {
102
+ let settled = false;
103
+ let frame = null;
104
+ const settle = (element) => {
105
+ if (settled)
106
+ return;
107
+ settled = true;
108
+ observer.disconnect();
109
+ clearTimeout(timer);
110
+ if (frame !== null)
111
+ cancelAnimationFrame(frame);
112
+ resolve(element);
113
+ };
114
+ const observer = new MutationObserver(() => {
115
+ if (frame !== null)
116
+ return;
117
+ frame = requestAnimationFrame(() => {
118
+ frame = null;
119
+ const element = probe();
120
+ if (element !== null)
121
+ settle(element);
122
+ });
123
+ });
124
+ observer.observe(container, { childList: true, subtree: true, attributes: true, attributeFilter: ["style"] });
125
+ const timer = setTimeout(() => settle(probe()), PANES_RENDER_TIMEOUT_MS);
126
+ });
62
127
  /**
63
128
  * Builds the Google Maps bridge for the shared drawing engine (ADR 0030).
64
129
  *
65
130
  * One loader per `google.maps.Map` instance: theme switches and traffic toggles
66
- * recreate the map, and `GoogleMapsAdapterInstance.connect` hands the controller a
67
- * fresh loader each time so the engine is rebuilt on the live map. Terra Draw and its
68
- * Google adapter are only downloaded when the loader runs, which the controller
69
- * defers until drawing is actually needed.
131
+ * recreate the map, and `GoogleMapsAdapterInstance` hands the controller a fresh loader
132
+ * on each map's first `idle`, or after its `DRAW_CONNECT_TIMEOUT_MS` fallback for a map
133
+ * that never goes idle, so the engine is rebuilt on the live map once Google has built
134
+ * it. Terra Draw and its Google adapter are only downloaded when the loader runs, which
135
+ * the controller defers until drawing is actually needed.
136
+ *
137
+ * Readiness probe, the second line after that gate: before the engine is built,
138
+ * the loader looks for the event layer the adapter will listen on. A miss watches the
139
+ * map container for the layer to appear, bounded by `PANES_RENDER_TIMEOUT_MS`, and
140
+ * probes once more; a miss after that rejects with `GoogleDrawEventLayerMissingError`,
141
+ * which the `DrawController` reports as `engine-load-failed`, and the controller loads
142
+ * again on the next connect, mode or value change. There is no retry loop. The wait is
143
+ * not cancelled by a disconnect: the observer goes with the layer or the timer, and an
144
+ * engine built for a map the controller has left is destroyed by its generation check,
145
+ * the same cost as a slow chunk download. The failure path downloads the adapter chunk
146
+ * and constructs an adapter only to run its selector; that is accepted, because the
147
+ * selector is the adapter's to own and a copy of it here would drift from it. History,
148
+ * the Maps JS version checklist and the upstream fix: ADR 0030, open items (SAGA-985).
70
149
  */
71
150
  const createGoogleDrawEngineLoader = (map) => async () => {
72
151
  const { TerraDrawGoogleMapsAdapter } = await import('terra-draw-google-maps-adapter');
@@ -78,11 +157,14 @@ const createGoogleDrawEngineLoader = (map) => async () => {
78
157
  isolatedData: true,
79
158
  coordinatePrecision: DRAW_COORDINATE_PRECISION,
80
159
  });
160
+ const probe = () => findMapEventElement(adapter);
161
+ const element = probe() ?? (await waitForEventLayer(map.getDiv(), probe));
162
+ if (element === null) {
163
+ throw new GoogleDrawEventLayerMissingError();
164
+ }
81
165
  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
166
  return withPointerCapture(engine, {
85
- resolveElement: () => findMapEventElement(adapter),
167
+ resolveElement: probe,
86
168
  resolveBounds: () => map.getDiv().getBoundingClientRect(),
87
169
  });
88
170
  };
@@ -2986,6 +3068,14 @@ class GoogleMapsLayerPort {
2986
3068
  }
2987
3069
  GoogleMapsLayerPort.DBLCLICK_THRESHOLD_MS = 400;
2988
3070
 
3071
+ /**
3072
+ * How long a connected map gets to fire its first `idle` before the draw loader is
3073
+ * connected anyway (ADR 0030, SAGA-985). A visible map goes idle within a frame or two
3074
+ * of its first render, so three seconds covers a slow tile fetch on a weak connection
3075
+ * without leaving a hidden or stalled map's drawing disconnected (no engine, no error,
3076
+ * no hint) for longer than that; past it the loader's own probe and bound decide.
3077
+ */
3078
+ const DRAW_CONNECT_TIMEOUT_MS = 3000;
2989
3079
  /**
2990
3080
  * Google Maps adapter instance implementation
2991
3081
  * Manages the connection between our abstract interface and Google Maps API
@@ -3013,6 +3103,14 @@ class GoogleMapsAdapterInstance {
3013
3103
  this.statusListeners = new Set();
3014
3104
  this.eventListeners = new Map();
3015
3105
  this.googleEventListeners = [];
3106
+ /**
3107
+ * The one-shot `idle` hook and its fallback timer that connect the draw loader once
3108
+ * Google has built the map, or after `DRAW_CONNECT_TIMEOUT_MS` if it never says so;
3109
+ * whichever fires first connects once, and both are cancelled with the other map
3110
+ * listeners so a map that is gone never connects a stale loader (ADR 0030, SAGA-985).
3111
+ */
3112
+ this.pendingDrawConnect = null;
3113
+ this.pendingDrawConnectTimer = null;
3016
3114
  /** Throttled pointermove channel shared by map mousemove and shape overlay mousemove. */
3017
3115
  this.pointerMoveRaf = null;
3018
3116
  this.lastPointerPosition = null;
@@ -3099,9 +3197,11 @@ class GoogleMapsAdapterInstance {
3099
3197
  this.updateStatusCache();
3100
3198
  this.layers.connect(map);
3101
3199
  // Theme changes recreate the google.maps.Map, so traffic and drawing must re-attach on every (re)connect.
3102
- // The draw controller rebuilds its engine from the committed value on the new map (ADR 0030).
3200
+ // The draw controller keeps mode and value while disconnected and rebuilds its engine from the
3201
+ // committed value on the new map once it first goes idle (ADR 0030): the loader is connected from
3202
+ // the one-shot idle hook in setupEventListeners, not here.
3103
3203
  this.syncTrafficLayer();
3104
- this.draw.connect(createGoogleDrawEngineLoader(map));
3204
+ this.draw.disconnect();
3105
3205
  this.setupEventListeners();
3106
3206
  this.layers.setPointerMoveReporter(position => {
3107
3207
  this.reportPointerMove(position);
@@ -3378,6 +3478,7 @@ class GoogleMapsAdapterInstance {
3378
3478
  google.maps.event.removeListener(listener);
3379
3479
  });
3380
3480
  this.googleEventListeners = [];
3481
+ this.cancelPendingDrawConnect();
3381
3482
  if (this.pointerMoveRaf !== null) {
3382
3483
  cancelAnimationFrame(this.pointerMoveRaf);
3383
3484
  this.pointerMoveRaf = null;
@@ -3404,6 +3505,16 @@ class GoogleMapsAdapterInstance {
3404
3505
  this.updateState(true);
3405
3506
  this.emitEvent({ type: "idle" });
3406
3507
  }));
3508
+ // Drawing connects on the map's first idle, once Google has built the map and its
3509
+ // panes exist for the engine to listen on, or after DRAW_CONNECT_TIMEOUT_MS for a map
3510
+ // that never says so (hidden, zero-sized, stalled); the loader's probe and bound then
3511
+ // decide between a live engine and engine-load-failed (ADR 0030, SAGA-985).
3512
+ const connectDraw = () => {
3513
+ this.cancelPendingDrawConnect();
3514
+ this.draw.connect(createGoogleDrawEngineLoader(currentMap));
3515
+ };
3516
+ this.pendingDrawConnect = currentMap.addListener("idle", connectDraw);
3517
+ this.pendingDrawConnectTimer = setTimeout(connectDraw, DRAW_CONNECT_TIMEOUT_MS);
3407
3518
  const markCameraActive = () => {
3408
3519
  if (this.state.isIdle) {
3409
3520
  this.state = { ...this.state, isIdle: false };
@@ -3447,6 +3558,14 @@ class GoogleMapsAdapterInstance {
3447
3558
  this.reportPointerMove(latLngToPosition(latLng));
3448
3559
  }));
3449
3560
  }
3561
+ cancelPendingDrawConnect() {
3562
+ this.pendingDrawConnect?.remove();
3563
+ this.pendingDrawConnect = null;
3564
+ if (this.pendingDrawConnectTimer !== null) {
3565
+ clearTimeout(this.pendingDrawConnectTimer);
3566
+ this.pendingDrawConnectTimer = null;
3567
+ }
3568
+ }
3450
3569
  updateState(isIdle) {
3451
3570
  const currentMap = this.map;
3452
3571
  if (currentMap === null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-map-adapter-google",
3
- "version": "0.0.197-alpha-375f337cfb9.0",
3
+ "version": "0.0.198",
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.207-alpha-375f337cfb9.0",
18
- "@trackunit/react-map-color-utils": "0.0.181-alpha-375f337cfb9.0",
19
- "@trackunit/geo-json-utils": "1.21.40-alpha-375f337cfb9.0",
17
+ "@trackunit/react-map-adapter-shared": "0.0.208",
18
+ "@trackunit/react-map-color-utils": "0.0.182",
19
+ "@trackunit/geo-json-utils": "1.21.41",
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.45-alpha-375f337cfb9.0",
25
+ "@trackunit/react-map-draw": "0.0.46",
26
26
  "terra-draw-google-maps-adapter": "^1.6.2"
27
27
  },
28
28
  "peerDependencies": {
@@ -1,6 +1,14 @@
1
1
  import { type AdapterInstance, type BaseAdapterConfig, type CameraState, type FitBoundsOptions, type GeoJsonBbox, type GeoJsonPosition, type MapEvent, type MapEventHandler, type MapStatus, type MapTheme, type MapType } from "@trackunit/react-map-adapter-shared";
2
2
  import { DrawController } from "@trackunit/react-map-draw";
3
3
  import { GoogleMapsLayerPort } from "./GoogleMapsLayerPort";
4
+ /**
5
+ * How long a connected map gets to fire its first `idle` before the draw loader is
6
+ * connected anyway (ADR 0030, SAGA-985). A visible map goes idle within a frame or two
7
+ * of its first render, so three seconds covers a slow tile fetch on a weak connection
8
+ * without leaving a hidden or stalled map's drawing disconnected (no engine, no error,
9
+ * no hint) for longer than that; past it the loader's own probe and bound decide.
10
+ */
11
+ export declare const DRAW_CONNECT_TIMEOUT_MS = 3000;
4
12
  /**
5
13
  * Configuration for Google Maps adapter
6
14
  */
@@ -36,6 +44,14 @@ export declare class GoogleMapsAdapterInstance implements AdapterInstance {
36
44
  private readonly statusListeners;
37
45
  private readonly eventListeners;
38
46
  private googleEventListeners;
47
+ /**
48
+ * The one-shot `idle` hook and its fallback timer that connect the draw loader once
49
+ * Google has built the map, or after `DRAW_CONNECT_TIMEOUT_MS` if it never says so;
50
+ * whichever fires first connects once, and both are cancelled with the other map
51
+ * listeners so a map that is gone never connects a stale loader (ADR 0030, SAGA-985).
52
+ */
53
+ private pendingDrawConnect;
54
+ private pendingDrawConnectTimer;
39
55
  /** Throttled pointermove channel shared by map mousemove and shape overlay mousemove. */
40
56
  private pointerMoveRaf;
41
57
  private lastPointerPosition;
@@ -106,6 +122,7 @@ export declare class GoogleMapsAdapterInstance implements AdapterInstance {
106
122
  /** Emit a throttled pointermove event (map canvas + shape overlays). */
107
123
  private reportPointerMove;
108
124
  private setupEventListeners;
125
+ private cancelPendingDrawConnect;
109
126
  private updateState;
110
127
  private mapTypeToGoogleMapTypeId;
111
128
  private updateCameraCache;
@@ -15,5 +15,9 @@ export declare const GOOGLE_MAP_IDS: {
15
15
  *
16
16
  * Temporary: Google deletes numbered versions after ~3 quarters. Remove the pin once
17
17
  * `HeatmapLayer` and `DrawingManager` usages are migrated to replacements.
18
+ *
19
+ * Checklist for every change of this version: draw a polygon on both the Create Site
20
+ * wizard map and the react-map Storybook `useDraw` story (why: ADR 0030, open items,
21
+ * SAGA-985).
18
22
  */
19
23
  export declare const GOOGLE_MAPS_API_VERSION = "3.64";
@@ -1,11 +1,42 @@
1
1
  import { type DrawEngineLoader } from "@trackunit/react-map-draw";
2
+ /**
3
+ * The engine could not be built because the element `terra-draw-google-maps-adapter`
4
+ * listens on is not in the map container. Surfaces as the `cause` of the
5
+ * `DrawController`'s `engine-load-failed` error (ADR 0030, open items, SAGA-985).
6
+ */
7
+ export declare class GoogleDrawEventLayerMissingError extends Error {
8
+ constructor();
9
+ }
10
+ /**
11
+ * How long a map gets to render its panes after the probe first misses before the
12
+ * loader gives up. The loader runs once `GoogleMapsAdapterInstance` has connected it,
13
+ * on the map's first `idle` or after its own fallback timer; the observer below then
14
+ * resolves as soon as the panes appear, and on a hidden or zero-sized map they may never
15
+ * appear, so this bound is what keeps the loader promise settling and the controller's
16
+ * "loads again on the next mode or value change" true.
17
+ */
18
+ export declare const PANES_RENDER_TIMEOUT_MS = 1000;
2
19
  /**
3
20
  * Builds the Google Maps bridge for the shared drawing engine (ADR 0030).
4
21
  *
5
22
  * One loader per `google.maps.Map` instance: theme switches and traffic toggles
6
- * recreate the map, and `GoogleMapsAdapterInstance.connect` hands the controller a
7
- * fresh loader each time so the engine is rebuilt on the live map. Terra Draw and its
8
- * Google adapter are only downloaded when the loader runs, which the controller
9
- * defers until drawing is actually needed.
23
+ * recreate the map, and `GoogleMapsAdapterInstance` hands the controller a fresh loader
24
+ * on each map's first `idle`, or after its `DRAW_CONNECT_TIMEOUT_MS` fallback for a map
25
+ * that never goes idle, so the engine is rebuilt on the live map once Google has built
26
+ * it. Terra Draw and its Google adapter are only downloaded when the loader runs, which
27
+ * the controller defers until drawing is actually needed.
28
+ *
29
+ * Readiness probe, the second line after that gate: before the engine is built,
30
+ * the loader looks for the event layer the adapter will listen on. A miss watches the
31
+ * map container for the layer to appear, bounded by `PANES_RENDER_TIMEOUT_MS`, and
32
+ * probes once more; a miss after that rejects with `GoogleDrawEventLayerMissingError`,
33
+ * which the `DrawController` reports as `engine-load-failed`, and the controller loads
34
+ * again on the next connect, mode or value change. There is no retry loop. The wait is
35
+ * not cancelled by a disconnect: the observer goes with the layer or the timer, and an
36
+ * engine built for a map the controller has left is destroyed by its generation check,
37
+ * the same cost as a slow chunk download. The failure path downloads the adapter chunk
38
+ * and constructs an adapter only to run its selector; that is accepted, because the
39
+ * selector is the adapter's to own and a copy of it here would drift from it. History,
40
+ * the Maps JS version checklist and the upstream fix: ADR 0030, open items (SAGA-985).
10
41
  */
11
42
  export declare const createGoogleDrawEngineLoader: (map: google.maps.Map) => DrawEngineLoader;