CartoDB / mobile-carto-libs

Internal dependencies for CARTO Mobile SDK
BSD 3-Clause "New" or "Revised" License
4 stars 5 forks source link

[feature-request] exp function based on zoom #14

Open farfromrefug opened 3 years ago

farfromrefug commented 3 years ago

It would be awesome to be able to use exp function for colors/numbers based on zoom The idea is achieve something like what mabpox does with exp

Screenshot 2021-08-13 at 16 13 23

In some discussion you talked about interpolation https://github.com/CartoDB/mobile-sdk/issues/9#issuecomment-237169983

that method does not exist anymore? Something like this would be awesome:

line-color: interpolate([view::zoom], (0, 24), (0.75, 32), exp, 15 /*base*/);
mtehver commented 3 years ago

I tried to understand how this works in MapBox Studio based on documentation but it is not very clear. Perhaps this can be done with existing functions/interpolation? For example:

line-width: pow(2.0, linear([view::zoom], (0, 0), (8, 0), (16, 1))
farfromrefug commented 3 years ago

@mtehver indeed it could be possible to do with pow. Managed to get something similar to the exp screenshot with pow(2.0, linear([view::zoom], (8, -4.4), (18, 3.6))) + 0.5;. But as you see getting the right parameters is really hard :s Would be nice to have a way to "express" it in a simpler way. But thanks for the idea!

farfromrefug commented 3 years ago

@mtehver found the source code for the exponential interpolator: https://github.com/maplibre/maplibre-gl-native/blob/ee94520bffeae2f6246284e1931d0cc1d615f708/src/mbgl/style/expression/interpolate.cpp