angular-cesium-ivy
Version:
Angular library for working with Angular-Cesium.
1,083 lines (1,069 loc) • 860 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('geodesy'), require('rxjs/operators'), require('rxjs'), require('primitive-primitives'), require('angular2parse'), require('json-string-mapper'), require('lodash.get')) :
typeof define === 'function' && define.amd ? define('angular-cesium-ivy', ['exports', '@angular/core', '@angular/common', 'geodesy', 'rxjs/operators', 'rxjs', 'primitive-primitives', 'angular2parse', 'json-string-mapper', 'lodash.get'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["angular-cesium-ivy"] = {}, global.ng.core, global.ng.common, global.geodesy, global.rxjs.operators, global.rxjs, global.primitivePrimitives, global.i1, global.jsonStringMapper, global._get));
})(this, (function (exports, i0, i3, geodesy, operators, rxjs, primitivePrimitives, i1, jsonStringMapper, _get) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
var geodesy__namespace = /*#__PURE__*/_interopNamespace(geodesy);
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
var _get__namespace = /*#__PURE__*/_interopNamespace(_get);
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.ɵfac = function ViewerFactory_Factory(t) { return new (t || ViewerFactory)(); };
ViewerFactory.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: ViewerFactory, factory: ViewerFactory.ɵfac });
(function () {
(typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ViewerFactory, [{
type: i0.Injectable
}], function () { return []; }, null);
})();
/**
* 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.ɵfac = function ViewerConfiguration_Factory(t) { return new (t || ViewerConfiguration)(); };
ViewerConfiguration.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: ViewerConfiguration, factory: ViewerConfiguration.ɵfac });
(function () {
(typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ViewerConfiguration, [{
type: i0.Injectable
}], null, null);
})();
/**
* 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.ɵfac = function CesiumService_Factory(t) { return new (t || CesiumService)(i0__namespace.ɵɵinject(i0__namespace.NgZone), i0__namespace.ɵɵinject(ViewerFactory), i0__namespace.ɵɵinject(ViewerConfiguration, 8)); };
CesiumService.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: CesiumService, factory: CesiumService.ɵfac });
(function () {
(typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(CesiumService, [{
type: i0.Injectable
}], function () {
return [{ type: i0__namespace.NgZone }, { type: ViewerFactory }, { type: ViewerConfiguration, decorators: [{
type: i0.Optional
}] }];
}, null);
})();
/**
* Cesium scene modes
*/
exports.SceneMode = void 0;
(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.ɵfac = function CameraService_Factory(t) { return new (t || CameraService)(); };
CameraService.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: CameraService, factory: CameraService.ɵfac });
(function () {
(typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(CameraService, [{
type: i0.Injectable
}], function () { return []; }, null);
})();
/**
* Event options for registration on map-event-manager.
*/
exports.CesiumEvent = void 0;
(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()
*/
exports.PickOptions = void 0;
(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 i0.EventEmitter();
this._onOpen = new i0.EventEmitter();
this._onClose = new i0.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.ɵfac = function ContextMenuService_Factory(t) { return new (t || ContextMenuService)(); };
ContextMenuService.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: ContextMenuService, factory: ContextMenuService.ɵfac });
(function () {
(typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(ContextMenuService, [{
type: i0.Injectable
}], null, null);
})();
var LatLonVectors = geodesy__namespace['LatLonVectors']; // doesnt exists on typings
window['geodesy'] = geodesy__namespace;
/**
* 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 geodesy.LatLonEllipsoidal(latitude, longitude).toUtm();
};
CoordinateConverter.prototype.UTMToDegrees = function (zone, hemisphereType, easting, northing) {
return this.geodesyToCesiumObject(new geodesy.Utm(zone, hemisphereType, easting, northing).toLatLonE());
};
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 = firstPoint.bearingTo(secondPoint);
return bearing;
};
/**
* initial bearing between two points
*
* @return bearing in degrees
*/
CoordinateConverter.prototype.bearingToCartesian = function (firstCartesian3, secondCartesian3) {
var firstCart = Cesium.Cartographic.fromCartesian(firstCartesian3);
var secondCart = Cesium.Cartographic.fromCartesian(secondCartesian3);
return this.bearingTo(firstCart, secondCart);
};
return CoordinateConverter;
}());
CoordinateConverter.ɵfac = function CoordinateConverter_Factory(t) { return new (t || CoordinateConverter)(i0__namespace.ɵɵinject(CesiumService, 8)); };
CoordinateConverter.ɵprov = /*@__PURE__*/ i0__namespace.ɵɵdefineInjectable({ token: CoordinateConverter, factory: CoordinateConverter.ɵfac });
(function () {
(typeof ngDevMode === "undefined" || ngDevMode) && i0__namespace.ɵsetClassMetadata(CoordinateConverter, [{
type: i0.Injectable
}], function () {
return [{ type: CesiumService, decorators: [{
type: i0.Optional
}] }];
}, null);
})();
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
function accept(f) { if (f !== void 0 && typeof f !== "function")
throw new TypeError("Function expected"); return f; }
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
var _, done = false;
for (var i = decorators.length - 1; i >= 0; i--) {
var context = {};
for (var p in contextIn)
context[p] = p === "access" ? {} : contextIn[p];
for (var p in contextIn.access)
context.access[p] = contextIn.access[p];
context.addInitializer = function (f) { if (done)
throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
if (kind === "accessor") {
if (result === void 0)
continue;
if (result === null || typeof result !== "object")
throw new TypeError("Object expected");
if (_ = accept(result.get))
descriptor.get = _;
if (_ = accept(result.set))
descriptor.set = _;
if (_ = accept(result.init))
initializers.unshift(_);
}
else if (_ = accept(result)) {
if (kind === "field")
initializers.unshift(_);
else
descriptor[key] = _;
}
}
if (target)
Object.defineProperty(target, contextIn.name, descriptor);
done = true;
}
;
function __runInitializers(thisArg, initializers, value) {
var useValue = arguments.length > 2;
for (var i = 0; i < initializers.length; i++) {
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
}
return useValue ? value : void 0;
}
;
function __propKey(x) {
return typeof x === "symbol" ? x : "".concat(x);
}
;
function __setFunctionName(f, name, prefix) {
if (typeof name === "symbol")
name = name.description ? "[".concat(name.description, "]") : "";
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
}
;
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function () { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var