在传单地图中添加WFS服务,需要控制当前比例尺



我需要在我的传单地图中加载一个WFS服务(点)。

我知道如何在我的地图中加载WFS服务,但我必须动态检查地图当前的比例/范围,因为我必须限制我必须请求服务器并在我的地图上渲染的功能的数量。

我的服务有很多点,我想限制我的图层的可视化,只有当我们的basemap (OpenStreetMap)的level=18时。

是否有任何方法可以动态检查地图当前范围/比例,从而决定是否调用我的WFS服务?

的例子吗?

非常感谢你提前,任何建议是感激!!!!

凯撒

我是这样解决的

        .....
        .....
        .....
            function onEachFeature(feature, layer) {
               if (feature.properties && feature.properties.popupContent) {
                       layer.bindPopup(feature.properties.popupContent);
               }
            };
            myGeoJSONLayeraddressPCN3 = L.geoJson(myGeoJSON, {
                            pointToLayer: function (feature, latlng) {
                                              return L.circleMarker(latlng, geojsonMarkerOptions);
                            },
                            onEachFeature: onEachFeature
            });
            var baseLayers = {
                    "OSM": background
            };
            var overlays = {
                   "My GeoJSON Layer name": myGeoJSONLayer
            };
            map = new L.Map('map', {
                                    center: [42, 12],
                                    zoom: 6,
                                    layers: [background]
            });
            // *** add base layers and overlay layers list to map ... ***
            TOC = L.control.layers(baseLayers, overlays);
            TOC.addTo(map);                              
            map.on('overlayadd', function(e) {
                                    map.removeLayer(myGeoJSONLayer); 
                                    TOC.removeLayer(myGeoJSONLayer);
                                    if ((e.name == "My GeoJSON Layer name") && (map.getZoom() < 18)){
                                     alert('To view the layer zoom at max details ...');
                                     TOC.addOverlay(myGeoJSONLayer, "My GeoJSON Layer name");
                                     isOnMap = 0;
                                    } 
                                    if ((e.name == "My GeoJSON Layer name") && (map.getZoom() >= 18)){
                                     var currentExtent = map.getBounds().toBBoxString();
                                     invokeService(currentExtent);
                                    } 
                                 });
            map.on('overlayremove', function(e) {
                                    if (e.name == "My GeoJSON Layer name"){
                                     isOnMap = 0;
                                    } 
                                 });
            map.on('dragend', function(e) {
                                    if ((map.getZoom() >= 18) && (isOnMap == 1)){
                                     map.removeLayer(myGeoJSONLayer); 
                                     TOC.removeLayer(myGeoJSONLayer);
                                     var currentExtent = map.getBounds().toBBoxString();
                                     invokeService(currentExtent);
                                    } 
                                 });
            map.on('zoomend', function(e) {
                                    if (map.getZoom() < 18) {
                                     map.removeLayer(myGeoJSONLayer); 
                                     TOC.removeLayer(myGeoJSONLayer);
                                     TOC.addOverlay(myGeoJSONLayer, "My GeoJSON Layer name");
                                    } 
                                 });

和我也有一个函数invokeService()我已经…

function invokeService (extent) {
             .....
             .....
             .....
                    function onEachFeature(feature, layer) {
                      if (feature.properties && feature.properties.popupContent) {
                         layer.bindPopup(feature.properties.popupContent);
                      }
                     }
                     myGeoJSONLayeraddressPCN3 = L.geoJson(MyGeoJSON, {
                                     pointToLayer: function (feature, latlng) {
                                                   return L.circleMarker(latlng, geojsonMarkerOptions);
                                     },
                                     onEachFeature: onEachFeature
                     });
                     addressPCN3.addTo(map);                         
                     TOC.addOverlay(addressPCN3, "My GeoJSON Layer name");
                     isOnMap = 1;
               }
             .....
             .....
             .....
}

它现在工作了!

最新更新