指定的geoJSON图层属性的传单设置缩放级别

问题描述 投票:2回答:1

我想为传单中的某些指定的geoJSON属性层设置单独的缩放级别。

我使用了以下代码(根据此过程的继续):Setting zoom level for layers in leaflet

   map.on('zoomend', function() {
   if (map.getZoom() <6){
        map.removeLayer(mylayer);
     }else{
    map.addLayer(mylayer);
    }
  });

哪个适用于geoJSON层?当缩放低于6时,图层消失。

我想对此GeoJSON图层中包含的某些feature.property执行相同的操作。

然后我尝试了类似的方法:

  map.on('zoomend', function() {
      if (map.getZoom() <8){
        map.removeLayer(feature.properties.Capacity>=40);
       }else{
        map.addLayer(feature.properties.Capacity>=40);
        }
       });

但是不幸的是结果很糟糕。上下翻转缩放级别时,我的所有点都没有起作用,而是在地图上浮动。

控制台状态:

Uncaught ReferenceError:未定义功能在我((索引):173)在i.fire(leaflet.js:5)在i._moveEnd(leaflet.js:5)在我(leaflet.js:5)(匿名)@(索引):173火@ leaflet.js:5_moveEnd @ leaflet.js:5(匿名)@ leaflet.js:5 requestAnimationFrame(异步)M @ leaflet.js:5_onZoomTransitionEnd @ leaflet.js:5 setTimeout(异步)_animateZoom @ leaflet.js:5(匿名)@ leaflet.js:5 requestAnimationFrame(异步)M @ leaflet.js:5_tryAnimatedZoom @ leaflet.js:5 setView @ leaflet.js:5 setZoomAround @ leaflet.js:5_performZoom @ leaflet.js:5 setTimeout(异步)_onWheelScroll @ leaflet.js:5 s @ leaflet.js:5 2

我不太了解,因为geoJSON图层已获取到地图。

您能帮我解决这个问题吗?enter image description here

我正在寻找的东西附近是这里:

https://gis.stackexchange.com/questions/41928/adding-removing-leaflet-geojson-layers

https://gis.stackexchange.com/questions/239795/leaflet-remove-filtered-layer

不幸的是,这导致我进行了第三次尝试,但没有成功

  map.on('zoomend', function() {
     if (map.getZoom() <6){
    if (feature.properties.Capacity >=40){
        map.removeLayer(feature.properties.Capacity);
     }else{
     map.addLayer(feature.properties.Capacity);
     }
   });

[我的另一尝试,您可以在此链接下看到:https://gis.stackexchange.com/questions/341684/leaflet-setting-zoom-level-for-a-specified-geojson-layer-feature

javascript leaflet zoom geojson
1个回答
0
投票

看起来好像动画出了问题,只需将zoomanimation设置为零。

https://leafletjs.com/reference-1.6.0.html#map-zoomanimation

© www.soinside.com 2019 - 2024. All rights reserved.