From 935ae8cc736e3d4dfaf28f060e862e2e2bb0acdf Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Thu, 4 Jan 2024 18:04:30 +0200 Subject: [PATCH 01/10] create AnalysisOverlayCollection --- .../geocompose/AnalysisOverlayCollection.kt | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt new file mode 100644 index 000000000..bb47ce8fd --- /dev/null +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt @@ -0,0 +1,164 @@ +/* + * Copyright 2023 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.arcgismaps.toolkit.geocompose + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.Stable +import androidx.compose.runtime.remember +import com.arcgismaps.mapping.view.AnalysisOverlay +import com.arcgismaps.mapping.view.SceneView +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.asSharedFlow + +/** + * A collection class to encapsulate the [AnalysisOverlay] list used by the [com.arcgismaps.toolkit.geocompose.SceneView] + * + * @since 200.4.0 + */ +@Stable +public class AnalysisOverlayCollection : Iterable { + + private val analysisOverlays = mutableListOf() + + private val _changed: MutableSharedFlow = MutableSharedFlow( + extraBufferCapacity = Int.MAX_VALUE, + onBufferOverflow = BufferOverflow.DROP_OLDEST + ) + + /** + * [SharedFlow] used to emit changes made to the [analysisOverlays] list + */ + internal val changed: SharedFlow = _changed.asSharedFlow() + + override fun iterator(): Iterator { + return analysisOverlays.iterator() + } + + /** + * Add a [analysisOverlay] to this AnalysisOverlayCollection. + * + * @return if the add operation succeeds, return true. + * @since 200.4.0 + */ + public fun add(analysisOverlay: AnalysisOverlay): Boolean { + return if (analysisOverlays.add(analysisOverlay)) { + _changed.tryEmit(ChangedEvent.Added(analysisOverlay)) + true + } else false + } + + /** + * Remove a [analysisOverlay] from this AnalysisOverlayCollection. + * + * @return if the remove operation succeeds, return true. + * @since 200.4.0 + */ + public fun remove(analysisOverlay: AnalysisOverlay): Boolean { + return if (analysisOverlays.remove(analysisOverlay)) { + _changed.tryEmit(ChangedEvent.Removed(analysisOverlay)) + true + } else false + } + + /** + * Returns the number of graphics overlays in this AnalysisOverlayCollection. + * + * @since 200.4.0 + */ + public val size: Int + get() = analysisOverlays.size + + /** + * Clears all graphics overlays from this AnalysisOverlayCollection. + * + * @since 200.4.0 + */ + public fun clear() { + analysisOverlays.clear() + _changed.tryEmit(ChangedEvent.Cleared) + } + + /** + * Sealed class used to notify the compose SceneView to update the GraphicOverlays on the + * type of [ChangedEvent]. + * + * @since 200.4.0 + */ + internal sealed class ChangedEvent() { + class Added(val element: AnalysisOverlay) : ChangedEvent() + class Removed(val element: AnalysisOverlay) : ChangedEvent() + object Cleared : ChangedEvent() + } +} + + +/** + * Update the view-based [geoView]'s analysisOverlays property to reflect changes made to the + * [analysisOverlayCollection] based on the type of [AnalysisOverlayCollection.ChangedEvent] + * + * @since 200.4.0 + */ +@Composable +internal fun AnalysisOverlaysUpdater( + analysisOverlayCollection: AnalysisOverlayCollection, + sceneView: SceneView +) { + LaunchedEffect(analysisOverlayCollection) { + // sync up the GeoView with the new graphics overlays + sceneView.analysisOverlays.clear() + analysisOverlayCollection.forEach { + sceneView.analysisOverlays.add(it) + } + // start observing analysisOverlays for subsequent changes + analysisOverlayCollection.changed.collect { changedEvent -> + when (changedEvent) { + // On AnalysisOverlay added: + is AnalysisOverlayCollection.ChangedEvent.Added -> + sceneView.analysisOverlays.add(changedEvent.element) + + // On AnalysisOverlay removed: + is AnalysisOverlayCollection.ChangedEvent.Removed -> + sceneView.analysisOverlays.remove(changedEvent.element) + + // On AnalysisOverlays cleared: + is AnalysisOverlayCollection.ChangedEvent.Cleared -> + sceneView.analysisOverlays.clear() + } + } + } +} + +/** + * Create and [remember] a [AnalysisOverlayCollection]. + * [init] will be called when the [AnalysisOverlayCollection] is first created to configure its + * initial state. + * + * @param key invalidates the remembered AnalysisOverlayCollection if different from the previous composition + * @param init called when the [AnalysisOverlayCollection] is created to configure its initial state + * @since 200.4.0 + */ +@Composable +public inline fun rememberAnalysisOverlayCollection( + key: Any? = null, + crossinline init: AnalysisOverlayCollection.() -> Unit = {} +): AnalysisOverlayCollection = remember(key) { + AnalysisOverlayCollection().apply(init) +} \ No newline at end of file From c678e65312cc7c5844c29290e95c07f9e7064181 Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Thu, 4 Jan 2024 18:05:02 +0200 Subject: [PATCH 02/10] mv factory for graphics overlay collection --- .../geocompose/GraphicsOverlayCollection.kt | 18 ++++++++++++++++++ .../arcgismaps/toolkit/geocompose/MapView.kt | 17 ----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt index d121613c3..34e8201a9 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt @@ -20,6 +20,7 @@ package com.arcgismaps.toolkit.geocompose import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.Stable +import androidx.compose.runtime.remember import com.arcgismaps.mapping.view.GeoView import com.arcgismaps.mapping.view.GraphicsOverlay import kotlinx.coroutines.channels.BufferOverflow @@ -144,3 +145,20 @@ internal fun GraphicsOverlaysUpdater( } } } + +/** + * Create and [remember] a [GraphicsOverlayCollection]. + * [init] will be called when the [GraphicsOverlayCollection] is first created to configure its + * initial state. + * + * @param key invalidates the remembered GraphicsOverlayCollection if different from the previous composition + * @param init called when the [GraphicsOverlayCollection] is created to configure its initial state + * @since 200.4.0 + */ +@Composable +public inline fun rememberGraphicsOverlayCollection( + key: Any? = null, + crossinline init: GraphicsOverlayCollection.() -> Unit = {} +): GraphicsOverlayCollection = remember(key) { + GraphicsOverlayCollection().apply(init) +} \ No newline at end of file diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/MapView.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/MapView.kt index 57803c103..07508cd96 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/MapView.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/MapView.kt @@ -400,20 +400,3 @@ public inline fun rememberLocationDisplay( LocationDisplay().apply(init) } } - -/** - * Create and [remember] a [GraphicsOverlayCollection]. - * [init] will be called when the [GraphicsOverlayCollection] is first created to configure its - * initial state. - * - * @param key invalidates the remembered GraphicsOverlayCollection if different from the previous composition - * @param init called when the [GraphicsOverlayCollection] is created to configure its initial state - * @since 200.4.0 - */ -@Composable -public inline fun rememberGraphicsOverlayCollection( - key: Any? = null, - crossinline init: GraphicsOverlayCollection.() -> Unit = {} -): GraphicsOverlayCollection = remember(key) { - GraphicsOverlayCollection().apply(init) -} From 6545487f0802f6b10e18f1914aeb38bd1a47a43d Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Thu, 4 Jan 2024 18:05:43 +0200 Subject: [PATCH 03/10] add analysis to scene view --- .../main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt index dfe41569b..0e582077c 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt @@ -91,6 +91,7 @@ public fun SceneView( viewLabelProperties: ViewLabelProperties = ViewLabelProperties(), selectionProperties: SelectionProperties = SelectionProperties(), attributionState: AttributionState = AttributionState(), + analysisOverlays: AnalysisOverlayCollection = rememberAnalysisOverlayCollection(), timeExtent: TimeExtent? = null, onTimeExtentChanged: ((TimeExtent?) -> Unit)? = null, onNavigationChanged: ((isNavigating: Boolean) -> Unit)? = null, @@ -140,6 +141,7 @@ public fun SceneView( ViewpointUpdater(sceneView, viewpointOperation) GraphicsOverlaysUpdater(graphicsOverlays, sceneView) + AnalysisOverlaysUpdater(analysisOverlays, sceneView) AttributionStateHandler(sceneView, attributionState) ViewpointChangedStateHandler(sceneView, viewpointChangedState) From 6ffd4c20d0a143977c255f89d03cceabde28b64f Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Thu, 4 Jan 2024 18:27:12 +0200 Subject: [PATCH 04/10] eof newlines --- .../arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt | 2 +- .../arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt index bb47ce8fd..7b7c31176 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt @@ -161,4 +161,4 @@ public inline fun rememberAnalysisOverlayCollection( crossinline init: AnalysisOverlayCollection.() -> Unit = {} ): AnalysisOverlayCollection = remember(key) { AnalysisOverlayCollection().apply(init) -} \ No newline at end of file +} diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt index 34e8201a9..09f4a818e 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/GraphicsOverlayCollection.kt @@ -161,4 +161,4 @@ public inline fun rememberGraphicsOverlayCollection( crossinline init: GraphicsOverlayCollection.() -> Unit = {} ): GraphicsOverlayCollection = remember(key) { GraphicsOverlayCollection().apply(init) -} \ No newline at end of file +} From fe6f3c259b8b599bfe7a274a888281255ec28d56 Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Thu, 4 Jan 2024 18:28:32 +0200 Subject: [PATCH 05/10] add doc --- .../src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt index 0e582077c..d61f7cde0 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt @@ -62,6 +62,7 @@ import kotlinx.coroutines.launch * @param viewLabelProperties the [ViewLabelProperties] used by the composable SceneView * @param selectionProperties the [SelectionProperties] used by the composable SceneView * @param attributionState specifies the attribution bar's visibility, text changed and layout changed events + * @param analysisOverlays a collection of analysis overlays that render the results of 3D visual analysis on the SceneView * @param timeExtent the [TimeExtent] used by the composable SceneView * @param onTimeExtentChanged lambda invoked when the composable SceneView's [TimeExtent] is changed * @param onNavigationChanged lambda invoked when the navigation status of the composable SceneView has changed From 4890151ec1baa2c268b4af06e75c0eb7c2bdb49a Mon Sep 17 00:00:00 2001 From: hud10837 Date: Mon, 8 Jan 2024 10:36:26 +0200 Subject: [PATCH 06/10] Fix doc that mentions graphics overlays Co-authored-by: Puneet Prakash --- .../toolkit/geocompose/AnalysisOverlayCollection.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt index 7b7c31176..b7e7df5c2 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt @@ -79,7 +79,7 @@ public class AnalysisOverlayCollection : Iterable { } /** - * Returns the number of graphics overlays in this AnalysisOverlayCollection. + * Returns the number of analysis overlays in this AnalysisOverlayCollection. * * @since 200.4.0 */ @@ -87,7 +87,7 @@ public class AnalysisOverlayCollection : Iterable { get() = analysisOverlays.size /** - * Clears all graphics overlays from this AnalysisOverlayCollection. + * Clears all analysis overlays from this AnalysisOverlayCollection. * * @since 200.4.0 */ @@ -97,7 +97,7 @@ public class AnalysisOverlayCollection : Iterable { } /** - * Sealed class used to notify the compose SceneView to update the GraphicOverlays on the + * Sealed class used to notify the compose SceneView to update the AnalysisOverlays on the * type of [ChangedEvent]. * * @since 200.4.0 From 14348d1851be0d2215b9517eb41bc1bb5d2238aa Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Mon, 8 Jan 2024 10:37:29 +0200 Subject: [PATCH 07/10] mv factory function to SceneView file --- .../geocompose/AnalysisOverlayCollection.kt | 17 ----------------- .../arcgismaps/toolkit/geocompose/SceneView.kt | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt index 7b7c31176..403aa4773 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt @@ -145,20 +145,3 @@ internal fun AnalysisOverlaysUpdater( } } } - -/** - * Create and [remember] a [AnalysisOverlayCollection]. - * [init] will be called when the [AnalysisOverlayCollection] is first created to configure its - * initial state. - * - * @param key invalidates the remembered AnalysisOverlayCollection if different from the previous composition - * @param init called when the [AnalysisOverlayCollection] is created to configure its initial state - * @since 200.4.0 - */ -@Composable -public inline fun rememberAnalysisOverlayCollection( - key: Any? = null, - crossinline init: AnalysisOverlayCollection.() -> Unit = {} -): AnalysisOverlayCollection = remember(key) { - AnalysisOverlayCollection().apply(init) -} diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt index d61f7cde0..894375aa5 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt @@ -291,3 +291,20 @@ private fun SceneViewEventHandler( } } } + +/** + * Create and [remember] a [AnalysisOverlayCollection]. + * [init] will be called when the [AnalysisOverlayCollection] is first created to configure its + * initial state. + * + * @param key invalidates the remembered AnalysisOverlayCollection if different from the previous composition + * @param init called when the [AnalysisOverlayCollection] is created to configure its initial state + * @since 200.4.0 + */ +@Composable +public inline fun rememberAnalysisOverlayCollection( + key: Any? = null, + crossinline init: AnalysisOverlayCollection.() -> Unit = {} +): AnalysisOverlayCollection = remember(key) { + AnalysisOverlayCollection().apply(init) +} From b09023577f14f57ba2e264134a64e673db23f38c Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Wed, 10 Jan 2024 12:09:58 +0200 Subject: [PATCH 08/10] address doc comments --- .../arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt | 3 +-- .../main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt index 65a8f278b..bc52484d7 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt @@ -20,7 +20,6 @@ package com.arcgismaps.toolkit.geocompose import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.Stable -import androidx.compose.runtime.remember import com.arcgismaps.mapping.view.AnalysisOverlay import com.arcgismaps.mapping.view.SceneView import kotlinx.coroutines.channels.BufferOverflow @@ -111,7 +110,7 @@ public class AnalysisOverlayCollection : Iterable { /** - * Update the view-based [geoView]'s analysisOverlays property to reflect changes made to the + * Update the view-based [SceneView]'s analysisOverlays property to reflect changes made to the * [analysisOverlayCollection] based on the type of [AnalysisOverlayCollection.ChangedEvent] * * @since 200.4.0 diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt index 6e153fe8a..478ebb290 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt @@ -68,7 +68,7 @@ import java.time.Instant * @param selectionProperties the [SelectionProperties] used by the composable SceneView * @param attributionState specifies the attribution bar's visibility, text changed and layout changed events * @param cameraController the [CameraController] to manage the position, orientation, and movement of the camera - * @param analysisOverlays a collection of analysis overlays that render the results of 3D visual analysis on the SceneView + * @param analysisOverlays a collection of analysis overlays that render the results of 3D visual analysis on the composable SceneView * @param timeExtent the [TimeExtent] used by the composable SceneView * @param sunTime the position of the sun in the scene view based on a specific date and time * @param sunLighting the type of ambient sunlight and shadows in the scene view From f86c75bd602751f4218bb15296b49cf9722b1ba9 Mon Sep 17 00:00:00 2001 From: Hudson Miears Date: Wed, 10 Jan 2024 12:24:03 +0200 Subject: [PATCH 09/10] mv updater to SceneView file --- .../geocompose/AnalysisOverlayCollection.kt | 37 ------------------- .../toolkit/geocompose/SceneView.kt | 36 ++++++++++++++++++ 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt index bc52484d7..6487388b2 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/AnalysisOverlayCollection.kt @@ -107,40 +107,3 @@ public class AnalysisOverlayCollection : Iterable { object Cleared : ChangedEvent() } } - - -/** - * Update the view-based [SceneView]'s analysisOverlays property to reflect changes made to the - * [analysisOverlayCollection] based on the type of [AnalysisOverlayCollection.ChangedEvent] - * - * @since 200.4.0 - */ -@Composable -internal fun AnalysisOverlaysUpdater( - analysisOverlayCollection: AnalysisOverlayCollection, - sceneView: SceneView -) { - LaunchedEffect(analysisOverlayCollection) { - // sync up the GeoView with the new graphics overlays - sceneView.analysisOverlays.clear() - analysisOverlayCollection.forEach { - sceneView.analysisOverlays.add(it) - } - // start observing analysisOverlays for subsequent changes - analysisOverlayCollection.changed.collect { changedEvent -> - when (changedEvent) { - // On AnalysisOverlay added: - is AnalysisOverlayCollection.ChangedEvent.Added -> - sceneView.analysisOverlays.add(changedEvent.element) - - // On AnalysisOverlay removed: - is AnalysisOverlayCollection.ChangedEvent.Removed -> - sceneView.analysisOverlays.remove(changedEvent.element) - - // On AnalysisOverlays cleared: - is AnalysisOverlayCollection.ChangedEvent.Cleared -> - sceneView.analysisOverlays.clear() - } - } - } -} diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt index 478ebb290..d8cee8395 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt @@ -199,6 +199,42 @@ private fun ViewpointUpdater( } } +/** + * Update the view-based [SceneView]'s analysisOverlays property to reflect changes made to the + * [analysisOverlayCollection] based on the type of [AnalysisOverlayCollection.ChangedEvent] + * + * @since 200.4.0 + */ +@Composable +internal fun AnalysisOverlaysUpdater( + analysisOverlayCollection: AnalysisOverlayCollection, + sceneView: SceneView +) { + LaunchedEffect(analysisOverlayCollection) { + // sync up the GeoView with the new graphics overlays + sceneView.analysisOverlays.clear() + analysisOverlayCollection.forEach { + sceneView.analysisOverlays.add(it) + } + // start observing analysisOverlays for subsequent changes + analysisOverlayCollection.changed.collect { changedEvent -> + when (changedEvent) { + // On AnalysisOverlay added: + is AnalysisOverlayCollection.ChangedEvent.Added -> + sceneView.analysisOverlays.add(changedEvent.element) + + // On AnalysisOverlay removed: + is AnalysisOverlayCollection.ChangedEvent.Removed -> + sceneView.analysisOverlays.remove(changedEvent.element) + + // On AnalysisOverlays cleared: + is AnalysisOverlayCollection.ChangedEvent.Cleared -> + sceneView.analysisOverlays.clear() + } + } + } +} + /** * Sets up the callbacks for all the view-based [sceneView] events. */ From 36fc514c28e62338fb988d4e05824834a68feead Mon Sep 17 00:00:00 2001 From: hud10837 Date: Thu, 11 Jan 2024 18:33:25 +0200 Subject: [PATCH 10/10] Update toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt Co-authored-by: Puneet Prakash --- .../main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt index 4895804e4..cd7db0cf9 100644 --- a/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt +++ b/toolkit/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneView.kt @@ -219,7 +219,7 @@ internal fun AnalysisOverlaysUpdater( sceneView: SceneView ) { LaunchedEffect(analysisOverlayCollection) { - // sync up the GeoView with the new graphics overlays + // sync up the SceneView with the new analysis overlays sceneView.analysisOverlays.clear() analysisOverlayCollection.forEach { sceneView.analysisOverlays.add(it)