@trackunit/react-map-adapter-google 0.0.201-alpha-b8d3d323d1a.0 → 0.0.202

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.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { setHitTargetInert, canPatchAdaptiveMarker, canPatchAdaptiveViewport, canPatchMarkerInPlace, extractPointCoordinates, mergeAntimeridianFeatures, extractPolygonPaths, extractLineCoordinates, patchPortalDescriptors, collectFeatureIdSet, removeGoneIndexedMarkers, getAdaptiveDomFeatureIds, extractSourceData, buildAdaptiveDomRenderFn, resolveCircleSymbolDefaults, resolveSymbolDescriptor, buildAdaptiveSymbolStyleFn, createSymbolDotElement, anchorFromBottomCenter, createDefaultClusterElement, createClusterPinElement, fadeInElement, anchorToGoogleOffsets, 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, extractLineCoordinates, patchPortalDescriptors, collectFeatureIdSet, removeGoneIndexedMarkers, getAdaptiveDomFeatureIds, extractSourceData, buildAdaptiveDomRenderFn, resolveCircleSymbolDefaults, resolveSymbolDescriptor, buildAdaptiveSymbolStyleFn, createSymbolDotElement, anchorFromBottomCenter, createDefaultClusterElement, createClusterPinElement, fadeInElement, anchorToGoogleOffsets, buildAdaptiveDomEntries, MAP_CURSORS, resolveSelectedStyle, resolveHoveredStyle, extractPolygonPaths, 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';
@@ -523,6 +523,32 @@ const collectFeatureIdsFromCluster = (cluster) => {
523
523
  /**
524
524
  * Convert a GeoJSON bbox [minLng, minLat, maxLng, maxLat] to Google Maps LatLngBoundsLiteral.
525
525
  */
526
+ /**
527
+ * Index a feature collection by `String(feature.id)`. Returns null when a
528
+ * feature has no id or two features share one: such a source has no per-feature
529
+ * identity to sync on and is rebuilt as a whole instead.
530
+ */
531
+ const indexFeaturesById = (features) => {
532
+ const byId = new Map();
533
+ for (const feature of features.features) {
534
+ if (feature.id === undefined)
535
+ return null;
536
+ const fid = String(feature.id);
537
+ if (byId.has(fid))
538
+ return null;
539
+ byId.set(fid, feature);
540
+ }
541
+ return byId;
542
+ };
543
+ /** The `ShapeType` a feature's own listeners report, from its geometry. */
544
+ const shapeTypeOfGeometry = (geometry) => {
545
+ const geometryType = geometry?.type;
546
+ if (geometryType === "LineString" || geometryType === "MultiLineString")
547
+ return "line";
548
+ if (geometryType === "Point" || geometryType === "MultiPoint")
549
+ return "point";
550
+ return "polygon";
551
+ };
526
552
  const bboxToGoogleBounds = (bbox) => ({
527
553
  west: bbox[0],
528
554
  south: bbox[1],
@@ -534,6 +560,8 @@ const CANVAS_VIEWPORT_PADDING = 50;
534
560
  * including hover-promoted fills (max fill z-index is HOVER_PROMOTION_Z_INDEX = 10_000
535
561
  * in useShapeFillTiling). A value of 1_000_000 keeps strokes visually complete. */
536
562
  const TILED_OUTLINE_Z_INDEX = 1000000;
563
+ // Thin strokes still need a grabbable hit target in stroke-only interaction mode.
564
+ const STROKE_HIT_MIN_WEIGHT = 3;
537
565
  // AdvancedMarkerElement zIndex for DOM-promoted adaptive markers. Must be high
538
566
  // enough to render above the canvas overlay (which has no explicit zIndex).
539
567
  const DOM_MARKER_Z_INDEX = 1000;
@@ -645,6 +673,17 @@ class GoogleMapsLayerPort {
645
673
  this.selectedShapeFeatureId = null;
646
674
  this.hoveredShapeHandleId = null;
647
675
  this.hoveredShapeFeatureId = null;
676
+ /**
677
+ * The shape feature under the pointer, from Google's own mouseover and
678
+ * mouseout. The snapshot hover above may instead come from `layers.hover()`
679
+ * (a list row), which no shape change may end on the consumer's behalf.
680
+ */
681
+ this.pointerShapeHover = null;
682
+ /**
683
+ * The `hover-end`s queued by `endShapeHover`, by handle id then feature id,
684
+ * so each feature has at most one queued and the reason it was queued for.
685
+ */
686
+ this.pendingShapeHoverEnds = new Map();
648
687
  this.theme = "light";
649
688
  // ---- Shape dblclick via DOM ----
650
689
  // Google Maps overlays suppress both the second click AND dblclick events
@@ -794,6 +833,8 @@ class GoogleMapsLayerPort {
794
833
  this.selectedShapeFeatureId = null;
795
834
  this.hoveredShapeHandleId = null;
796
835
  this.hoveredShapeFeatureId = null;
836
+ this.pointerShapeHover = null;
837
+ this.pendingShapeHoverEnds.clear();
797
838
  this.mapDblClickListenerCleanup?.();
798
839
  this.mapDblClickListenerCleanup = null;
799
840
  if (this.mapClickListener !== null) {
@@ -836,8 +877,14 @@ class GoogleMapsLayerPort {
836
877
  this.removeMarkerSourceInternal(id);
837
878
  }
838
879
  for (const id of [...this.shapeSources.keys()]) {
839
- if (!shapeIds.has(id))
840
- this.removeShapeSourceInternal(id);
880
+ if (shapeIds.has(id))
881
+ continue;
882
+ // A source that leaves the snapshot takes its pointer-hover record with it, so a
883
+ // source that later returns under the same id cannot inherit a stale one. A rebuild
884
+ // keeps the record (it goes through removeShapeSourceInternal directly).
885
+ if (this.pointerShapeHover?.handleId === id)
886
+ this.pointerShapeHover = null;
887
+ this.removeShapeSourceInternal(id);
841
888
  }
842
889
  for (const id of [...this.routeSources.keys()]) {
843
890
  if (!routeIds.has(id))
@@ -1031,127 +1078,239 @@ class GoogleMapsLayerPort {
1031
1078
  if (this.map === null)
1032
1079
  return;
1033
1080
  const existingShape = this.shapeSources.get(config.id);
1034
- if (existingShape !== undefined) {
1035
- const prev = existingShape.config;
1036
- if (prev.features === config.features &&
1037
- prev.style === config.style &&
1038
- prev.featureStyles === config.featureStyles &&
1039
- prev.featureFillGeometries === config.featureFillGeometries &&
1040
- prev.featureZIndexOverrides === config.featureZIndexOverrides &&
1041
- prev.interactive === config.interactive) {
1042
- return;
1081
+ if (existingShape !== undefined && this.isShapeConfigUnchanged(existingShape.config, config))
1082
+ return;
1083
+ // Only a hover the pointer started can be ended here; a `layers.hover()` from
1084
+ // a list row is the consumer's to keep.
1085
+ const pointerHover = this.pointerShapeHover;
1086
+ const hoveredFeatureId = pointerHover !== null && pointerHover.handleId === config.id ? pointerHover.featureId : null;
1087
+ // The features the hover started on are kept for the entity type, since the
1088
+ // sync may drop the feature from the new ones.
1089
+ const hoverableBefore = hoveredFeatureId !== null &&
1090
+ existingShape !== undefined &&
1091
+ this.isFeatureHoverable(existingShape, hoveredFeatureId)
1092
+ ? { featureId: hoveredFeatureId, features: existingShape.config.features }
1093
+ : null;
1094
+ // A changed features collection is synced per feature id, and changed
1095
+ // styles or per-feature overrides (Path B promotion, clipped fills, the
1096
+ // viewport-inside flip) are patched in place. Only an interactive-mode
1097
+ // change, or a source without usable feature ids, rebuilds the source,
1098
+ // which paints an empty frame in between the teardown and the re-add.
1099
+ const touchedFeatureIds = existingShape !== undefined ? this.patchShapeSourceInPlace(existingShape, config) : null;
1100
+ const tracked = touchedFeatureIds !== null && existingShape !== undefined
1101
+ ? existingShape
1102
+ : this.rebuildShapeSource(config, this.map);
1103
+ // Google only fires mouseout on a clickable shape, so a hovered feature that
1104
+ // just lost its last pointer surface would stay hovered for good.
1105
+ if (hoverableBefore !== null && !this.isFeatureHoverable(tracked, hoverableBefore.featureId)) {
1106
+ const { featureId, features } = hoverableBefore;
1107
+ this.endShapeHover(tracked, featureId, this.shapeTypeOfFeature(features, featureId), "lost-surface");
1108
+ }
1109
+ // After an in-place patch, re-apply hover and selection overrides on the
1110
+ // touched features only. After a rebuild of an existing source there is
1111
+ // nothing to re-apply: removing it reset the hovered and selected ids, and
1112
+ // applySnapshot re-applies them. A source added while those ids already
1113
+ // name it (a layer toggled off and on with its selection still in the
1114
+ // snapshot) is painted here, since applySnapshot sees unchanged ids.
1115
+ if (touchedFeatureIds === null) {
1116
+ const namedFeatureIds = new Set();
1117
+ if (this.selectedShapeHandleId === config.id && this.selectedShapeFeatureId !== null) {
1118
+ namedFeatureIds.add(this.selectedShapeFeatureId);
1119
+ }
1120
+ if (this.hoveredShapeHandleId === config.id && this.hoveredShapeFeatureId !== null) {
1121
+ namedFeatureIds.add(this.hoveredShapeFeatureId);
1122
+ }
1123
+ if (namedFeatureIds.size > 0)
1124
+ this.applyGoogleShapeInteraction(config.id, namedFeatureIds);
1125
+ return;
1126
+ }
1127
+ const selectedFeatureId = this.selectedShapeHandleId === config.id ? this.selectedShapeFeatureId : null;
1128
+ const hoveredNowFeatureId = this.hoveredShapeHandleId === config.id ? this.hoveredShapeFeatureId : null;
1129
+ if ((selectedFeatureId !== null && touchedFeatureIds.has(selectedFeatureId)) ||
1130
+ (hoveredNowFeatureId !== null && touchedFeatureIds.has(hoveredNowFeatureId))) {
1131
+ this.applyGoogleShapeInteraction(config.id, touchedFeatureIds);
1132
+ }
1133
+ }
1134
+ isShapeConfigUnchanged(prev, config) {
1135
+ return (prev.features === config.features &&
1136
+ prev.style === config.style &&
1137
+ prev.featureStyles === config.featureStyles &&
1138
+ prev.featureFillGeometries === config.featureFillGeometries &&
1139
+ prev.featureZIndexOverrides === config.featureZIndexOverrides &&
1140
+ prev.interactive === config.interactive);
1141
+ }
1142
+ /**
1143
+ * Patch a source in place. Returns the ids of the features whose shapes were
1144
+ * touched, or null when the change needs a rebuild: the interactive mode
1145
+ * changed, or a feature without an id (or with a duplicate id) has to be
1146
+ * restyled or re-synced, since only shapes mapped by id can be touched one
1147
+ * feature at a time.
1148
+ */
1149
+ patchShapeSourceInPlace(existingShape, config) {
1150
+ const prev = existingShape.config;
1151
+ if (prev.interactive !== config.interactive)
1152
+ return null;
1153
+ if (prev.features !== config.features)
1154
+ return this.syncShapeFeaturesById(existingShape, config);
1155
+ if (prev.style !== config.style && existingShape.featuresById === null)
1156
+ return null;
1157
+ existingShape.config = config;
1158
+ const touchedFeatureIds = prev.featureFillGeometries !== config.featureFillGeometries ||
1159
+ prev.featureZIndexOverrides !== config.featureZIndexOverrides
1160
+ ? this.syncShapeTilingOverrides(existingShape, prev, config)
1161
+ : new Set();
1162
+ if (prev.featureStyles !== config.featureStyles || prev.style !== config.style) {
1163
+ for (const fid of this.syncShapeFeatureStyles(existingShape, prev, config, touchedFeatureIds)) {
1164
+ touchedFeatureIds.add(fid);
1043
1165
  }
1044
- const coreUnchanged = prev.features === config.features &&
1045
- prev.style === config.style &&
1046
- prev.featureStyles === config.featureStyles &&
1047
- prev.interactive === config.interactive;
1048
- // Path B promotion: only clipped-fill / z-index overrides changed — patch
1049
- // affected features in place instead of rebuilding the entire source (~180 sites).
1050
- if (coreUnchanged &&
1051
- (prev.featureFillGeometries !== config.featureFillGeometries ||
1052
- prev.featureZIndexOverrides !== config.featureZIndexOverrides)) {
1053
- this.syncShapeTilingOverrides(existingShape, prev, config);
1054
- existingShape.config = config;
1055
- if ((this.selectedShapeHandleId === config.id && this.selectedShapeFeatureId !== null) ||
1056
- (this.hoveredShapeHandleId === config.id && this.hoveredShapeFeatureId !== null)) {
1057
- this.applyGoogleShapeInteraction(config.id);
1166
+ }
1167
+ return touchedFeatureIds;
1168
+ }
1169
+ /**
1170
+ * Sync a changed features collection one feature at a time, keyed on feature
1171
+ * id, so the shapes of every feature that is still there stay on the map: a
1172
+ * fleet map re-emits its whole site collection after each clusters query,
1173
+ * usually with the same sites in it, and tearing every polygon down for that
1174
+ * blanks the map for a frame. A feature whose geometry or clipped fill changed
1175
+ * is re-rendered, one whose resolved style or z-index changed is patched in
1176
+ * place, a new one is rendered and a gone one removed. The antimeridian merge
1177
+ * runs on the new collection first (the previous one is kept merged and
1178
+ * indexed on `tracked`), so a merged feature is compared with its merged
1179
+ * predecessor. Returns the ids of the features that are still there and were
1180
+ * repainted with their base style (re-rendered, added or restyled; a z-index
1181
+ * change alone repaints nothing), or null (nothing changed yet) when either
1182
+ * collection has a feature without an id or with a duplicate id: that source
1183
+ * is rebuilt as a whole.
1184
+ */
1185
+ syncShapeFeaturesById(tracked, config) {
1186
+ if (this.map === null)
1187
+ return null;
1188
+ const prev = tracked.config;
1189
+ const prevById = tracked.featuresById;
1190
+ const nextById = indexFeaturesById(mergeAntimeridianFeatures(config.features));
1191
+ if (prevById === null || nextById === null)
1192
+ return null;
1193
+ const currentMap = this.map;
1194
+ tracked.config = config;
1195
+ tracked.featuresById = nextById;
1196
+ const pointerHover = this.pointerShapeHover;
1197
+ const touchedFeatureIds = new Set();
1198
+ for (const fid of prevById.keys()) {
1199
+ if (nextById.has(fid))
1200
+ continue;
1201
+ this.removeFeatureShapes(tracked, fid);
1202
+ this.removeFeaturePointMarkers(tracked, fid);
1203
+ }
1204
+ for (const [fid, feature] of nextById) {
1205
+ const prevFeature = prevById.get(fid);
1206
+ if (prevFeature === undefined) {
1207
+ this.renderShapeFeature(feature, config, tracked, currentMap);
1208
+ touchedFeatureIds.add(fid);
1209
+ continue;
1210
+ }
1211
+ // A collection rebuilt from the same data mostly carries the same
1212
+ // feature and geometry objects; the deep compare is for the rest.
1213
+ const geometryChanged = prevFeature !== feature &&
1214
+ prevFeature.geometry !== feature.geometry &&
1215
+ !isEqual(prevFeature.geometry, feature.geometry);
1216
+ const fillChanged = !isEqual(prev.featureFillGeometries?.get(fid), config.featureFillGeometries?.get(fid));
1217
+ if (geometryChanged || fillChanged) {
1218
+ // Google fires no mouseout for the shapes taken off the map, and the new
1219
+ // geometry may not cover the pointer: end a pointer hover on this feature
1220
+ // the way a lost surface does.
1221
+ if (pointerHover !== null && pointerHover.handleId === config.id && pointerHover.featureId === fid) {
1222
+ this.endShapeHover(tracked, fid, shapeTypeOfGeometry(prevFeature.geometry), "re-rendered");
1058
1223
  }
1059
- return;
1224
+ this.removeFeatureShapes(tracked, fid);
1225
+ this.removeFeaturePointMarkers(tracked, fid);
1226
+ this.renderShapeFeature(feature, config, tracked, currentMap);
1227
+ touchedFeatureIds.add(fid);
1228
+ continue;
1229
+ }
1230
+ const prevZ = prev.featureZIndexOverrides?.get(fid);
1231
+ const nextZ = config.featureZIndexOverrides?.get(fid);
1232
+ if (prevZ !== nextZ) {
1233
+ this.updateFeatureShapeZIndex(tracked, fid, nextZ);
1234
+ }
1235
+ const prevStyle = prev.featureStyles?.get(fid) ?? prev.style;
1236
+ const nextStyle = config.featureStyles?.get(fid) ?? config.style;
1237
+ if (!isEqual(prevStyle, nextStyle) && this.restyleFeatureShapes(tracked, config, fid, nextStyle)) {
1238
+ touchedFeatureIds.add(fid);
1060
1239
  }
1061
1240
  }
1062
- // Remove existing shapes for this source (update case)
1241
+ return touchedFeatureIds;
1242
+ }
1243
+ /** Tear the source down (update case) and build every shape from scratch. */
1244
+ rebuildShapeSource(config, currentMap) {
1063
1245
  this.removeShapeSourceInternal(config.id);
1246
+ const renderFeatures = mergeAntimeridianFeatures(config.features);
1064
1247
  const tracked = {
1065
- shapes: [],
1066
- hitPolylines: [],
1067
- pointMarkers: [],
1068
- listeners: [],
1248
+ shapes: new Set(),
1249
+ hitPolylines: new Set(),
1250
+ pointMarkers: new Set(),
1069
1251
  shapeListeners: new WeakMap(),
1070
1252
  config,
1071
1253
  featureIdToShapes: new Map(),
1072
1254
  featureIdToPointMarkers: new Map(),
1255
+ featuresById: indexFeaturesById(renderFeatures),
1073
1256
  fillOnlyShapes: new Set(),
1074
1257
  };
1075
- const currentMap = this.map;
1076
- const isStrokeOnly = config.interactive === "stroke";
1077
- const renderFeatures = mergeAntimeridianFeatures(config.features);
1078
1258
  for (const feature of renderFeatures.features) {
1079
- const geometry = feature.geometry;
1080
- if (geometry === null)
1081
- continue;
1082
- const { type } = geometry;
1083
- const fid = feature.id !== undefined ? String(feature.id) : undefined;
1084
- const featureStyle = (fid !== undefined ? config.featureStyles?.get(fid) : undefined) ?? config.style;
1085
- // ADR-0021 fill tiling: when a clipped fill geometry is present, draw the
1086
- // outline from the full geometry and the fill from the clipped geometry.
1087
- const fillOverride = (type === "Polygon" || type === "MultiPolygon") && fid !== undefined
1088
- ? config.featureFillGeometries?.get(fid)
1089
- : undefined;
1090
- if (fillOverride !== undefined && fid !== undefined) {
1091
- this.renderTiledPolygonFeature(geometry, fillOverride, featureStyle, fid, isStrokeOnly, config, tracked, currentMap);
1092
- continue;
1259
+ this.renderShapeFeature(feature, config, tracked, currentMap);
1260
+ }
1261
+ this.shapeSources.set(config.id, tracked);
1262
+ return tracked;
1263
+ }
1264
+ /** Render one feature's shapes and point markers onto `tracked`, the same way for a rebuild and an id-keyed sync. */
1265
+ renderShapeFeature(feature, config, tracked, currentMap) {
1266
+ const geometry = feature.geometry;
1267
+ if (geometry === null)
1268
+ return;
1269
+ const { type } = geometry;
1270
+ const fid = feature.id !== undefined ? String(feature.id) : undefined;
1271
+ const featureStyle = (fid !== undefined ? config.featureStyles?.get(fid) : undefined) ?? config.style;
1272
+ // ADR-0021 fill tiling: when a clipped fill geometry is present, draw the
1273
+ // outline from the full geometry and the fill from the clipped geometry.
1274
+ const fillOverride = (type === "Polygon" || type === "MultiPolygon") && fid !== undefined
1275
+ ? config.featureFillGeometries?.get(fid)
1276
+ : undefined;
1277
+ if (fillOverride !== undefined && fid !== undefined) {
1278
+ this.renderTiledPolygonFeature(geometry, fillOverride, featureStyle, fid, config, tracked, currentMap);
1279
+ return;
1280
+ }
1281
+ if (type === "Polygon") {
1282
+ const polygonZIndex = fid !== undefined ? config.featureZIndexOverrides?.get(fid) : undefined;
1283
+ this.renderPolygonPart(geometry.coordinates, featureStyle, fid, polygonZIndex, config, tracked, currentMap);
1284
+ }
1285
+ else if (type === "MultiPolygon") {
1286
+ const multiCoords = geometry.coordinates;
1287
+ if (!Array.isArray(multiCoords))
1288
+ return;
1289
+ const polygonZIndex = fid !== undefined ? config.featureZIndexOverrides?.get(fid) : undefined;
1290
+ for (const polygonCoords of multiCoords) {
1291
+ this.renderPolygonPart(polygonCoords, featureStyle, fid, polygonZIndex, config, tracked, currentMap);
1093
1292
  }
1094
- if (type === "Polygon") {
1095
- const paths = extractPolygonPaths(geometry.coordinates);
1096
- if (paths === null)
1097
- continue;
1098
- const fillVisible = (featureStyle.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity) > 0;
1099
- const polygonZIndex = fid !== undefined ? config.featureZIndexOverrides?.get(fid) : undefined;
1100
- const polygon = this.createPolygon(paths, featureStyle, currentMap, !isStrokeOnly && fillVisible, polygonZIndex);
1101
- tracked.shapes.push(polygon);
1102
- if (fid !== undefined) {
1103
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, polygon);
1104
- }
1105
- if (config.interactive !== "none" && fid !== undefined) {
1106
- if (isStrokeOnly) {
1107
- const hitPls = this.createStrokeHitPolylines(paths, featureStyle.strokeWidth ?? this.shapeStyleDefaults.polygon.strokeWidth, currentMap);
1108
- for (const pl of hitPls) {
1109
- tracked.hitPolylines.push(pl);
1110
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, pl);
1111
- this.attachShapeInteractionListeners(pl, fid, "polygon", tracked, config.id);
1112
- }
1113
- }
1114
- else {
1115
- this.attachShapeInteractionListeners(polygon, fid, "polygon", tracked, config.id);
1116
- }
1117
- }
1293
+ }
1294
+ else if (type === "LineString") {
1295
+ const path = extractLineCoordinates(feature);
1296
+ if (path === null)
1297
+ return;
1298
+ const polyline = this.createPolyline(path, featureStyle, currentMap);
1299
+ tracked.shapes.add(polyline);
1300
+ if (fid !== undefined) {
1301
+ this.pushToFeatureMap(tracked.featureIdToShapes, fid, polyline);
1118
1302
  }
1119
- else if (type === "MultiPolygon") {
1120
- const multiCoords = geometry.coordinates;
1121
- if (!Array.isArray(multiCoords))
1122
- continue;
1123
- for (const polygonCoords of multiCoords) {
1124
- const paths = extractPolygonPaths(polygonCoords);
1125
- if (paths === null)
1126
- continue;
1127
- const fillVisible = (featureStyle.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity) > 0;
1128
- const polygonZIndex = fid !== undefined ? config.featureZIndexOverrides?.get(fid) : undefined;
1129
- const polygon = this.createPolygon(paths, featureStyle, currentMap, !isStrokeOnly && fillVisible, polygonZIndex);
1130
- tracked.shapes.push(polygon);
1131
- if (fid !== undefined) {
1132
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, polygon);
1133
- }
1134
- if (config.interactive !== "none" && fid !== undefined) {
1135
- if (isStrokeOnly) {
1136
- const hitPls = this.createStrokeHitPolylines(paths, featureStyle.strokeWidth ?? this.shapeStyleDefaults.polygon.strokeWidth, currentMap);
1137
- for (const pl of hitPls) {
1138
- tracked.hitPolylines.push(pl);
1139
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, pl);
1140
- this.attachShapeInteractionListeners(pl, fid, "polygon", tracked, config.id);
1141
- }
1142
- }
1143
- else {
1144
- this.attachShapeInteractionListeners(polygon, fid, "polygon", tracked, config.id);
1145
- }
1146
- }
1147
- }
1303
+ if (config.interactive !== "none" && fid !== undefined) {
1304
+ this.attachShapeInteractionListeners(polyline, fid, "line", tracked, config.id);
1148
1305
  }
1149
- else if (type === "LineString") {
1150
- const path = extractLineCoordinates(feature);
1151
- if (path === null)
1306
+ }
1307
+ else if (type === "MultiLineString") {
1308
+ for (const lineCoords of geometry.coordinates) {
1309
+ const path = lineCoords.map(([lng, lat]) => ({ lng, lat }));
1310
+ if (path.length === 0)
1152
1311
  continue;
1153
1312
  const polyline = this.createPolyline(path, featureStyle, currentMap);
1154
- tracked.shapes.push(polyline);
1313
+ tracked.shapes.add(polyline);
1155
1314
  if (fid !== undefined) {
1156
1315
  this.pushToFeatureMap(tracked.featureIdToShapes, fid, polyline);
1157
1316
  }
@@ -1159,25 +1318,23 @@ class GoogleMapsLayerPort {
1159
1318
  this.attachShapeInteractionListeners(polyline, fid, "line", tracked, config.id);
1160
1319
  }
1161
1320
  }
1162
- else if (type === "MultiLineString") {
1163
- for (const lineCoords of geometry.coordinates) {
1164
- const path = lineCoords.map(([lng, lat]) => ({ lng, lat }));
1165
- if (path.length === 0)
1166
- continue;
1167
- const polyline = this.createPolyline(path, featureStyle, currentMap);
1168
- tracked.shapes.push(polyline);
1169
- if (fid !== undefined) {
1170
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, polyline);
1171
- }
1172
- if (config.interactive !== "none" && fid !== undefined) {
1173
- this.attachShapeInteractionListeners(polyline, fid, "line", tracked, config.id);
1174
- }
1175
- }
1321
+ }
1322
+ else if (type === "Point") {
1323
+ const [lng, lat] = geometry.coordinates;
1324
+ const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap, config.interactive !== "none");
1325
+ tracked.pointMarkers.add(marker);
1326
+ if (fid !== undefined) {
1327
+ this.pushToFeatureMap(tracked.featureIdToPointMarkers, fid, marker);
1328
+ }
1329
+ if (config.interactive !== "none" && fid !== undefined) {
1330
+ this.attachShapePointInteractionListeners(marker, fid, "point", config.id);
1176
1331
  }
1177
- else if (type === "Point") {
1178
- const [lng, lat] = geometry.coordinates;
1332
+ }
1333
+ else if (type === "MultiPoint") {
1334
+ for (const coords of geometry.coordinates) {
1335
+ const [lng, lat] = coords;
1179
1336
  const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap, config.interactive !== "none");
1180
- tracked.pointMarkers.push(marker);
1337
+ tracked.pointMarkers.add(marker);
1181
1338
  if (fid !== undefined) {
1182
1339
  this.pushToFeatureMap(tracked.featureIdToPointMarkers, fid, marker);
1183
1340
  }
@@ -1185,47 +1342,25 @@ class GoogleMapsLayerPort {
1185
1342
  this.attachShapePointInteractionListeners(marker, fid, "point", config.id);
1186
1343
  }
1187
1344
  }
1188
- else if (type === "MultiPoint") {
1189
- for (const coords of geometry.coordinates) {
1190
- const [lng, lat] = coords;
1191
- const marker = this.createShapePointMarker({ lng, lat }, featureStyle, currentMap, config.interactive !== "none");
1192
- tracked.pointMarkers.push(marker);
1193
- if (fid !== undefined) {
1194
- this.pushToFeatureMap(tracked.featureIdToPointMarkers, fid, marker);
1195
- }
1196
- if (config.interactive !== "none" && fid !== undefined) {
1197
- this.attachShapePointInteractionListeners(marker, fid, "point", config.id);
1198
- }
1199
- }
1200
- }
1201
- }
1202
- this.shapeSources.set(config.id, tracked);
1203
- // Re-apply interaction styles if this source is currently hovered or selected
1204
- if ((this.selectedShapeHandleId === config.id && this.selectedShapeFeatureId !== null) ||
1205
- (this.hoveredShapeHandleId === config.id && this.hoveredShapeFeatureId !== null)) {
1206
- this.applyGoogleShapeInteraction(config.id);
1207
1345
  }
1208
1346
  }
1209
- /** Deep equality for clipped fill overrides — map emissions create new Map refs every time. */
1210
- fillOverrideEqual(prev, next) {
1211
- if (prev === next)
1212
- return true;
1213
- if (prev === undefined || next === undefined)
1214
- return false;
1215
- return isEqual(prev, next);
1216
- }
1217
1347
  /**
1218
1348
  * Patch only features whose fill-override or z-index changed (ADR-0021 Path B).
1219
- * Returns the number of features that were updated or re-rendered.
1349
+ * Returns the ids of the features that were re-rendered, already carrying the
1350
+ * style from `config`.
1220
1351
  */
1221
1352
  syncShapeTilingOverrides(tracked, prevConfig, config) {
1353
+ const rebuiltFeatureIds = new Set();
1222
1354
  if (this.map === null)
1223
- return 0;
1355
+ return rebuiltFeatureIds;
1224
1356
  const currentMap = this.map;
1225
- const isStrokeOnly = config.interactive === "stroke";
1226
- const renderFeatures = mergeAntimeridianFeatures(config.features);
1227
- let changedCount = 0;
1228
- for (const feature of renderFeatures.features) {
1357
+ const pointerHover = this.pointerShapeHover;
1358
+ // The merged collection is kept indexed on `tracked`; only a source without
1359
+ // usable ids (which has no per-feature overrides anyway) is merged again.
1360
+ const renderFeatures = tracked.featuresById !== null
1361
+ ? tracked.featuresById.values()
1362
+ : mergeAntimeridianFeatures(config.features).features;
1363
+ for (const feature of renderFeatures) {
1229
1364
  if (feature.id === undefined)
1230
1365
  continue;
1231
1366
  const fid = String(feature.id);
@@ -1239,73 +1374,205 @@ class GoogleMapsLayerPort {
1239
1374
  const nextFill = config.featureFillGeometries?.get(fid);
1240
1375
  const prevZ = prevConfig.featureZIndexOverrides?.get(fid);
1241
1376
  const nextZ = config.featureZIndexOverrides?.get(fid);
1242
- const fillChanged = !this.fillOverrideEqual(prevFill, nextFill);
1377
+ const fillChanged = !isEqual(prevFill, nextFill);
1243
1378
  const zChanged = prevZ !== nextZ;
1244
1379
  if (!fillChanged && !zChanged)
1245
1380
  continue;
1246
- changedCount += 1;
1247
1381
  if (!fillChanged) {
1248
1382
  this.updateFeatureShapeZIndex(tracked, fid, nextZ);
1249
1383
  continue;
1250
1384
  }
1385
+ // Google fires no mouseout for the shapes taken off the map, and the new
1386
+ // clipped fill may not cover the pointer: end a pointer hover on this
1387
+ // feature the way a lost surface does.
1388
+ if (pointerHover !== null && pointerHover.handleId === config.id && pointerHover.featureId === fid) {
1389
+ this.endShapeHover(tracked, fid, "polygon", "re-rendered");
1390
+ }
1251
1391
  this.removeFeatureShapes(tracked, fid);
1392
+ rebuiltFeatureIds.add(fid);
1252
1393
  const featureStyle = config.featureStyles?.get(fid) ?? config.style;
1253
1394
  const fillOverride = config.featureFillGeometries?.get(fid);
1254
1395
  if (fillOverride !== undefined) {
1255
- this.renderTiledPolygonFeature(geometry, fillOverride, featureStyle, fid, isStrokeOnly, config, tracked, currentMap);
1396
+ this.renderTiledPolygonFeature(geometry, fillOverride, featureStyle, fid, config, tracked, currentMap);
1256
1397
  continue;
1257
1398
  }
1258
1399
  if (type === "Polygon") {
1259
- const paths = extractPolygonPaths(geometry.coordinates);
1260
- if (paths === null)
1261
- continue;
1262
- const fillVisible = (featureStyle.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity) > 0;
1263
- const polygon = this.createPolygon(paths, featureStyle, currentMap, !isStrokeOnly && fillVisible, nextZ);
1264
- tracked.shapes.push(polygon);
1265
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, polygon);
1266
- if (config.interactive !== "none") {
1267
- if (isStrokeOnly) {
1268
- const hitPls = this.createStrokeHitPolylines(paths, featureStyle.strokeWidth ?? 1, currentMap);
1269
- for (const pl of hitPls) {
1270
- tracked.hitPolylines.push(pl);
1271
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, pl);
1272
- this.attachShapeInteractionListeners(pl, fid, "polygon", tracked, config.id);
1273
- }
1274
- }
1275
- else {
1276
- this.attachShapeInteractionListeners(polygon, fid, "polygon", tracked, config.id);
1277
- }
1278
- }
1400
+ this.renderPolygonPart(geometry.coordinates, featureStyle, fid, nextZ, config, tracked, currentMap);
1279
1401
  }
1280
1402
  else {
1281
1403
  const multiCoords = geometry.coordinates;
1282
1404
  if (!Array.isArray(multiCoords))
1283
1405
  continue;
1284
1406
  for (const polygonCoords of multiCoords) {
1285
- const paths = extractPolygonPaths(polygonCoords);
1286
- if (paths === null)
1287
- continue;
1288
- const fillVisible = (featureStyle.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity) > 0;
1289
- const polygon = this.createPolygon(paths, featureStyle, currentMap, !isStrokeOnly && fillVisible, nextZ);
1290
- tracked.shapes.push(polygon);
1291
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, polygon);
1292
- if (config.interactive !== "none") {
1293
- if (isStrokeOnly) {
1294
- const hitPls = this.createStrokeHitPolylines(paths, featureStyle.strokeWidth ?? 1, currentMap);
1295
- for (const pl of hitPls) {
1296
- tracked.hitPolylines.push(pl);
1297
- this.pushToFeatureMap(tracked.featureIdToShapes, fid, pl);
1298
- this.attachShapeInteractionListeners(pl, fid, "polygon", tracked, config.id);
1299
- }
1300
- }
1301
- else {
1302
- this.attachShapeInteractionListeners(polygon, fid, "polygon", tracked, config.id);
1303
- }
1304
- }
1407
+ this.renderPolygonPart(polygonCoords, featureStyle, fid, nextZ, config, tracked, currentMap);
1305
1408
  }
1306
1409
  }
1307
1410
  }
1308
- return changedCount;
1411
+ return rebuiltFeatureIds;
1412
+ }
1413
+ /**
1414
+ * Restyle only the features whose resolved style (feature style or base
1415
+ * style) changed between two configs, on the shapes that already sit on the
1416
+ * map. Mirrors
1417
+ * what the create helpers derive from a style (clickability from fill
1418
+ * visibility, hit-polyline weight from stroke width) so a patched source is
1419
+ * indistinguishable from a rebuilt one. Features in `alreadyRebuiltFeatureIds`
1420
+ * were just re-rendered with the new style and are skipped. Returns the ids
1421
+ * of the features it restyled.
1422
+ */
1423
+ syncShapeFeatureStyles(tracked, prevConfig, config, alreadyRebuiltFeatureIds) {
1424
+ const prevStyles = prevConfig.featureStyles;
1425
+ const nextStyles = config.featureStyles;
1426
+ const restyledFeatureIds = new Set();
1427
+ const syncFeature = (fid) => {
1428
+ const prevStyle = prevStyles?.get(fid) ?? prevConfig.style;
1429
+ const nextStyle = nextStyles?.get(fid) ?? config.style;
1430
+ if (isEqual(prevStyle, nextStyle) || alreadyRebuiltFeatureIds.has(fid))
1431
+ return;
1432
+ if (this.restyleFeatureShapes(tracked, config, fid, nextStyle)) {
1433
+ restyledFeatureIds.add(fid);
1434
+ }
1435
+ };
1436
+ // A base style change can reach every feature without its own entry, so
1437
+ // walk every feature on the map. The caller has checked that each one has
1438
+ // an id, so all of them are mapped.
1439
+ if (prevConfig.style !== config.style) {
1440
+ for (const fid of tracked.featureIdToShapes.keys()) {
1441
+ syncFeature(fid);
1442
+ }
1443
+ for (const fid of tracked.featureIdToPointMarkers.keys()) {
1444
+ if (!tracked.featureIdToShapes.has(fid))
1445
+ syncFeature(fid);
1446
+ }
1447
+ return restyledFeatureIds;
1448
+ }
1449
+ // A fresh map for every site arrives on each viewport move, usually with no
1450
+ // entry changed: walk the larger map and probe the smaller instead of
1451
+ // building a union.
1452
+ const prevIsLarger = (prevStyles?.size ?? 0) >= (nextStyles?.size ?? 0);
1453
+ const larger = prevIsLarger ? prevStyles : nextStyles;
1454
+ const smaller = prevIsLarger ? nextStyles : prevStyles;
1455
+ for (const fid of larger?.keys() ?? []) {
1456
+ syncFeature(fid);
1457
+ }
1458
+ for (const fid of smaller?.keys() ?? []) {
1459
+ if (larger?.has(fid) !== true)
1460
+ syncFeature(fid);
1461
+ }
1462
+ return restyledFeatureIds;
1463
+ }
1464
+ /**
1465
+ * Apply `style` to every shape and point marker of one feature, in place.
1466
+ * Returns whether the feature had anything on the map to restyle.
1467
+ */
1468
+ restyleFeatureShapes(tracked, config, fid, style) {
1469
+ const shapes = tracked.featureIdToShapes.get(fid) ?? [];
1470
+ const pointMarkers = tracked.featureIdToPointMarkers.get(fid) ?? [];
1471
+ for (const shape of shapes) {
1472
+ if ("getPaths" in shape) {
1473
+ const isFillOnly = tracked.fillOnlyShapes.has(shape);
1474
+ const clickable = this.isPolygonClickable(style, config, isFillOnly);
1475
+ shape.setOptions(isFillOnly
1476
+ ? { ...this.polygonFillOptionsFromStyle(style), clickable }
1477
+ : { ...this.polygonOptionsFromStyle(style), clickable });
1478
+ if (config.interactive !== "none") {
1479
+ this.syncPolygonListeners(shape, clickable, fid, tracked, config.id);
1480
+ }
1481
+ continue;
1482
+ }
1483
+ if (tracked.hitPolylines.has(shape)) {
1484
+ shape.setOptions({ geodesic: style.geodesic ?? true, strokeWeight: this.strokeHitWeightFromStyle(style) });
1485
+ continue;
1486
+ }
1487
+ shape.setOptions(this.polylineOptionsFromStyle(style));
1488
+ }
1489
+ for (const marker of pointMarkers) {
1490
+ const el = marker.content;
1491
+ if (!(el instanceof HTMLElement))
1492
+ continue;
1493
+ this.applyShapePointStyle(el, style);
1494
+ }
1495
+ return shapes.length > 0 || pointMarkers.length > 0;
1496
+ }
1497
+ /**
1498
+ * Whether the port can still get mouse events for a feature. Google only
1499
+ * dispatches them on clickable shapes, and a polygon whose fill is hidden is
1500
+ * not clickable outside stroke mode, unless the feature keeps an interactive
1501
+ * polyline (stroke hit target, tiled outline, line) or a point marker. A
1502
+ * feature with nothing on the map, or on a non-interactive source, has no
1503
+ * listeners at all.
1504
+ */
1505
+ isFeatureHoverable(tracked, featureId) {
1506
+ const shapes = tracked.featureIdToShapes.get(featureId) ?? [];
1507
+ const pointMarkers = tracked.featureIdToPointMarkers.get(featureId) ?? [];
1508
+ if (shapes.length === 0 && pointMarkers.length === 0)
1509
+ return false;
1510
+ const { interactive, featureStyles, style } = tracked.config;
1511
+ if (interactive === "none")
1512
+ return false;
1513
+ if (interactive === "stroke")
1514
+ return true;
1515
+ if (this.isFillVisible(featureStyles?.get(featureId) ?? style))
1516
+ return true;
1517
+ if (shapes.some(shape => !("getPaths" in shape)))
1518
+ return true;
1519
+ return pointMarkers.length > 0;
1520
+ }
1521
+ /**
1522
+ * End a shape hover that Google can no longer end for us. The emit is deferred
1523
+ * because a consumer reacting to hover-end may synchronously push a new
1524
+ * snapshot while this sync is still running. When it runs, the hover-end goes
1525
+ * out if the latest snapshot still names this feature as hovered, or if the
1526
+ * snapshot names no hovered feature while the pointer record still names this
1527
+ * one (a consumer that never mirrors pointer hovers into the snapshot gets its
1528
+ * hover-end too). A hover the consumer moved elsewhere by then is left alone:
1529
+ * its hover-end handler clears whatever is hovered. The pointer record is
1530
+ * kept until then, and cleared only here or by Google's own mouseout. A
1531
+ * hover ended for a lost surface is kept after all when the surface is back
1532
+ * by the time the emit runs (a fill hidden and shown within one tick) and the
1533
+ * pointer still rests on the feature: Google can end that hover itself.
1534
+ */
1535
+ endShapeHover(tracked, featureId, shapeType, reason) {
1536
+ const handleId = tracked.config.id;
1537
+ const pendingForHandle = this.pendingShapeHoverEnds.get(handleId) ?? new Map();
1538
+ if (pendingForHandle.has(featureId))
1539
+ return;
1540
+ pendingForHandle.set(featureId, reason);
1541
+ this.pendingShapeHoverEnds.set(handleId, pendingForHandle);
1542
+ const entity = { type: "shape", id: featureId, shapeType, handleId };
1543
+ queueMicrotask(() => {
1544
+ // A disconnect in between dropped every queued end.
1545
+ if (this.pendingShapeHoverEnds.get(handleId) !== pendingForHandle)
1546
+ return;
1547
+ pendingForHandle.delete(featureId);
1548
+ if (pendingForHandle.size === 0)
1549
+ this.pendingShapeHoverEnds.delete(handleId);
1550
+ const pointerHover = this.pointerShapeHover;
1551
+ const pointerNamesFeature = pointerHover !== null && pointerHover.handleId === handleId && pointerHover.featureId === featureId;
1552
+ if (reason === "lost-surface" && pointerNamesFeature) {
1553
+ const current = this.shapeSources.get(handleId);
1554
+ if (current !== undefined && this.isFeatureHoverable(current, featureId))
1555
+ return;
1556
+ }
1557
+ if (pointerNamesFeature)
1558
+ this.pointerShapeHover = null;
1559
+ const snapshotNamesFeature = this.hoveredShapeHandleId === handleId && this.hoveredShapeFeatureId === featureId;
1560
+ const snapshotNamesNothing = this.hoveredShapeFeatureId === null;
1561
+ if (!snapshotNamesFeature && !(snapshotNamesNothing && pointerNamesFeature))
1562
+ return;
1563
+ this.emitEntityInteraction("hover-end", entity);
1564
+ });
1565
+ }
1566
+ clearPointerShapeHover(handleId, featureId) {
1567
+ const pointerHover = this.pointerShapeHover;
1568
+ if (pointerHover !== null && pointerHover.handleId === handleId && pointerHover.featureId === featureId) {
1569
+ this.pointerShapeHover = null;
1570
+ }
1571
+ }
1572
+ /** The `ShapeType` a feature's own listeners report, looked up by id in `features`. */
1573
+ shapeTypeOfFeature(features, featureId) {
1574
+ const feature = features.features.find(candidate => String(candidate.id) === featureId);
1575
+ return shapeTypeOfGeometry(feature?.geometry ?? null);
1309
1576
  }
1310
1577
  /** Remove all map shapes (and their listeners) for a single feature id. */
1311
1578
  removeFeatureShapes(tracked, featureId) {
@@ -1313,30 +1580,61 @@ class GoogleMapsLayerPort {
1313
1580
  if (shapes === undefined)
1314
1581
  return;
1315
1582
  for (const shape of shapes) {
1316
- const listeners = tracked.shapeListeners.get(shape) ?? [];
1317
- const listenersToRemove = new Set(listeners);
1318
- for (const listener of listeners) {
1319
- google.maps.event.removeListener(listener);
1320
- }
1321
- tracked.listeners = tracked.listeners.filter(listener => !listenersToRemove.has(listener));
1322
- tracked.shapeListeners.delete(shape);
1583
+ this.detachShapeInteractionListeners(shape, tracked);
1323
1584
  google.maps.event.clearInstanceListeners(shape);
1324
1585
  shape.setMap(null);
1325
1586
  if ("getPaths" in shape) {
1326
1587
  tracked.fillOnlyShapes.delete(shape);
1327
1588
  }
1328
- const shapeIndex = tracked.shapes.indexOf(shape);
1329
- if (shapeIndex >= 0) {
1330
- tracked.shapes.splice(shapeIndex, 1);
1331
- }
1332
- const hitIndex = tracked.hitPolylines.indexOf(shape);
1333
- if (hitIndex >= 0) {
1334
- tracked.hitPolylines.splice(hitIndex, 1);
1589
+ else {
1590
+ tracked.hitPolylines.delete(shape);
1335
1591
  }
1592
+ tracked.shapes.delete(shape);
1336
1593
  }
1337
1594
  tracked.featureIdToShapes.delete(featureId);
1338
1595
  }
1339
- /** Update z-index on fill-bearing polygons for one feature without a geometry rebuild. */
1596
+ /** Take a single feature's point markers off the map; their listeners live on the dropped elements. */
1597
+ removeFeaturePointMarkers(tracked, featureId) {
1598
+ const markers = tracked.featureIdToPointMarkers.get(featureId);
1599
+ if (markers === undefined)
1600
+ return;
1601
+ for (const marker of markers) {
1602
+ marker.map = null;
1603
+ tracked.pointMarkers.delete(marker);
1604
+ }
1605
+ tracked.featureIdToPointMarkers.delete(featureId);
1606
+ }
1607
+ /**
1608
+ * Listener rule for polygons, applied at creation and in place: a polygon of
1609
+ * an interactive source has interaction listeners if and only if it is
1610
+ * clickable. Google dispatches nothing on an unclickable polygon, so
1611
+ * listeners there would only be stale state.
1612
+ */
1613
+ syncPolygonListeners(polygon, clickable, fid, tracked, handleId) {
1614
+ if (!clickable) {
1615
+ this.detachShapeInteractionListeners(polygon, tracked);
1616
+ return;
1617
+ }
1618
+ if (!tracked.shapeListeners.has(polygon)) {
1619
+ this.attachShapeInteractionListeners(polygon, fid, "polygon", tracked, handleId);
1620
+ }
1621
+ }
1622
+ /** Undo `attachShapeInteractionListeners` for one shape; a no-op when it has none. */
1623
+ detachShapeInteractionListeners(shape, tracked) {
1624
+ const listeners = tracked.shapeListeners.get(shape);
1625
+ if (listeners === undefined)
1626
+ return;
1627
+ for (const listener of listeners) {
1628
+ google.maps.event.removeListener(listener);
1629
+ }
1630
+ tracked.shapeListeners.delete(shape);
1631
+ }
1632
+ /**
1633
+ * Update the z-index of one feature's fill-bearing polygons (full and
1634
+ * fill-only alike) without a geometry rebuild. Without an override the render
1635
+ * path passes no `zIndex`, so a dropped override (a hover promotion that
1636
+ * ended) restores that default by setting the option to undefined.
1637
+ */
1340
1638
  updateFeatureShapeZIndex(tracked, featureId, zIndex) {
1341
1639
  const shapes = tracked.featureIdToShapes.get(featureId);
1342
1640
  if (shapes === undefined)
@@ -1344,23 +1642,19 @@ class GoogleMapsLayerPort {
1344
1642
  for (const shape of shapes) {
1345
1643
  if (!("getPaths" in shape))
1346
1644
  continue;
1347
- const isFillOnly = tracked.fillOnlyShapes.has(shape);
1348
- if (isFillOnly || zIndex !== undefined) {
1349
- shape.setOptions(zIndex !== undefined ? { zIndex } : {});
1350
- }
1645
+ shape.setOptions({ zIndex });
1351
1646
  }
1352
1647
  }
1353
1648
  removeShapeSourceInternal(id) {
1354
1649
  const tracked = this.shapeSources.get(id);
1355
1650
  if (tracked === undefined)
1356
1651
  return;
1357
- for (const listener of tracked.listeners) {
1358
- google.maps.event.removeListener(listener);
1359
- }
1360
1652
  for (const shape of tracked.shapes) {
1653
+ this.detachShapeInteractionListeners(shape, tracked);
1361
1654
  shape.setMap(null);
1362
1655
  }
1363
1656
  for (const pl of tracked.hitPolylines) {
1657
+ this.detachShapeInteractionListeners(pl, tracked);
1364
1658
  pl.setMap(null);
1365
1659
  }
1366
1660
  for (const marker of tracked.pointMarkers) {
@@ -1381,26 +1675,37 @@ class GoogleMapsLayerPort {
1381
1675
  if (this.selectedShapeHandleId === handleId && this.selectedShapeFeatureId === featureId)
1382
1676
  return;
1383
1677
  const prevHandleId = this.selectedShapeHandleId;
1678
+ const prevFeatureId = this.selectedShapeFeatureId;
1384
1679
  this.selectedShapeHandleId = handleId;
1385
1680
  this.selectedShapeFeatureId = featureId;
1386
- if (prevHandleId !== null) {
1387
- this.applyGoogleShapeInteraction(prevHandleId);
1388
- }
1389
- if (handleId !== null && handleId !== prevHandleId) {
1390
- this.applyGoogleShapeInteraction(handleId);
1391
- }
1681
+ this.repaintInteractionTransition(prevHandleId, prevFeatureId, handleId, featureId);
1392
1682
  }
1393
1683
  applyShapeHoverState(handleId, featureId) {
1394
1684
  if (this.hoveredShapeHandleId === handleId && this.hoveredShapeFeatureId === featureId)
1395
1685
  return;
1396
1686
  const prevHandleId = this.hoveredShapeHandleId;
1687
+ const prevFeatureId = this.hoveredShapeFeatureId;
1397
1688
  this.hoveredShapeHandleId = handleId;
1398
1689
  this.hoveredShapeFeatureId = featureId;
1690
+ this.repaintInteractionTransition(prevHandleId, prevFeatureId, handleId, featureId);
1691
+ }
1692
+ /**
1693
+ * Repaint only the features a hover or selection transition touches: the one
1694
+ * that lost it and the one that got it, each on its own source. The rest of
1695
+ * a source keeps its paint. `setTheme` is the one full repaint.
1696
+ */
1697
+ repaintInteractionTransition(prevHandleId, prevFeatureId, handleId, featureId) {
1399
1698
  if (prevHandleId !== null) {
1400
- this.applyGoogleShapeInteraction(prevHandleId);
1699
+ const featureIds = new Set();
1700
+ if (prevFeatureId !== null)
1701
+ featureIds.add(prevFeatureId);
1702
+ if (handleId === prevHandleId && featureId !== null)
1703
+ featureIds.add(featureId);
1704
+ if (featureIds.size > 0)
1705
+ this.applyGoogleShapeInteraction(prevHandleId, featureIds);
1401
1706
  }
1402
- if (handleId !== null && handleId !== prevHandleId) {
1403
- this.applyGoogleShapeInteraction(handleId);
1707
+ if (handleId !== null && handleId !== prevHandleId && featureId !== null) {
1708
+ this.applyGoogleShapeInteraction(handleId, new Set([featureId]));
1404
1709
  }
1405
1710
  }
1406
1711
  // ---- Route sources ----
@@ -2456,8 +2761,9 @@ class GoogleMapsLayerPort {
2456
2761
  *
2457
2762
  * Called whenever hover, selection, or theme changes on the given handleId.
2458
2763
  * When neither hover nor selection targets a feature, it reverts to its base style.
2764
+ * `onlyFeatureIds` limits the repaint to those features (in-place restyles).
2459
2765
  */
2460
- applyGoogleShapeInteraction(handleId) {
2766
+ applyGoogleShapeInteraction(handleId, onlyFeatureIds) {
2461
2767
  const tracked = this.shapeSources.get(handleId);
2462
2768
  if (tracked === undefined)
2463
2769
  return;
@@ -2482,67 +2788,124 @@ class GoogleMapsLayerPort {
2482
2788
  return null;
2483
2789
  };
2484
2790
  for (const [featureId, shapes] of tracked.featureIdToShapes) {
2791
+ if (onlyFeatureIds !== undefined && !onlyFeatureIds.has(featureId))
2792
+ continue;
2485
2793
  const overrides = resolveForFeature(featureId);
2486
2794
  const base = featureStyles?.get(featureId) ?? style;
2795
+ const effective = this.styleWithOverrides(base, overrides);
2796
+ const polygonPaint = this.polygonOptionsFromStyle(effective);
2797
+ const polylinePaint = this.polylineOptionsFromStyle(effective);
2487
2798
  for (const shape of shapes) {
2488
2799
  if ("getPaths" in shape) {
2489
2800
  // Fill-only tiled polygons (ADR-0021) carry no stroke — their outline is a
2490
2801
  // separate polyline. Restyle only the fill so hover/select never paints a
2491
2802
  // stroke back onto them.
2492
2803
  if (tracked.fillOnlyShapes.has(shape)) {
2493
- shape.setOptions({
2494
- fillColor: overrides?.fill ?? base.fill ?? "rgba(0,0,0,0.1)",
2495
- fillOpacity: overrides?.fillOpacity ?? base.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity,
2496
- });
2804
+ shape.setOptions({ fillColor: polygonPaint.fillColor, fillOpacity: polygonPaint.fillOpacity });
2497
2805
  continue;
2498
2806
  }
2499
2807
  shape.setOptions({
2500
- fillColor: overrides?.fill ?? base.fill ?? "rgba(0,0,0,0.1)",
2501
- fillOpacity: overrides?.fillOpacity ?? base.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity,
2502
- strokeColor: overrides?.stroke ?? base.stroke ?? "#000000",
2503
- strokeWeight: overrides?.strokeWidth ?? base.strokeWidth ?? this.shapeStyleDefaults.polygon.strokeWidth,
2504
- strokeOpacity: overrides?.strokeOpacity ?? base.strokeOpacity ?? this.shapeStyleDefaults.polygon.strokeOpacity,
2808
+ fillColor: polygonPaint.fillColor,
2809
+ fillOpacity: polygonPaint.fillOpacity,
2810
+ strokeColor: polygonPaint.strokeColor,
2811
+ strokeWeight: polygonPaint.strokeWeight,
2812
+ strokeOpacity: polygonPaint.strokeOpacity,
2505
2813
  });
2506
2814
  }
2815
+ else if (tracked.hitPolylines.has(shape)) {
2816
+ // Invisible stroke hit targets: only the hit width follows the override.
2817
+ shape.setOptions({ strokeWeight: this.strokeHitWeightFromStyle(effective) });
2818
+ }
2507
2819
  else {
2508
2820
  shape.setOptions({
2509
- strokeColor: overrides?.stroke ?? base.stroke ?? "#000000",
2510
- strokeWeight: overrides?.strokeWidth ?? base.strokeWidth ?? this.shapeStyleDefaults.line.strokeWidth,
2511
- strokeOpacity: overrides?.strokeOpacity ?? base.strokeOpacity ?? this.shapeStyleDefaults.line.strokeOpacity,
2821
+ strokeColor: polylinePaint.strokeColor,
2822
+ strokeWeight: polylinePaint.strokeWeight,
2823
+ strokeOpacity: polylinePaint.strokeOpacity,
2512
2824
  });
2513
2825
  }
2514
2826
  }
2515
2827
  }
2516
2828
  for (const [featureId, pointMarkers] of tracked.featureIdToPointMarkers) {
2517
- const overrides = resolveForFeature(featureId);
2518
- const base = featureStyles?.get(featureId) ?? style;
2829
+ if (onlyFeatureIds !== undefined && !onlyFeatureIds.has(featureId))
2830
+ continue;
2831
+ const effective = this.styleWithOverrides(featureStyles?.get(featureId) ?? style, resolveForFeature(featureId));
2519
2832
  for (const marker of pointMarkers) {
2520
2833
  const el = marker.content;
2521
2834
  if (!(el instanceof HTMLElement))
2522
2835
  continue;
2523
- const fillOpacity = overrides?.fillOpacity ?? base.fillOpacity ?? this.shapeStyleDefaults.point.fillOpacity;
2524
- const strokeOpacity = overrides?.strokeOpacity ?? base.strokeOpacity ?? this.shapeStyleDefaults.point.strokeOpacity;
2525
- el.style.backgroundColor = colorWithOpacity(overrides?.fill ?? base.fill ?? "rgba(0,0,0,0.1)", fillOpacity);
2526
- el.style.borderColor = colorWithOpacity(overrides?.stroke ?? base.stroke ?? "#000", strokeOpacity);
2527
- el.style.borderWidth = `${overrides?.strokeWidth ?? base.strokeWidth ?? this.shapeStyleDefaults.point.strokeWidth}px`;
2836
+ this.applyShapePointStyle(el, effective);
2528
2837
  }
2529
2838
  }
2530
2839
  }
2840
+ /** `base` with the interaction overrides that are set layered on top of it. */
2841
+ styleWithOverrides(base, overrides) {
2842
+ if (overrides === null)
2843
+ return base;
2844
+ return {
2845
+ ...base,
2846
+ fill: overrides.fill ?? base.fill,
2847
+ fillOpacity: overrides.fillOpacity ?? base.fillOpacity,
2848
+ stroke: overrides.stroke ?? base.stroke,
2849
+ strokeOpacity: overrides.strokeOpacity ?? base.strokeOpacity,
2850
+ strokeWidth: overrides.strokeWidth ?? base.strokeWidth,
2851
+ };
2852
+ }
2531
2853
  // ============================================================================
2532
2854
  // Private: Shape creation
2533
2855
  // ============================================================================
2534
- createPolygon(paths, style, map, clickable = true, zIndex) {
2535
- return new google.maps.Polygon({
2536
- paths,
2537
- map,
2856
+ isFillVisible(style) {
2857
+ return (style.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity) > 0;
2858
+ }
2859
+ /**
2860
+ * Whether a polygon is a hit target, at creation and in place: never in stroke
2861
+ * mode (the hit polylines take over) and never with a hidden fill. A fill-only
2862
+ * tiling polygon additionally needs an interactive source; a full polygon stays
2863
+ * clickable on a non-interactive source, as it always has.
2864
+ */
2865
+ isPolygonClickable(style, config, isFillOnly) {
2866
+ if (config.interactive === "stroke" || !this.isFillVisible(style))
2867
+ return false;
2868
+ return !isFillOnly || config.interactive !== "none";
2869
+ }
2870
+ /** Fill paint shared by full and fill-only polygons. */
2871
+ polygonFillOptionsFromStyle(style) {
2872
+ return {
2873
+ fillColor: style.fill ?? "rgba(0,0,0,0.1)",
2874
+ fillOpacity: style.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity,
2875
+ };
2876
+ }
2877
+ /** The one place polygon paint and its defaults are derived from a `ShapeStyle`. */
2878
+ polygonOptionsFromStyle(style) {
2879
+ return {
2538
2880
  // Great-circle edges natively (no densification needed); honours the shape
2539
2881
  // style flag, defaulting to true per the ShapeStyle.geodesic contract.
2540
2882
  geodesic: style.geodesic ?? true,
2541
- fillColor: style.fill ?? "rgba(0,0,0,0.1)",
2542
- fillOpacity: style.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity,
2883
+ ...this.polygonFillOptionsFromStyle(style),
2543
2884
  strokeColor: style.stroke ?? "#000000",
2544
2885
  strokeWeight: style.strokeWidth ?? this.shapeStyleDefaults.polygon.strokeWidth,
2545
2886
  strokeOpacity: style.strokeOpacity ?? this.shapeStyleDefaults.polygon.strokeOpacity,
2887
+ };
2888
+ }
2889
+ /** The one place polyline paint and its defaults are derived from a `ShapeStyle`. */
2890
+ polylineOptionsFromStyle(style) {
2891
+ return {
2892
+ // Match the polygon: native great-circle stroke so a tiled outline curves
2893
+ // the same way as its densified fill instead of drawing a straight chord.
2894
+ geodesic: style.geodesic ?? true,
2895
+ strokeColor: style.stroke ?? "#000000",
2896
+ strokeWeight: style.strokeWidth ?? this.shapeStyleDefaults.line.strokeWidth,
2897
+ strokeOpacity: style.strokeOpacity ?? this.shapeStyleDefaults.line.strokeOpacity,
2898
+ };
2899
+ }
2900
+ /** Width of the invisible stroke hit target; thin strokes still need a grabbable one. */
2901
+ strokeHitWeightFromStyle(style) {
2902
+ return Math.max(style.strokeWidth ?? this.shapeStyleDefaults.polygon.strokeWidth, STROKE_HIT_MIN_WEIGHT);
2903
+ }
2904
+ createPolygon(paths, style, map, clickable = true, zIndex) {
2905
+ return new google.maps.Polygon({
2906
+ paths,
2907
+ map,
2908
+ ...this.polygonOptionsFromStyle(style),
2546
2909
  clickable,
2547
2910
  ...(zIndex !== undefined ? { zIndex } : {}),
2548
2911
  });
@@ -2551,12 +2914,7 @@ class GoogleMapsLayerPort {
2551
2914
  return new google.maps.Polyline({
2552
2915
  path,
2553
2916
  map,
2554
- // Match the polygon: native great-circle stroke so a tiled outline curves
2555
- // the same way as its densified fill instead of drawing a straight chord.
2556
- geodesic: style.geodesic ?? true,
2557
- strokeColor: style.stroke ?? "#000000",
2558
- strokeWeight: style.strokeWidth ?? this.shapeStyleDefaults.line.strokeWidth,
2559
- strokeOpacity: style.strokeOpacity ?? this.shapeStyleDefaults.line.strokeOpacity,
2917
+ ...this.polylineOptionsFromStyle(style),
2560
2918
  clickable: true,
2561
2919
  ...(zIndex !== undefined ? { zIndex } : {}),
2562
2920
  });
@@ -2575,14 +2933,41 @@ class GoogleMapsLayerPort {
2575
2933
  // while the clip cuts must stay as straight Web-Mercator segments so they
2576
2934
  // land exactly on the covering shape's rendered edge. geodesic:true would
2577
2935
  // re-curve those straight cuts and break the tiling seam.
2578
- fillColor: style.fill ?? "rgba(0,0,0,0.1)",
2579
- fillOpacity: style.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity,
2936
+ ...this.polygonFillOptionsFromStyle(style),
2580
2937
  strokeWeight: 0,
2581
2938
  strokeOpacity: 0,
2582
2939
  clickable,
2583
2940
  ...(zIndex !== undefined ? { zIndex } : {}),
2584
2941
  });
2585
2942
  }
2943
+ /**
2944
+ * One polygon ring set (a Polygon, or one part of a MultiPolygon) with its
2945
+ * hit targets: the polygon itself outside stroke mode, invisible hit
2946
+ * polylines in stroke mode.
2947
+ */
2948
+ renderPolygonPart(coordinates, featureStyle, fid, zIndex, config, tracked, map) {
2949
+ const paths = extractPolygonPaths(coordinates);
2950
+ if (paths === null)
2951
+ return;
2952
+ const isStrokeOnly = config.interactive === "stroke";
2953
+ const clickable = this.isPolygonClickable(featureStyle, config, false);
2954
+ const polygon = this.createPolygon(paths, featureStyle, map, clickable, zIndex);
2955
+ tracked.shapes.add(polygon);
2956
+ if (fid === undefined)
2957
+ return;
2958
+ this.pushToFeatureMap(tracked.featureIdToShapes, fid, polygon);
2959
+ if (config.interactive === "none")
2960
+ return;
2961
+ if (isStrokeOnly) {
2962
+ for (const pl of this.createStrokeHitPolylines(paths, featureStyle, map)) {
2963
+ tracked.hitPolylines.add(pl);
2964
+ this.pushToFeatureMap(tracked.featureIdToShapes, fid, pl);
2965
+ this.attachShapeInteractionListeners(pl, fid, "polygon", tracked, config.id);
2966
+ }
2967
+ return;
2968
+ }
2969
+ this.syncPolygonListeners(polygon, clickable, fid, tracked, config.id);
2970
+ }
2586
2971
  /**
2587
2972
  * Render a polygonal feature whose fill is tiled (ADR-0021): the visible
2588
2973
  * outline is drawn from the feature's full geometry as polylines (so it stays
@@ -2590,7 +2975,7 @@ class GoogleMapsLayerPort {
2590
2975
  * clipped geometry as fill-only polygons. A fully covered loser yields no fill
2591
2976
  * polygon — just its outline.
2592
2977
  */
2593
- renderTiledPolygonFeature(fullGeometry, fillGeometry, style, fid, isStrokeOnly, config, tracked, map) {
2978
+ renderTiledPolygonFeature(fullGeometry, fillGeometry, style, fid, config, tracked, map) {
2594
2979
  const polygonParts = (geometry) => {
2595
2980
  if (geometry.type === "Polygon")
2596
2981
  return [geometry.coordinates];
@@ -2610,7 +2995,7 @@ class GoogleMapsLayerPort {
2610
2995
  if (first === undefined)
2611
2996
  continue;
2612
2997
  const outline = this.createPolyline([...ring, first], style, map, TILED_OUTLINE_Z_INDEX);
2613
- tracked.shapes.push(outline);
2998
+ tracked.shapes.add(outline);
2614
2999
  this.pushToFeatureMap(tracked.featureIdToShapes, fid, outline);
2615
3000
  if (config.interactive !== "none") {
2616
3001
  this.attachShapeInteractionListeners(outline, fid, "polygon", tracked, config.id);
@@ -2618,19 +3003,18 @@ class GoogleMapsLayerPort {
2618
3003
  }
2619
3004
  }
2620
3005
  // Fill-only polygons from the clipped geometry.
2621
- const fillVisible = (style.fillOpacity ?? this.shapeStyleDefaults.polygon.fillOpacity) > 0;
2622
- const fillClickable = !isStrokeOnly && fillVisible && config.interactive !== "none";
3006
+ const fillClickable = this.isPolygonClickable(style, config, true);
2623
3007
  const fillZIndex = config.featureZIndexOverrides?.get(fid);
2624
3008
  for (const partCoords of polygonParts(fillGeometry)) {
2625
3009
  const paths = extractPolygonPaths(partCoords);
2626
3010
  if (paths === null)
2627
3011
  continue;
2628
3012
  const fillPolygon = this.createFillOnlyPolygon(paths, style, map, fillClickable, fillZIndex);
2629
- tracked.shapes.push(fillPolygon);
3013
+ tracked.shapes.add(fillPolygon);
2630
3014
  tracked.fillOnlyShapes.add(fillPolygon);
2631
3015
  this.pushToFeatureMap(tracked.featureIdToShapes, fid, fillPolygon);
2632
- if (fillClickable) {
2633
- this.attachShapeInteractionListeners(fillPolygon, fid, "polygon", tracked, config.id);
3016
+ if (config.interactive !== "none") {
3017
+ this.syncPolygonListeners(fillPolygon, fillClickable, fid, tracked, config.id);
2634
3018
  }
2635
3019
  }
2636
3020
  }
@@ -2643,8 +3027,9 @@ class GoogleMapsLayerPort {
2643
3027
  * `geodesic` must match the parent polygon so hit areas align with the
2644
3028
  * visible stroke.
2645
3029
  */
2646
- createStrokeHitPolylines(paths, strokeWeight, map, geodesic = true) {
2647
- const hitWeight = Math.max(strokeWeight, 3);
3030
+ createStrokeHitPolylines(paths, style, map) {
3031
+ const hitWeight = this.strokeHitWeightFromStyle(style);
3032
+ const geodesic = style.geodesic ?? true;
2648
3033
  const polylines = [];
2649
3034
  for (const ring of paths) {
2650
3035
  if (ring.length < 2)
@@ -2665,26 +3050,30 @@ class GoogleMapsLayerPort {
2665
3050
  return polylines;
2666
3051
  }
2667
3052
  createShapePointMarker(position, style, map, interactive) {
2668
- const diameter = (style.pointRadius ?? this.shapeStyleDefaults.point.pointRadius) * 2;
2669
3053
  const el = document.createElement("div");
2670
3054
  el.style.boxSizing = "content-box";
2671
3055
  // A non-interactive source (drawing in progress) must let clicks through to the map.
2672
3056
  el.style.pointerEvents = interactive ? "auto" : "none";
2673
- el.style.width = `${diameter}px`;
2674
- el.style.height = `${diameter}px`;
2675
3057
  el.style.borderRadius = "50%";
2676
- const fillOpacity = style.fillOpacity ?? this.shapeStyleDefaults.point.fillOpacity;
2677
- const strokeOpacity = style.strokeOpacity ?? this.shapeStyleDefaults.point.strokeOpacity;
2678
- el.style.backgroundColor = colorWithOpacity(style.fill ?? "rgba(0,0,0,0.1)", fillOpacity);
2679
- el.style.borderWidth = `${style.strokeWidth ?? this.shapeStyleDefaults.point.strokeWidth}px`;
2680
3058
  el.style.borderStyle = "solid";
2681
- el.style.borderColor = colorWithOpacity(style.stroke ?? "#000", strokeOpacity);
2682
3059
  el.style.transform = anchorFromBottomCenter("center");
3060
+ this.applyShapePointStyle(el, style);
2683
3061
  const marker = new google.maps.marker.AdvancedMarkerElement({ map, position, content: el });
2684
3062
  if (!interactive)
2685
3063
  setHitTargetInert(marker.element, true);
2686
3064
  return marker;
2687
3065
  }
3066
+ /** The style-derived part of a point marker's element; shared by creation and in-place restyling. */
3067
+ applyShapePointStyle(el, style) {
3068
+ const diameter = (style.pointRadius ?? this.shapeStyleDefaults.point.pointRadius) * 2;
3069
+ const fillOpacity = style.fillOpacity ?? this.shapeStyleDefaults.point.fillOpacity;
3070
+ const strokeOpacity = style.strokeOpacity ?? this.shapeStyleDefaults.point.strokeOpacity;
3071
+ el.style.width = `${diameter}px`;
3072
+ el.style.height = `${diameter}px`;
3073
+ el.style.backgroundColor = colorWithOpacity(style.fill ?? "rgba(0,0,0,0.1)", fillOpacity);
3074
+ el.style.borderWidth = `${style.strokeWidth ?? this.shapeStyleDefaults.point.strokeWidth}px`;
3075
+ el.style.borderColor = colorWithOpacity(style.stroke ?? "#000", strokeOpacity);
3076
+ }
2688
3077
  // ============================================================================
2689
3078
  // Private: Route creation
2690
3079
  // ============================================================================
@@ -2817,6 +3206,7 @@ class GoogleMapsLayerPort {
2817
3206
  if (domEvent instanceof MouseEvent && this.isSymbolMarkerAtClientPosition(domEvent.clientX, domEvent.clientY)) {
2818
3207
  return;
2819
3208
  }
3209
+ this.pointerShapeHover = { handleId, featureId };
2820
3210
  this.emitEntityInteraction("hover-start", entity);
2821
3211
  }),
2822
3212
  shape.addListener("mousemove", (e) => {
@@ -2826,10 +3216,10 @@ class GoogleMapsLayerPort {
2826
3216
  this.pointerMoveReporter?.(latLngToPosition(latLng));
2827
3217
  }),
2828
3218
  shape.addListener("mouseout", () => {
3219
+ this.clearPointerShapeHover(handleId, featureId);
2829
3220
  this.emitEntityInteraction("hover-end", entity);
2830
3221
  }),
2831
3222
  ];
2832
- tracked.listeners.push(...listeners);
2833
3223
  tracked.shapeListeners.set(shape, listeners);
2834
3224
  }
2835
3225
  attachShapePointInteractionListeners(marker, featureId, shapeType, handleId) {
@@ -2852,9 +3242,11 @@ class GoogleMapsLayerPort {
2852
3242
  this.emitEntityInteraction("dblclick", entity);
2853
3243
  });
2854
3244
  content.addEventListener("mouseenter", () => {
3245
+ this.pointerShapeHover = { handleId, featureId };
2855
3246
  this.emitEntityInteraction("hover-start", entity);
2856
3247
  });
2857
3248
  content.addEventListener("mouseleave", () => {
3249
+ this.clearPointerShapeHover(handleId, featureId);
2858
3250
  this.emitEntityInteraction("hover-end", entity);
2859
3251
  });
2860
3252
  }