-
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
Merged
hud10837
merged 15 commits into
feature-branches/geo-compose
from
hud10837/scene-viewpoint-operation
Dec 19, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
aa41bb4
create SceneViewpointOperation
hud10837 ef697c3
add operation to sceneview
hud10837 5f855d7
add all operations for sceneview
hud10837 5d64f3f
add doc
hud10837 ddd21a7
eof newline
hud10837 1d9f330
eof newline
hud10837 9f8dbf7
Don't use named params on viewpoint updater
hud10837 0297d1e
use kotlinx cancellation exception
hud10837 1890d20
Merge branch 'feature-branches/geo-compose' of github.com:ArcGIS/arcg…
hud10837 5a2c380
add copyright
hud10837 2edfa44
use duration in viewpoint operations
hud10837 1592b9b
doc
hud10837 f4027d4
rename durationSeconds and fix microapp
hud10837 a518abf
Merge branch 'feature-branches/geo-compose' of github.com:ArcGIS/arcg…
hud10837 5cb6f9a
Merge branch 'feature-branches/geo-compose' of github.com:ArcGIS/arcg…
hud10837 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
...it/geo-compose/src/main/java/com/arcgismaps/toolkit/geocompose/SceneViewpointOperation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
* | ||
* 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.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.CancellationException | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.seconds | ||
import kotlin.time.DurationUnit | ||
|
||
|
||
/** | ||
* 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 duration the duration of the animation | ||
* @since 200.4.0 | ||
*/ | ||
public class Animate( | ||
public val viewpoint: Viewpoint, | ||
public val duration: Duration = 0.25.seconds | ||
) : SceneViewpointOperation() | ||
|
||
/** | ||
* Changes the scene view to the viewpoint specified by the given camera. The viewpoint is updated instantaneously. | ||
* | ||
* @property camera the new camera | ||
* @since 200.4.0 | ||
*/ | ||
public class SetCamera(public val camera: Camera) : SceneViewpointOperation() | ||
|
||
/** | ||
* Animates the scene view to the viewpoint specified by the given camera using the specified duration. | ||
* | ||
* @property camera the new camera | ||
* @property duration the duration of the animation | ||
* @since 200.4.0 | ||
*/ | ||
public class AnimateCamera( | ||
public val camera: Camera, | ||
public val duration: Duration = 0.25.seconds | ||
) : 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.duration.toDouble(DurationUnit.SECONDS).toFloat()) | ||
this.complete(result) | ||
} catch (e: CancellationException) { | ||
this.complete(Result.success(false)) | ||
throw e | ||
} | ||
} | ||
is SceneViewpointOperation.AnimateCamera -> { | ||
try { | ||
val result = sceneView.setViewpointCameraAnimated(this.camera, this.duration.toDouble(DurationUnit.SECONDS).toFloat()) | ||
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)) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.