@@ -135,9 +135,6 @@ public class TraceState(
135
135
136
136
private val currentTraceGeometryResultsGraphics: MutableList <Graphic > = mutableListOf ()
137
137
138
- private val _currentScreen : MutableState <TraceNavRoute > = mutableStateOf(TraceNavRoute .TraceOptions )
139
- internal var currentScreen: State <TraceNavRoute > = _currentScreen
140
-
141
138
private val _completedTraces : SnapshotStateList <TraceRun > = mutableStateListOf()
142
139
internal val completedTraces: List <TraceRun > = _completedTraces
143
140
@@ -164,27 +161,6 @@ public class TraceState(
164
161
private var _currentTraceZoomToResults : MutableState <Boolean > = mutableStateOf(true )
165
162
internal var currentTraceZoomToResults: State <Boolean > = _currentTraceZoomToResults
166
163
167
- private val currentTraceResultGeometriesExtent: Envelope ?
168
- get() {
169
- val utilityGeometryTraceResult = currentTraceRun?.geometryTraceResult ? : return null
170
-
171
- val geometries = listOf (
172
- utilityGeometryTraceResult.polygon,
173
- utilityGeometryTraceResult.polyline,
174
- utilityGeometryTraceResult.multipoint
175
- ).mapNotNull { geometry ->
176
- if (geometry != null && ! geometry.isEmpty) {
177
- geometry
178
- } else {
179
- null
180
- }
181
- }
182
- val combinedExtents = GeometryEngine .combineExtentsOrNull(geometries) ? : return null
183
- val expandedEnvelope = GeometryEngine .bufferOrNull(combinedExtents, 200.0 ) ? : return null
184
-
185
- return expandedEnvelope.extent
186
- }
187
-
188
164
private var navigateToRoute: ((TraceNavRoute ) -> Unit )? = null
189
165
190
166
internal fun setNavigationCallback (navigateToRoute : (TraceNavRoute ) -> Unit ) {
@@ -360,11 +336,18 @@ public class TraceState(
360
336
}
361
337
}
362
338
}
339
+
340
+ val currentTraceResultGeometriesExtent = currentTraceGeometryResults?.let {
341
+ getResultGeometriesExtent(it)
342
+ }
343
+
363
344
currentTraceRun = TraceRun (
364
345
name = _currentTraceName .value,
365
346
configuration = traceConfiguration,
366
347
startingPoints = _currentTraceStartingPoints .toList(),
367
348
geometryResultsGraphics = currentTraceGeometryResultsGraphics.toList(),
349
+ resultsGraphicExtent = currentTraceResultGeometriesExtent,
350
+ resultGraphicColor = currentTraceGraphicsColorAsComposeColor,
368
351
featureResults = currentTraceElementResults,
369
352
functionResults = currentTraceFunctionResults,
370
353
geometryTraceResult = currentTraceGeometryResults
@@ -393,6 +376,24 @@ public class TraceState(
393
376
_currentTraceZoomToResults .value = true
394
377
}
395
378
379
+ private fun getResultGeometriesExtent (utilityGeometryTraceResult : UtilityGeometryTraceResult ): Envelope ? {
380
+ val geometries = listOf (
381
+ utilityGeometryTraceResult.polygon,
382
+ utilityGeometryTraceResult.polyline,
383
+ utilityGeometryTraceResult.multipoint
384
+ ).mapNotNull { geometry ->
385
+ if (geometry != null && ! geometry.isEmpty) {
386
+ geometry
387
+ } else {
388
+ null
389
+ }
390
+ }
391
+ val combinedExtents = GeometryEngine .combineExtentsOrNull(geometries) ? : return null
392
+ val expandedEnvelope = GeometryEngine .bufferOrNull(combinedExtents, 200.0 ) ? : return null
393
+
394
+ return expandedEnvelope.extent
395
+ }
396
+
396
397
private fun createGraphicForSimpleLineSymbol (geometry : Geometry , style : SimpleLineSymbolStyle , color : Color ) =
397
398
Graphic (
398
399
geometry = geometry,
@@ -573,6 +574,30 @@ public class TraceState(
573
574
}
574
575
}
575
576
577
+ internal fun setGraphicsColorForSelectedTraceRun (color : androidx.compose.ui.graphics.Color ) {
578
+ val arcgisColor = Color .fromRgba(
579
+ color.red.toInt() * 255 ,
580
+ color.green.toInt() * 255 ,
581
+ color.blue.toInt() * 255 ,
582
+ color.alpha.toInt() * 255
583
+ )
584
+ val selectedTraceRun = completedTraces[_selectedCompletedTraceIndex .value]
585
+ selectedTraceRun.resultGraphicColor = color
586
+
587
+ // update the color of the starting points
588
+ selectedTraceRun.startingPoints.forEach { startingPoint ->
589
+ val symbol = startingPoint.graphic.symbol as SimpleMarkerSymbol
590
+ symbol.color = arcgisColor
591
+ }
592
+ // update the color of the trace results graphics
593
+ selectedTraceRun.geometryResultsGraphics.forEach { graphic ->
594
+ if (graphic.symbol is SimpleLineSymbol ) {
595
+ val symbol = graphic.symbol as SimpleLineSymbol
596
+ symbol.color = arcgisColor
597
+ }
598
+ }
599
+ }
600
+
576
601
/* *
577
602
* Set whether to zoom to the results.
578
603
*
@@ -597,6 +622,35 @@ public class TraceState(
597
622
return completedTraces[_selectedCompletedTraceIndex .value].featureResults.filter { it.assetGroup.name == selectedAssetGroupName }
598
623
}
599
624
625
+ internal fun clearAllResults () {
626
+ _completedTraces .clear()
627
+ _selectedCompletedTraceIndex .value = 0
628
+ currentTraceGeometryResultsGraphics.clear()
629
+ _currentTraceStartingPoints .clear()
630
+ graphicsOverlay.graphics.clear()
631
+ }
632
+
633
+ internal fun clearSelectedTraceResult () {
634
+ val selectedTrace = _completedTraces [_selectedCompletedTraceIndex .value]
635
+ selectedTrace.geometryResultsGraphics.forEach { graphicsOverlay.graphics.remove(it) }
636
+ selectedTrace.startingPoints.forEach { it.graphic.isSelected = false }
637
+ _completedTraces .removeAt(_selectedCompletedTraceIndex .value)
638
+ if (_selectedCompletedTraceIndex .value - 1 >= 0 ) {
639
+ _selectedCompletedTraceIndex .value - = 1
640
+ updateSelectedStateForTraceResultsGraphics(_selectedCompletedTraceIndex .value, true )
641
+ }
642
+ }
643
+
644
+ internal suspend fun zoomToSelectedTrace () {
645
+ val currentTrace = completedTraces[_selectedCompletedTraceIndex .value]
646
+ val extent = currentTrace.resultsGraphicExtent ? : return
647
+ mapViewProxy.setViewpointAnimated(
648
+ Viewpoint (extent.extent),
649
+ 1.0 .seconds,
650
+ AnimationCurve .EaseInOutCubic
651
+ )
652
+ }
653
+
600
654
/* *
601
655
* Set the [error] that occurred during the trace.
602
656
*
@@ -681,7 +735,8 @@ internal enum class TraceNavRoute {
681
735
TraceResults ,
682
736
FeatureResultsDetails ,
683
737
StartingPointDetails ,
684
- TraceError
738
+ TraceError ,
739
+ ClearResults
685
740
}
686
741
687
742
@Immutable
@@ -703,6 +758,8 @@ internal data class TraceRun(
703
758
val configuration : UtilityNamedTraceConfiguration ,
704
759
val startingPoints : List <StartingPoint >,
705
760
val geometryResultsGraphics : List <Graphic >,
761
+ val resultsGraphicExtent : Envelope ? = null ,
762
+ var resultGraphicColor : androidx.compose.ui.graphics.Color ,
706
763
val featureResults : List <UtilityElement >,
707
764
val functionResults : List <UtilityTraceFunctionOutput >,
708
765
val geometryTraceResult : UtilityGeometryTraceResult ?
0 commit comments