I loaded Cesium.js with requirejs, but when I tried to simply create a viewer (var viewer = new Cesium.Viewer(‘cesiumContainer’);), I got an error of "Uncaught TypeError: Cannot read property ‘Viewer’ of undefined ". I think this means that Cesium.js didn’t successfully load. Please see the code attached:
index.html
TODO supply a title
@import url(js/libs/Cesium/Widgets/widgets.css);
#cesiumContainer {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
margin: 0;
overflow: hidden;
padding: 0;
font-family: sans-serif;
}
body {
padding: 0;
margin: 0;
overflow: hidden;
}
test.js
require([‘libs/Cesium/Cesium’], function(Cesium){
var viewer = new Cesium.Viewer(‘cesiumContainer’);
The combined Cesium.js produced by the build file is designed for standalone use (to be loaded from a script tag), and not with RequireJS. To use RequireJS, you can download the full Cesium zip file (or clone from GitHub and run the build), and copy the contents of the Source directory into your libs/Cesium directory instead. You can then either require in the Cesium module as you are currently, which will in turn load all the Cesium modules, or you can require in each module individually that you want to use, which gives you control over how much code gets loaded by your application.
If you’re copying the Source directory from a clone of the GitHub repository, you’ll need to run the build, which creates .js files from the .glsl files. In the Cesium repository, run
./Tools/apache-ant-1.8.2/bin/ant build
Then you can re-copy the contents of the Source directory.