requirejs load Cesium.js failed.

Hi everyone,

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’);

});

Directory Structure

3DVisualization

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.

Thanks, Scott.

Hi Scott,
I copy all the contents of source directory, then I require viewer.js, it was successfully loaded.

However, when the shader files get loaded, requirejs treats them as .js files instead of .glsl files.

This leads to the errors of “Files Not Found”.

How do I solve this problem?

Thanks again.

Steven.

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.

Hi Scott,

Thank you very much.

This solves the problem. I can load the files now.

Steven