0

This is just a snippet of the code, but I'm trying to get a grasp on Mapbox interpolate/zoom syntax.

 "layerStyle": [
                {
                    "type": "line",
                    "layout": {},
                    "paint": {
                        "line-color": "#6a6a6a",
                        "line-opacity": [
                            "interpolate",
                            [
                                "linear"
                            ],
                            [
                                "zoom"
                            ],
                            0,
                            0,
                            14,
                            0.3,
                            22,
                            0.6
                        ]
                    }
                }
            ],

So each of these numbers represents a degree of line opacity at a given zoom level right? Or are they in pairs(I didn't write this code, just inherited it)? I've seen examples online of numbers under line-opacity written as pairs in square brackets.

My goal is to have this layer be "invisible" when zoomed out the most (zoom level 1?) and appear closer to a county level (zoom level I'm not sure).

1 Answer 1

1

There is some documentation online:

https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#paint-line-line-opacity https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#interpolate

Meaning of this style

"interpolate",["linear"],["zoom"],0,0,14,0.3,22,0.6]

is that at zoom level 0 the opacity is 0 (totally invisible). Opacity value is changing linearly between zoom levels 0 and 14 so that at zoom level 14 it will reach 0.3. From zoom level 14 till zoom level 22 the opacity changes linearly from 0.3 till 0.6.

If you want that the layer should stay invisible for example from level 0 to level 5 you can add one more stop for level 5 and interpolate opacity value from 0 to 0:

"interpolate",["linear"],["zoom"],0,0,5,0,14,0.3,22,0.6]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.