Could anyone provide a working example of using SystemJS (not Webpack) with Angular2 (in TypeScript, not Dart) and Cesium (npm)?
I came across a blog post on cesiumjs' site that discusses this:
The author mentioned, "You can't simply do a require('cesium')
." However, the article focuses on the Webpack way which I don't have access to.
I am encountering this error in the browser:
Error: (SystemJS) AMD module http://localhost:3000/node_modules/cesium/Build/CesiumUnminified/Cesium.js did not define
This is what my systemjs.config.js
file looks like:
paths: {'npm:' : 'node_modules/'},
map: {
app: 'dist',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
...
'require': 'npm:requirejs/require.js',
'cesium': 'npm:cesium/Build/CesiumUnminified/Cesium.js',
...
}
Example of using @Injectable()
:
let Cesium = require('cesium');
import { Injectable } from '@angular/core';
@Injectable()
export class CesiumClock {
private _start:any = Cesium.JulianDate.now();
private _stop:any = Cesium.JulianDate.addHours(this._start,12,new Cesium.JulianDate());
private _clock:any = new Cesium.Clock({
startTime: this._start,
stopTime: this._stop,
currentTime: this._start,
clockRange: Cesium.ClockRange.LOOP_STOP,
mutliplier: 1,
shouldAnimate: true
});
}
And here's the client code that attempts to use my 'CesiumClock', resulting in an error in the browser after transpiling:
import { Component } from '@angular/core';
import { CesiumClock } from '../services/index';
@Component({
moduleId: module.id.replace("/dist", "/app"),
templateUrl: 'stuff.component.html',
styleUrls: [
'stuff.css',
'node_modules/cesium/Build/Cesium/Widgets/widgets.css'
]
})
export class StuffComponent {
constructor(private _cesiumClock:CesiumClock) {}
}
UPDATE:
Thanks to @artem
's input, I managed to resolve the specific 'Error: (SystemJS) AMD' issue in the browser. However, now when trying to utilize anything related to Cesium, such as new Cesium.Viewer(...)
, the Cesium
object appears empty leading to the error
Cesium.Viewer is not a constructor