forked from radiantearth/stac-browser
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCesium.js
More file actions
50 lines (43 loc) · 1.53 KB
/
Cesium.js
File metadata and controls
50 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import AssetActionPlugin from "../AssetActionPlugin";
import URI from 'urijs';
import i18n from "../../i18n";
// See mime types discussion for 3d-tiles here and there
// https://github.com/opengeospatial/ogcapi-3d-geovolumes/issues/13
const OGC3DTILES_SUPPORTED_TYPES = [
// 'application/json',
'application/3dtiles+json',
];
export default class Cesium extends AssetActionPlugin {
get show() {
return this.component.isBrowserProtocol && OGC3DTILES_SUPPORTED_TYPES.includes(this.asset.type);
}
get uri() {
// https://sandcastle.cesium.com/standalone.html vs https://sandcastle.cesium.com/index.html
let uri = new URI("https://sandcastle.cesium.com/standalone.html");
const tileset_url = this.component.href;
const code_payload = {
html: `
<style> @import url(../templates/bucket.css); </style>
<div id="cesiumContainer" class="fullSize"></div>
`,
code: `
const viewer = new Cesium.Viewer("cesiumContainer", {
terrain: Cesium.Terrain.fromWorldTerrain(),
});
try {
const tileset = await Cesium.Cesium3DTileset.fromUrl('${tileset_url}');
viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset);
} catch (error) {
console.log('Error loading tileset');
}
`.replaceAll(' ', '')
};
const code_str = btoa(JSON.stringify(code_payload));
uri.addQuery('code', code_str);
return uri;
}
get text() {
return i18n.t('actions.openIn', {service: 'Cesium Sandcastle'});
}
}