question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why doesn't ol-cesium import Cesium?

See original GitHub issue

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).

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mholthausencommented, Aug 27, 2021

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.

1reaction
gberaudocommented, May 20, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OL-Cesium - Example doesn't work - GIS Stack Exchange
You have two options, either download the 1.62 Cesium library cesium and import the Cesium.js as in the example or change this:
Read more >
vue.js - Problem with Cesium integration in OpenLayers 5
Ok, I've figured it out. I only needed to add script tag inside an index.html file that points to Cesium build. Example below:...
Read more >
Ol-Cesium | OpenLayers - Cesium integration library
There are several ways to integrate OL-Cesium in your application. In all cases OpenLayers and Cesium are peer-dependencies of OL-Cesium, your application need ......
Read more >
Adding wms layers issue in ol-cesium - CesiumJS
Hi, I am using ol-cesium in visual studio project. I added WMS, Vector, WMTS layers in openlayers map. I can see Vector and...
Read more >
czml import - labels, description - Google Groups
I recently found out about Cesium and love the application so far. ... it doesn't do anything but I'm sure I saw this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found