Declarative custom elements for Cesium
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 15.8k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
Overview
Use custom element web components to allow cesium to be used declaratively in HTML.
Currently Cesium is an imperative library that requires writing Javascript code with step by step instructions to set up the view. Many newer UI frameworks (like React, Vue, Svlete) are declarative. They allow the developer to declare what they want to display.
Example of current imperative Javascript code
const viewer = new Cesium.Viewer("cesiumContainer", {
animation: true,
homeButton: true,
navigationHelpButton: false,
shadows: true,
shouldAnimate: true,
});
viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: "../SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json"
}));
viewer.entities.add({
position: position,
orientation: orientation,
model: {
uri: "../SampleData/models/CesiumAir/Cesium_Air.glb",
minimumPixelSize: 128,
maximumScale: 20000,
},
});
Example of what a declarative custom element interface could look like
<cesium-view shadows animate>
<cesium-animation-controls></cesium-animation-controls>
<cesium-navigation-controls hide-help></cesium-navigation-controls>
<cesium-tileset src= "../SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json"></cesium-tileset>.
<cesium-model
src="../SampleData/models/CesiumAir/Cesium_Air.glb"
minium-pixel-size="128"
maximum-scale="20000"
></cesium-model>
</cesium-view>
Other custom element functionality
Using custom elements would also allow functionality like:
- automatically resizing the canvas to the containing element using
ResizeObserver. This way it just works if the layout changes. - Exposing events as native DOM events eg.
document.querySelector('cesium-view').addEventListener('selected-entity-changed', ...). Makes it easier to learn for developers already familiar with other HTML DOM events. - CSS style isolation
First steps
I think the first steps would be to create a proof of concept cesium-viewer element that mirrors the exposes Viewer interface today. It would not support any sub-elements like the example above (there would still need to be some imperative configuration).
This could be used as a building block to start adding more elements like cesium-tileset.
Long term vision
Longer term I would like to see the viewer element be more modular and extensible for widgets. It provides a generic set of hosting capability for widgets (such as accessing the scene, maybe some basic positioning for widgets). Instead of the current system where the viewer knows about all possible widgets and they all get configured via the viewer object. That puts cesium created widgets on the same level as user created widgets. The cesium created widgets can serve as examples for how to create your own custom widgets.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing Cesium's existing Viewer interface and the proposed proof-of-concept cesium-viewer element. No source file or test is named in the issue, so first locate the Viewer entry point and related tests. Done would mean agreeing on and implementing a scoped declarative viewer foundation before adding sub-elements such as cesium-tileset.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100