Error "can not read property 'setFilter' of undefined" with mapbox js 3.1.1

0

The code below captures when the user zooms in on the map, when it reaches 13 it should hide layer privLayer but does not recognize the function that filters the results.

I already tried with

privLayer.setFilter(function() { 
return true; 
}).addTo(map);

and for some reason it does not show anything, it's as if it omitted the function.

var map = render_map();
var privLayer = L.mapbox.featureLayer()
.addTo(map);

map.on('zoomend', function() {
    // here's where you decided what zoom levels the layer should and should
    // not be available for: use javascript comparisons like < and > if
    // you want something other than just one zoom level, like
    // (map.getZoom > 10)
    if (map.getZoom() > 13) {

        // setFilter is available on L.mapbox.featureLayers only. Here
        // we're hiding and showing the default marker layer that's attached
        // to the map - change the reference if you want to hide or show a
        // different featureLayer.
        // If you want to hide or show a different kind of layer, you can use
        // similar methods like .setOpacity(0) and .setOpacity(1)
        // to hide or show it.
        map.privLayer.setFilter(function() { 
            return false;});
        console.log('Zoom > 13');
    } else {
        console.log('Zoom < 13');
        map.privLayer.setFilter(function() { return true; });
    }
});
    
asked by Juan Solorzano 18.07.2018 в 20:55
source

0 answers