Skip to content

feat(RasterSource): add prefetchZoomDelta and tileNetworkRequestsDela… - #4356

Merged
mfazekas merged 3 commits into
rnmapbox:mainfrom
oliverfernandez:feat/raster-source-prefetch-and-network-delay
Nov 9, 2026
Merged

mfazekas merged 3 commits into
rnmapbox:mainfrom
oliverfernandez:feat/raster-source-prefetch-and-network-delay

Conversation

@oliverfernandez

@oliverfernandez oliverfernandez commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Added prefetchZoomDelta and tileNetworkRequestsDelay props to RasterSource. They expose two Mapbox v11 raster source options that are set today only by the SDK defaults:

  • prefetchZoomDelta: when greater than 0, the map first requests a tile at a zoom level below zoom - delta, rounded to a multiple of the delta, to show a low-resolution map quickly. Mapbox defaults to 4. 0 turns the prefetch off, which suits overlays such as weather radar where the placeholder is never visible.
  • tileNetworkRequestsDelay: milliseconds to wait before a tile's network request goes out while a gesture or camera animation is in progress. Tiles that leave the viewport before the delay elapses are never requested. Mapbox defaults to 0.

Both map straight to RasterSource.prefetchZoomDelta / tileNetworkRequestsDelay on iOS and RasterSource.Builder.prefetchZoomDelta() / tileNetworkRequestsDelay() on Android. They are read when the source is created, like the other source props.

Motivation: a weather app with 25 raster frames at one camera position. With the defaults, each frame also fetched parent tiles it never showed, and a pan requested tiles for positions the finger had already left. With these two options the same open costs a quarter of the tile requests.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Testing notes: verified on iOS (v11, New Architecture) and compiled on Android (v11, New Architecture) through a production React Native 0.81 app that consumes this branch as a patch: the Fabric codegen picks up the new spec props, the component view and the Swift source compile, the Kotlin manager and source compile, and the raster tiles render on the iOS simulator with prefetchZoomDelta={0} and tileNetworkRequestsDelay={200}. A proxy capture on iOS confirmed that only tiles of the current zoom level are requested. Android was compile-checked only; the new example scene RasterSourceTileRequests is the place to confirm it at runtime.

Screenshot OR Video

No visual change. The example scene Fill/Raster Layer > Raster Source tile requests shows the props in use; compare the network log with Raster Source while panning.

…y props

Expose two Mapbox v11 raster source options that were not reachable from
JavaScript:

- prefetchZoomDelta: how many zoom levels above the current one are requested
  as placeholders while the current tiles load. 0 turns the prefetch off.
- tileNetworkRequestsDelay: milliseconds to wait before a tile's network
  request goes out during a gesture or camera animation, so tiles that leave
  the viewport first are never requested.

Both map straight to the native source builders on iOS and Android. Docs
regenerated with yarn generate, and a new example scene uses both props.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@mfazekas mfazekas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is useful and the wiring matches tileSize on both platforms. A few changes before merging:

  1. Android: setPrefetchZoomDelta / setTileNetworkRequestsDelay in RNMBXRasterSourceManager call asInt() / asDouble() without checking value.isNull. If an app sets one of these props and later removes it, Fabric passes a null Dynamic and the call throws. Please skip (or reset to null) when the value is null.
  2. The prefetchZoomDelta doc says tiles "up to this many zoom levels above it" are requested. Per the SDK, the map first requests a single lower-zoom tile, at a zoom below zoom - delta rounded to a multiple of delta, to show a coarse map quickly. Please align the wording with that.
  3. Both props are only read when the source is created, so changing them after mount has no effect. Please say so in both docs.
  4. The example uses tile.openstreetmap.org with no attribution; OSM's tile usage policy requires it and discourages app traffic. Either add attribution on the source or reuse the tile URL from the existing RasterSource example.

We'll also check the Android side at runtime on an emulator, since it has only been compile-checked so far.

@mfazekas

mfazekas commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @oliverfernandez! Since this has been quiet for a while, we have taken it over and pushed the remaining review fixes on top: null-safe prop removal on Android, corrected prefetchZoomDelta docs, "only read when the source is created" on both props, and OSM attribution in the example. We will merge once CI is green.

@mfazekas mfazekas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review fixes are in; verified on Android.

@mfazekas
mfazekas merged commit dc1e5ee into rnmapbox:main Nov 9, 2026
19 of 20 checks passed

This branch was previously deployed

1 inactive deployment
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.

2 participants