Flexberry / Leaflet-WFST

OGC WFS-T client layer for Leaflet.
http://flexberry.github.io/Leaflet-WFST/
MIT License
151 stars 50 forks source link

WFS data by mapExtent #10

Open Prusdrum opened 9 years ago

Prusdrum commented 9 years ago

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.

kuzkok commented 9 years ago

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

Prusdrum commented 9 years ago

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.