ol-cesium: Why doesn't ol-cesium import Cesium?

I’m trying to use ol-cesium inside a react app, built with create-react-app. When using ol-cesium, i get the Cesium is not defined error. I see the references to loading Cesium onto the window object, and i’ve tried importing Cesium in the root index.html, with no luck.

I’m trying to load it with:

<script type="text/javascript" src="node_modules/cesium/Build/Cesium/Cesium.js"></script>

I see the network tab load the .js, but its not globally available on the window object. So why doesn’t ol-cesium just import Cesium from cesium/Cesium’`. It seems like that would be a fairly standard way of loading the library (in addition to having a cesium dependency defined in package.json).

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Unfortunately, I can’t get ol-cesium to run with the ol-app either. I have made the following:

mkdir olcesium_test
cd olcesium_test
npx create-ol-app
npm i
npm start

–> ol map is running fine, npm stopped. npm i --save olcs Then extend the main.js file as follows:

import { Map, View } from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
import OLCesium from 'olcs/OLCesium.js';

const map = new Map({
  target: 'map',
  layers: [
    new TileLayer({
      source: new OSM()
    })
  ],
  view: new View({
    center: [0, 0],
    zoom: 2
  })
});

const ol3d = new OLCesium({ map }); // ol2dMap is the ol.Map instance
ol3d.setEnabled(true);

npm start The 2D map can be displayed, but the following message from OLCesium.js (from the NPM package itself) appears:

OLCesium.js:170 Uncaught ReferenceError: Cesium is not defined
    at new OLCesium (OLCesium.js:170)
    at Object.hTXjU.ol (main.js:19)
    at newRequire (index.6b9ca3e8.js:71)
    at index.6b9ca3e8.js:120
    at index.6b9ca3e8.js:143

Are there any further adjustments to be made there, so that ol-cesium is executable within the create-ol-app?

I am using ol-cesium in version 2.13 and have also run additional npm i cesium@1.82, but this also does not change the error message.

@b4l8ter, Your use of ol-cesium is the standard one. Some people use ol-cesium, ol and CesiumJS as “old-fashioned” libs (no ES6 modules at all).

This is historical, “inject_ol_cesium.js” used to load OL, hence its name.