UNPKG

terriajs

Version:

Geospatial data visualization platform.

103 lines 4.19 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, makeObservable, override } from "mobx"; import KmlDataSource from "terriajs-cesium/Source/DataSources/KmlDataSource"; import TerriaError, { networkRequestError } from "../../../Core/TerriaError"; import isDefined from "../../../Core/isDefined"; import CatalogMemberMixin from "../../../ModelMixins/CatalogMemberMixin"; import MappableMixin from "../../../ModelMixins/MappableMixin"; import UrlMixin from "../../../ModelMixins/UrlMixin"; import KmlCatalogItemTraits from "../../../Traits/TraitsClasses/KmlCatalogItemTraits"; import CommonStrata from "../../Definition/CommonStrata"; import CreateModel from "../../Definition/CreateModel"; import proxyCatalogItemUrl from "../proxyCatalogItemUrl"; import CesiumIonMixin from "../../../ModelMixins/CesiumIonMixin"; class KmlCatalogItem extends MappableMixin(UrlMixin(CesiumIonMixin(CatalogMemberMixin(CreateModel(KmlCatalogItemTraits))))) { static type = "kml"; constructor(...args) { super(...args); makeObservable(this); } get type() { return KmlCatalogItem.type; } _dataSource; setFileInput(file) { this.setTrait(CommonStrata.user, "url", URL.createObjectURL(file) + "#" + file.name); } get hasLocalData() { return this.url?.startsWith("blob:") ?? false; } get cacheDuration() { if (isDefined(super.cacheDuration)) { return super.cacheDuration; } return "1d"; } async forceLoadMapItems() { try { let kmlLoadInput = undefined; if (isDefined(this.kmlString)) { const parser = new DOMParser(); kmlLoadInput = parser.parseFromString(this.kmlString, "text/xml"); } else if (isDefined(this.ionResource)) { kmlLoadInput = this.ionResource; } else if (isDefined(this.url)) { kmlLoadInput = proxyCatalogItemUrl(this, this.url); } if (!kmlLoadInput) { throw networkRequestError({ sender: this, title: i18next.t("models.kml.unableToLoadItemTitle"), message: i18next.t("models.kml.unableToLoadItemMessage") }); } this._dataSource = await KmlDataSource.load(kmlLoadInput, { clampToGround: this.clampToGround, sourceUri: this.dataSourceUri ? proxyCatalogItemUrl(this, this.dataSourceUri, "1d") : undefined }); } catch (e) { throw networkRequestError(TerriaError.from(e, { sender: this, title: i18next.t("models.kml.errorLoadingTitle"), message: i18next.t("models.kml.errorLoadingMessage", { appName: this.terria.appName }) })); } } get mapItems() { if (this.isLoadingMapItems || this._dataSource === undefined) { return []; } this._dataSource.show = this.show; return [this._dataSource]; } forceLoadMetadata() { return this.loadIonResource(); } } __decorate([ action ], KmlCatalogItem.prototype, "setFileInput", null); __decorate([ computed ], KmlCatalogItem.prototype, "hasLocalData", null); __decorate([ override ], KmlCatalogItem.prototype, "cacheDuration", null); __decorate([ computed ], KmlCatalogItem.prototype, "mapItems", null); export default KmlCatalogItem; //# sourceMappingURL=KmlCatalogItem.js.map