WFSLayer

This sample shows how to access an OGC WFS service, view the available feature types, and add features to the map with a WFSLayer. Enter the URL to your WFS endpoint, select the GetCapabilities button, and then select a FeatureType from the list to add it to the map as a WFSLayer.

Creating a WFSLayer

To create a WFSLayer, all you need is the URL to a WFS service that supports WFS 2.0.0 and has GeoJSON output format enabled. Optionally, you can set the name to the FeatureType you want to access in the service. If no name is provided, the layer will default to the first FeatureType in the service.

Use dark colors for code blocksCopy
1
2
3
4
5
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
});
map.add(layer); // add the layer to the map

Using wfsUtils to browse feature types in the service

This sample shows how you can use the wfsUtils class to browse FeatureTypes in the WFS service before adding them to your map. To do this, we use wfsUtils.getCapabilities, which executes the GetCapabilities request on the WFS service and returns the feature types.

Use dark colors for code blocksCopy
1
2
3
4
wfsUtils.getCapabilities(url).then((capabilities) => {
  // create a list of the returned feature types
  createLayerList(wfsCapabilities.featureTypes);
});

To create the list of available feature types on the service, we use calcite components, a set of responsive, reusable web components from Esri's new design system.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// create a list from the featureTypes available in the service
function createLayerList(featureTypes) {
  const list = document.createElement("calcite-pick-list");
  list.filterEnabled = true;
  featureTypes.forEach((feature) => {
    const listitem = document.createElement("calcite-pick-list-item");
    listitem.label = feature.title;
    listitem.value = feature.name;
    list.appendChild(listitem);
  });
  listArea.appendChild(list);
  loader.active = false; // stop loading
  list.addEventListener("calciteListChange", updateSelectedLayer);
}

When an item is selected from the list, we will get information about the selected feature type using the getWFSLayerInfo method on wfsUtils. Then we can use the results of that method to create our WFSLayer and add it to the map.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
function updateSelectedLayer(event) {
  // get the layer name from the clicked item
  const layerName = event.detail.keys().next().value;
  // get layer info for the feature type that was clicked
  wfsUtils.getWFSLayerInfo(wfsCapabilities, layerName).then((wfsLayerInfo) => {
    // create a WFSLayer from the layer info
    const layer = WFSLayer.fromWFSLayerInfo(wfsLayerInfo);
    map.add(layer);
  })
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.