Map object option reconciliation
Map object option reconciliation keeps Google Maps overlay options aligned with React props without repeating unchanged writes. It compares the desired option set with the values known to be applied, resets removed values to map defaults, and records a safe snapshot for the next update. Camera tilt uses a separate map-specific constraint because the allowed tilt depends on zoom.
Overlay option updates
Overlay components use a shared update path for options such as style, edit, drag, and click behavior. Creation applies the initial options with the object, then records that baseline; later prop changes update the existing map object instead of recreating it. This keeps the React lifecycle separate from the map object's lifetime while avoiding redundant redraw work on editable shapes. References: src/…/circle.tsx• L80-105, src/…/polyline.tsx• L92-137, src/…/polygon.tsx• L106-151, src/…/rectangle.tsx• L76-100
The reconciliation state belongs to each map object. A newly seen object receives the full option set, while an object created with its options already applied can record that baseline without a second write. The latter signal is important when creation and a prop change happen in the same React commit: the update must not be mistaken for an already-applied value. References: src/…/set-map-object-options.ts• L7-33, src/…/set-map-object-options.ts• L36-56
flowchart LR
P[React overlay props] --> O[Normalized overlay options]
O --> C{Known applied values}
C -->|No change| N[No map write]
C -->|Changed or removed key| D[Changed option set]
D --> M[Map object setOptions]
M --> S[Stored option snapshot]
O -->|Object creation| B[Record already-applied baseline]
B --> S
Option change detection
The change detector compares the union of keys in the desired options and the tracked options. It returns only changed keys or no result when the two sets match, so the map API receives the smallest meaningful update. References: src/…/get-changed-options.ts• L19-66
Option removal is an explicit reset. If a key was tracked before but is absent from the next option set, the detector sends null, which the Maps API uses to return that option to its default. An explicitly present undefined remains distinct from a missing key, because key presence carries the update contract. References: src/…/get-changed-options.ts• L8-17, src/…/get-changed-options.ts• L44-63, src/…/get-changed-options.test.ts• L54-76
Value normalization
The comparison uses deep value equality for nested option values. This means equivalent arrays or objects, such as icon definitions, do not trigger a write only because a caller created a new container. References: src/…/get-changed-options.ts• L1-3, src/…/get-changed-options.test.ts• L26-43
Tracked values are copied before they are stored. Arrays and plain objects are copied recursively so later mutation of a prop value cannot change the comparison baseline; map API class instances and other non-plain objects remain references. This normalization protects reconciliation when option values are mutable. References: src/…/get-changed-options.ts• L68-96, src/…/get-changed-options.test.ts• L79-96
Map option updates
Map-level options follow a broader update path than overlay options. The map component selects supported map option props and sends them through a deep-compare effect when the map is available. Camera position is handled separately so center, zoom, heading, and tilt can be compared with the map's tracked camera state. References: src/…/use-map-options.ts• L4-40, src/…/use-map-options.ts• L42-73, src/…/index.tsx• L130-135
Camera tilt constraints
Camera tilt is a view-state value, not an overlay option. When the map receives a finite tilt prop, the camera update path compares it with the known map state and moves the camera only when it differs. References: src/…/use-map-camera-params.ts• L21-29, src/…/use-map-camera-params.ts• L31-70
The exported limitTiltRange helper protects map-compatible view state for integrations that use a pitch value. It converts the integration zoom to Google Maps zoom, derives a maximum tilt from that zoom, fixes the field of view at 25, and caps pitch at the maximum. The limit rises from 30 at low zoom to 67.5 at high zoom, with linear ranges between those bounds. References: src/…/limit-tilt-range.ts• L1-30, src/index.ts• L24-26
flowchart TD
V[Integration view state] --> Z[Convert view zoom]
Z --> L[Derive max tilt from zoom]
V --> P[Read pitch]
L --> C[Cap pitch at max tilt]
P --> C
C --> R[View state with fovy 25 and bounded pitch]
Related concepts
Use the parent page for the wider set of React integration utilities. Use the map runtime page for map creation and camera lifecycle context, and the geometric overlays page for the overlay features that consume this option update path.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the baseline recorded at object creation aligned with every option passed to the map object's constructor or initial
setOptionscall. - Preserve the
nullreset contract when an option disappears; a missing key must not be treated as an unchanged value. - If option values gain new nested mutable forms, confirm that snapshots and equality still prevent false no-change results.
- If camera zoom or tilt semantics change, update both the camera comparison path and the zoom-based tilt limit.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An option is removed without sending a reset value | The map object keeps the old setting | The detector writes null for tracked keys missing from the next set |
| Creation options are recorded as a later update | The map receives a redundant write or a same-commit change can be lost | Callers record an already-applied baseline after creation |
| A nested option value is mutated after tracking | A real change can look unchanged | Snapshots copy arrays and plain objects recursively |
| A view pitch exceeds the zoom-specific map limit | The integration requests a camera state the map should not use | limitTiltRange caps pitch from the derived maximum tilt |
Key files
| File | Why to read it |
|---|---|
| src/…/get-changed-options.ts | Defines key comparison, reset values, and tracked-value snapshots |
| src/…/set-map-object-options.ts | Connects change detection to per-object map updates |
| src/…/circle.tsx | Shows creation, baseline recording, and later option reconciliation for an overlay |
| src/…/polyline.tsx | Shows the same flow for an overlay with controlled path state |
| src/…/polygon.tsx | Shows option reconciliation with nested controlled paths |
| src/…/use-map-options.ts | Defines map-level option selection and updates |
| src/…/use-map-camera-params.ts | Defines controlled camera comparison and updates |
| src/…/limit-tilt-range.ts | Defines the zoom-dependent tilt constraint |