Getting cesium-sensors working in 1.1

Hi all,

I am working in Cesium 1.1, and I am currently working on trying to draw a radar’s field of view and search volumes in Cesium. I believe the easiest way to do this is with the cesium-sensors plugin because it has shapes such as a dome already built. I’m having issues getting the plugin working in the viewer, I’ve been trying to follow the instructions on usage from the github page, but when I try to run the viewer the Firefox console gives the error:

“ReferenceError: Cesium is not defined” in CesiumSensors:2556 in the unminified CesiumSensors.js file.

This line refers to “define(‘Cesium/Core/Cartesian3’, function() { return Cesium[“Cartesian3”]; });”, which is in the middle of similar calls. I don’t understand why this is the only one that seems to error, since there are many lines around it that call similar things. Does this have anything to do with the change away from calls in Cesium such as “new Cesium.Viewer()”?

Or does anyone have experience with drawing these radar properties in Cesium and have a better way to go about this?

Thanks,
Chris

Are you using the combined Cesium.js file? The combined CesiumSensors.js file is designed to work with the combined Cesium file, which exports a global Cesium variable.

Alternatively, if you’re using the individual Cesium AMD modules with a loader such as RequireJS, the sensors plugin will work with that too. The Source directory in the sensors plugin also contains individual modules which can be mapped and loaded as normal. The plugin modules have a dependency on the Cesium modules with a Cesium prefix, so you need to add a path mapping pointing ‘Cesium’ to the Cesium Source directory.

I’m not sure exactly what you mean by the combined Cesium.js file. The CesiumSensors file I am calling is under the Build folder in the main cesium-sensors-master folder. I put the call for CesiumSensors.js in the index.html file under the script call to CesiumViewerStartup. Do you mean I should put the call to the Sensors file in the ViewerStartup with the other require.js stuff instead?

I just realized the source folder you were talking about in the last sentence was in the main cesium folder, not the one within the CesiumSensors folder. So do I need to add in a path to the CesiumSensors.js file that points to Cesium.js in the Source?

OK. It sounds like you are trying to modify the CesiumViewer application directly, which is an AMD application. In that case, yes, you’ll need to include the AMD modules for the sensors plugin, modify CesiumViewerStartup.js to add the proper RequireJS configuration to locate the sensor modules, then modify CesiumViewer.js to require in the modules for the sensors that you’d like to use. The sensors plugin also includes an initialize module, which is a function that hooks up CZML processing for sensors in CZML, which you can use if you’re using sensor definitions in CZML.

I tried it out locally and here’s the changes I made. If you want, you can organize things differently, and update the paths accordingly.

  1. copy the contents of the Source folder from the sensors plugin into the Cesium directory Apps/CesiumViewer/Sensors

  2. copy the RequireJS text plugin from the sensors plugin (in the ThirdParty/requirejs-2.1.14 directory) into the Cesium directory Apps/CesiumViewer

3a) Modify the config in CesiumViewerStartup to configure the location of those items.

3b) Because the sensors plugin expects the Cesium modules to be available under a Cesium package prefix, we also need to add mappings so it can find them there. This could be improved in the future by making CesiumViewer use the Cesium prefix on the modules by default. Conceptually, CesiumViewer is an application that builds on top of Cesium, so it really shouldn’t use the Cesium Source directory as its baseUrl.

The result config object I ended up with is:

{

baseUrl : ‘…/…/Source’,

paths : {

CesiumViewer : ‘…/Apps/CesiumViewer’,

domReady : ‘…/ThirdParty/requirejs-2.1.9/domReady’,

text : ‘…/Apps/CesiumViewer/text’,

CesiumSensors : ‘…/Apps/CesiumViewer/Sensors’

},

map : {

‘*’ : {

‘Cesium/Core’ : ‘Core’,

‘Cesium/DataSources’ : ‘DataSources’,

‘Cesium/Renderer’ : ‘Renderer’,

‘Cesium/Scene’ : ‘Scene’

}

}

}

  1. Modify CesiumViewer.js to include the feature(s) from the plugin that you’d like to use. In my case, I added

‘CesiumSensors/initialize’,

to the list of module IDs, and then added a parameter

cesiumSensorsInitialize

to the corresponding location in the parameter list.

Then, inside the function, I can call the initialize function, which installs support for the sensor-related CZML properties.

cesiumSensorsInitialize();

In your case, if you want to use one of the primitive types directly, for example, RectangularPyramidSensorVolume, you could include that module the same way, and then construct an instance and add it to the scene’s primitives as normal.

Thank you so much for the instructions, they worked perfectly! There aren’t any more errors and it can read the czml in the examples from the the Sensors folder. I was wondering you happened to have a simple example of the conicSensors, I’m trying to write one but nothing is ever showing up. I think I’m just missing a property somewhere, but I want to make sure its a syntax thing and not a problem with loading the Sensors into the viewer.