Initialize Cesium Viewer with Nextspace API
HTML
<script src="https://nextspace-limited.github.io/nextspace-web-bundle/dist/nextspace.js?v1"></script>
<div id="viewer"></div>
CSS
html {
font-family: "Roboto", sans-serif;
}
html, body {
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
height: 100%;
position: relative;
}
#viewer {
height: 100vh;
width: 100vw;
position: relative;
}
JavaScript
// This is dictating what data to load from your account.
const VIEW_ID = "913a8070";
const BOOKMARK_ID = "2b744082-4a87-4c55-9cc2-e6706a5d92d3";
// Setup defaults to point at your account and region.
BModels.ENVIRONMENT.Reset({
// Check "Overview" within the "This Account" sidebar section of Operator to see your Account ID.
accountId: "openstreetmapdemo1",
// UAT is for early access to features, for a stable release use PROD.
env: BModels.Api.EEnv.UAT,
sessionId: "anonymous"
});
const init = async () => {
// Proxy Cesium Ion requests through the Nextspace API.
// This allows for access to Cesium Ion resources without exposing your token, or the default token.
const api = BModels.ENVIRONMENT.Api().GetBruceApi({});
await api.Loading;
Cesium.Ion.defaultServer = api.GetBaseUrl() + "proxy/cesium-ion/";
Cesium.Ion.defaultAccessToken = "proxy";
const container = document.getElementById("viewer");
const viewer = new Cesium.Viewer(container, {
// Excluding the default imagery and terrain providers.
// This is to avoid a flicker as the options change when your bookmark loads in.
terrainProvider: false,
imageryProvider: false
});
viewer.scene.globe.baseColor = Cesium.Color.fromCssColorString("#0326BE");
// Removing Cesium's default double click.
viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
BEngine.ViewerUtils.InitViewer({
viewer,
// If you're seeing Cesium default widgets then set this to true.
destroyWidgets: false
});
// Render data.
await BEngine.ViewRenderEngine.Render({
viewId: VIEW_ID,
bookmarkId: BOOKMARK_ID,
skipTransition: true,
viewer: viewer
});
};
init();