UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

85 lines 4.2 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module MapLayers */ Object.defineProperty(exports, "__esModule", { value: true }); exports.MapImagerySettings = exports.BaseLayerSettings = void 0; const ColorDef_1 = require("./ColorDef"); const MapLayerSettings_1 = require("./MapLayerSettings"); /** @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare var BaseLayerSettings; (function (BaseLayerSettings) { /** Create a base layer from its JSON representation. */ function fromJSON(props) { return typeof props === "number" ? ColorDef_1.ColorDef.fromJSON(props) : MapLayerSettings_1.BaseMapLayerSettings.fromJSON(props); } BaseLayerSettings.fromJSON = fromJSON; })(BaseLayerSettings || (exports.BaseLayerSettings = BaseLayerSettings = {})); /** Provides access to the map imagery settings (Base and layers). * In earlier versions only a background map was supported as specified by the providerName and mapType members of [[BackgroundMapSettings]] object. * In order to provide backward compatibility the original [[BackgroundMapSettings]] are synchronized with the [[MapImagerySettings]] base layer as long as * the settings are compatible. * @public */ class MapImagerySettings { _backgroundBase; _backgroundLayers = new Array(); _overlayLayers = new Array(); constructor(base, backgroundLayerProps, overlayLayersProps) { this._backgroundBase = base; if (backgroundLayerProps) { for (const layerProps of backgroundLayerProps) { const layer = MapLayerSettings_1.MapLayerSettings.fromJSON(layerProps); if (layer) this._backgroundLayers.push(layer); } } if (overlayLayersProps) { for (const overlayLayerProps of overlayLayersProps) { const overlayLayer = MapLayerSettings_1.MapLayerSettings.fromJSON(overlayLayerProps); if (overlayLayer) this._overlayLayers.push(overlayLayer); } } } /** The settings for the base layer. * @note If changing the base provider it is currently necessary to also update the background map settings. */ get backgroundBase() { return this._backgroundBase; } set backgroundBase(base) { this._backgroundBase = base; } get backgroundLayers() { return this._backgroundLayers; } get overlayLayers() { return this._overlayLayers; } /** Return base transparency as a number between 0 and 1. * @internal */ get baseTransparency() { return (this._backgroundBase instanceof ColorDef_1.ColorDef) ? (this._backgroundBase.getTransparency() / 255) : this._backgroundBase.transparency; } /** Construct from JSON, performing validation and applying default values for undefined fields. */ static fromJSON(imageryJson) { return this.createFromJSON(imageryJson, undefined); } /** @internal */ static createFromJSON(imageryJson, mapProps) { const backgroundBase = imageryJson?.backgroundBase; const baseLayer = undefined !== backgroundBase ? BaseLayerSettings.fromJSON(backgroundBase) : MapLayerSettings_1.BaseMapLayerSettings.fromBackgroundMapProps(mapProps ?? {}); return new MapImagerySettings(baseLayer, imageryJson?.backgroundLayers, imageryJson?.overlayLayers); } toJSON() { const props = { backgroundBase: this._backgroundBase.toJSON() }; if (this._backgroundLayers.length > 0) props.backgroundLayers = this._backgroundLayers.map((layer) => layer.toJSON()); if (this._overlayLayers.length > 0) props.overlayLayers = this._overlayLayers.map((layer) => layer.toJSON()); return props; } } exports.MapImagerySettings = MapImagerySettings; //# sourceMappingURL=MapImagerySettings.js.map