iceye-angular-cesium-fork
Version:
Angular library for working with Cesium.
1,075 lines (1,064 loc) • 707 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('geodesy/mgrs'), require('geodesy/utm'), require('util'), require('rxjs/operators'), require('rxjs'), require('primitive-primitives'), require('json-string-mapper'), require('angular2parse'), require('lodash.get')) :
typeof define === 'function' && define.amd ? define('iceye-angular-cesium-fork', ['exports', '@angular/core', '@angular/common', 'geodesy/mgrs', 'geodesy/utm', 'util', 'rxjs/operators', 'rxjs', 'primitive-primitives', 'json-string-mapper', 'angular2parse', 'lodash.get'], factory) :
(global = global || self, factory(global['iceye-angular-cesium-fork'] = {}, global.ng.core, global.ng.common, global.mgrs, global.utm, global.util, global.rxjs.operators, global.rxjs, global.primitivePrimitives, global.jsonStringMapper, global.angular2parse, global._get));
}(this, (function (exports, core, common, mgrs, utm, util, operators, rxjs, primitivePrimitives, jsonStringMapper, angular2parse, _get) { 'use strict';
var ViewerFactory = /** @class */ (function () {
function ViewerFactory() {
this.cesium = Cesium;
}
/**
* Creates a viewer with default or custom options
* @param mapContainer - container to initialize the viewer on
* @param options - Options to create the viewer with - Optional
*
* @returns new viewer
*/
ViewerFactory.prototype.createViewer = function (mapContainer, options) {
var viewer = null;
if (options) {
viewer = new this.cesium.Viewer(mapContainer, Object.assign({ contextOptions: {
webgl: { preserveDrawingBuffer: true }
} }, options));
}
else {
viewer = new this.cesium.Viewer(mapContainer, {
contextOptions: {
webgl: { preserveDrawingBuffer: true }
},
});
}
return viewer;
};
return ViewerFactory;
}());
ViewerFactory.decorators = [
{ type: core.Injectable }
];
ViewerFactory.ctorParameters = function () { return []; };
/**
* Service for setting cesium viewer map options.
* defaulty angular-cesium doesnt provide this service and viewer is created with default options.
* In order set specific options you must set this service as provider in your component and
* set the wanted options.
* ```typescript
* constructor(viewerConf :ViewerConfiguration ) {
* viewerConf.viewerOptions = { timeline: false };
* }
* ```
* notice this configuration will be for all <ac-maps> in your component.
*/
var ViewerConfiguration = /** @class */ (function () {
function ViewerConfiguration() {
this.nextViewerOptionsIndex = 0;
this.nextViewerModifierIndex = 0;
}
Object.defineProperty(ViewerConfiguration.prototype, "viewerOptions", {
get: function () {
return this._viewerOptions;
},
/**
* Can be used to set initial map viewer options.
* If there is more than one map you can give the function an array of options.
* The map initialized first will be set with the first option object in the options array and so on.
*/
set: function (value) {
this._viewerOptions = value;
},
enumerable: false,
configurable: true
});
ViewerConfiguration.prototype.getNextViewerOptions = function () {
if (this._viewerOptions instanceof Array) {
return this._viewerOptions[this.nextViewerOptionsIndex++];
}
else {
return this._viewerOptions;
}
};
Object.defineProperty(ViewerConfiguration.prototype, "viewerModifier", {
get: function () {
return this._viewerModifier;
},
/**
* Can be used to set map viewer options after the map has been initialized.
* If there is more than one map you can give the function an array of functions.
* The map initialized first will be set with the first option object in the options array and so on.
*/
set: function (value) {
this._viewerModifier = value;
},
enumerable: false,
configurable: true
});
ViewerConfiguration.prototype.getNextViewerModifier = function () {
if (this._viewerModifier instanceof Array) {
return this._viewerModifier[this.nextViewerModifierIndex++];
}
else {
return this._viewerModifier;
}
};
return ViewerConfiguration;
}());
ViewerConfiguration.decorators = [
{ type: core.Injectable }
];
/**
* Service that initialize cesium viewer and expose cesium viewer and scene.
*/
var CesiumService = /** @class */ (function () {
function CesiumService(ngZone, viewerFactory, viewerConfiguration) {
this.ngZone = ngZone;
this.viewerFactory = viewerFactory;
this.viewerConfiguration = viewerConfiguration;
}
CesiumService.prototype.init = function (mapContainer, map) {
var _this = this;
this.map = map;
this.ngZone.runOutsideAngular(function () {
var options = _this.viewerConfiguration ? _this.viewerConfiguration.getNextViewerOptions() : undefined;
_this.cesiumViewer = _this.viewerFactory.createViewer(mapContainer, options);
var viewerModifier = _this.viewerConfiguration && _this.viewerConfiguration.getNextViewerModifier();
if (typeof viewerModifier === 'function') {
viewerModifier(_this.cesiumViewer);
}
});
};
/**
* For more information see https://cesiumjs.org/Cesium/Build/Documentation/Viewer.html?classFilter=viewe
* @returns cesiumViewer
*/
CesiumService.prototype.getViewer = function () {
return this.cesiumViewer;
};
/**
* For more information see https://cesiumjs.org/Cesium/Build/Documentation/Scene.html?classFilter=scene
* @returns cesium scene
*/
CesiumService.prototype.getScene = function () {
return this.cesiumViewer.scene;
};
/**
* For more information see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
* @returns cesium canvas
*/
CesiumService.prototype.getCanvas = function () {
return this.cesiumViewer.canvas;
};
CesiumService.prototype.getMap = function () {
return this.map;
};
return CesiumService;
}());
CesiumService.decorators = [
{ type: core.Injectable }
];
CesiumService.ctorParameters = function () { return [
{ type: core.NgZone },
{ type: ViewerFactory },
{ type: ViewerConfiguration, decorators: [{ type: core.Optional }] }
]; };
/**
* Fix for the constant entity shadowing.
* PR in Cesium repo: https://github.com/AnalyticalGraphicsInc/cesium/pull/5736
*/
// tslint:disable
var AssociativeArray = Cesium.AssociativeArray;
var Color = Cesium.Color;
var ColorGeometryInstanceAttribute = Cesium.ColorGeometryInstanceAttribute;
var defined = Cesium.defined;
var DistanceDisplayCondition = Cesium.DistanceDisplayCondition;
var DistanceDisplayConditionGeometryInstanceAttribute = Cesium.DistanceDisplayConditionGeometryInstanceAttribute;
var ShowGeometryInstanceAttribute = Cesium.ShowGeometryInstanceAttribute;
var Primitive = Cesium.Primitive;
var ShadowMode = Cesium.ShadowMode;
var BoundingSphereState = Cesium.BoundingSphereState;
var ColorMaterialProperty = Cesium.ColorMaterialProperty;
var MaterialProperty = Cesium.MaterialProperty;
var Property = Cesium.Property;
var colorScratch = new Color();
var distanceDisplayConditionScratch = new DistanceDisplayCondition();
var defaultDistanceDisplayCondition = new DistanceDisplayCondition();
function Batch(primitives, translucent, appearanceType, depthFailAppearanceType, depthFailMaterialProperty, closed, shadows) {
this.translucent = translucent;
this.appearanceType = appearanceType;
this.depthFailAppearanceType = depthFailAppearanceType;
this.depthFailMaterialProperty = depthFailMaterialProperty;
this.depthFailMaterial = undefined;
this.closed = closed;
this.shadows = shadows;
this.primitives = primitives;
this.createPrimitive = false;
this.waitingOnCreate = false;
this.primitive = undefined;
this.oldPrimitive = undefined;
this.geometry = new AssociativeArray();
this.updaters = new AssociativeArray();
this.updatersWithAttributes = new AssociativeArray();
this.attributes = new AssociativeArray();
this.subscriptions = new AssociativeArray();
this.showsUpdated = new AssociativeArray();
this.itemsToRemove = [];
this.invalidated = false;
var removeMaterialSubscription;
if (defined(depthFailMaterialProperty)) {
removeMaterialSubscription = depthFailMaterialProperty.definitionChanged.addEventListener(Batch.prototype.onMaterialChanged, this);
}
this.removeMaterialSubscription = removeMaterialSubscription;
}
Batch.prototype.onMaterialChanged = function () {
this.invalidated = true;
};
Batch.prototype.isMaterial = function (updater) {
var material = this.depthFailMaterialProperty;
var updaterMaterial = updater.depthFailMaterialProperty;
if (updaterMaterial === material) {
return true;
}
if (defined(material)) {
return material.equals(updaterMaterial);
}
return false;
};
Batch.prototype.add = function (updater, instance) {
var id = updater.id;
this.createPrimitive = true;
this.geometry.set(id, instance);
this.updaters.set(id, updater);
if (!updater.hasConstantFill || !updater.fillMaterialProperty.isConstant || !Property.isConstant(updater.distanceDisplayConditionProperty)) {
this.updatersWithAttributes.set(id, updater);
}
else {
var that = this;
this.subscriptions.set(id, updater.entity.definitionChanged.addEventListener(function (entity, propertyName, newValue, oldValue) {
if (propertyName === 'isShowing') {
that.showsUpdated.set(updater.id, updater);
}
}));
}
};
Batch.prototype.remove = function (updater) {
var id = updater.id;
this.createPrimitive = this.geometry.remove(id) || this.createPrimitive;
if (this.updaters.remove(id)) {
this.updatersWithAttributes.remove(id);
var unsubscribe = this.subscriptions.get(id);
if (defined(unsubscribe)) {
unsubscribe();
this.subscriptions.remove(id);
}
}
};
Batch.prototype.update = function (time) {
var isUpdated = true;
var removedCount = 0;
var primitive = this.primitive;
var primitives = this.primitives;
var attributes;
var i;
if (this.createPrimitive) {
var geometries = this.geometry.values;
var geometriesLength = geometries.length;
if (geometriesLength > 0) {
if (defined(primitive)) {
if (!defined(this.oldPrimitive)) {
this.oldPrimitive = primitive;
}
else {
primitives.remove(primitive);
}
}
for (i = 0; i < geometriesLength; i++) {
var geometryItem = geometries[i];
var originalAttributes = geometryItem.attributes;
attributes = this.attributes.get(geometryItem.id.id);
if (defined(attributes)) {
if (defined(originalAttributes.show)) {
originalAttributes.show.value = attributes.show;
}
if (defined(originalAttributes.color)) {
originalAttributes.color.value = attributes.color;
}
if (defined(originalAttributes.depthFailColor)) {
originalAttributes.depthFailColor.value = attributes.depthFailColor;
}
}
}
var depthFailAppearance;
if (defined(this.depthFailAppearanceType)) {
if (defined(this.depthFailMaterialProperty)) {
this.depthFailMaterial = MaterialProperty.getValue(time, this.depthFailMaterialProperty, this.depthFailMaterial);
}
depthFailAppearance = new this.depthFailAppearanceType({
material: this.depthFailMaterial,
translucent: this.translucent,
closed: this.closed
});
}
primitive = new Primitive({
show: false,
asynchronous: true,
geometryInstances: geometries,
appearance: new this.appearanceType({
flat: this.shadows === ShadowMode.DISABLED || this.shadows === ShadowMode.CAST_ONLY,
translucent: this.translucent,
closed: this.closed
}),
depthFailAppearance: depthFailAppearance,
shadows: this.shadows
});
primitives.add(primitive);
isUpdated = false;
}
else {
if (defined(primitive)) {
primitives.remove(primitive);
primitive = undefined;
}
var oldPrimitive = this.oldPrimitive;
if (defined(oldPrimitive)) {
primitives.remove(oldPrimitive);
this.oldPrimitive = undefined;
}
}
this.attributes.removeAll();
this.primitive = primitive;
this.createPrimitive = false;
this.waitingOnCreate = true;
}
else if (defined(primitive) && primitive.ready) {
primitive.show = true;
if (defined(this.oldPrimitive)) {
primitives.remove(this.oldPrimitive);
this.oldPrimitive = undefined;
}
if (defined(this.depthFailAppearanceType) && !(this.depthFailMaterialProperty instanceof ColorMaterialProperty)) {
this.depthFailMaterial = MaterialProperty.getValue(time, this.depthFailMaterialProperty, this.depthFailMaterial);
this.primitive.depthFailAppearance.material = this.depthFailMaterial;
}
var updatersWithAttributes = this.updatersWithAttributes.values;
var length = updatersWithAttributes.length;
var waitingOnCreate = this.waitingOnCreate;
for (i = 0; i < length; i++) {
var updater = updatersWithAttributes[i];
var instance = this.geometry.get(updater.id);
attributes = this.attributes.get(instance.id.id);
if (!defined(attributes)) {
attributes = primitive.getGeometryInstanceAttributes(instance.id);
this.attributes.set(instance.id.id, attributes);
}
if (!updater.fillMaterialProperty.isConstant || waitingOnCreate) {
var colorProperty = updater.fillMaterialProperty.color;
var resultColor = Property.getValueOrDefault(colorProperty, time, Color.WHITE, colorScratch);
if (!Color.equals(attributes._lastColor, resultColor)) {
attributes._lastColor = Color.clone(resultColor, attributes._lastColor);
attributes.color = ColorGeometryInstanceAttribute.toValue(resultColor, attributes.color);
if ((this.translucent && attributes.color[3] === 255) || (!this.translucent && attributes.color[3] !== 255)) {
this.itemsToRemove[removedCount++] = updater;
}
}
}
if (defined(this.depthFailAppearanceType) && updater.depthFailMaterialProperty instanceof ColorMaterialProperty && (!updater.depthFailMaterialProperty.isConstant || waitingOnCreate)) {
var depthFailColorProperty = updater.depthFailMaterialProperty.color;
var depthColor = Property.getValueOrDefault(depthFailColorProperty, time, Color.WHITE, colorScratch);
if (!Color.equals(attributes._lastDepthFailColor, depthColor)) {
attributes._lastDepthFailColor = Color.clone(depthColor, attributes._lastDepthFailColor);
attributes.depthFailColor = ColorGeometryInstanceAttribute.toValue(depthColor, attributes.depthFailColor);
}
}
var show = updater.entity.isShowing && (updater.hasConstantFill || updater.isFilled(time));
var currentShow = attributes.show[0] === 1;
if (show !== currentShow) {
attributes.show = ShowGeometryInstanceAttribute.toValue(show, attributes.show);
}
var distanceDisplayConditionProperty = updater.distanceDisplayConditionProperty;
if (!Property.isConstant(distanceDisplayConditionProperty)) {
var distanceDisplayCondition = Property.getValueOrDefault(distanceDisplayConditionProperty, time, defaultDistanceDisplayCondition, distanceDisplayConditionScratch);
if (!DistanceDisplayCondition.equals(distanceDisplayCondition, attributes._lastDistanceDisplayCondition)) {
attributes._lastDistanceDisplayCondition = DistanceDisplayCondition.clone(distanceDisplayCondition, attributes._lastDistanceDisplayCondition);
attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.toValue(distanceDisplayCondition, attributes.distanceDisplayCondition);
}
}
}
this.updateShows(primitive);
this.waitingOnCreate = false;
}
else if (defined(primitive) && !primitive.ready) {
isUpdated = false;
}
this.itemsToRemove.length = removedCount;
return isUpdated;
};
Batch.prototype.updateShows = function (primitive) {
var showsUpdated = this.showsUpdated.values;
var length = showsUpdated.length;
for (var i = 0; i < length; i++) {
var updater = showsUpdated[i];
var instance = this.geometry.get(updater.id);
var attributes = this.attributes.get(instance.id.id);
if (!defined(attributes)) {
attributes = primitive.getGeometryInstanceAttributes(instance.id);
this.attributes.set(instance.id.id, attributes);
}
var show = updater.entity.isShowing;
var currentShow = attributes.show[0] === 1;
if (show !== currentShow) {
attributes.show = ShowGeometryInstanceAttribute.toValue(show, attributes.show);
}
}
this.showsUpdated.removeAll();
};
Batch.prototype.contains = function (updater) {
return this.updaters.contains(updater.id);
};
Batch.prototype.getBoundingSphere = function (updater, result) {
var primitive = this.primitive;
if (!primitive.ready) {
return BoundingSphereState.PENDING;
}
var attributes = primitive.getGeometryInstanceAttributes(updater.entity);
if (!defined(attributes) || !defined(attributes.boundingSphere) || //
(defined(attributes.show) && attributes.show[0] === 0)) {
return BoundingSphereState.FAILED;
}
attributes.boundingSphere.clone(result);
return BoundingSphereState.DONE;
};
Batch.prototype.removeAllPrimitives = function () {
var primitives = this.primitives;
var primitive = this.primitive;
if (defined(primitive)) {
primitives.remove(primitive);
this.primitive = undefined;
this.geometry.removeAll();
this.updaters.removeAll();
}
var oldPrimitive = this.oldPrimitive;
if (defined(oldPrimitive)) {
primitives.remove(oldPrimitive);
this.oldPrimitive = undefined;
}
};
Batch.prototype.destroy = function () {
var primitive = this.primitive;
var primitives = this.primitives;
if (defined(primitive)) {
primitives.remove(primitive);
}
var oldPrimitive = this.oldPrimitive;
if (defined(oldPrimitive)) {
primitives.remove(oldPrimitive);
}
if (defined(this.removeMaterialSubscription)) {
this.removeMaterialSubscription();
}
};
var wasFixed = false;
function fixCesiumEntitiesShadows() {
if (wasFixed) {
return;
}
Cesium.StaticGeometryColorBatch.prototype.add = function (time, updater) {
var items;
var translucent;
var instance = updater.createFillGeometryInstance(time);
if (instance.attributes.color.value[3] === 255) {
items = this._solidItems;
translucent = false;
}
else {
items = this._translucentItems;
translucent = true;
}
var length = items.length;
for (var i = 0; i < length; i++) {
var item = items[i];
if (item.isMaterial(updater)) {
item.add(updater, instance);
return;
}
}
var batch = new Batch(this._primitives, translucent, this._appearanceType, this._depthFailAppearanceType, updater.depthFailMaterialProperty, this._closed, this._shadows);
batch.add(updater, instance);
items.push(batch);
};
wasFixed = true;
}
var ANGULAR_CESIUM_CONFIG = new core.InjectionToken('ANGULAR_CESIUM_CONFIG');
var ConfigurationService = /** @class */ (function () {
function ConfigurationService(config) {
this.config = config;
var fixEntitiesShadows = config ? config.fixEntitiesShadows : true;
if (fixEntitiesShadows !== false) {
fixCesiumEntitiesShadows();
}
}
return ConfigurationService;
}());
ConfigurationService.decorators = [
{ type: core.Injectable }
];
ConfigurationService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [ANGULAR_CESIUM_CONFIG,] }] }
]; };
/**
* Cesium scene modes
*/
(function (SceneMode) {
SceneMode[SceneMode["SCENE3D"] = 0] = "SCENE3D";
SceneMode[SceneMode["COLUMBUS_VIEW"] = 1] = "COLUMBUS_VIEW";
SceneMode[SceneMode["SCENE2D"] = 2] = "SCENE2D";
SceneMode[SceneMode["PERFORMANCE_SCENE2D"] = 3] = "PERFORMANCE_SCENE2D";
})(exports.SceneMode || (exports.SceneMode = {}));
/**
* The service exposes the scene's camera and screenSpaceCameraController
* SceneMode.PERFORMANCE_SCENE2D - is a 3D scene mode that acts like Cesium 2D mode,
* but is more efficient performance wise.
*/
var CameraService = /** @class */ (function () {
function CameraService() {
this.isSceneModePerformance2D = false;
}
CameraService.prototype.init = function (cesiumService) {
this.viewer = cesiumService.getViewer();
this.scene = cesiumService.getScene();
this.screenSpaceCameraController = this.scene.screenSpaceCameraController;
this.camera = this.scene.camera;
this.lastRotate = this.screenSpaceCameraController.enableRotate;
this.lastTilt = this.screenSpaceCameraController.enableTilt;
this.lastLook = this.screenSpaceCameraController.enableLook;
};
CameraService.prototype._listenToSceneModeMorph = function (callback) {
this.morphListenerCancelFn = this.scene.morphStart.addEventListener(callback);
};
CameraService.prototype._revertCameraProperties = function () {
this.isSceneModePerformance2D = false;
this.enableTilt(this.lastTilt);
this.enableRotate(this.lastRotate);
this.enableLook(this.lastLook);
};
/**
* Gets the scene's camera
*/
CameraService.prototype.getCamera = function () {
return this.camera;
};
/**
* Gets the scene's screenSpaceCameraController
*/
CameraService.prototype.getScreenSpaceCameraController = function () {
return this.screenSpaceCameraController;
};
/**
* Gets the minimum zoom value in meters
*/
CameraService.prototype.getMinimumZoom = function () {
return this.screenSpaceCameraController.minimumZoomDistance;
};
/**
* Sets the minimum zoom value in meters
* @param zoom amount
*/
CameraService.prototype.setMinimumZoom = function (amount) {
this.screenSpaceCameraController.minimumZoomDistance = amount;
};
/**
* Gets the maximum zoom value in meters
*/
CameraService.prototype.getMaximumZoom = function () {
return this.screenSpaceCameraController.maximumZoomDistance;
};
/**
* Sets the maximum zoom value in meters
* @param zoom amount
*/
CameraService.prototype.setMaximumZoom = function (amount) {
this.screenSpaceCameraController.maximumZoomDistance = amount;
};
/**
* Sets if the camera is able to tilt
*/
CameraService.prototype.enableTilt = function (tilt) {
this.screenSpaceCameraController.enableTilt = tilt;
};
/**
* Sets if the camera is able to rotate
*/
CameraService.prototype.enableRotate = function (rotate) {
this.screenSpaceCameraController.enableRotate = rotate;
};
/**
* Sets if the camera is able to free-look
*/
CameraService.prototype.enableLook = function (lock) {
this.screenSpaceCameraController.enableLook = lock;
};
/**
* Sets if the camera is able to translate
*/
CameraService.prototype.enableTranslate = function (translate) {
this.screenSpaceCameraController.enableTranslate = translate;
};
/**
* Sets if the camera is able to zoom
*/
CameraService.prototype.enableZoom = function (zoom) {
this.screenSpaceCameraController.enableZoom = zoom;
};
/**
* Sets if the camera receives inputs
*/
CameraService.prototype.enableInputs = function (inputs) {
this.screenSpaceCameraController.enableInputs = inputs;
};
/**
* Sets the map's SceneMode
* @param sceneMode - The SceneMode to morph the scene into.
* @param duration - The duration of scene morph animations, in seconds
*/
CameraService.prototype.setSceneMode = function (sceneMode, duration) {
var _this = this;
switch (sceneMode) {
case exports.SceneMode.SCENE3D: {
if (this.isSceneModePerformance2D) {
this._revertCameraProperties();
}
this.scene.morphTo3D(duration);
break;
}
case exports.SceneMode.COLUMBUS_VIEW: {
if (this.isSceneModePerformance2D) {
this._revertCameraProperties();
}
this.scene.morphToColumbusView(duration);
break;
}
case exports.SceneMode.SCENE2D: {
if (this.isSceneModePerformance2D) {
this._revertCameraProperties();
}
this.scene.morphTo2D(duration);
break;
}
case exports.SceneMode.PERFORMANCE_SCENE2D: {
this.isSceneModePerformance2D = true;
this.lastLook = this.screenSpaceCameraController.enableLook;
this.lastTilt = this.screenSpaceCameraController.enableTilt;
this.lastRotate = this.screenSpaceCameraController.enableRotate;
this.screenSpaceCameraController.enableTilt = false;
this.screenSpaceCameraController.enableRotate = false;
this.screenSpaceCameraController.enableLook = false;
if (this.morphListenerCancelFn) {
this.morphListenerCancelFn();
}
this.scene.morphToColumbusView(duration);
var morphCompleteEventListener_1 = this.scene.morphComplete.addEventListener(function () {
_this.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(0.0, 0.0, Math.min(CameraService.PERFORMANCE_2D_ALTITUDE, _this.getMaximumZoom())),
orientation: {
pitch: Cesium.Math.toRadians(-90)
}
});
morphCompleteEventListener_1();
_this._listenToSceneModeMorph(_this._revertCameraProperties.bind(_this));
});
break;
}
}
};
/**
* Flies the camera to a destination
* API: https://cesiumjs.org/Cesium/Build/Documentation/Camera.html?classFilter=cam#flyTo
*/
CameraService.prototype.cameraFlyTo = function (options) {
return this.camera.flyTo(options);
};
/**
* Flies the camera to a target
* API: https://cesiumjs.org/Cesium/Build/Documentation/Viewer.html?classFilter=viewer#flyTo
* @returns Promise<boolean>
*/
CameraService.prototype.flyTo = function (target, options) {
return this.viewer.flyTo(target, options);
};
/**
* Zooms amount along the camera's view vector.
* API: https://cesiumjs.org/Cesium/Build/Documentation/Camera.html#zoomIn
*/
CameraService.prototype.zoomIn = function (amount) {
return this.camera.zoomIn(amount || this.camera.defaultZoomAmount);
};
/**
* Zooms amount along the opposite direction of the camera's view vector.
* API: https://cesiumjs.org/Cesium/Build/Documentation/Camera.html#zoomOut
*/
CameraService.prototype.zoomOut = function (amount) {
return this.camera.zoomOut(amount || this.camera.defaultZoomAmount);
};
/**
* Zoom the camera to a target
* API: https://cesiumjs.org/Cesium/Build/Documentation/Viewer.html?classFilter=viewer#zoomTo
* @returns Promise<boolean>
*/
CameraService.prototype.zoomTo = function (target, offset) {
return this.viewer.zoomTo(target, offset);
};
/**
* Flies the camera to a destination
* API: https://cesiumjs.org/Cesium/Build/Documentation/Camera.html?classFilter=camera#setView
* @param options viewer options
*/
CameraService.prototype.setView = function (options) {
this.camera.setView(options);
};
/**
* Set camera's rotation
*/
CameraService.prototype.setRotation = function (degreesInRadians) {
this.setView({ orientation: { heading: degreesInRadians } });
};
/**
* Locks or unlocks camera rotation
*/
CameraService.prototype.lockRotation = function (lock) {
this.scene.screenSpaceCameraController.enableRotate = !lock;
};
/**
* Make the camera track a specific entity
* API: https://cesiumjs.org/Cesium/Build/Documentation/Viewer.html?classFilter=viewer#trackedEntity
* @param cesiumEntity - cesium entity( billboard, polygon...) to track
* @param options - track entity options
*/
CameraService.prototype.trackEntity = function (cesiumEntity, options) {
var _this = this;
var flyTo = (options && options.flyTo) || false;
this.viewer.trackedEntity = undefined;
return new Promise(function (resolve) {
if (flyTo) {
var flyToDuration = (options && options.flyToDuration) || 1;
var altitude = (options && options.altitude) || 10000;
// Calc entity flyTo position and wanted altitude
var entPosCar3 = cesiumEntity.position.getValue(Cesium.JulianDate.now());
var entPosCart = Cesium.Cartographic.fromCartesian(entPosCar3);
var zoomAmount_1 = altitude - entPosCart.height;
entPosCart.height = altitude;
var flyToPosition = Cesium.Cartesian3.fromRadians(entPosCart.longitude, entPosCart.latitude, entPosCart.height);
_this.cameraFlyTo({
duration: flyToDuration,
destination: flyToPosition,
complete: function () {
_this.viewer.trackedEntity = cesiumEntity;
setTimeout(function () {
if (zoomAmount_1 > 0) {
_this.camera.zoomOut(zoomAmount_1);
}
else {
_this.camera.zoomIn(zoomAmount_1);
}
}, 0);
resolve();
}
});
}
else {
_this.viewer.trackedEntity = cesiumEntity;
resolve();
}
});
};
CameraService.prototype.untrackEntity = function () {
this.trackEntity();
};
return CameraService;
}());
CameraService.PERFORMANCE_2D_ALTITUDE = 25000000;
CameraService.decorators = [
{ type: core.Injectable }
];
CameraService.ctorParameters = function () { return []; };
/**
* Event options for registration on map-event-manager.
*/
(function (CesiumEvent) {
CesiumEvent[CesiumEvent["MOUSE_MOVE"] = Cesium.ScreenSpaceEventType.MOUSE_MOVE] = "MOUSE_MOVE";
CesiumEvent[CesiumEvent["LEFT_CLICK"] = Cesium.ScreenSpaceEventType.LEFT_CLICK] = "LEFT_CLICK";
CesiumEvent[CesiumEvent["LEFT_DOUBLE_CLICK"] = Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK] = "LEFT_DOUBLE_CLICK";
CesiumEvent[CesiumEvent["LEFT_DOWN"] = Cesium.ScreenSpaceEventType.LEFT_DOWN] = "LEFT_DOWN";
CesiumEvent[CesiumEvent["LEFT_UP"] = Cesium.ScreenSpaceEventType.LEFT_UP] = "LEFT_UP";
CesiumEvent[CesiumEvent["MIDDLE_CLICK"] = Cesium.ScreenSpaceEventType.MIDDLE_CLICK] = "MIDDLE_CLICK";
CesiumEvent[CesiumEvent["MIDDLE_DOUBLE_CLICK"] = Cesium.ScreenSpaceEventType.MIDDLE_DOUBLE_CLICK] = "MIDDLE_DOUBLE_CLICK";
CesiumEvent[CesiumEvent["MIDDLE_DOWN"] = Cesium.ScreenSpaceEventType.MIDDLE_DOWN] = "MIDDLE_DOWN";
CesiumEvent[CesiumEvent["MIDDLE_UP"] = Cesium.ScreenSpaceEventType.MIDDLE_UP] = "MIDDLE_UP";
CesiumEvent[CesiumEvent["PINCH_START"] = Cesium.ScreenSpaceEventType.PINCH_START] = "PINCH_START";
CesiumEvent[CesiumEvent["PINCH_END"] = Cesium.ScreenSpaceEventType.PINCH_END] = "PINCH_END";
CesiumEvent[CesiumEvent["PINCH_MOVE"] = Cesium.ScreenSpaceEventType.PINCH_MOVE] = "PINCH_MOVE";
CesiumEvent[CesiumEvent["RIGHT_CLICK"] = Cesium.ScreenSpaceEventType.RIGHT_CLICK] = "RIGHT_CLICK";
CesiumEvent[CesiumEvent["RIGHT_DOUBLE_CLICK"] = Cesium.ScreenSpaceEventType.RIGHT_DOUBLE_CLICK] = "RIGHT_DOUBLE_CLICK";
CesiumEvent[CesiumEvent["RIGHT_DOWN"] = Cesium.ScreenSpaceEventType.RIGHT_DOWN] = "RIGHT_DOWN";
CesiumEvent[CesiumEvent["RIGHT_UP"] = Cesium.ScreenSpaceEventType.RIGHT_UP] = "RIGHT_UP";
CesiumEvent[CesiumEvent["WHEEL"] = Cesium.ScreenSpaceEventType.WHEEL] = "WHEEL";
CesiumEvent[CesiumEvent["LONG_LEFT_PRESS"] = 110] = "LONG_LEFT_PRESS";
CesiumEvent[CesiumEvent["LONG_RIGHT_PRESS"] = 111] = "LONG_RIGHT_PRESS";
CesiumEvent[CesiumEvent["LONG_MIDDLE_PRESS"] = 112] = "LONG_MIDDLE_PRESS";
CesiumEvent[CesiumEvent["LEFT_CLICK_DRAG"] = 113] = "LEFT_CLICK_DRAG";
CesiumEvent[CesiumEvent["RIGHT_CLICK_DRAG"] = 114] = "RIGHT_CLICK_DRAG";
CesiumEvent[CesiumEvent["MIDDLE_CLICK_DRAG"] = 115] = "MIDDLE_CLICK_DRAG";
})(exports.CesiumEvent || (exports.CesiumEvent = {}));
/**
* NO_PICK, - will not pick entities
* PICK_FIRST - first entity will be picked . use Cesium.scene.pick()
* PICK_ONE - in case a few entities are picked plonter is resolved . use Cesium.scene.drillPick()
* PICK_ALL - all entities are picked. use Cesium.scene.drillPick()
*/
(function (PickOptions) {
PickOptions[PickOptions["NO_PICK"] = 0] = "NO_PICK";
PickOptions[PickOptions["PICK_FIRST"] = 1] = "PICK_FIRST";
PickOptions[PickOptions["PICK_ONE"] = 2] = "PICK_ONE";
PickOptions[PickOptions["PICK_ALL"] = 3] = "PICK_ALL";
})(exports.PickOptions || (exports.PickOptions = {}));
/**
* The Service manages a singleton context menu over the map. It should be initialized with MapEventsManager.
* The Service allows opening and closing of the context menu and passing data to the context menu inner component.
*
* notice, `data` will be injected to your custom menu component into the `data` field in the component.
* __Usage :__
* ```
* ngOnInit() {
* this.clickEvent$ = this.eventsManager.register({ event: CesiumEvent.RIGHT_CLICK, pick: PickOptions.PICK_ONE });
* this.clickEvent$.subscribe(result => {
* if (result.entities) {
* const pickedMarker = result.entities[0];
* this.contextMenuService.open(MapContextmenuComponent, pickedMarker.position, {
* data: {
* myData: data,
* onDelete: () => this.delete(pickedMarker.id)
* }
* });
* }
* });
* }
*
*
* private delete(id) {
* this.mapMenu.close();
* this.detailedSiteService.removeMarker(id);
* }
* ```
*/
var ContextMenuService = /** @class */ (function () {
function ContextMenuService() {
this._showContextMenu = false;
this._contextMenuChangeNotifier = new core.EventEmitter();
this._onOpen = new core.EventEmitter();
this._onClose = new core.EventEmitter();
this._defaultContextMenuOptions = {
closeOnLeftCLick: true,
closeOnLeftClickPriority: 10,
};
}
Object.defineProperty(ContextMenuService.prototype, "contextMenuChangeNotifier", {
get: function () {
return this._contextMenuChangeNotifier;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ContextMenuService.prototype, "showContextMenu", {
get: function () {
return this._showContextMenu;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ContextMenuService.prototype, "options", {
get: function () {
return this._options;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ContextMenuService.prototype, "position", {
get: function () {
return this._position;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ContextMenuService.prototype, "content", {
get: function () {
return this._content;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ContextMenuService.prototype, "onOpen", {
get: function () {
return this._onOpen;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ContextMenuService.prototype, "onClose", {
get: function () {
return this._onClose;
},
enumerable: false,
configurable: true
});
ContextMenuService.prototype.init = function (mapEventsManager) {
this.mapEventsManager = mapEventsManager;
};
ContextMenuService.prototype.open = function (contentComponent, position, options) {
var _this = this;
if (options === void 0) { options = {}; }
this.close();
this._content = contentComponent;
this._position = position;
this._options = Object.assign({}, this._defaultContextMenuOptions, options);
this._showContextMenu = true;
if (this.mapEventsManager && this._options.closeOnLeftCLick) {
this.leftClickRegistration = this.mapEventsManager.register({
event: exports.CesiumEvent.LEFT_CLICK,
pick: exports.PickOptions.NO_PICK,
priority: this._options.closeOnLeftClickPriority,
});
this.leftClickSubscription = this.leftClickRegistration.subscribe(function () {
_this.leftClickSubscription.unsubscribe();
_this.close();
});
}
this._contextMenuChangeNotifier.emit();
this._onOpen.emit();
};
ContextMenuService.prototype.close = function () {
this._content = undefined;
this._position = undefined;
this._options = undefined;
this._showContextMenu = false;
if (this.leftClickRegistration) {
this.leftClickRegistration.dispose();
this.leftClickRegistration = undefined;
}
if (this.leftClickSubscription) {
this.leftClickSubscription.unsubscribe();
this.leftClickSubscription = undefined;
}
this._contextMenuChangeNotifier.emit();
this._onClose.emit();
};
return ContextMenuService;
}());
ContextMenuService.decorators = [
{ type: core.Injectable }
];
var LatLonVectors = window['geodesy']['LatLonVectors']; // doesnt exists on typings
/**
* Given different types of coordinates, we provide you a service converting those types to the most common other types.
* We are using the geodesy implementation of UTM conversion. see: https://github.com/chrisveness/geodesy.
*
* @example
* import { Component, OnInit } from '@angular/core';
* import { CoordinateConverter } from 'angular2-cesium';
*
* @Component({
* selector:'my-component',
* template:'<div>{{showCartographic}}</div>',
* providers:[CoordinateConverter]
* })
* export class MyComponent implements OnInit {
* showCartographic;
*
* constructor(private coordinateConverter:CoordinateConverter){
* }
*
* ngOnInit(){
* this.showCartographic = this.coordinateConverter.degreesToCartographic(5, 5, 5);
* }
* }
*
*/
var CoordinateConverter = /** @class */ (function () {
function CoordinateConverter(cesiumService) {
this.cesiumService = cesiumService;
}
CoordinateConverter.cartesian3ToLatLon = function (cartesian3, ellipsoid) {
var cart = Cesium.Cartographic.fromCartesian(cartesian3, ellipsoid);
return {
lon: Cesium.Math.toDegrees(cart.longitude),
lat: Cesium.Math.toDegrees(cart.latitude),
height: cart.height
};
};
CoordinateConverter.prototype.screenToCartesian3 = function (screenPos, addMapCanvasBoundsToPos) {
if (!this.cesiumService) {
throw new Error('ANGULAR2-CESIUM - Cesium service should be provided in order' +
' to do screen position calculations');
}
else {
var screenPosition = Object.assign({}, screenPos);
if (addMapCanvasBoundsToPos) {
var mapBounds = this.cesiumService.getViewer().canvas.getBoundingClientRect();
screenPosition.x += mapBounds.left;
screenPosition.y += mapBounds.top;
}
var camera = this.cesiumService.getViewer().camera;
return camera.pickEllipsoid(screenPosition);
}
};
CoordinateConverter.prototype.screenToCartographic = function (screenPos, ellipsoid) {
return this.cartesian3ToCartographic(this.screenToCartesian3(screenPos), ellipsoid);
};
CoordinateConverter.prototype.cartesian3ToCartographic = function (cartesian, ellipsoid) {
return Cesium.Cartographic.fromCartesian(cartesian, ellipsoid);
};
CoordinateConverter.prototype.degreesToCartographic = function (longitude, latitude, height) {
return Cesium.Cartographic.fromDegrees(longitude, latitude, height);
};
CoordinateConverter.prototype.radiansToCartographic = function (longitude, latitude, height) {
return Cesium.Cartographic.fromRadians(longitude, latitude, height);
};
CoordinateConverter.prototype.degreesToUTM = function (longitude, latitude) {
return new utm.LatLon(latitude, longitude).toUtm();
};
CoordinateConverter.prototype.UTMToDegrees = function (zone, hemisphereType, easting, northing) {
return this.geodesyToCesiumObject(new mgrs.Utm(zone, hemisphereType, easting, northing).toLatLon());
};
CoordinateConverter.prototype.geodesyToCesiumObject = function (geodesyRadians) {
return {
longitude: geodesyRadians.lon,
latitude: geodesyRadians.lat,
height: geodesyRadians['height'] ? geodesyRadians['height'] : 0
};
};
/**
* middle point between two points
* @param first (latitude,longitude) in radians
* @param second (latitude,longitude) in radians
*/
CoordinateConverter.prototype.midPointToCartesian3 = function (first, second) {
var toDeg = function (rad) { return Cesium.Math.toDegrees(rad); };
var firstPoint = new LatLonVectors(toDeg(first.latitude), toDeg(first.longitude));
var secondPoint = new LatLonVectors(toDeg(second.latitude), toDeg(second.longitude));
var middlePoint = firstPoint.midpointTo(secondPoint);
return Cesium.Cartesian3.fromDegrees(middlePoint.lon, middlePoint.lat);
};
CoordinateConverter.prototype.middlePointByScreen = function (position0, position1) {
var scene = this.cesiumService.getScene();
var screenPosition1 = Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, position0);
var screenPosition2 = Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, position1);
var middleScreenPoint = new Cesium.Cartesian2((screenPosition2.x + screenPosition1.x) / 2.0, (screenPosition2.y + screenPosition1.y) / 2.0);
return scene.pickPosition(middleScreenPoint);
};
/**
* initial bearing between two points
*
* * @return bearing in degrees
* @param first - {latitude,longitude} in radians
* @param second - {latitude,longitude} in radians
*/
CoordinateConverter.prototype.bearingTo = function (first, second) {
var toDeg = function (rad) { return Cesium.Math.toDegrees(rad); };
var firstPoint = new LatLonVectors(toDeg(first.latitude), toDeg(first.longitude));
var secondPoint = new LatLonVectors(toDeg(second.latitude), toDeg(second.longitude));
var bearing = firstP