-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Custom filter functions #4490
Comments
Just found #4077 and realized you may not want that kind of solution because it is js-only and not cross-platform. Nevertheless I would enjoy. |
Yes, we need to keep the style serializable as JSON for a variety of reasons. #4077 covers what we're likely to implement in this area. |
Motivation
I want to visualize a big dataset that should get filtered depending on the records in an array property. The array has a variable number of timestamps that all belong to the very same geometry (the variable size of the array is the reason why I can´t split it to seperate key value pairs
timestamp1, timestamp2, ... , timestampN
).With the current filter-functions it is not possible to get this kind of filtering done.
I already did a monky-hack to to give it a test and it works great (see "design" + disabling style validation ;-).
But I would wish this would come to mainline.
Design Alternatives
That is always an option. But I could think others would like custom filters as well. Some uses and posibilities I can imagine:
Math
functions; e.g.Math.abs
using the value as a filter but the sign determins the paint color (a lot of this is possible by preprocessing the data; but if I wouln´t have to I wouldn´t do)substring
,lowercase
,charAt
, ....Design
allow a new type of filter where the operator is
custom
and the value is a function-body as a string. Use the function-body directly in the createFilter function like so:Mock-Up
Concepts
a short addition in docs. The only tricky aspect is that you have to know and trust blindly that
f
is there and it is the featureThe name of the operator should be one of those (if there has to be one):
["custom", "<fnBody>"]
["fn", "<fnBody>"]
I like "fn" but I also think it is more easy to say "I use a custom filter-function" then "I use a fn filter function" or "function filter-function"
Implementation
as shown above but with some validation here and there.
It would be also a good thing to make the devs aware of...
A. The function gets called in a worker.
B. The feature is not just the plain JSON-object.
C. The filter-function should be a "pure function" and not too complex
BTW Thanks for your work.
P.S.: Cances are good that I will also want this for data-driven paint properties at some point ;-)
The text was updated successfully, but these errors were encountered: