@itwin/core-common
Version:
iTwin.js components common to frontend and backend
78 lines • 3.84 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* 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
*/
import { ColorDef } from "./ColorDef";
import { BaseMapLayerSettings, MapLayerSettings } from "./MapLayerSettings";
/** @public */
// eslint-disable-next-line @typescript-eslint/no-redeclare
export var BaseLayerSettings;
(function (BaseLayerSettings) {
/** Create a base layer from its JSON representation. */
function fromJSON(props) {
return typeof props === "number" ? ColorDef.fromJSON(props) : BaseMapLayerSettings.fromJSON(props);
}
BaseLayerSettings.fromJSON = fromJSON;
})(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
*/
export 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.fromJSON(layerProps);
if (layer)
this._backgroundLayers.push(layer);
}
}
if (overlayLayersProps) {
for (const overlayLayerProps of overlayLayersProps) {
const overlayLayer = 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) ? (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 baseLayer = imageryJson?.backgroundBase ? BaseLayerSettings.fromJSON(imageryJson.backgroundBase) : 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;
}
}
//# sourceMappingURL=MapImagerySettings.js.map