I expected a WFS call to be made when a Vector Layer was added to the map, but it doesn't happen until the layer is marked as visible.
Here is how I'm currently creating my vector layers. The visible
param is initially marked as false via layer.checked
function createVectorLayer (layer, zIndex) {
const source = new VectorSource({
format: new GeoJSON(),
url: function (extent) {
return `${process.env.GEOSERVER_URL}/wfs?service=WFS&version=${process.env.WFS_VERSION}&request=GetFeature&typename=${layer.name}&outputFormat=application/json`
}
})
return new VectorLayer({
source,
style: VectorStyle,
opacity: layer.opacity,
visible: layer.checked,
zIndex
})
}
I then add them to the map via the standard method:
map.addLayer(vectorLayer)
The problem is that until I update the layer's visibility via
vectorLayer.setVisible(true)
the wfs call made to the url
defined in VectorSource
won't be made and therefore the layer has no features which is causing problems.
Again, I assumed would be that the wfs call would be made when the Layer was added to the map and not on the condition of its visibility.
I haven't been able to find anything in the docs that explains this, so I could use some help/information.
How can I get a vector features (via wfs call) before the layer is marked visible?
app-specific information
- I'm creating a feature search that sets the map's center to that feature's coordinates
- but, if the layer is not 'visible' yet (the user just opened the map and everything is at default settings), the layer has no features to search from
- I can then set the layer as visible on search, but then the wfs call is made in the background and I have no way to listen to it's return. I could listen to a layer's
change
event but that's irregardless of the main question of: - how (if possible) can I get a layer's features via wfs before the layer is visible
- I can then set the layer as visible on search, but then the wfs call is made in the background and I have no way to listen to it's return. I could listen to a layer's