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?
strategy: ol.loadingstrategy.bbox
.strategy: ol.loadingstrategy.all
, change it tostrategy: 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.+ ',EPSG:4326';
or transform the extent to EPSG:4326 (and to Lat Lon order)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)