Select to view content in your preferred language

Trying to get a WFSLayer to use the bbox parameter.

1697
6
03-17-2022 03:38 AM
LewInMadrid
New Contributor

Hi ESRI Community.

We would like our WFS requests from the JavaScript library to use the bbox parameter, requesting just the features in the current window. Currently the request brings back all the features which for a some layers is not viable as it could mean requesting 100s of Mbytes.

We thought that the mode parameter might help but get a read-only exception when doing the following.

// create and add a WFSLayer to the map
const layer = new WFSLayer({
url: "https://geobretagne.fr/geoserver/ows", // url to your WFS endpoint
name: "fma:bvme_zhp_vs_culture", // name of the FeatureType
copyright: "GéoBretagne",
mode:1
});
map.add(layer);

Any ideas how to get around this problem?

We're using MapServer to provide the WFS service.

0 Kudos
6 Replies
AnneFitz
Esri Regular Contributor

Hi @LewInMadrid - you can use the customParameters property to use the bbox parameter. There's an example in the documentation here: https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-WFSLayer.html#customParame...

0 Kudos
igarcia_genasys
Emerging Contributor

I have same question or similar.

I think @LewInMadrid  asks about get bbox dynamically, getting service on demand dynamically. When you are over it in map view

0 Kudos
LewInMadrid
New Contributor

Isaac is right. This only works if the bbox can be sent dynamically as you zoom and scroll around the map. If you have a Gbyte of spatial data it's dynamic bbox or bust.

0 Kudos
AnneFitz
Esri Regular Contributor

Ah, I see - you can still do this using customParameters - just update the bbox in the customParameters whenever you change the extent of the view and call refresh(). Here's an example: https://codepen.io/ycabon/pen/GRyqVPp?editors=1000

0 Kudos
igarcia_genasys
Emerging Contributor

Thanks for your help.

Now I find that it takes a long time to load the WFS, I see that the server is called 3 times, but I do not understand why.
I would like to be able to call the service only when I move the map or just load it once and then refresh when I move around the map

This is a example of my code:

var wfsurl = '/mapserver?'
wfsLayer = new WFSLayer({
                    title: example,
                    url: wfsurl, //
                    name: "wfs_layers", //table name of mysql
                    customParameters: {
                        map: mapfile, //my file .map
                        company_id: id
                        layer_name: cities
                    },
                    outFields: ["*"]
});
map.add(wfsLayer);
 
igarcia_genasys_0-1648560025145.png

How can I optimize it so that it takes a short time to load, even if it is reducing the number of features?

thanks again

0 Kudos
SebastianFrey1
Occasional Contributor

A little bit late here, but it worked for me, and so it may work for others as well.

 

You can initialize the WFSLayer with a custom parameter of COUNT=1 to avoid the massive lookup request from the JSAPI web worker:

const layer = new WFSLayer({
  url: "https://geobretagne.fr/geoserver/ows",
  name: "fma:bvme_zhp_vs_culture",
  customParameters: {
    COUNT: 1,
  },
});

 
You can than reset this parameter when the layer is loaded successfully.

0 Kudos