angular-cesium
Version:
Angular library for working with Cesium.
1,048 lines (1,010 loc) • 733 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('geodesy'), 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('angular-cesium', ['exports', '@angular/core', '@angular/common', 'geodesy', 'util', 'rxjs/operators', 'rxjs', 'primitive-primitives', 'json-string-mapper', 'angular2parse', 'lodash.get'], factory) :
(global = global || self, factory(global['angular-cesium'] = {}, global.ng.core, global.ng.common, global.geodesy, global.util, global.rxjs.operators, global.rxjs, global.primitivePrimitives, global.jsonStringMapper, global.angular2parse, global._get));
}(this, (function (exports, core, common, geodesy, util, operators, rxjs, primitivePrimitives, jsonStringMapper, angular2parse, _get) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
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 __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 (_) 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 };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = 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;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
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, __assign({ contextOptions: {
webgl: { preserveDrawingBuffer: true }
} }, options));
}
else {
viewer = new this.cesium.Viewer(mapContainer, {
contextOptions: {
webgl: { preserveDrawingBuffer: true }
},
});
}
return viewer;
};
ViewerFactory = __decorate([
core.Injectable(),
__metadata("design:paramtypes", [])
], ViewerFactory);
return ViewerFactory;
}());
/**
* 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: true,
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: true,
configurable: true
});
ViewerConfiguration.prototype.getNextViewerModifier = function () {
if (this._viewerModifier instanceof Array) {
return this._viewerModifier[this.nextViewerModifierIndex++];
}
else {
return this._viewerModifier;
}
};
ViewerConfiguration = __decorate([
core.Injectable()
], ViewerConfiguration);
return ViewerConfiguration;
}());
/**
* 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;
};
CesiumService.ctorParameters = function () { return [
{ type: core.NgZone },
{ type: ViewerFactory },
{ type: ViewerConfiguration, decorators: [{ type: core.Optional }] }
]; };
CesiumService = __decorate([
core.Injectable(),
__param(2, core.Optional()),
__metadata("design:paramtypes", [core.NgZone, ViewerFactory, ViewerConfiguration])
], CesiumService);
return CesiumService;
}());
/**
* 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();
}
}
ConfigurationService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [ANGULAR_CESIUM_CONFIG,] }] }
]; };
ConfigurationService = __decorate([
core.Injectable(),
__param(0, core.Optional()), __param(0, core.Inject(ANGULAR_CESIUM_CONFIG)),
__metadata("design:paramtypes", [Object])
], ConfigurationService);
return ConfigurationService;
}());
/**
* 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_1 = CameraService;
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_1.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();
};
var CameraService_1;
CameraService.PERFORMANCE_2D_ALTITUDE = 25000000;
CameraService = CameraService_1 = __decorate([
core.Injectable(),
__metadata("design:paramtypes", [])
], CameraService);
return CameraService;
}());
/**
* 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"