View on GitHub Sample viewer app

Display a layer from a WFS service, requesting only features for the current extent.

Image of add WFS layer

Use case

WFS is an open standard with functionality similar to ArcGIS feature services. ArcGIS Maps SDK support for WFS allows you to interoperate with open systems, which are often used in inter-agency efforts, like those for disaster relief.

How to use the sample

Pan and zoom the map to see features within the current map extent. The WFS layer will be populated with features for the visible area whenever you stop navigating the map.

How it works

  1. Create a WfsFeatureTable with a service URL and table name.
  2. Set the feature request mode to ManualCache and axis order to NoSwap.
  3. Create a FeatureLayer from the WFS feature table and add it to the map’s operational layers.
  4. Listen for the onVisibleAreaChanged event to detect the visible map area, and for the onNavigationChanged event to detect when the user has stopped navigating.
  5. When navigation ends, call populateFromService(...) on the WFS feature table, passing a query for the current visible extent.
  6. Display a loading indicator while the WFS table is being populated.

Relevant API

  • FeatureLayer
  • MapView.onNavigationChanged
  • MapView.onVisibleAreaChanged
  • WfsFeatureTable
  • WfsFeatureTable.populateFromService

About the data

This sample uses a WFS service showing building footprints for downtown Seattle. For more information, see the ArcGIS Online item.

Tags

browse, catalog, feature, interaction cache, layers, OGC, service, web, WFS

Sample Code

MainActivity.kt MainActivity.kt AddWfsLayerViewModel.kt AddWfsLayerScreen.kt
/* Copyright 2025 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.addwfslayer
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.addwfslayer.screens.AddWfsLayerScreen
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.ACCESS_TOKEN)
enableEdgeToEdge()
setContent {
SampleAppTheme {
AddWfsLayerApp()
}
}
}
@Composable
private fun AddWfsLayerApp() {
Surface(color = MaterialTheme.colorScheme.background) {
AddWfsLayerScreen(
sampleName = getString(R.string.add_wfs_layer_app_name)
)
}
}
}