Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox gl geojson layer disappears on higher zoom

I have a geojson representing contour layers of interpolated weather data. Certain contours disappear at higher zoom levels as seen in following screengrab. Layer disappears on higher zoom

When adding the multipolygon to Mapbox as a layer, using the following code:

map.addSource('mintempContour', {
        type: 'geojson',
        data: geojson_source
        });

        map.addLayer({
            "id": 'mintemp',
            "type": "fill",
            "minzoom": 2,
            "maxzoom": 15,
            "source": "mintempContour",
            "layout": {
                'visibility': 'visible'
            },
            "paint": {
                "fill-color": { type: 'identity', property: 'fill' },
                "fill-opacity": 1

            }

            //"filter": ["==", "$type", "Polygon"]
        }, 'water');

I have tested the geojson file on sites like geojson.io and the contours remain visible at all zoom levels.

I want all contours to be present all the time, regardless of the zoom level. How can I fix this?

Quick and dirty JSFiddle replicating issue: https://jsfiddle.net/stefmarais/ae9nzmrt/12/

like image 777
Stef Marais Avatar asked Nov 16 '25 05:11

Stef Marais


1 Answers

You are setting maxZoom when calling addLayer, which according to the docs does:

The maximum zoom level for the layer. At zoom levels equal to or greater than the maxzoom, the layer will be hidden. https://docs.mapbox.com/mapbox-gl-js/style-spec/#layer-maxzoom

I think you actually want to set maxzoom on the source, not the layer:

Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels). https://docs.mapbox.com/mapbox-gl-js/style-spec/#sources-geojson-maxzoom

(or just none at all).

like image 129
Scarysize Avatar answered Nov 17 '25 21:11

Scarysize



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!