首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在小叶地图中添加WFS服务并需要控制当前比例

在小叶地图中添加WFS服务并需要控制当前比例
EN

Stack Overflow用户
提问于 2014-08-10 04:13:59
回答 1查看 1.2K关注 0票数 1

我需要在我的单张地图中加载WFS服务(点数)。

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

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

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

有什么例子吗?

非常提前感谢您,任何建议都将不胜感激!

Cesare

EN

回答 1

Stack Overflow用户

发布于 2014-08-14 20:42:53

我就是这样解决的

代码语言:javascript
复制
        .....
        .....
        .....
            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(),其中我...

代码语言:javascript
复制
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;
               }
             .....
             .....
             .....
}

它现在可以工作了!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25222605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档