Introducing a new way to review your PRs.

Read the announcement

visgl / react-google-maps

React components and hooks for the Google Maps JavaScript API

View on GitHub

19 documents · Updated Nov 2, 2026

docs / three-dimensional-scene-elements

3D scene elements

3D scene elements add geographic content to a Map3D scene. The library exposes React components for custom markers, 3D models, filled areas, connected lines, circular paths, and terrain flattening. These components pass their position, shape, style, and click behavior to the Google Maps 3D custom elements that render the scene; see three-dimensional-maps for the map and camera model and three-dimensional-map-access for access and loading concerns.

Scene element model

Each scene element is a child of Map3D and represents one visual object in the camera view. Coordinates can include altitude, while an altitude mode tells the Google Maps 3D API how to interpret that altitude. Elements can also opt into camera fitting, control whether hidden parts remain visible, and set their draw order.

The public 3D entry point groups these elements with Map3D, marker content helpers, and map access utilities. Applications can therefore build a scene from one import surface while keeping the map responsible for the camera and the elements responsible for scene content. (src/3d/index.ts#L5-L15)

ElementScene roleMain spatial input
MarkerPlaces custom HTML content at a location.position
Marker3DPlaces a 3D marker with a label or custom content.position
Model3DPlaces a glTF model in the scene.position, src
Polygon3DDraws a filled area with an optional hole.path, innerPaths
Polyline3DDraws a connected line through locations.path
CirclePathDescribes a circle path from a center and radius.center, radius
FlattenerChanges the 3D surface inside a path.path, innerPaths

References: src/…/index.ts• L5-15 src/…/types.ts• L1-6

Marker elements

Markers represent point features that should stay associated with a geographic position. Marker uses custom HTML content and selects an interactive Google Maps element when an onClick handler is present. Marker3D provides the dedicated 3D marker behavior, including labels, altitude display, collision handling, and child content such as Pin, images, or SVG.

The two marker components serve related but distinct roles: Marker is the current custom-element adapter in the 3D component group, while Marker3D also manages marker content for child components and exposes marker context. Both turn click behavior into an interactive marker variant rather than treating the event as a separate overlay. (src/…/marker.tsx• L9-29, src/…/marker.tsx• L47-75, src/…/marker-3d.tsx• L19-37, src/…/marker-3d.tsx• L77-87)

Marker3D can render a standard pin or custom child content. A child such as Pin can use the marker context to manage its own content. Otherwise, the marker relocates supported React children into the marker's content area so that images and SVG content render as marker visuals. (src/…/marker-3d.tsx• L135-194, src/…/marker-3d.tsx• L216-224)

Marker interactions

An onClick prop changes a marker from a display-only element to an interactive element that emits gmp-click. The same choice applies to models, polygons, and polylines, so applications can use one interaction pattern across different scene objects. (src/…/marker.tsx• L47-75, src/…/model-3d.tsx• L27-50, src/…/polygon-3d.tsx• L46-73, src/…/polyline-3d.tsx• L45-71)

References: src/…/marker.tsx• L9-29 src/…/marker.tsx• L47-75 src/…/marker-3d.tsx• L19-37 src/…/marker-3d.tsx• L77-87 src/…/marker-3d.tsx• L135-224

3D models

Model3D places a glTF model in the scene. The model needs both a source URL and a position, then uses altitude mode, orientation, and scale to align the model with the map. This makes it suitable for objects that need real 3D form instead of a point marker. (src/…/model-3d.tsx• L21-26, docs/…/model-3d.md• L18-46)

The component keeps model placement and model appearance separate. Position and altitude define where the model sits, orientation defines how it faces, and scale defines its size. A click handler enables the interactive model variant and exposes the location click event. (src/…/model-3d.tsx• L27-50)

References: src/…/model-3d.tsx• L9-19 src/…/model-3d.tsx• L21-50 docs/…/model-3d.md• L18-53

Polygon and polyline geometry

Polygon3D and Polyline3D turn ordered geographic coordinates into surface or line geometry. A polygon fills an outer path and can contain inner paths as holes. A polyline connects its path points without an area fill. Both can use altitude modes, geodesic edges, extrusion, occlusion rules, color, width, and draw order to fit the scene. (src/…/polygon-3d.tsx• L27-67, src/…/polyline-3d.tsx• L27-65)

The following diagram shows how coordinate paths become the two main kinds of drawn geometry and then participate in the 3D scene.

flowchart LR
  A[Coordinate path] --> B{Geometry type}
  B -->|outer path plus inner paths| C[Polygon3D]
  B -->|ordered path| D[Polyline3D]
  C --> E[Filled or extruded area]
  D --> F[Connected or extruded line]
  E --> G[Map3D scene]
  F --> G

Both components can opt into camera fitting. Both also support interactive variants when onClick is set, which lets an application treat a selected boundary or route as a scene object rather than as passive decoration. (src/…/polygon-3d.tsx• L46-73, src/…/polyline-3d.tsx• L45-71)

References: src/…/polygon-3d.tsx• L9-19 src/…/polygon-3d.tsx• L27-73 src/…/polyline-3d.tsx• L9-19 src/…/polyline-3d.tsx• L27-71 docs/…/polygon-3d.md• L22-94 docs/…/polyline-3d.md• L21-91

Surface helpers

CirclePath provides a reusable circular path from a center and radius. Flattener uses a path and optional inner paths to describe an area whose 3D surface should be flattened. These helpers support scene shaping rather than acting as clickable content elements. (src/…/circle-path.tsx• L6-24, src/…/flattener.tsx• L6-24)

The helpers use the same adapter pattern as the drawn elements. React props describe the map object, and the underlying Google Maps custom element receives the current values through a ref-backed binding. This keeps them declarative while allowing the Maps 3D API to own the final scene effect. (src/…/circle-path.tsx• L17-24, src/…/flattener.tsx• L17-24)

References: src/…/circle-path.tsx• L6-24 src/…/flattener.tsx• L6-24

Custom-element adapters

The 3D components are React adapters over Google Maps custom elements. Each adapter keeps a ref to the underlying element, binds changing React props to that element, and renders the matching gmp-* element name. The adapter layer lets React describe scene state without replacing the Google Maps 3D rendering model. (src/…/use-custom-element-ref.ts• L3-14, src/…/model-3d.tsx• L27-50)

Interactive components share a common contract: the presence of onClick selects the interactive custom element and attaches a gmp-click listener. Non-interactive components keep the display-only element. Refs expose the selected underlying element when application code needs direct access. (src/…/types.ts• L3-6, src/…/marker.tsx• L47-75, src/…/model-3d.tsx• L31-50)

When an element accepts geographic paths or positions, the adapter binds those values as scene state. When it accepts visual settings, the adapter binds those too. This gives markers, models, and geometry the same update model even though each has different scene behavior. (src/…/polygon-3d.tsx• L51-67, src/…/polyline-3d.tsx• L50-65, src/…/flattener.tsx• L17-24)

References: src/…/use-custom-element-ref.ts• L3-14 src/…/types.ts• L1-6 src/…/marker.tsx• L47-75 src/…/model-3d.tsx• L27-50 src/…/polygon-3d.tsx• L46-73 src/…/polyline-3d.tsx• L45-71

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the public exports in src/…/index.ts aligned with each supported scene element and its related element type.
  • Preserve the rule that onClick selects the interactive custom-element variant for every interactive scene component.
  • Keep altitude values and altitude-mode handling consistent across markers, models, polygons, and polylines.
  • When marker child content changes, preserve the contract between Marker3DContext, Pin, and the marker content slot.
  • When a Google Maps 3D custom-element option changes, update the matching React prop binding and the corresponding public API reference.

Important failure modes

TriggerConsequenceGuard
A model has no valid src or position.The model does not appear in the scene.Set both the model source and its geographic position.
A click handler is used with a display-only element contract.The scene object cannot receive the expected gmp-click event.Let the adapter choose the interactive variant through onClick.
Marker child content bypasses the marker content contract.Custom content can fail to render as the marker visual.Use supported child content or a content-aware child such as Pin.
A path uses altitude without the intended altitude mode.Geometry can appear at an unexpected height.Set the altitude mode together with altitude-bearing coordinates.
A polygon path or hole has invalid geometry.The filled area can render incorrectly or not at all.Keep the outer path and each inner path as valid ordered coordinate sequences.

Key files

FileWhy to read it
src/…/index.tsShows the public 3D component surface and its relationship to map access.
src/…/marker-3d.tsxExplains 3D marker content, interaction, and child context.
src/…/marker.tsxShows the custom HTML marker adapter and interactive selection.
src/…/model-3d.tsxShows how a 3D model becomes a scene object.
src/…/polygon-3d.tsxShows filled and extruded area behavior.
src/…/polyline-3d.tsxShows connected line and path behavior.
src/…/circle-path.tsxShows the circular path helper.
src/…/flattener.tsxShows the surface-flattening helper.
src/…/use-custom-element-ref.tsShows how React refs connect to underlying custom elements.
docs/…/marker-3d.mdGives the public marker behavior and content model.
docs/…/model-3d.mdGives the public model placement and display model.
docs/…/polygon-3d.mdGives the public polygon path and style model.
docs/…/polyline-3d.mdGives the public polyline path and style model.