Skip to content

feat(ShapeSource, VectorSource): add promoteId - #4396

Merged
mfazekas merged 1 commit into
mainfrom
feat/promote-id
Oct 25, 2026
Merged

mfazekas merged 1 commit into
mainfrom
feat/promote-id

Conversation

@mfazekas

@mfazekas mfazekas commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Added promoteId?: string | Expression to ShapeSource and VectorSource. It makes a feature property, or an expression, the feature id, so setFeatureState / getFeatureState work with string ids and with vector tiles that have no numeric ids.

The native mapping is 1:1. On iOS it uses GeoJSONSource.promoteId2 and VectorSource.promoteId2 = .global(...), both typed Value<String>. On Android it uses GeoJsonSource.Builder.promoteId(PromoteId(...)) and VectorSource.Builder.promoteId(PromoteId(...)), with the PromoteId(String) or PromoteId(Expression) constructor. These exist in the current default 11.23.1 (iOS promoteId2 since 11.12). The per-source-layer object form is left out so the prop stays 1:1 with promoteId2. The web ShapeSource passes the value through to mapbox-gl's promoteId, but I haven't run the web build.

The FeatureState example now uses promoteId="name" and keys the state by the name property instead of numeric feature ids.

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)

Screenshot OR Video

I tested on the iOS simulator (iPhone 17 Pro, iOS 26.5) and an Android emulator (Pixel 6), using SDK 11.23.1.

  1. ShapeSource with string promoteId: on Android, tapping the east shape calls setFeatureState('east', …) and the shape switches to its selected colour. On iOS, simulated taps didn't reach the map's onPress in my setup, so I called setFeatureState('west', { selected: true }, 'shapes') from code instead, and the west shape turned red.
  2. VectorSource with expression promoteId: I added a temporary VectorSource (mapbox.mapbox-streets-v8, promoteId={['get', 'name']}) with a CircleLayer on place_label coloured by feature state. setFeatureState('Chicago', { selected: true }, …, 'place_label') turned the Chicago circle red on both platforms. On Android, getFeatureState returned {"selected":true} for Denver, Chicago and Dallas. This check is not part of the PR.
4396-shapesource-promoteId-west-selected 4396-vectorsource-promoteId

@mfazekas
mfazekas merged commit 5937411 into main Oct 25, 2026
10 checks passed
@mfazekas
mfazekas deleted the feat/promote-id branch October 25, 2026 15:54

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.

1 participant