Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

filter or style mvt layer by external function #649

Closed
abenrob opened this issue Jan 5, 2017 · 1 comment
Closed

filter or style mvt layer by external function #649

abenrob opened this issue Jan 5, 2017 · 1 comment

Comments

@abenrob
Copy link

abenrob commented Jan 5, 2017

How would it be possible to filter or apply style functions based on the results of an external function? That is to say a function that derives it's result from data not contained in the mvt source?

For example, I have mvt tiles returning census grid coverage for an area. There are lots and lots of polygons (thousands and thousands.) I would like to be able to filter and/or style these based on the results of a computation (in my case, the results out a routing function that measures census units that are accessible within a certain travel time.) The computation returns an array of ids that are reachable. I would like to filter, or change color or change opacity of the already displayed mvt layer based on the presence of a unit's id in my computed array.

Using the filter syntax, the only way I see to do this is ["in", id_field, id1, id2, id3..., idn]. The two negatives I see there are that a) this needs to be constructed, which will create a massive filter (with several hundreds of ids potentially reachable, and b) the filter is defined on layer definition. I might run this computation many times, and would would want the filter to update with each run, as the array will have changed.

Using data-driven styles, I can access properties in the mvt layer (id being one of them,) but the available functions are based on static classification of those values, not derived values base on a property. So I can do stops or categories based on this value, but not, say, compare this value to my array of ids, and determine style based on the results.

Are any of these options possible? How would I approach this? The examples that show ui-derived filtering are based on small groups, and using map.setLayoutProperty() on individual layers, which will obviously not work with mvt and thousands of census units...

Thanks for the input!

@jfirebaugh
Copy link
Contributor

It sounds like you have a good sense of the current ways to approach this and the tradeoffs. I'll link https://www.mapbox.com/mapbox-gl-js/example/data-join/ just as another example. https://github.com/mapbox/mapbox-gl-js/projects/2 is we're planning on for the future. Related discussion in mapbox/mapbox-gl-js#1399 and other issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants