Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to style each feature in a GeoJson layer #2878

Closed
aravind-lattis opened this issue Jul 15, 2016 · 2 comments
Closed

Ability to style each feature in a GeoJson layer #2878

aravind-lattis opened this issue Jul 15, 2016 · 2 comments

Comments

@aravind-lattis
Copy link

Consider I am having a GeoJson Layer with 5 features, I am able to set a style to the total layer only, I need to control the style for each feature of that layer dynamically not by a GeoJson Property while adding the layer, should be programmatic(for example change the colour of the 1st feature of the GeoJson Layer in a click event).

@lucaswoj
Copy link
Contributor

There are two ways to go about this:

  1. Create a layer per feature. Use filters to only draw one feature per layer. Style each layer independently.

  2. Use data-driven styling to style features based on their properties https://www.mapbox.com/blog/data-driven-styling. This feature is still rolling out and only supported for certain style properties. See the style spec for compatibility information.

@jfirebaugh
Copy link
Contributor

for example change the colour of the 1st feature of the GeoJson Layer in a click event

See https://www.mapbox.com/mapbox-gl-js/example/hover-styles/ for a way to accomplish this specific goal.

Other plans we have in the pipeline for addressing these types of use cases include #200 and #2874.

Closing here since we have existing issues that cover this ground.

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

No branches or pull requests

3 participants