-
Notifications
You must be signed in to change notification settings - Fork 6
SceneView: add scene viewpoint operation #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
aa41bb4
ef697c3
5f855d7
5d64f3f
ddd21a7
1d9f330
9f8dbf7
0297d1e
1890d20
5a2c380
2edfa44
1592b9b
f4027d4
a518abf
5cb6f9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,132 @@ | ||||||
package com.arcgismaps.toolkit.geocompose | ||||||
hud10837 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
import androidx.compose.runtime.Stable | ||||||
import com.arcgismaps.mapping.Bookmark | ||||||
import com.arcgismaps.mapping.Viewpoint | ||||||
import com.arcgismaps.mapping.view.Camera | ||||||
import com.arcgismaps.mapping.view.SceneView | ||||||
import kotlinx.coroutines.CompletableDeferred | ||||||
import kotlin.coroutines.cancellation.CancellationException | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
/** | ||||||
* Defines operations for setting the viewpoint of a composable [SceneView]. | ||||||
* | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
@Stable | ||||||
public sealed class SceneViewpointOperation { | ||||||
private val deferred = CompletableDeferred<Result<Boolean>>() | ||||||
|
||||||
/** | ||||||
* Awaits the completion of this SceneViewpointOperation. | ||||||
* | ||||||
* @return a Result returning a boolean used to indicate if the operation completed successfully or not | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
public suspend fun await(): Result<Boolean> = deferred.await() | ||||||
|
||||||
internal fun complete(result: Result<Boolean>) { | ||||||
deferred.complete(result) | ||||||
} | ||||||
|
||||||
/** | ||||||
* Changes the scene view to the new viewpoint. The viewpoint is updated instantaneously. | ||||||
* | ||||||
* @property viewpoint the new viewpoint | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
public class Set(public val viewpoint: Viewpoint) : SceneViewpointOperation() | ||||||
|
||||||
/** | ||||||
* Animates the scene view to the new viewpoint, taking the given number of seconds to complete the | ||||||
* navigation. | ||||||
* | ||||||
* @property viewpoint the new viewpoint | ||||||
* @property durationSeconds the duration of the animation in seconds | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
public class Animate( | ||||||
public val viewpoint: Viewpoint, | ||||||
public val durationSeconds: Float = 0.25f | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be better to use Duration here instead of |
||||||
) : SceneViewpointOperation() | ||||||
|
||||||
/** | ||||||
* Updates the display to the viewpoint specified by the given camera. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* @property camera the new camera | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
public class SetCamera(public val camera: Camera) : SceneViewpointOperation() | ||||||
|
||||||
/** | ||||||
* Animates the display to the viewpoint specified by the given camera using the specified duration | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* to arrive. | ||||||
* | ||||||
* @property camera the new camera | ||||||
* @property duration the duration of the animation in seconds | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
public class AnimateCamera( | ||||||
public val camera: Camera, | ||||||
public val durationSeconds: Float = 0.25f | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, should use |
||||||
) : SceneViewpointOperation() | ||||||
|
||||||
/** | ||||||
* Animates the scene view's viewpoint to the viewpoint of the bookmark. | ||||||
* | ||||||
* @property bookmark bookmark to set | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
public class SetBookmark(public val bookmark: Bookmark) : SceneViewpointOperation() | ||||||
} | ||||||
|
||||||
/** | ||||||
* Executes the [SceneViewpointOperation] on the given view-based [SceneView]. The operation can be awaited using | ||||||
* [SceneViewpointOperation.await]. If the coroutine on which the viewpoint operation is executed is cancelled, | ||||||
* for example due to another viewpoint operation being executed, the [SceneViewpointOperation.await] call | ||||||
* will return a Result with a boolean set to `false`, indicating that the viewpoint operation failed | ||||||
* to complete. | ||||||
* | ||||||
* @param sceneView the view-based SceneView to execute this operation on | ||||||
* @since 200.4.0 | ||||||
*/ | ||||||
internal suspend fun SceneViewpointOperation.execute(sceneView: SceneView) { | ||||||
when (this) { | ||||||
is SceneViewpointOperation.Set -> { | ||||||
sceneView.setViewpoint(this.viewpoint) | ||||||
this.complete(Result.success(true)) | ||||||
} | ||||||
is SceneViewpointOperation.Animate -> { | ||||||
try { | ||||||
val result = sceneView.setViewpointAnimated(this.viewpoint, this.durationSeconds) | ||||||
this.complete(result) | ||||||
} catch (e: CancellationException) { | ||||||
this.complete(Result.success(false)) | ||||||
throw e | ||||||
} | ||||||
} | ||||||
is SceneViewpointOperation.AnimateCamera -> { | ||||||
try { | ||||||
val result = sceneView.setViewpointCameraAnimated(this.camera, this.durationSeconds) | ||||||
this.complete(result) | ||||||
} catch (e: CancellationException) { | ||||||
this.complete(Result.success(false)) | ||||||
throw e | ||||||
} | ||||||
} | ||||||
is SceneViewpointOperation.SetBookmark -> { | ||||||
try { | ||||||
val result = sceneView.setBookmark(this.bookmark) | ||||||
this.complete(result) | ||||||
} catch (e: CancellationException) { | ||||||
this.complete(Result.success(false)) | ||||||
throw e | ||||||
} | ||||||
} | ||||||
is SceneViewpointOperation.SetCamera -> { | ||||||
sceneView.setViewpointCamera(this.camera) | ||||||
this.complete(Result.success(true)) | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.