Skip to content

Repaint the map when the origin of <Canvas> or <Coordinates> changes - #177

Open
quassy wants to merge 2 commits into
RodrigoHamuy:mainfrom
quassy:fix/repaint-on-origin-change
Open

quassy wants to merge 2 commits into
RodrigoHamuy:mainfrom
quassy:fix/repaint-on-origin-change

Conversation

@quassy

@quassy quassy commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

This also came up on our work on adding ellipsoid support to react-three-map. I'm not sure what your (agentic) contribution policy is, so happy to work on the PR based on your feedback :)

Built with help from @RichardMEN11.


Problem

Both canvas modes draw only when the map repaints: in a map layer, the layer's render, and over the map, the custom layer that feeds the overlay its view projection. With frameloop="demand", nothing asks for a repaint when the latitude, longitude or altitude of <Canvas> or of a <Coordinates> change. So the scene, and the camera that pointer events use, keep the old origin until the map moves for another reason. R3F only asks for one when an object's props change, which a moved origin doesn't do.

Change

  • In a map layer (useRender), over the map (SyncCameraFC) and in <Coordinates>, an effect asks the map to repaint when the origin matrix changes.
  • A patch changeset.

Testing

  • The first commit, Render <Canvas> in happy-dom for component tests, is shared with the <NearCoordinates> PR; see there.
  • src/test/repaint.test.tsx, in both canvas modes with frameloop="demand" and a scene with nothing that changes with the origin: the map is asked to repaint when the canvas moves, when it rises, and when a <Coordinates> moves, before any frame is drawn.
  • On main, all 6 tests fail. Removing any one of the three effects fails the tests for its mode.
  • CI runs R3F 8.15.12. The tests also passed once by hand on R3F 9.6.1 with React 19.2.7.
  • yarn lint, ts:check, test and build pass.

Notes

  • This PR and the <NearCoordinates> PR share their first commit, and merging both conflicts only in the React import line of src/api/coordinates.tsx, where each adds a hook.

🤖 Generated with Claude Code

A WebGL context that draws nothing, and helpers that render <Canvas> in a map layer or over the map and draw
frames. vitest loads R3F's ES build, because its CommonJS build would load three's CommonJS build next to the
ES build the tests use.
Both canvas modes draw only when the map repaints. With frameloop="demand", nothing asked for a repaint when
the latitude, longitude or altitude of <Canvas> or <Coordinates> changed, so the scene and the pointer camera
kept the old origin until the map moved. They now ask for one when their origin matrix changes.
@quassy
quassy requested a review from RodrigoHamuy as a code owner December 1, 2026 13:43
@changeset-bot

changeset-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 817c30c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-three-map Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant