Leaflet-WFST icon indicating copy to clipboard operation
Leaflet-WFST copied to clipboard

WFS data by mapExtent

Open Prusdrum opened this issue 9 years ago • 2 comments

Hello. Thanks for plugin, but i have one issue. I have weight data on my geoserver, and i don't want to load it all at once, but specified by map extent. Is it possible with your plugin? I tried to do it on my own with ajax sending request to wfs with parameter bbox on mapmove event, but it downloaded huge response data on every map move. Maybe your plugin can handle this easily?

Mat.

Prusdrum avatar Jul 15 '15 11:07 Prusdrum

Hi. At this moment it's not possible do continuous data load. In future we will add more filters and this feature.

kuzkok avatar Jul 16 '15 06:07 kuzkok

Thank you for response. This is my temporary solution anyway:

//uses leaflet, jquery, proj4, proj4leaflet
        var geojsonWoj = L.Proj.geoJson(),
            wellmaxzoom = 7,
            wojGroup = [],
            layGroup = new L.layerGroup().addTo(map);
        function loadGeoJson(data){
            console.log(data);
            L.Proj.geoJson(data, {
                onEachFeature: function (feature, featureLayer) {
                    var id = feature.id;
                    if (wojGroup[id] === undefined) {
                        layGroup.addLayer(featureLayer);
                        wojGroup[id] = feature;
                    }
                }
            })
        }
        map.on('move', function(){
         if(map.getZoom() > wellmaxzoom){
            var geoJsonUrl ='http://localhost:8080/geoserver/namespace/ows'; 
            var defaultParameters = {
                service: 'WFS',
                version: '1.1.0',
                request: 'getFeature',
                typeNames: 'namespace:layer',
                maxFeatures: 3000,
                outputFormat: 'application/json'
                };

            var customParams = {
                bbox: map.getBounds().toBBoxString()+',EPSG:4326'
                };
            var parameters = L.Util.extend(defaultParameters, customParams);
            console.log(geoJsonUrl + L.Util.getParamString(parameters));

            $.ajax({
                url: geoJsonUrl + L.Util.getParamString(parameters),
                datatype: 'json',
                jsonCallback: 'getJson',
                success: loadGeoJson
                });
            } else {
            map.removeLayer(geojsonWoj);
            };
        });     

I modified solution from here: http://stackoverflow.com/questions/25187937/loading-geojson-layers-from-geoserver-to-leaflet-map-based-on-the-current-boundi

I also had a little problem with bbox parameter but i found solution here: http://augusttown.blogspot.com/2010/08/mysterious-bbox-parameter-in-web.html Its structure depends on version of WFS request.

Prusdrum avatar Jul 16 '15 07:07 Prusdrum