@@ -70,6 +70,7 @@ import java.time.Instant
70
70
* @param selectionProperties the [SelectionProperties] used by the composable SceneView
71
71
* @param attributionState specifies the attribution bar's visibility, text changed and layout changed events
72
72
* @param cameraController the [CameraController] to manage the position, orientation, and movement of the camera
73
+ * @param analysisOverlays a collection of analysis overlays that render the results of 3D visual analysis on the composable SceneView
73
74
* @param atmosphereEffect the effect applied to the scene's atmosphere
74
75
* @param timeExtent the [TimeExtent] used by the composable SceneView
75
76
* @param onTimeExtentChanged lambda invoked when the composable SceneView's [TimeExtent] is changed
@@ -105,6 +106,7 @@ public fun SceneView(
105
106
selectionProperties: SelectionProperties = SelectionProperties(),
106
107
attributionState: AttributionState = AttributionState(),
107
108
cameraController: CameraController = GlobeCameraController(),
109
+ analysisOverlays: AnalysisOverlayCollection = rememberAnalysisOverlayCollection(),
108
110
atmosphereEffect: AtmosphereEffect = AtmosphereEffect.HorizonOnly,
109
111
timeExtent: TimeExtent? = null,
110
112
onTimeExtentChanged: ((TimeExtent?) -> Unit)? = null,
@@ -163,6 +165,7 @@ public fun SceneView(
163
165
ViewpointUpdater(sceneView, viewpointOperation)
164
166
165
167
GraphicsOverlaysUpdater(graphicsOverlays, sceneView)
168
+ AnalysisOverlaysUpdater(analysisOverlays, sceneView)
166
169
167
170
AttributionStateHandler(sceneView, attributionState)
168
171
ViewpointChangedStateHandler(sceneView, viewpointChangedState)
@@ -204,6 +207,42 @@ private fun ViewpointUpdater(
204
207
}
205
208
}
206
209
210
+ /**
211
+ * Update the view-based [SceneView]'s analysisOverlays property to reflect changes made to the
212
+ * [analysisOverlayCollection] based on the type of [AnalysisOverlayCollection.ChangedEvent]
213
+ *
214
+ * @since 200.4.0
215
+ */
216
+ @Composable
217
+ internal fun AnalysisOverlaysUpdater(
218
+ analysisOverlayCollection: AnalysisOverlayCollection,
219
+ sceneView: SceneView
220
+ ) {
221
+ LaunchedEffect(analysisOverlayCollection) {
222
+ // sync up the SceneView with the new analysis overlays
223
+ sceneView.analysisOverlays.clear()
224
+ analysisOverlayCollection.forEach {
225
+ sceneView.analysisOverlays.add(it)
226
+ }
227
+ // start observing analysisOverlays for subsequent changes
228
+ analysisOverlayCollection.changed.collect { changedEvent ->
229
+ when (changedEvent) {
230
+ // On AnalysisOverlay added:
231
+ is AnalysisOverlayCollection.ChangedEvent.Added ->
232
+ sceneView.analysisOverlays.add(changedEvent.element)
233
+
234
+ // On AnalysisOverlay removed:
235
+ is AnalysisOverlayCollection.ChangedEvent.Removed ->
236
+ sceneView.analysisOverlays.remove(changedEvent.element)
237
+
238
+ // On AnalysisOverlays cleared:
239
+ is AnalysisOverlayCollection.ChangedEvent.Cleared ->
240
+ sceneView.analysisOverlays.clear()
241
+ }
242
+ }
243
+ }
244
+ }
245
+
207
246
/**
208
247
* Sets up the callbacks for all the view-based [sceneView] events.
209
248
*/
@@ -327,3 +366,20 @@ private fun SceneViewEventHandler(
327
366
}
328
367
}
329
368
}
369
+
370
+ /**
371
+ * Create and [remember] a [AnalysisOverlayCollection].
372
+ * [init] will be called when the [AnalysisOverlayCollection] is first created to configure its
373
+ * initial state.
374
+ *
375
+ * @param key invalidates the remembered AnalysisOverlayCollection if different from the previous composition
376
+ * @param init called when the [AnalysisOverlayCollection] is created to configure its initial state
377
+ * @since 200.4.0
378
+ */
379
+ @Composable
380
+ public inline fun rememberAnalysisOverlayCollection(
381
+ key: Any? = null,
382
+ crossinline init: AnalysisOverlayCollection.() -> Unit = {}
383
+ ): AnalysisOverlayCollection = remember(key) {
384
+ AnalysisOverlayCollection().apply(init)
385
+ }
0 commit comments