-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from geoblocks/basic_cesium_plugin
Add plugin-cesium-widget component
- Loading branch information
Showing
9 changed files
with
204 additions
and
104 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
import type {IIlluminationConfig} from './ingv-config-illumination.js'; | ||
|
||
export const defaultConfig: IIlluminationConfig = { | ||
header: { | ||
languages: ['de', 'fr', 'en', 'it'], | ||
title: { | ||
fr: 'Ma super app', | ||
en: 'My super app', | ||
de: 'Meine supper app', | ||
it: 'Mia super app', | ||
}, | ||
}, | ||
footer: { | ||
contact: '[email protected]', | ||
impressum: { | ||
fr: 'Bla bla FR impressim', | ||
en: 'Bla bla EN impressim', | ||
de: 'Bla bla DE impressim', | ||
it: 'Bla bla IT impressim', | ||
}, | ||
}, | ||
app: { | ||
cesiumContext: { | ||
layers: { | ||
terrain: 'https://3d.geo.admin.ch/ch.swisstopo.terrain.3d/v1/', | ||
buildings: | ||
'https://vectortiles0.geo.admin.ch/3d-tiles/ch.swisstopo.swisstlm3d.3d/20201020/tileset.json', | ||
vegetation: | ||
'https://vectortiles.geo.admin.ch/3d-tiles/ch.swisstopo.vegetation.3d/20190313/tileset.json', | ||
}, | ||
initialView: { | ||
destination: [6.628484, 46.5, 1000], | ||
orientation: { | ||
heading: 0, | ||
pitch: -30.0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,16 +1,8 @@ | ||
import {IngvCesiumContext} from 'src/interfaces/ingv-cesium-context.js'; | ||
import {INgvStructureApp} from '../../structure/ngv-structure-app.js'; | ||
|
||
export interface IIlluminationConfig extends INgvStructureApp { | ||
app: { | ||
terrain: string; | ||
buildings: string; | ||
vegetation: string; | ||
initialView: { | ||
destination: [number, number, number]; | ||
orientation: { | ||
heading: number; | ||
pitch: number; | ||
}; | ||
}; | ||
cesiumContext: IngvCesiumContext; | ||
}; | ||
} |
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,16 @@ | ||
export interface IngvCesiumContext { | ||
cesiumApiKey?: string; | ||
baseUrl?: string; | ||
layers: { | ||
terrain: string; | ||
buildings: string; | ||
vegetation: string; | ||
}; | ||
initialView: { | ||
destination: [number, number, number]; | ||
orientation: { | ||
heading: number; | ||
pitch: number; | ||
}; | ||
}; | ||
} |
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,117 @@ | ||
import {LitElement, css, unsafeCSS, html} from 'lit'; | ||
import {customElement, property, query} from 'lit/decorators.js'; | ||
|
||
import { | ||
Ion, | ||
Math as CesiumMath, | ||
CesiumWidget, | ||
Cartesian3, | ||
CesiumTerrainProvider, | ||
Terrain, | ||
ShadowMode, | ||
Cesium3DTileset, | ||
} from '@cesium/engine'; | ||
|
||
// @ts-expect-error Vite specific ?inline parameter | ||
import style from '@cesium/engine/Source/Widget/CesiumWidget.css?inline'; | ||
import {IngvCesiumContext} from 'src/interfaces/ingv-cesium-context.js'; | ||
|
||
/** | ||
* FIXME: this is really specific: | ||
* - it has a not very flexible set of layers; | ||
* - there is no concept of a catalog / identifier | ||
* - it hardcodes dependency on various types: terrain, 3dtiles, ... (maybe fine?) | ||
* - it forces shadows, backfaceculling, ... | ||
*/ | ||
async function initCesium( | ||
container: HTMLDivElement, | ||
config: IngvCesiumContext, | ||
): Promise<CesiumWidget> { | ||
window.CESIUM_BASE_URL = config.baseUrl || '/'; | ||
|
||
if (config.cesiumApiKey) { | ||
Ion.defaultAccessToken = config.cesiumApiKey; | ||
} | ||
|
||
window.CESIUM_BASE_URL = '/'; | ||
const { | ||
terrain: terrainUrl, | ||
buildings: buildingsUrl, | ||
vegetation: vegetationUrl, | ||
} = config.layers; | ||
const initialView = config.initialView; | ||
|
||
const viewer = new CesiumWidget(container, { | ||
shadows: true, | ||
scene3DOnly: true, | ||
terrain: new Terrain(CesiumTerrainProvider.fromUrl(terrainUrl)), | ||
terrainShadows: ShadowMode.ENABLED, | ||
}); | ||
const scene = viewer.scene; | ||
const buildingsTS = await Cesium3DTileset.fromUrl(buildingsUrl, { | ||
show: true, | ||
backFaceCulling: false, | ||
}); | ||
scene.primitives.add(buildingsTS); | ||
const vegetationTS = await Cesium3DTileset.fromUrl(vegetationUrl, { | ||
show: true, | ||
backFaceCulling: false, | ||
}); | ||
scene.primitives.add(vegetationTS); | ||
|
||
viewer.camera.flyTo({ | ||
destination: Cartesian3.fromDegrees(...initialView.destination), | ||
orientation: { | ||
heading: CesiumMath.toRadians(initialView.orientation.heading), | ||
pitch: CesiumMath.toRadians(initialView.orientation.pitch), | ||
}, | ||
duration: 0, | ||
}); | ||
|
||
return viewer; | ||
} | ||
|
||
@customElement('ngv-plugin-cesium-widget') | ||
export class NgvPluginCesiumWidget extends LitElement { | ||
public viewer: CesiumWidget; | ||
|
||
static styles = css` | ||
${unsafeCSS(style)} | ||
:host { | ||
width: 100%; | ||
height: 100%; | ||
display: block; | ||
} | ||
.cesium-credit-logoContainer { | ||
display: none !important; | ||
} | ||
`; | ||
|
||
@property({type: Object}) | ||
config: IngvCesiumContext; | ||
|
||
// The configuration should provide a catalog | ||
@query('#globe') | ||
private element: HTMLDivElement; | ||
|
||
protected async firstUpdated(): Promise<void> { | ||
this.viewer = await initCesium(this.element, this.config); | ||
} | ||
|
||
render() { | ||
return html`<div id="globe"></div>`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'ngv-plugin-cesium-widget': NgvPluginCesiumWidget; | ||
} | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
CESIUM_BASE_URL: string; | ||
} | ||
} |
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