What is the easiest way to use cesium?

I am interested in using Cesium to create 3D Earth with custom tiles, but following the instructions to โ€œstartโ€ here , it seems that you need to upload a massive 30mb directory and include everything in the project so that it works correctly. It's true? Can I just not turn on Cesium.js and run like that? I don't need 80% of the user interface elements that they include anyway.

At the end of the Getting Started tutorial, they seem to indicate that all you need to run is these bits:

<script src="Cesium/Cesium.js"></script> @import url(Cesium/Widgets/widgets.css); <div id="cesiumContainer"></div> var viewer = new Cesium.CesiumViewer('cesiumContainer'); 

But when I set these bits, I get this error: "define is not defined" and "Cesium is not defined".

What is the easiest way to start cesium?

+7
javascript cesium
source share
1 answer

This tutorial definitely needs to be updated and I will take a note to clear it. (To begin with, there is an error at the bottom, because Cesium.CesiumViewer should only be Cesium.Viewer .) What is said here means a low value of what is included in the zip and what you need / need for the actual development.

  • Applications โ†’ Application Examples.
  • Source -> AMD Modules for Modular Development (requirejs, browsify, etc.), also used by sample applications.
  • Characteristics โ†’ Unit tests.
  • ThirdParty -> Third-party libraries required for the above.
  • Build / Apps โ†’ Built-in and smaller versions of selected applications.
  • Assembly / documentation โ†’ Reference documentation.

This leaves two directories: Build / Cesium and Build / CesiumUnminified , which I will talk about in a minute.

But first, the technically correct answer to your question is to create the lightest cesium-based application, use the AMD modules that we provide. This means that you need to include the source folder during development, and then your build process will create a mini and concatenated version of your deployment application. Using modules ensures that you enable only the cesium functions that you use. This is different from the โ€œtraditionalโ€ web development practice, which includes mini-versions of all your codes and libraries in the correct order using script tags at the bottom of the page. Modules are gaining momentum on a daily basis, and ES6, along with build systems like Babel, is slowly taking over the landscape of web developers. We ourselves use requirejs , but there are many options.

An example of an application built in this way is the example of Cesium Viewer in Build \ Apps \ CesiumViewer (the source is in applications \ CesiumViewer). The entire built-in application (uncompressed) is 8.77 megabytes and provides almost all the functions and capabilities of cesium. 3.65 megabytes are natural images of the Earth that are sent by default and other data files that the application only suppresses on demand if you use a function that launches it. The remaining JavaScript is greatly reduced in size by using gzipping compression on the server. To verify this, run the latest Cage Viewer link and open the network tab in your developer tools. The entire application only sucks out 2.2 megabytes (and this includes the original images downloaded from Bing. Part of the cesium is only about 426 kilobytes. When downloading GeoJSON or KML files, it may take a few extra kilobytes, but not so much.

Since the modular approach requires additional configuration and is still not so common in web development in general, we also supply the Build / Cesium and Build / CesiumUnminified folders. These include fully miniature and concatenated versions of cesium, which suck all the modules into a single file. However, deployment requires more than just the Cesium.js file. These folders are broken here:

  • Build / Assets -> Default images / assets that come with cesium (images / icons / stars / data for ICRF conversions). This data is reset as necessary, depending on how you configure the Cesium application. This is 3.65 megabytes, but touching your application will only touch a few kilobytes (depending on the features that you use). Instead of trying to determine what needs to be deployed to the server, I suggest deploying the entire directory (but, as I said, the client may never get most of it).
  • Build / Workers and Build / ThirdParty -> They contained the combined web workers used by Cesium. This includes code used by images / terrain, tessellation geometry, and zip file processing. He reached out on demand, and even if you did something to demand it all, still under mega-gzipped. These files cannot be included in the main Cesium.js due to the nature of WebWorkers (in our opinion, this is a complexity in the specification).
  • Build / > Widgets -> contains the combined CSS, both in the form of individual widgets, and in the combined file widgets.css. I recommend just turning on widgets.css and making it (4kb gzipped); but if you are really worried about size, you can bring down individual css files. This folder also contains the icons used by various widgets. And again, they are retrieved only from the server, if necessary.

Like their names, both Build/Cesium and Build/CesiumUnminified are almost the same. The main difference is that assembly / cesium has been reduced and significantly less. It is also faster because it has a lot of debugging code removed to improve performance. Our official recommendation is to develop against CesiumUnminified and deploy using cesium. This will simplify development because you will get better error handling and calls if there is a problem in your code.

An example of an application built in this way is the Hello World application. In fact, there is not much difference in size from the built-in Cesium Viewer application that I linked above, but this is because they are essentially the same application built in two different ways.

Thus, this answer turned out to be much longer than I wanted, but Web Development is diverse, and Cesium is trying to do everything possible to support all its different approaches. Cesium itself is also incredibly ambitious, so we had to overcome many obstacles that other projects never face. Is there room for improvement, absolutely, but we are trying to make cesium as light as it can be, delivering the functions that it has. I think that in version 2.0 we will probably take it even more and try to make things more modular.

I hope the answers to your questions and concerns.

+6
source share

All Articles