[GIS] Leaflet making features gone when zoom out

googlejavascriptleaflet

I am wondering about an option to make all or at least majority of placemarks (depends on their internal zoom settings) invisible when zooming out.

It can be something alternative to the leaflet markerclusters:

https://github.com/Leaflet/Leaflet.markercluster

where the placemarks are clustered as we are zooming out.

My goal is to make them completely dissapeared when my zoom level drops. If you don't know what I mean you can open some tile maps i.e. OpenstreetMap or Google. Having a zoom 1 level you have got a blank map, whereas your zoom level increase, a new features are coming up.
Google tile map details dissapear when zooming out

However i don't know, why this attidude doesn't apply to the markers or another features created by an user. It refers both to Google, Google Earth, Leaflet and another interactive mapping tools.

This situation applies to the polygons too, although due to their square features, they tend to be smaller when zoom out.

My own features don't dissapear when zooming out

Is there some way to make it gone, at least in the Leaflet map software?
rise an opposite situation as below:

Features disappear from Leaflet after zooming in

Best Answer

It looks like I found a solution:

An example is based here:

https://stackoverflow.com/questions/19658564/leaflet-control-geojson-layers-by-zoom-level

and also here

Load or display differents geojson data on zoom level for leaflet maps

which leads to the live example here:

http://jsfiddle.net/expedio/kuovyw8m/

regarding to my code I would like to display the snippet below:

  map.on('zoomend', function (e) {
   zoom_based_layerchange();
  });

   function clean_map() {
     map.eachLayer(function (layer) {
    if (layer instanceof L.GeoJSON)
    {
        map.removeLayer(layer);
    }
    //console.log(layer);
});
  }

     function zoom_based_layerchange() {
//console.log(map.getZoom());

    var currentZoom = map.getZoom();
       switch (currentZoom) {
    case 8:     //refers to the zoom level: 8
        clean_map();
        sitis.addTo(map); //show "sitis" geoJSON layer
        break;
    case 12:
        //clean_map(); - removed, as I don't need to remove the layer visible at lower zoom level
        church.addTo(map);   //show "church" geoJSON layer
        break;
    default:
        // do nothing
        break;
}
   }