mapbox / mapbox-gl-leaflet

binding from Mapbox GL JS to the Leaflet API
ISC License
522 stars 154 forks source link

Uncaught Map has no maxZoom specified. markercluster #113

Open dmis53 opened 5 years ago

dmis53 commented 5 years ago

If I first build markers in a cluster group on a different tile, and therefore switch to MapBox GL, everything is fine. But if you turn on MapBox GL first and then add a cluster to the group, then I fall into the error: "Uncaught Map has no maxZoom specified"

I added MapBox GL to my tile list:

    createMapBoxGlLayer: function () {
        return L.mapboxGL({
            accessToken: 'my-token',
            style: 'mapbox://styles/mapbox/light-v10'
        });
    },

My baselayerchange event:

        leafletMap.on('baselayerchange', function(tile){
            if (tile.name === 'My Tile Name') {
                var map = tile.layer._glMap;
                map.on('load', function () {
                    var layers = map.getStyle().layers;

                    var labelLayerId;
                    for (var i = 0; i < layers.length; i++) {
                        if (layers[i].type === 'symbol' && layers[i].layout['text-field']) {
                            labelLayerId = layers[i].id;
                            break;
                        }
                    }

                    map.addLayer({
                        'id': '3d-buildings',
                        'source': 'composite',
                        'source-layer': 'building',
                        'filter': ['==', 'extrude', 'true'],
                        'type': 'fill-extrusion',
                        'minzoom': 15,
                        'paint': {
                            'fill-extrusion-color': '#bfbcbf',
                            'fill-extrusion-height': [
                                "interpolate", ["linear"], ["zoom"],
                                15, 0,
                                15.05, ["get", "height"]
                            ],
                            'fill-extrusion-base': [
                                "interpolate", ["linear"], ["zoom"],
                                15, 0,
                                15.05, ["get", "min_height"]
                            ],
                            'fill-extrusion-opacity': .6
                        }
                    }, labelLayerId);
                });
            }
        });
bpatrik commented 3 years ago

It seems to be related to: https://github.com/Leaflet/Leaflet.markercluster/issues/611