Skip to content

Commit db9b47b

Browse files
committed
Refactor Trace utility network to add back renderer.
1 parent a25b309 commit db9b47b

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

Shared/Samples/Trace utility network/README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ Tap "Start a new trace" to select the type of trace using the confirmation dialo
1414

1515
## How it works
1616

17-
1. Create a `MapView` with a `Map` that contains one more utility networks.
17+
1. Create a `MapView` with a `Map` that contains utility networks.
1818
2. Add a `GraphicsOverlay` to hold symbology that distinguishes starting locations from barriers.
1919
3. Get and load the first `UtilityNetwork` from the web map.
20-
4. Allow users to choose a trace type from the set of `UtilityTraceParameters.TraceType`(s).
21-
5. Create `UtilityTraceParameters` with the selected trace type.
22-
6. Set the `UtilityTraceConfiguration` with the utility tier's `defaultTraceConfiguration` property.
23-
7. Use the `onSingleTapGesture` modifier to listen for tap events on the map view.
24-
8. Identify tapped features on the map and add a `Graphic` that represents its purpose (starting point or barrier) at the tapped location.
25-
9. Create a `UtilityElement` for the identified feature.
26-
10. Determine the type of the identified feature using `UtilityNetworkSource.sourceType`.
27-
11. If the type is `junction`, display a terminal picker when more than one terminal is found.
28-
12. If the type is `edge`, compute how far along the edge the user tapped using `GeometryEngine.polyline(_:fractionalLengthClosestTo:tolerance:)`.
29-
13. Add any created `UtilityElement`(s) to the collection of starting locations or barriers in the `UtilityTraceParameters`.
30-
14. Run `UtilityNetwork.trace(using:)` using the `UtilityTraceParameters`.
31-
15. Group the `UtilityElementTraceResult.elements` by their `networkSource.name`.
32-
16. For every `FeatureLayer` in this map with trace result elements, select features by converting `UtilityElement`(s) to `ArcGISFeature`(s) using `UtilityNetwork.features(for:)`.
20+
4. Get the `ServiceGeodatabase` from the utility network and fetch the line `FeatureLayer` from the `ServiceGeodatabase`'s tables for customized renderer.
21+
5. Allow users to choose a trace type from the set of `UtilityTraceParameters.TraceType`(s).
22+
6. Create `UtilityTraceParameters` with the selected trace type.
23+
7. Set the `UtilityTraceConfiguration` with the utility tier's `defaultTraceConfiguration` property.
24+
8. Use the `onSingleTapGesture` modifier to listen for tap events on the map view.
25+
9. Identify tapped features on the map and add a `Graphic` that represents its purpose (starting point or barrier) at the tapped location.
26+
10. Create a `UtilityElement` for the identified feature.
27+
11. Determine the type of the identified feature using `UtilityNetworkSource.sourceType`.
28+
12. If the type is `junction`, display a terminal picker when more than one terminal is found.
29+
13. If the type is `edge`, compute how far along the edge the user tapped using `GeometryEngine.polyline(_:fractionalLengthClosestTo:tolerance:)`.
30+
14. Add any created `UtilityElement`(s) to the collection of starting locations or barriers in the `UtilityTraceParameters`.
31+
15. Run `UtilityNetwork.trace(using:)` using the `UtilityTraceParameters`.
32+
16. Group the `UtilityElementTraceResult.elements` by their `networkSource.name`.
33+
17. For every `FeatureLayer` in this map with trace result elements, select features by converting `UtilityElement`(s) to `ArcGISFeature`(s) using `UtilityNetwork.features(for:)`.
3334

3435
## Relevant API
3536

Shared/Samples/Trace utility network/TraceUtilityNetworkView.Model.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ extension TraceUtilityNetworkView {
189189
updateUserHint(withMessage: "An error occurred while loading the network.")
190190
return
191191
}
192+
193+
if let table = network.serviceGeodatabase?.table(withLayerID: 3),
194+
let layer = table.layer as? FeatureLayer {
195+
layer.renderer = UniqueValueRenderer(
196+
fieldNames: ["ASSETGROUP"],
197+
uniqueValues: [.lowVoltage, .mediumVoltage],
198+
defaultSymbol: SimpleLineSymbol()
199+
)
200+
}
192201
}
193202

194203
/// Runs a trace with the pending trace configuration and selects features in the map that
@@ -279,6 +288,33 @@ private extension SimpleMarkerSymbol {
279288
.init(style: .cross, color: .green, size: 20)
280289
}
281290
}
291+
292+
private extension UniqueValue {
293+
/// The rendering style for low voltage lines in the utility network.
294+
static var lowVoltage: UniqueValue {
295+
.init(
296+
label: "Low voltage",
297+
symbol: SimpleLineSymbol(style: .dash, color: .darkCyan, width: 3),
298+
values: [3]
299+
)
300+
}
301+
302+
/// The rendering style for medium voltage lines in the utility network.
303+
static var mediumVoltage: UniqueValue {
304+
.init(
305+
label: "Medium voltage",
306+
symbol: SimpleLineSymbol(style: .solid, color: .darkCyan, width: 3),
307+
values: [5]
308+
)
309+
}
310+
}
311+
312+
private extension UIColor {
313+
/// A custom color for electrical lines in the utility network.
314+
static var darkCyan: UIColor {
315+
.init(red: 0, green: 0.55, blue: 0.55, alpha: 1)
316+
}
317+
}
282318

283319
private extension URL {
284320
/// The server containing the data for this sample.
-651 Bytes
Loading

0 commit comments

Comments
 (0)