Skip to content

[New] Add WFS layer #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Samples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
1C26ED202A8BEC63009B7721 /* FilterFeaturesInSceneView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 1C26ED152A859525009B7721 /* FilterFeaturesInSceneView.swift */; };
1C29C9592DBAE50D0074028F /* AddWMTSLayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C29C9532DBAE50D0074028F /* AddWMTSLayerView.swift */; };
1C29C95A2DBAE5770074028F /* AddWMTSLayerView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 1C29C9532DBAE50D0074028F /* AddWMTSLayerView.swift */; };
1C38915D2DBC36C800ADFDDC /* AddWFSLayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C38915C2DBC36C700ADFDDC /* AddWFSLayerView.swift */; };
1C38915E2DBC3EDC00ADFDDC /* AddWFSLayerView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 1C38915C2DBC36C700ADFDDC /* AddWFSLayerView.swift */; };
1C3B7DC82A5F64FC00907443 /* AnalyzeNetworkWithSubnetworkTraceView.Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C3B7DC32A5F64FC00907443 /* AnalyzeNetworkWithSubnetworkTraceView.Model.swift */; };
1C3B7DCB2A5F64FC00907443 /* AnalyzeNetworkWithSubnetworkTraceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C3B7DC62A5F64FC00907443 /* AnalyzeNetworkWithSubnetworkTraceView.swift */; };
1C3B7DCD2A5F652500907443 /* AnalyzeNetworkWithSubnetworkTraceView.Model.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 1C3B7DC32A5F64FC00907443 /* AnalyzeNetworkWithSubnetworkTraceView.Model.swift */; };
Expand Down Expand Up @@ -602,6 +604,7 @@
dstPath = "";
dstSubfolderSpec = 7;
files = (
1C38915E2DBC3EDC00ADFDDC /* AddWFSLayerView.swift in Copy Source Code Files */,
1C29C95A2DBAE5770074028F /* AddWMTSLayerView.swift in Copy Source Code Files */,
004421912DB96A7800249FEE /* AddFeatureCollectionLayerFromQueryView.swift in Copy Source Code Files */,
0044218B2DB9575600249FEE /* AddFeatureCollectionLayerFromPortalItemView.swift in Copy Source Code Files */,
Expand Down Expand Up @@ -906,6 +909,7 @@
1C2538532BABACB100337307 /* AugmentRealityToNavigateRouteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AugmentRealityToNavigateRouteView.swift; sourceTree = "<group>"; };
1C26ED152A859525009B7721 /* FilterFeaturesInSceneView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilterFeaturesInSceneView.swift; sourceTree = "<group>"; };
1C29C9532DBAE50D0074028F /* AddWMTSLayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWMTSLayerView.swift; sourceTree = "<group>"; };
1C38915C2DBC36C700ADFDDC /* AddWFSLayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWFSLayerView.swift; sourceTree = "<group>"; };
1C3B7DC32A5F64FC00907443 /* AnalyzeNetworkWithSubnetworkTraceView.Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnalyzeNetworkWithSubnetworkTraceView.Model.swift; sourceTree = "<group>"; };
1C3B7DC62A5F64FC00907443 /* AnalyzeNetworkWithSubnetworkTraceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnalyzeNetworkWithSubnetworkTraceView.swift; sourceTree = "<group>"; };
1C42E04329D2396B004FC4BE /* ShowPopupView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowPopupView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1313,6 +1317,7 @@
D7201CD72CC6B710004BDB7D /* Add tiled layer as basemap */,
D7201D032CC6D3B5004BDB7D /* Add vector tiled layer from custom style */,
3E54CF202C66AFA400DD2F18 /* Add web tiled layer */,
1C38915B2DBC36B000ADFDDC /* Add WFS layer */,
D7E557602A1D743100B9FB09 /* Add WMS layer */,
1C29C9622DBAE5D10074028F /* Add WMTS layer */,
1C3B7DC22A5F64FC00907443 /* Analyze network with subnetwork trace */,
Expand Down Expand Up @@ -1764,6 +1769,14 @@
path = "Add WMTS layer";
sourceTree = "<group>";
};
1C38915B2DBC36B000ADFDDC /* Add WFS layer */ = {
isa = PBXGroup;
children = (
1C38915C2DBC36C700ADFDDC /* AddWFSLayerView.swift */,
);
path = "Add WFS layer";
sourceTree = "<group>";
};
1C3B7DC22A5F64FC00907443 /* Analyze network with subnetwork trace */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3643,6 +3656,7 @@
D7497F3C2AC4B4C100167AD2 /* DisplayDimensionsView.swift in Sources */,
D7C97B562B75C10C0097CDA1 /* ValidateUtilityNetworkTopologyView.Views.swift in Sources */,
D73FCFF72B02A3AA0006360D /* FindAddressWithReverseGeocodeView.swift in Sources */,
1C38915D2DBC36C800ADFDDC /* AddWFSLayerView.swift in Sources */,
D789AAAD2D66C718007A8E0E /* CreateKMLMultiTrackView.Model.swift in Sources */,
0005580A2817C51E00224BC6 /* SampleDetailView.swift in Sources */,
D75F66362B48EABC00434974 /* SearchForWebMapView.swift in Sources */,
Expand Down
134 changes: 134 additions & 0 deletions Shared/Samples/Add WFS layer/AddWFSLayerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// 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
//
// https://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.

