![]() With feature state, you can update the styling of a map layer's individual features based on user interaction, without needing to re-render the underlying geometry and data after each interaction event. In this case, the trigger is a user mousing over or away from a feature, which will update the style of the feature based on the rules set by the expressions. You will use feature state to define what the switch is, and expressions to set the style. You can think of feature state as a switch that turns a fan on or off. For vector sources or GeoJSON sources that are added before runtime, you must set a unique id for each feature before the source is added to the map. If you are adding a GeoJSON source at runtime, which is what you will do in this tutorial, you can use the generateId option in map.addSource() to add an id to each feature. Each feature in the source must have a unique numeric id in order for feature state to work correctly. ![]() You can use feature state with expressions to style the features of a vector or GeoJSON source in either a dataset or tileset. You will use the USGS Earthquake Catalog API to retrieve information about all earthquakes with a magnitude of one or more that have happened within the past week.įeature state is a set of user-defined attributes that can be dynamically assigned to a feature on the map. Use the text editor of your choice for writing HTML, CSS, and JavaScript. Mapbox GL JS is a JavaScript API for building web maps. Your Mapbox access tokens are on your Account page. To complete this tutorial, you will need:
0 Comments
Leave a Reply. |