[CesiumJS]Cesium Getting Started 3 – Cesium Directory and Framework Structure

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

1
<script src="ThirdParty/Cesium/Cesium.js"></script>

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:

1
<div id="cesiumContainer"></div>

An app.js file is needed to activate the Cesium Viewer. It’s best to include app.js at the end of the HTML:

1
<script src="Source/App.js"></script>

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:

1
<link rel="stylesheet" href="index.css" media="screen">

Add the following default Cesium CSS to index.css:

1
@import url(ThirdParty/Cesium/Widgets/widgets.css);

Steps

  1. Open Source/App.js and delete its contents
  2. Copy Source/AppSkeleton.js to Source/App.js
  3. Make sure server.js is in the Cesium root directory and run server.js (npm server.js)
  4. Enter localhost:8080 in a modern browser (with WebGL support)

If you have any issues:

Full code: https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html?src=Hello%20World.html&label=Showcases&gist=8d9d3daadd197cffd501d7210bcca3b6

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