import ArcGIS
import SwiftUI

@MainActor
struct AddWFSLayerView: View {
/// A map with a topographic basemap centered on downtown Seattle.
@State private var map: Map = {
let map = Map(basemapStyle: .arcGISTopographic)
map.initialViewpoint = Viewpoint(
boundingGeometry: Envelope(
xRange: -122.341581 ... -122.332662,
yRange: 47.613758...47.617207,
spatialReference: .wgs84
)
)

let featureTable = WFSFeatureTable(url: .downtownSeattle, tableName: "Seattle_Downtown_Features:Buildings")
// Sets the feature request mode to manual. In this mode, the table must be populated
// manually. Panning and zooming won't request features automatically.
featureTable.featureRequestMode = .manualCache
// Sets the axis order.
featureTable.axisOrder = .noSwap

let wfsFeatureLayer = FeatureLayer(featureTable: featureTable)
wfsFeatureLayer.renderer = SimpleRenderer(
symbol: SimpleLineSymbol(
style: .solid,
color: .red,
width: 3
)
)
map.addOperationalLayer(wfsFeatureLayer)

return map
}()

/// The visible area on the map.
@State private var visibleArea: ArcGIS.Polygon?

/// A feature table of building footprints for downtown Seattle.
private var featureTable: WFSFeatureTable {
(map.operationalLayers[0] as! FeatureLayer).featureTable as! WFSFeatureTable
}

/// The extent with which to populate the WFS layer.
@State private var populateExtent: Envelope?

/// A Boolean value indicating whether the feature table is being populated.
@State private var isPopulating = false

/// The error shown in the error alert.
@State private var error: Error?

var body: some View {
MapView(map: map)
.onVisibleAreaChanged {
if visibleArea == nil {
// Populate the initial extent.
populateExtent = $0.extent
}
// Update visible area state.
visibleArea = $0
}
.onNavigatingChanged { isNavigating in
if !isNavigating {
// Populate when the user stops navigating.
populateExtent = visibleArea?.extent
}
}
.task(id: populateExtent) {
do {
guard let populateExtent else { return }
try await populateFeatures(within: populateExtent)
} catch {
self.error = error
}
}
.overlay(alignment: .center) {
if isPopulating {
VStack {
Text("Populating")
ProgressView()
.progressViewStyle(.circular)
}
.padding()
.background(.ultraThickMaterial)
.clipShape(.rect(cornerRadius: 10))
.shadow(radius: 50)
}
}
.errorAlert(presentingError: $error)
}

/// Populates the feature table using queried features contained within a given extent.
/// - Parameter extent: The extent used to filter the results.
private func populateFeatures(within extent: Envelope) async throws {
isPopulating = true
defer { isPopulating = false }

let queryParameters = QueryParameters()
queryParameters.geometry = extent
queryParameters.spatialRelationship = .intersects
_ = try await featureTable.populateFromService(
using: queryParameters,
clearCache: false,
outFields: []
)
}
}

private extension URL {
/// Downtown Seattle feature service URL used to create a feature layer.
static var downtownSeattle: URL {
URL(string: "https://dservices2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/services/Seattle_Downtown_Features/WFSServer?service=wfs&request=getcapabilities")!
}
}

#Preview {
AddWFSLayerView()
}
35 changes: 35 additions & 0 deletions Shared/Samples/Add WFS layer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Add WFS layer

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

![Image of Add WFS Layer sample](add-wfs-layer.png)

## 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 to see features within the current map extent.

## How it works

1. Create a `WFSFeatureTable` with a URL.
2. Create a `FeatureLayer` from the feature table and add it to the map.
3. Listen for the `MapView.onNavigatingChanged(action:)` event to detect when the user has stopped navigating the map.
4. When the user is finished navigating, use `WFSFeatureTable.populateFromService(using:clearCache:outFields:)` to load the table with data for the current visible extent.

## Relevant API

* FeatureLayer
* MapView.onNavigatingChanged(action:)
* WFSFeatureTable
* WFSFeatureTable.populateFromService(using:clearCache:outFields:)

## About the data

This service shows building footprints for downtown Seattle. For additional information, see the underlying service on [ArcGIS Online](https://arcgisruntime.maps.arcgis.com/home/item.html?id=1b81d35c5b0942678140efc29bc25391).

## Tags

browse, catalog, feature, interaction cache, layers, OGC, service, web, WFS
34 changes: 34 additions & 0 deletions Shared/Samples/Add WFS layer/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"category": "Layers",
"description": "Display a layer from a WFS service, requesting only features for the current extent.",
"ignore": false,
"images": [
"add-wfs-layer.png"
],
"keywords": [
"OGC",
"WFS",
"browse",
"catalog",
"feature",
"interaction cache",
"layers",
"service",
"web",
"FeatureLayer",
"MapView.onNavigatingChanged(action:)",
"WFSFeatureTable",
"WFSFeatureTable.populateFromService(using:clearCache:outFields:)"
],
"redirect_from": [],
"relevant_apis": [
"FeatureLayer",
"MapView.onNavigatingChanged(action:)",
"WFSFeatureTable",
"WFSFeatureTable.populateFromService(using:clearCache:outFields:)"
],
"snippets": [
"AddWFSLayerView.swift"
],
"title": "Add WFS layer"
}
Binary file added Shared/Samples/Add WFS layer/add-wfs-layer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading