Skip to content

Commit 6aef569

Browse files
committed
Add source code.
1 parent 85a4447 commit 6aef569

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

Shared/Samples/Add KML layer with network links/AddKMLLayerWithNetworkLinksView.swift

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,82 @@ import ArcGIS
1616
import SwiftUI
1717

1818
struct AddKMLLayerWithNetworkLinksView: View {
19-
@State private var map = Map(basemapStyle: .arcGISTopographic)
19+
/// A scene with the current air traffic in parts of Europe.
20+
@State private var scene: ArcGIS.Scene = {
21+
let scene = Scene(basemapStyle: .arcGISImagery)
22+
23+
// Creates a KML dataset from a remote KMZ file.
24+
let kmlDataset = KMLDataset(url: .radarKMZFile)
25+
26+
// Creates a KML layer from the dataset and adds it to the scene's operational layers.
27+
let kmlLayer = KMLLayer(dataset: kmlDataset)
28+
scene.addOperationalLayer(kmlLayer)
29+
30+
// Sets the viewpoint to be initially centered on the data coverage.
31+
scene.initialViewpoint = Viewpoint(latitude: 50.472421, longitude: 8.150526, scale: 1e7)
32+
33+
return scene
34+
}()
35+
36+
/// The messages from the KML dataset's network links.
37+
@State private var networkLinkMessages: [String] = []
38+
39+
/// A Boolean value indicating whether network link messages popover is showing.
40+
@State private var isShowingMessages = false
2041

2142
var body: some View {
22-
MapView(map: map)
43+
SceneView(scene: scene)
44+
.toolbar {
45+
ToolbarItem(placement: .bottomBar) {
46+
Button("Network Link Messages") {
47+
isShowingMessages = true
48+
}
49+
.popover(isPresented: $isShowingMessages) { [networkLinkMessages] in
50+
MessagesList(messages: networkLinkMessages)
51+
.presentationDetents([.fraction(0.5), .large])
52+
.frame(idealWidth: 320, idealHeight: 380)
53+
}
54+
}
55+
}
56+
.task {
57+
// Listens for new KML network link messages.
58+
let kmlLayer = scene.operationalLayers.first as! KMLLayer
59+
60+
for await (_, message) in kmlLayer.dataset.networkLinkMessages {
61+
networkLinkMessages.append(message)
62+
}
63+
}
64+
}
65+
66+
/// A list of KML network link messages.
67+
private struct MessagesList: View {
68+
/// The messages to show in the list.
69+
let messages: [String]
70+
71+
/// The action to dismiss the view.
72+
@Environment(\.dismiss) private var dismiss
73+
74+
var body: some View {
75+
NavigationStack {
76+
List(messages, id: \.self) { message in
77+
Text(message)
78+
}
79+
.navigationTitle("Network Link Messages")
80+
.navigationBarTitleDisplayMode(.inline)
81+
.toolbar {
82+
ToolbarItem(placement: .confirmationAction) {
83+
Button("Done") { dismiss() }
84+
}
85+
}
86+
}
87+
}
88+
}
89+
}
90+
91+
private extension URL {
92+
/// The web URL to the "radar" KMZ file containing network links for the current air traffic in parts of Europe.
93+
static var radarKMZFile: URL {
94+
URL(string: "https://www.arcgis.com/sharing/rest/content/items/600748d4464442288f6db8a4ba27dc95/data")!
2395
}
2496
}
2597

0 commit comments

Comments
 (0)