0

I have a WFS layer on GeoServer with more than 260,000 features, which contains data from an entire municipality. Thus, it takes a long time to load the entire layer on the map.

To test, I used a filter and it was possible to load part of the data. However, I need to load everything.

Is it possible to load the layer by blocks, that is, as you drag the map / screen, do you load the values? I'm using OpenLayers version 5.

[CODE EDITED]

This is the version that works, with filter. I want to switch to using bbox, it loads new features from GeoServer WFS when view span changes. What do I need to change? Need to transform extend?

var my_layer = new ol.layer.Vector({
    visible: false,
    style: my_style,
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: function(extent) {
            return urlGeoserver +'wfs?service=WFS&' +
              'version='+versionGeoserver+'&request=GetFeature&typename=geo:MY_LAYER_CITY&' +
              '&outputFormat=application/json&srsname=EPSG:4326&' +
              'CQL_FILTER=COD_SETOR = '+value_setor+'&' +
              'all=' + extent.join(',') + ',EPSG:4326';
        },
        strategy: ol.loadingstrategy.bbox
    })
});

All tests below did not work. Using ol.proj.transformExtent I made the changes suggested in the comments. It does not show the data and the OSM base is still deformed.

Obs: The following code works for one layer, but not for another. Could it be some setting? Any idea?

var my_layer = new ol.layer.Vector({
    visible: false,
    style: my_style,
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: function(extent) {
            const new_extend = ol.proj.transformExtent(extend.bbox, 'EPSG:4326', 'EPSG:3857');
            return urlGeoserver +'wfs?service=WFS&' +
              'version='+versionGeoserver+'&request=GetFeature&typename=geo:MY_LAYER_CITY&' +
              '&outputFormat=application/json&srsname=EPSG:3857&' +
              'bbox=' + new_extent + ',EPSG:3857';
        },
        strategy: ol.loadingstrategy.bbox
    })
});

I also changed according to the code https://openlayers.org/en/v4.6.5/examples/vector-wfs.html?q=wfs, however, nothing shows the data. Observation, I only managed with filter and EPSG:4326&.

    var my_layer = new ol.layer.Vector({
    visible: false,
    style: my_style,
    source: new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: function(extent) {
            return urlGeoserver +'wfs?service=WFS&' +
              'version='+versionGeoserver+'&request=GetFeature&typename=geo:MY_LAYER_CITY&' +
              '&outputFormat=application/json&srsname=EPSG:3857&' +
              'bbox=' + extent.join(',') + ',EPSG:3857';
        },
        strategy: ol.loadingstrategy.bbox
    })
});

Does anyone know what can it be? Where is my mistake?

enter image description here

18
  • Use strategy: ol.loadingstrategy.bbox.
    – TomazicM
    Dec 22, 2022 at 20:05
  • Where is the layer strategy: ol.loadingstrategy.all, change it to strategy: ol.loadingstrategy.bbox? In the layer, I won't have the filter either 'CQL_FILTER=NAME_B = '+value_filter+'. I made those changes, but it didn't load the layer. Dec 22, 2022 at 20:28
  • OpenLayers passes the extent to the url function in view projection. You will need change the + ',EPSG:4326'; or transform the extent to EPSG:4326 (and to Lat Lon order)
    – Mike
    Dec 23, 2022 at 0:14
  • @Mike I didn't understand. Could you explain to me "You will need change the + ',EPSG:4326'; or transform the extent to EPSG:4326 (and to Lat Lon order)"? Dec 23, 2022 at 16:58
  • If the view projection is EPSG:3857 you would need extent.join(',') + ',EPSG:3857'; Even if view projection is EPSG:4326 OpenLayers uses Lon Lat and WFS uses Lat Lon so you could not simply join the OpenLayers coordinate array (unlike EPSG:3857 where the order is always easting, northing)
    – Mike
    Dec 23, 2022 at 17:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.