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
Currently when an expression is created with a call to a function the passed arguments are not evaluated before calling that function. For example the following expression won't be evaluated as intended:
["<=", new Date(["get", "inservicedate"]).getTime(), new Date().getTime()]
The idea is that I would get the property inservicedate from my feature, create a date from it and get the time in as a number so that I can use it in my expression to filter. The issue is that ["get", "inservicedate"] doesn't get evaluated (thus not getting the property), but just passed as a parameter (array objec) to the Date() function which results in a null value.
Is this a bug or am I interpreting the docs of mapbox incorrectly? I can change this into a feature request with the following proposed solutions.
Proposed solutions
Support for date objects (besides number, string, boolean, color, array) since this a basic property type when working with a companies assets on a map.
Ability to call a function in an "expressions" way. ["fn", function, value, value, value, ...], so that in my case this would result in: ["fn", new Date(), ["get", "inservicedate"]], where my "get" would actually be evaluated before passed to the function that would return a value of the users choosing.
The text was updated successfully, but these errors were encountered:
Hi @rconjaerts, thanks for using Mapbox. As you've discovered, you can't intermix Mapbox GL expressions with Javascript execution in this way. In the course of constructing an expression (which takes the form of a Javascript array), you can evaluate Javascript -- for instance, including the result of new Date().getTime(). But after that, you should think of an expression as its own self-contained program, which will be evaluated separately from Javascript execution. So you can't feed ["get", "inservicedate"] into the constructor of Date, as you're trying to do here. That's invalid because at the point that new Date(...) is evaluated, ["get", "inservicedate"] is just an array, and the Date constructor doesn't accept that kind of argument.
You could potentially implement date parsing via a (likely very complex) expression, but it would be quite challenging. So I've added a request for support for date and time types within the expression language to #6484. Until then, the best way to accomplish what you're going for here is probably to adapt the data, supplying a field that contains a count of milliseconds-since-the-epoch directly, and using that for the comparison.
+1 on this request. Would be immensely helpful to use DateTimes in expressions to do something like Kepler.gl's DateTime slider (http://kepler.gl/#/demo/earthquakes).
Issue
Currently when an expression is created with a call to a function the passed arguments are not evaluated before calling that function. For example the following expression won't be evaluated as intended:
["<=", new Date(["get", "inservicedate"]).getTime(), new Date().getTime()]
The idea is that I would get the property inservicedate from my feature, create a date from it and get the time in as a number so that I can use it in my expression to filter. The issue is that ["get", "inservicedate"] doesn't get evaluated (thus not getting the property), but just passed as a parameter (array objec) to the Date() function which results in a null value.
Is this a bug or am I interpreting the docs of mapbox incorrectly? I can change this into a feature request with the following proposed solutions.
Proposed solutions
The text was updated successfully, but these errors were encountered: