1

リーフレット マップに WFS サービス (ポイント) をロードする必要があります。

マップに WFS サービスを読み込む方法は知っていますが、サーバーに要求してマップにレンダリングするフィーチャの数を制限する必要があるため、マップの現在の縮尺/範囲を動的に確認する必要があります。

私のサービスには多くのポイントがあり、ベースマップ (OpenStreetMap) のレベルが 18 の場合にのみレイヤーの視覚化を制限したいと考えています。

マップの現在の範囲/縮尺を動的にチェックして、WFS サービスを呼び出すかどうかを決定する方法はありますか?

例はありますか?

よろしくお願いします。どんな提案でも大歓迎です!!!!

チェザーレ

4

1 に答える 1

0

私はこの方法で解決しました

        .....
        .....
        .....
            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;
               }
             .....
             .....
             .....
}

それは今働いています!

于 2014-08-14T12:42:52.650 に答える