UNPKG

terriajs

Version:

Geospatial data visualization platform.

174 lines 7.05 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 { computed, makeObservable, observable, runInAction } from "mobx"; import Rectangle from "terriajs-cesium/Source/Core/Rectangle"; import AsyncLoader from "../Core/AsyncLoader"; import Result from "../Core/Result"; import CatalogMemberMixin, { getName } from "./CatalogMemberMixin"; export class ImageryParts { imageryProvider = undefined; alpha = 0.8; clippingRectangle = undefined; show = true; static fromAsync(options) { const result = new ImageryParts({ imageryProvider: undefined, alpha: options.alpha, clippingRectangle: options.clippingRectangle, show: options.show }); options.imageryProviderPromise.then((imageryProvider) => { if (imageryProvider) { runInAction(() => { result.imageryProvider = imageryProvider; }); } }); return result; } constructor(options) { this.imageryProvider = options.imageryProvider; this.alpha = options.alpha ?? 0.8; this.clippingRectangle = options.clippingRectangle; this.show = options.show ?? true; } } __decorate([ observable ], ImageryParts.prototype, "imageryProvider", void 0); // This discriminator only discriminates between ImageryParts and DataSource (function (ImageryParts) { function is(object) { return "imageryProvider" in object; } ImageryParts.is = is; })(ImageryParts || (ImageryParts = {})); export function isPrimitive(mapItem) { return "isDestroyed" in mapItem; } export function isCesium3DTileset(mapItem) { return "allTilesLoaded" in mapItem; } export function isTerrainProvider(mapItem) { return "hasVertexNormals" in mapItem; } export function isDataSource(object) { return "entities" in object; } function MappableMixin(Base) { class MappableMixin extends Base { initialMessageShown = false; constructor(...args) { super(...args); makeObservable(this); } get isMappable() { return true; } get cesiumRectangle() { if (this.rectangle !== undefined && this.rectangle.east !== undefined && this.rectangle.west !== undefined && this.rectangle.north !== undefined && this.rectangle.south !== undefined) { return Rectangle.fromDegrees(this.rectangle.west, this.rectangle.south, this.rectangle.east, this.rectangle.north); } return undefined; } get shouldShowInitialMessage() { if (this.initialMessage !== undefined) { const hasTitle = this.initialMessage.title !== undefined && this.initialMessage.title !== "" && this.initialMessage.title !== null; const hasContent = this.initialMessage.content !== undefined && this.initialMessage.content !== "" && this.initialMessage.content !== null; return (hasTitle || hasContent) && !this.initialMessageShown; } return false; } _mapItemsLoader = new AsyncLoader(this.forceLoadMapItems.bind(this)); get loadMapItemsResult() { return this._mapItemsLoader.result; } /** * Gets a value indicating whether map items are currently loading. */ get isLoadingMapItems() { return this._mapItemsLoader.isLoading; } /** * Loads the map items. It is safe to call this as often as necessary. * This will also call `loadMetadata()`. * If the map items are already loaded or already loading, it will * return the existing promise. * * This returns a Result object, it will contain errors if they occur - they will not be thrown. * To throw errors, use `(await loadMetadata()).throwIfError()` * * {@see AsyncLoader} */ async loadMapItems(force) { try { if (CatalogMemberMixin.isMixedInto(this)) (await this.loadMetadata()).throwIfError(); (await this._mapItemsLoader.load(force)).throwIfError(); } catch (e) { return Result.error(e, { message: `Failed to load \`${getName(this)}\` mapItems`, importance: -1 }); } return Result.none(); } showInitialMessage() { // This function is deliberately not a computed, // this.terria.notificationState.addNotificationToQueue changes state this.initialMessageShown = true; return new Promise((resolve) => { this.terria.notificationState.addNotificationToQueue({ title: this.initialMessage.title ?? i18next.t("notification.title"), width: this.initialMessage.width, height: this.initialMessage.height, confirmText: this.initialMessage.confirmation ? this.initialMessage.confirmText : undefined, message: this.initialMessage.content ?? "", key: "initialMessage:" + this.initialMessage.key, confirmAction: () => resolve(), showAsToast: this.initialMessage.showAsToast, toastVisibleDuration: this.initialMessage.toastVisibleDuration }); // No need to wait for confirmation if the message is a toast if (this.initialMessage.showAsToast) { resolve(); } }); } dispose() { super.dispose(); this._mapItemsLoader.dispose(); } } __decorate([ computed ], MappableMixin.prototype, "cesiumRectangle", null); return MappableMixin; } (function (MappableMixin) { function isMixedInto(model) { return (model && model.isMappable && "forceLoadMapItems" in model && typeof model.forceLoadMapItems === "function"); } MappableMixin.isMixedInto = isMixedInto; })(MappableMixin || (MappableMixin = {})); export default MappableMixin; //# sourceMappingURL=MappableMixin.js.map