You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/ui/map.js
+92-27Lines changed: 92 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -1914,23 +1914,42 @@ class Map extends Camera {
1914
1914
1915
1915
// eslint-disable-next-line jsdoc/require-returns
1916
1916
/**
1917
-
* Sets the state of a feature. The `state` object is merged in with the existing state of the feature.
1918
-
* Features are identified by their `id` attribute, which must be an integer or a string that can be
1919
-
* cast to an integer.
1917
+
* Sets the `state` of a feature.
1918
+
* A feature's `state` is a set of user-defined key-value pairs that are assigned to a feature at runtime.
1919
+
* When using this method, the `state` object is merged with any existing key-value pairs in the feature's state.
1920
+
* Features are identified by their `feature.id` attribute, which can be any number or string.
1921
+
*
1922
+
* This method can only be used with sources that have a `feature.id` attribute. The `feature.id` attribute can be defined in three ways:
1923
+
* - For vector or GeoJSON sources, including an `id` attribute in the original data file.
1924
+
* - For vector or GeoJSON sources, using the [`promoteId`](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector-promoteId) option at the time the source is defined.
1925
+
* - For GeoJSON sources, using the [`generateId`](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#geojson-generateId) option to auto-assign an `id` based on the feature's index in the source data. If you change feature data using `map.getSource('some id').setData(..)`, you may need to re-apply state taking into account updated `id` values.
1926
+
*
1927
+
* _Note: You can use the [`feature-state` expression](https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#feature-state) to access the values in a feature's state object for the purposes of styling._
1920
1928
*
1921
1929
* @param {Object} feature Feature identifier. Feature objects returned from
1922
1930
* {@link Map#queryRenderedFeatures} or event handlers can be used as feature identifiers.
1923
1931
* @param {string | number} feature.id Unique id of the feature.
1924
-
* @param {string} feature.source The Id of the vector source or GeoJSON source for the feature.
1925
-
* @param {string} [feature.sourceLayer] (optional) *For vector tile sources, the sourceLayer is
1926
-
* required.*
1932
+
* @param {string} feature.source The id of the vector or GeoJSON source for the feature.
* Features are identified by their `id` attribute, which must be an integer or a string that can be
1964
-
* cast to an integer.
2012
+
* Gets the `state` of a feature.
2013
+
* A feature's `state` is a set of user-defined key-value pairs that are assigned to a feature at runtime.
2014
+
* Features are identified by their `feature.id` attribute, which can be any number or string.
2015
+
*
2016
+
* _Note: To access the values in a feature's state object for the purposes of styling the feature, use the [`feature-state` expression](https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#feature-state)._
1965
2017
*
1966
2018
* @param {Object} feature Feature identifier. Feature objects returned from
1967
2019
* {@link Map#queryRenderedFeatures} or event handlers can be used as feature identifiers.
1968
2020
* @param {string | number} feature.id Unique id of the feature.
1969
-
* @param {string} feature.source The Id of the vector source or GeoJSON source for the feature.
1970
-
* @param {string} [feature.sourceLayer] (optional) *For vector tile sources, the sourceLayer is
1971
-
* required.*
2021
+
* @param {string} feature.source The id of the vector or GeoJSON source for the feature.
0 commit comments