App Directory
After downloading the files from the official website, we can see the following CesiumJS library structure:
- Source/: Cesium application code and data
- ThirdParty/: External dependency libraries, third-party libraries separate from Cesium
- LICENSE.md: Cesium license information
- index.html: Web homepage, which needs to be defined according to Cesium requirements and include Cesium dependency libraries
- server.js: Node.js-based web server application
Note
CesiumJS is adapted to work with third-party JavaScript libraries and frameworks:
React: Integrating Cesium with React
ThreeJS: Integrating Cesium with ThreeJS
Page Structure
Including CesiumJS
| |
Developers can also pick and choose their dependency libraries from ThirdParty/Cesium/source/ according to their needs, trimming the JS file size.
HTML Structure
A div is needed as the container for the Cesium Viewer widget:
| |
An app.js file is needed to activate the Cesium Viewer. It’s best to include app.js at the end of the HTML:
| |
Adding CSS Styles
The styles for various widgets in the Cesium viewer need to be imported. Create a new index.css and include it in index.html:
| |
Add the following default Cesium CSS to index.css:
| |
Steps
- Open Source/App.js and delete its contents
- Copy Source/AppSkeleton.js to Source/App.js
- Make sure server.js is in the Cesium root directory and run server.js (npm server.js)
- Enter localhost:8080 in a modern browser (with WebGL support)
If you have any issues:
Recommended code: https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html?src=Hello%20World.html&label=Showcases&gist=113c3467755fc38d9f9bce16a94475fc
Cesium Chinese Website QQ Group: 807482793
Original link: http://cesiumcn.org/topic/144.html | Quick access: http://cesium.coinidea.com/topic/144.html