Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
dev:developer:3dmapping_sdk:viewer_state [2019/01/31 10:38] pieter.bonne@orbitgt.com |
dev:developer:3dmapping_sdk:viewer_state [2020/05/15 11:22] jeroen removed |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
Closing your host application usually means that the viewer component is destroyed and loses all state. | Closing your host application usually means that the viewer component is destroyed and loses all state. | ||
Line 8: | Line 8: | ||
To listen for state changes, we listen to the '' | To listen for state changes, we listen to the '' | ||
+ | |||
+ | Below is a pseudocode example of storing application state in the browser' | ||
<code javascript> | <code javascript> | ||
- | // Listen to the state-changed signal | + | // Listen to state changes |
viewer.onAppStateChanged.add(handleAppStateChanged); | viewer.onAppStateChanged.add(handleAppStateChanged); | ||
+ | |||
+ | // Save state | ||
+ | function handleAppStateChanged(state) { | ||
+ | window.localStorage.getItem(" | ||
+ | } | ||
</ | </ | ||
Line 18: | Line 25: | ||
When creating the viewer, you have the ability to pass [[glossary|startup options]]. The available options are defined by the '' | When creating the viewer, you have the ability to pass [[glossary|startup options]]. The available options are defined by the '' | ||
- | Startup options can be provided only once. | + | Startup options can be provided only once, on viewer construction. |
- | ===== Example ===== | + | Below is a pseudocode |
- | + | ||
- | Below is a Javascript-specific | + | |
- | Try logging | + | |
<code javascript> | <code javascript> | ||
- | var viewer; | + | // Get a reference to some API elements we will use. |
+ | var Constansts = orbitgt.mapping3d.sdk.viewer.Constants; | ||
+ | var SDKViewer = orbitgt.mapping3d.sdk.viewer.SDKViewer; | ||
+ | var AMap = orbitgt.mapping3d.sdk.viewer.AMap; | ||
- | /** | + | // Prepare options and set state. |
- | * Called when something changes to the viewer | + | var options = new AMap(); |
- | */ | + | options.set(Constants.STARTUP_APP_STATE, |
- | function handleAppStateChanged(state) { | + | |
- | // Save state somewhere... | + | |
- | | + | |
- | } | + | |
- | /** | + | // Create viewer |
- | * Called when the viewer component is ready for interaction. | + | var appElement = document.getElementById(" |
- | */ | + | var viewer = new SDKViewer(" |
- | function handleReady() { | + | |
- | // Listen to the state-changed signal | + | |
- | viewer.onAppStateChanged.add(handleAppStateChanged); | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * Called when the page is full loaded. | + | |
- | */ | + | |
- | function handleDOMReady() { | + | |
- | | + | |
- | var options = new orbitgt.mapping3d.sdk.viewer.AMap(); | + | |
- | options.set(orbitgt.mapping3d.sdk.viewer.Constants.STARTUP_APP_STATE, | + | |
- | // Create viewer | + | |
- | | + | |
- | viewer = new orbitgt.mapping3d.sdk.viewer.SDKViewer(" | + | |
- | viewer.setSize(600, | + | |
- | viewer.isReady.then(handleReady); | + | |
- | } | + | |
- | + | ||
- | // Wait for page to load | + | |
- | document.addEventListener(" | + | |
</ | </ | ||
- | |||
- | < | ||
- | <iframe scrolling=" | ||
- | </ | ||
- | </ | ||
- | |||