I want to use the remember camera code from /Apps/CesiumViewer/CesiumViewer.js with the /Build/Cesium/Cesium.js (minified).
if (defined(view)) {
const splitQuery = view.split(/[ ,]+/);
if (splitQuery.length > 1) {
const longitude = !isNaN(+splitQuery[0]) ? +splitQuery[0] : 0.0;
const latitude = !isNaN(+splitQuery[1]) ? +splitQuery[1] : 0.0;
const height =
splitQuery.length > 2 && !isNaN(+splitQuery[2])
? +splitQuery[2]
: 300.0;
const heading =
splitQuery.length > 3 && !isNaN(+splitQuery[3])
? CesiumMath.toRadians(+splitQuery[3])
: undefined;
const pitch =
splitQuery.length > 4 && !isNaN(+splitQuery[4])
? CesiumMath.toRadians(+splitQuery[4])
: undefined;
const roll =
splitQuery.length > 5 && !isNaN(+splitQuery[5])
? CesiumMath.toRadians(+splitQuery[5])
: undefined;
viewer.camera.setView({
destination: Cartesian3.fromDegrees(longitude, latitude, height),
orientation: {
heading: heading,
pitch: pitch,
roll: roll,
},
});
}
}
const camera = viewer.camera;
function saveCamera() {
const position = camera.positionCartographic;
let hpr = "";
if (defined(camera.heading)) {
hpr = `,${CesiumMath.toDegrees(camera.heading)},${CesiumMath.toDegrees(
camera.pitch
)},${CesiumMath.toDegrees(camera.roll)}`;
}
endUserOptions.view = `${CesiumMath.toDegrees(
position.longitude
)},${CesiumMath.toDegrees(position.latitude)},${position.height}${hpr}`;
history.replaceState(undefined, "", `?${objectToQuery(endUserOptions)}`);
}
let timeout;
if (endUserOptions.saveCamera !== "false") {
camera.changed.addEventListener(function () {
window.clearTimeout(timeout);
timeout = window.setTimeout(saveCamera, 1000);
});
}
All of this code is imported from the Unminified folder:
import {
Cartesian3,
createWorldTerrain,
defined,
formatError,
Math as CesiumMath,
objectToQuery,
queryToObject,
CzmlDataSource,
GeoJsonDataSource,
KmlDataSource,
GpxDataSource,
TileMapServiceImageryProvider,
Viewer,
viewerCesiumInspectorMixin,
viewerDragDropMixin,
} from "../../Build/CesiumUnminified/index.js";
Is there a simpler way to include this code and have it update the URL as the user changes camera view AND do this with the already built, minified cesium.js?