UNPKG

terriajs

Version:

Geospatial data visualization platform.

188 lines 7.03 kB
var __decorate = (this && this.__decorate) || function (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; }; import i18next from "i18next"; import { action, computed, observable, toJS, makeObservable } from "mobx"; import JulianDate from "terriajs-cesium/Source/Core/JulianDate"; import CzmlDataSource from "terriajs-cesium/Source/DataSources/CzmlDataSource"; import isDefined from "../../../Core/isDefined"; import TerriaError, { networkRequestError } from "../../../Core/TerriaError"; import AutoRefreshingMixin from "../../../ModelMixins/AutoRefreshingMixin"; import CatalogMemberMixin from "../../../ModelMixins/CatalogMemberMixin"; import MappableMixin from "../../../ModelMixins/MappableMixin"; import UrlMixin from "../../../ModelMixins/UrlMixin"; import CzmlCatalogItemTraits from "../../../Traits/TraitsClasses/CzmlCatalogItemTraits"; import CreateModel from "../../Definition/CreateModel"; import LoadableStratum from "../../Definition/LoadableStratum"; import StratumOrder from "../../Definition/StratumOrder"; import CommonStrata from "../../Definition/CommonStrata"; import proxyCatalogItemUrl from "../proxyCatalogItemUrl"; import CesiumIonMixin from "../../../ModelMixins/CesiumIonMixin"; /** * A loadable stratum for CzmlCatalogItemTraits that derives TimeVaryingTraits * from the CzmlDataSource */ class CzmlTimeVaryingStratum extends LoadableStratum(CzmlCatalogItemTraits) { catalogItem; static stratumName = "czmlLoadableStratum"; constructor(catalogItem) { super(); this.catalogItem = catalogItem; makeObservable(this); } duplicateLoadableStratum(model) { return new CzmlTimeVaryingStratum(model); } get clock() { return this.catalogItem._dataSource?.clock; } get currentTime() { const currentTime = this.clock?.currentTime; return currentTime ? JulianDate.toIso8601(currentTime) : undefined; } get startTime() { const startTime = this.clock?.startTime; return startTime ? JulianDate.toIso8601(startTime) : undefined; } get stopTime() { const stopTime = this.clock?.stopTime; return stopTime ? JulianDate.toIso8601(stopTime) : undefined; } get multiplier() { return this.clock?.multiplier; } } __decorate([ computed ], CzmlTimeVaryingStratum.prototype, "clock", null); __decorate([ computed ], CzmlTimeVaryingStratum.prototype, "currentTime", null); __decorate([ computed ], CzmlTimeVaryingStratum.prototype, "startTime", null); __decorate([ computed ], CzmlTimeVaryingStratum.prototype, "stopTime", null); __decorate([ computed ], CzmlTimeVaryingStratum.prototype, "multiplier", null); StratumOrder.addLoadStratum(CzmlTimeVaryingStratum.stratumName); export default class CzmlCatalogItem extends AutoRefreshingMixin(MappableMixin(UrlMixin(CesiumIonMixin(CatalogMemberMixin(CreateModel(CzmlCatalogItemTraits)))))) { static type = "czml"; constructor(...args) { super(...args); makeObservable(this); } get type() { return CzmlCatalogItem.type; } _dataSource; setFileInput(file) { this.setTrait(CommonStrata.user, "url", URL.createObjectURL(file) + "#" + file.name); } get hasLocalData() { return this.url?.startsWith("blob:") ?? false; } forceLoadMapItems() { const attribution = this.attribution; let loadableData = undefined; if (isDefined(this.czmlData)) { loadableData = toJS(this.czmlData); } else if (isDefined(this.czmlString)) { loadableData = JSON.parse(this.czmlString); } else if (isDefined(this.ionResource)) { loadableData = this.ionResource; } else if (isDefined(this.url)) { loadableData = proxyCatalogItemUrl(this, this.url, this.cacheDuration); } if (loadableData === undefined) { throw new TerriaError({ sender: this, title: i18next.t("models.czml.unableToLoadItemTitle"), message: i18next.t("models.czml.unableToLoadItemMessage") }); } return CzmlDataSource.load(loadableData, { credit: attribution }) .then(action((czmlDataSource) => { this._dataSource = czmlDataSource; this.strata.set(CzmlTimeVaryingStratum.stratumName, new CzmlTimeVaryingStratum(this)); })) .catch((e) => { if (e instanceof TerriaError) { throw e; } else { throw networkRequestError({ sender: this, title: i18next.t("models.czml.errorLoadingTitle"), message: i18next.t("models.czml.errorLoadingMessage") }); } }); } forceLoadMetadata() { return this.loadIonResource(); } get mapItems() { if (this.isLoadingMapItems || this._dataSource === undefined) { return []; } this._dataSource.show = this.show; return [this._dataSource]; } get currentTimeAsJulianDate() { return toJulianDate(this.currentTime); } get startTimeAsJulianDate() { return toJulianDate(this.startTime); } get stopTimeAsJulianDate() { return toJulianDate(this.stopTime); } /** * Reloads CzmlDataSource if the source is a URL * Required for AutoRefreshingMixin */ refreshData() { if (this.url === undefined) return; const url = proxyCatalogItemUrl(this, this.url, this.cacheDuration); this._dataSource?.process(url); } } __decorate([ observable ], CzmlCatalogItem.prototype, "_dataSource", void 0); __decorate([ action ], CzmlCatalogItem.prototype, "setFileInput", null); __decorate([ computed ], CzmlCatalogItem.prototype, "hasLocalData", null); __decorate([ computed ], CzmlCatalogItem.prototype, "mapItems", null); __decorate([ computed({ equals: JulianDate.equals }) ], CzmlCatalogItem.prototype, "currentTimeAsJulianDate", null); __decorate([ computed({ equals: JulianDate.equals }) ], CzmlCatalogItem.prototype, "startTimeAsJulianDate", null); __decorate([ computed({ equals: JulianDate.equals }) ], CzmlCatalogItem.prototype, "stopTimeAsJulianDate", null); function toJulianDate(time) { return time === undefined || time === null ? undefined : JulianDate.fromIso8601(time); } //# sourceMappingURL=CzmlCatalogItem.js.map