-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add backward, forward and enter 360 image for navigation (#4827)
* Renaming * Add history * Update Image360History.ts * Image actions * Fix * Update Image360History.ts * Refacoring * Fix api * Fix api * Update reveal.api.md * Fix api * Update Image360UI.ts * Diff Fixes * Update Image360History.ts * Update Image360History.ts * Update Image360Action.ts * Fix exceptions * updated reveal.api.md file * Update Image360ApiHelper.ts * Update package.json * Update package.json * Update package.json --------- Co-authored-by: Pramod S <[email protected]>
- Loading branch information
1 parent
a14e906
commit 1cdd5c5
Showing
7 changed files
with
194 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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,26 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
|
||
/** | ||
* 360 image action to be used by the CogniteViewer.canDo360Action and do360Action | ||
* @beta | ||
*/ | ||
export enum Image360Action { | ||
/** | ||
* When inside 360 image, forwards on the history list. | ||
*/ | ||
Forward, | ||
/** | ||
* When inside 360 image, backwards on the history list. | ||
*/ | ||
Backward, | ||
/** | ||
* When outside 360 image, go to current in the history list (where you exit from). | ||
*/ | ||
Enter, | ||
/** | ||
* When inside 360, exit. | ||
*/ | ||
Exit | ||
} |
This file contains 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,69 @@ | ||
/*! | ||
* Copyright 2022 Cognite AS | ||
*/ | ||
|
||
import { Image360 } from './entity/Image360'; | ||
import { Image360Action } from './Image360Action'; | ||
|
||
export class Image360History { | ||
private readonly _history: Image360[] = []; | ||
private _currentIndex: number = -1; // Negative mean no current index (avoid empty because of harder logic) | ||
|
||
public start(history: Image360): void { | ||
if (this.isLegalIndex(this._currentIndex + 1)) { | ||
this._history.slice(this._currentIndex + 1); | ||
} | ||
this._history.push(history); | ||
this._currentIndex = this._history.length - 1; | ||
} | ||
|
||
private current(): Image360 | undefined { | ||
if (!this.isLegalIndex(this._currentIndex)) { | ||
return undefined; | ||
} | ||
return this._history[this._currentIndex]; | ||
} | ||
|
||
public clear(): void { | ||
this._history.splice(0, this._history.length); | ||
this._currentIndex = -1; | ||
} | ||
|
||
private isLegalIndex(index: number): boolean { | ||
return index >= 0 && index < this._history.length; | ||
} | ||
|
||
public canDoAction(action: Image360Action): boolean { | ||
switch (action) { | ||
case Image360Action.Forward: | ||
return this.isLegalIndex(this._currentIndex + 1); | ||
case Image360Action.Backward: | ||
return this.isLegalIndex(this._currentIndex - 1); | ||
case Image360Action.Enter: | ||
return this.isLegalIndex(this._currentIndex); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
public doAction(action: Image360Action): Image360 | undefined { | ||
let currentIndex = this._currentIndex; | ||
switch (action) { | ||
case Image360Action.Forward: | ||
currentIndex++; | ||
break; | ||
case Image360Action.Backward: | ||
currentIndex--; | ||
break; | ||
case Image360Action.Enter: | ||
break; | ||
default: | ||
throw new Error(`Unknown movement ${action}`); | ||
} | ||
if (!this.isLegalIndex(currentIndex)) { | ||
return undefined; | ||
} | ||
this._currentIndex = currentIndex; | ||
return this.current(); | ||
} | ||
} |
This file contains 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 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 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