-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Data driven properties on line-gradient colors #8977
Comments
For the heatmap, this is technically impossible since the heatmap layer gets colorized after the accumulation stage (when all features are rendered into one grayscale texture), using a single gradient as lookup. For the line gradient though, this might be possible — needs investigation. |
Ok. I thought I was the same "engine" underneath since they share common API but, yeah, I'm mostly interested in |
Is there a some kind of "standard procedure" in order to implement a data driven property ? I'm trying to investigate on my own but I'm not familiar with the code so it's not very efficient 😄 |
I've been using something like this:
Seems to work well, but ideally I want there to be a hard line between the colour transitions. But I can't seem to figure out how to do that. |
Hello, I have a need to put several animated lines with different gradients on the map. Trying to read gradient values from a line's properties (in the same manner as matthieugouel did) ended up with this error:
Will it be fixed sometime? It looks like the only way to do my task is to put lines in different layers which will hit performance, and I would rather not to do that. |
any update? |
I'm also very much interested in having such functionality. |
Adding another request for this feature! |
This feature would be great, thanks :) |
Also it would be great if the gradient values (not colors) were to be taken from a property or an array that matches the line points array. |
Hi. I found a solution for this, maybe.
PS: Code for getDistanceFromLatLng
|
@EarlOld this only works for a single feature. Ideally, we would be able to set data-driven line-gradients for tons of lines in the same layer (such as a road network visualizing traffic). One way we could do that is by keeping 'line-gradient-progress': [
'interpolate', 'linear', ['line-progress'],
0, ['get', 'start_speed'],
1, ['get', 'end_speed']
] |
Any updates? Would love to have this feature to track altitude above the ground for a flight tracking app. |
Also very interested in this feature. We have a lot of line segments that we want to dynamically aplly a gradient to, and currently the only way to achieve this is to split them into individual layers, which comes with a huge performance hit (we have hundreds of them). Having an ability to use data driven properties to control gradient would be extremely useful! |
Adding my support here - this would be perfect for visualizing a vehicle's speed along a route (collection of |
Ultimately we've decided to implement a custom mapbox layer with three.js (via threebox) and some custom gradient logic. Now we have one layer with hundreds of lines and we can change the gradient dynamicly on a per-line basis. The performance with this approach is really nice, we notice virtually no difference compared to the vanilla implementation. Since it's a custom layer for mapbox, this means all the higher-level logic related to mapbox required very little changes - most of the effort was spent building this custom layer itself. This is not the ideal solution since it introduces some extra dependencies and extra complexity, but if the dynamic gradients are a key feature for your particular use-case (as it is for us), I would recommend looking into supplementing mapbox with three.js. |
@eslavnov |
@nickfaughey @eslavnov @dalbani There's actually another way to achieve this that scales with only the numbers of colors in your ramp. Instead of adding your line geometry and varying the gradient stops, we can tweak the source geometry such that it's representable by a static gradient scheme. Here's how it would work, with a color ramp that goes In the style, we add a line layer for every pairwise colors in the ramp sequence: In the geometry, we figure out where each stop would be, and chop up the line at those points (this is easy with a utility like turf.lineSliceAlong), so that the original line is now up to We use layer
The ideal solution is probably data-driven gradient stops, but this should be viable until then. |
Here is an implementation with the Mapbox custom layer and Three.js (via ThreeBox-plugin). It only uses one layer, but you can define different lines with different start and end colors. You can also extend it easily in order to support more-points gradient. Hope this will help! |
Any update on this? It would be great to have data-driven gradient stops. Thanks |
Adding my interest in this feature, especially considering threebox is now archived. Would be great to paint different gradients in the same layer as opposed to sorting features by color and then painting them to different layers. |
Has anyone tried splitting the line into features and adding a layer for each feature? Should work, no idea at which amount of layers it might break though 🙈 |
@LunicLynx Can you please share your solution code as soon as possible ? Has anyone tried splitting the line into features and adding a layer for each feature? |
@GadhiyaRiddhi there is no code. I just think it should be possible. |
We would also be very interested in this. |
Also expressing interest in this! |
Thanks. That approach works great |
I implemented it this way now:
This colors the line in a gradient green to yellow to red depending on the value of myProperty. myProperty has two values, one for the starting point and one for the end point. Everything <= 0 is green and >=10 is red. So if I have myProperty=[2.5, 7.5] the start is yellow-green, the end is orange and the colors in between a smooth gradient. Here is the function to get the RGB tuple based on an input number (myProperty) and the upper and lower bounds (here 0 and 10):
|
Motivation
As far as I tested for know, it seems not possible to use data driven property to set the color associated with the percentages in the line-gradient / heatmap paint property.
For instance see this API example below :
Cheers,
Matthieu.
The text was updated successfully, but these errors were encountered: