Repository navigation
feat(ShapeSource, VectorSource): add promoteId - #4396
Merged
Merged
Conversation
3 of 8 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added
promoteId?: string | ExpressiontoShapeSourceandVectorSource. It makes a feature property, or an expression, the feature id, sosetFeatureState/getFeatureStatework with string ids and with vector tiles that have no numeric ids.The native mapping is 1:1. On iOS it uses
GeoJSONSource.promoteId2andVectorSource.promoteId2 = .global(...), both typedValue<String>. On Android it usesGeoJsonSource.Builder.promoteId(PromoteId(...))andVectorSource.Builder.promoteId(PromoteId(...)), with thePromoteId(String)orPromoteId(Expression)constructor. These exist in the current default 11.23.1 (iOSpromoteId2since 11.12). The per-source-layer object form is left out so the prop stays 1:1 withpromoteId2. The webShapeSourcepasses the value through to mapbox-gl'spromoteId, but I haven't run the web build.The FeatureState example now uses
promoteId="name"and keys the state by thenameproperty instead of numeric feature ids.Checklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp./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.
promoteId: on Android, tapping the east shape callssetFeatureState('east', …)and the shape switches to its selected colour. On iOS, simulated taps didn't reach the map'sonPressin my setup, so I calledsetFeatureState('west', { selected: true }, 'shapes')from code instead, and the west shape turned red.promoteId: I added a temporaryVectorSource(mapbox.mapbox-streets-v8,promoteId={['get', 'name']}) with a CircleLayer onplace_labelcoloured by feature state.setFeatureState('Chicago', { selected: true }, …, 'place_label')turned the Chicago circle red on both platforms. On Android,getFeatureStatereturned{"selected":true}for Denver, Chicago and Dallas. This check is not part of the PR.