When building web applications, you have several options and you probably know already, which libraries and build-stack you are going to use. You can find a lot of useful examples at the Sandcastle of the Cesium project. We will demonstrate, how to create a 3D web mapping application based on the cesium-webpack-example
Step 1: Install and run a minimal Cesium application using webpack
Then run the command, which should install all necessary dependencies.
And after all necessary packages are successfully downloaded, you can start the development server, which will make it easy to develop a custom 3D mapping application.
And open the link http://localhost:8080/ in your browser.
A basic example with Cesium data sources will pop up. Now let’s start hacking around this example. The sources are located in the
src/ folder, the file
src/index.js is of main interest:
We will restructure the code, so it uses sources directed to MapTiler cloud services. Let’s start from scratch, and delete all the code, maybe except for the imports.
First, we need to define the TerrainProvider instance.
As the second step, we need to define the ImageProvider - and we will use the URL reference to one of the Maptiler services, in this case, it will be the Outdoor map.
We now have two important data sources: the terrain and the imagery overlay. This can be now plugged into the application. This can be done, using very complex Cesium.Viewer class or much simpler Cesium.Widget class.
Don’t forget to add used classes, which is
CesiumTerrainProvider, UrlTemplateImageryProvider and the
CesiumWidget to the import statement. The node server will reload automatically every time you change the code.
Now we just have to zoom to the desired location (e.g. Alps region), this is done with the help of the Camera object
The full example now looks like this: