@itwin/core-frontend 4.1.0-dev.73 → 4.1.0-dev.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"MapLayerSources.js","sourceRoot":"","sources":["../../../../src/tile/map/MapLayerSources.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,qBAAqB,EAAE,iBAAiB,EAAE,oBAAoB,EAAgC,qBAAqB,GACpH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAA2B,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAA4B,MAAM,aAAa,CAAC;AAE3F;;GAEG;AACH,MAAM,CAAN,IAAY,oBAkBX;AAlBD,WAAY,oBAAoB;IAC9B,4BAA4B;IAC5B,iEAAK,CAAA;IACL,iEAAiE;IACjE,2FAAkB,CAAA;IAClB,6EAA6E;IAC7E,iFAAa,CAAA;IACb,uDAAuD;IACvD,qFAAe,CAAA;IACf,oEAAoE;IACpE,2EAAU,CAAA;IACV,iEAAiE;IACjE,6EAAW,CAAA;IACX,mDAAmD;IACnD,qGAAuB,CAAA;IACvB;OACG;IACH,2FAAkB,CAAA;AACpB,CAAC,EAlBW,oBAAoB,KAApB,oBAAoB,QAkB/B;AAmBD;;GAEG;AACH,MAAM,OAAO,cAAc;IASzB,YAAoB,QAAQ,GAAG,KAAK,EAAE,IAAY,EAAE,GAAW,EAAE,OAAO,GAAG,KAAK,EAAE,qBAAqB,GAAG,IAAI;QALvG,YAAO,GAAG,KAAK,CAAC;QAMrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,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W,EAAE,CAAC,CAAC,CAAC;QAC9I,OAAO,eAAe,CAAC,SAAS,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,IAAY;QAC1C,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,mCAAmC;QACnC,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrE,eAAe,CAAC,SAAS,CAAC,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;YACxF,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,kBAAkB,KAAK,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MapLayers\r\n */\r\n\r\nimport { compareStrings } from \"@itwin/core-bentley\";\r\nimport {\r\n BackgroundMapProvider, BackgroundMapType, BaseMapLayerSettings, DeprecatedBackgroundMapProps, ImageMapLayerSettings, MapSubLayerProps,\r\n} from \"@itwin/core-common\";\r\nimport { Point2d } from \"@itwin/core-geometry\";\r\nimport { IModelApp } from \"../../IModelApp\";\r\nimport { IModelConnection } from \"../../IModelConnection\";\r\nimport { request, RequestBasicCredentials } from \"../../request/Request\";\r\nimport { ArcGisUtilities, MapCartoRectangle, MapLayerSourceValidation } from \"../internal\";\r\n\r\n/** Values for return codes from [[MapLayerSource.validateSource]]\r\n * @public\r\n */\r\nexport enum MapLayerSourceStatus {\r\n /** Layer source is valid */\r\n Valid,\r\n /** Authorization has failed when accessing this layer source. */\r\n InvalidCredentials,\r\n /** Provided format id could not be resolved in [[MapLayerFormatRegistry]] */\r\n InvalidFormat,\r\n /** The tiling schema of the source is not supported */\r\n InvalidTileTree,\r\n /** Could not not connect to remote server using the provided URL.*/\r\n InvalidUrl,\r\n /** Authorization is required to access this map layer source. */\r\n RequireAuth,\r\n /** Map-layer coordinate system is not supported */\r\n InvalidCoordinateSystem,\r\n /** Format is not compatible with the URL provided.\r\n */\r\n IncompatibleFormat,\r\n}\r\n\r\n/** JSON representation of a map layer source.\r\n * @see [ImageryMapLayerFormatId]($common)\r\n * @public\r\n */\r\ninterface MapLayerSourceProps {\r\n /** Identifies the map layers source. Defaults to 'WMS'. */\r\n formatId?: string;\r\n /** Name */\r\n name: string;\r\n /** URL */\r\n url: string;\r\n /** True to indicate background is transparent. Defaults to 'true'. */\r\n transparentBackground?: boolean;\r\n /** Indicate if this source definition should be used as a base map. Defaults to false. */\r\n baseMap?: boolean;\r\n}\r\n\r\n/** A source for map layers. These may be catalogued for convenient use by users or applications.\r\n * @public\r\n */\r\nexport class MapLayerSource {\r\n public formatId: string;\r\n public name: string;\r\n public url: string;\r\n public baseMap = false;\r\n public transparentBackground?: boolean;\r\n public userName?: string;\r\n public password?: string;\r\n\r\n private constructor(formatId = \"WMS\", name: string, url: string, baseMap = false, transparentBackground = true) {\r\n this.formatId = formatId;\r\n this.name = name;\r\n this.url = url;\r\n this.baseMap = baseMap;\r\n this.transparentBackground = transparentBackground;\r\n }\r\n\r\n public static fromJSON(json: MapLayerSourceProps): MapLayerSource | undefined {\r\n if (json === undefined)\r\n return undefined;\r\n\r\n return new MapLayerSource(json.formatId, json.name, json.url, json.baseMap, json.transparentBackground);\r\n }\r\n\r\n public async validateSource(ignoreCache?: boolean): Promise<MapLayerSourceValidation> {\r\n return IModelApp.mapLayerFormatRegistry.validateSource(this.formatId, this.url, this.userName, this.password, ignoreCache);\r\n }\r\n\r\n /** @internal*/\r\n public static fromBackgroundMapProps(props: DeprecatedBackgroundMapProps) {\r\n const provider = BackgroundMapProvider.fromBackgroundMapProps(props);\r\n const layerSettings = BaseMapLayerSettings.fromProvider(provider);\r\n if (undefined !== layerSettings) {\r\n const source = MapLayerSource.fromJSON(layerSettings);\r\n if (source) {\r\n source.baseMap = true;\r\n return source;\r\n }\r\n }\r\n\r\n return undefined;\r\n }\r\n public toJSON() {\r\n return { url: this.url, name: this.name, formatId: this.formatId, transparentBackground: this.transparentBackground };\r\n }\r\n\r\n public toLayerSettings(subLayers?: MapSubLayerProps[]): ImageMapLayerSettings | undefined {\r\n // When MapLayerSetting is created from a MapLayerSource, sub-layers and credentials need to be set separately.\r\n const layerSettings = ImageMapLayerSettings.fromJSON({ ...this, subLayers });\r\n if (this.userName !== undefined || this.password !== undefined) {\r\n layerSettings?.setCredentials(this.userName, this.password);\r\n }\r\n\r\n return layerSettings;\r\n }\r\n\r\n private getCredentials(): RequestBasicCredentials | undefined {\r\n return this.userName && this.password ? { user: this.userName, password: this.password } : undefined;\r\n }\r\n}\r\n\r\n/** A collection of [[MapLayerSource]] objects.\r\n * @beta\r\n */\r\nexport class MapLayerSources {\r\n private static _instance?: MapLayerSources;\r\n private constructor(private _sources: MapLayerSource[]) { }\r\n\r\n public static getInstance() { return MapLayerSources._instance; }\r\n\r\n public findByName(name: string, baseMap: boolean = false): MapLayerSource | undefined {\r\n const nameTest = name.toLowerCase();\r\n for (const source of this._sources)\r\n if (source.baseMap === baseMap && source.name.toLowerCase().indexOf(nameTest) !== -1)\r\n return source;\r\n\r\n return undefined;\r\n }\r\n public get layers(): MapLayerSource[] {\r\n const layers = new Array<MapLayerSource>();\r\n this._sources.forEach((source) => {\r\n if (!source.baseMap)\r\n layers.push(source);\r\n });\r\n\r\n return layers;\r\n }\r\n public get allSource() { return this._sources; }\r\n public get bases(): MapLayerSource[] {\r\n const layers = new Array<MapLayerSource>();\r\n this._sources.forEach((source) => {\r\n if (source.baseMap)\r\n layers.push(source);\r\n });\r\n\r\n return layers;\r\n }\r\n\r\n private static getBingMapLayerSource(): MapLayerSource[] {\r\n const mapLayerSources: MapLayerSource[] = [];\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"BingProvider\", providerData: { mapType: BackgroundMapType.Street } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"BingProvider\", providerData: { mapType: BackgroundMapType.Aerial } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"BingProvider\", providerData: { mapType: BackgroundMapType.Hybrid } })!);\r\n return mapLayerSources;\r\n }\r\n\r\n private static getMapBoxLayerSource(): MapLayerSource[] {\r\n const mapLayerSources: MapLayerSource[] = [];\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"MapBoxProvider\", providerData: { mapType: BackgroundMapType.Street } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"MapBoxProvider\", providerData: { mapType: BackgroundMapType.Aerial } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"MapBoxProvider\", providerData: { mapType: BackgroundMapType.Hybrid } })!);\r\n return mapLayerSources;\r\n }\r\n\r\n public static async create(iModel?: IModelConnection, queryForPublicSources = false, addMapBoxSources = false): Promise<MapLayerSources> {\r\n if (!queryForPublicSources && MapLayerSources._instance)\r\n return MapLayerSources._instance;\r\n\r\n if (!iModel)\r\n iModel = IModelApp.viewManager.selectedView ? IModelApp.viewManager.selectedView.iModel : undefined;\r\n\r\n let sourceRange = MapCartoRectangle.createMaximum();\r\n if (iModel) {\r\n const projectCenter = iModel.projectExtents.localXYZToWorld(.5, .5, .5)!;\r\n const cartoCenter = iModel.spatialToCartographicFromEcef(projectCenter);\r\n const globeRange = MapCartoRectangle.createMaximum();\r\n const nearDelta = Point2d.create(globeRange.xLength() / 100, globeRange.yLength() / 100);\r\n sourceRange = MapCartoRectangle.fromRadians(cartoCenter.longitude - nearDelta.x, cartoCenter.latitude - nearDelta.y, cartoCenter.longitude + nearDelta.x, cartoCenter.latitude + nearDelta.y);\r\n }\r\n\r\n const sources = new Array<MapLayerSource>();\r\n const urlSet = new Set<string>();\r\n const addSource = ((source: MapLayerSource) => {\r\n if (!urlSet.has(source.url)) {\r\n sources.push(source);\r\n urlSet.add(source.url);\r\n }\r\n });\r\n\r\n this.getBingMapLayerSource().forEach((source) => {\r\n addSource(source);\r\n });\r\n\r\n if (addMapBoxSources) {\r\n this.getMapBoxLayerSource().forEach((source) => {\r\n addSource(source);\r\n });\r\n }\r\n\r\n if (queryForPublicSources) {\r\n const sourcesJson = await request(`${IModelApp.publicPath}assets/MapLayerSources.json`, \"json\");\r\n\r\n for (const sourceJson of sourcesJson) {\r\n const source = MapLayerSource.fromJSON(sourceJson);\r\n if (source)\r\n addSource(source);\r\n }\r\n\r\n (await ArcGisUtilities.getSourcesFromQuery(sourceRange)).forEach((queriedSource) => addSource(queriedSource));\r\n }\r\n\r\n sources.sort((a: MapLayerSource, b: MapLayerSource) => compareStrings(a.name.toLowerCase(), b.name.toLowerCase()));\r\n\r\n const mapLayerSources = new MapLayerSources(sources);\r\n MapLayerSources._instance = mapLayerSources;\r\n\r\n return mapLayerSources;\r\n }\r\n public static async addSourceToMapLayerSources(mapLayerSource?: MapLayerSource): Promise<MapLayerSources | undefined> {\r\n if (!MapLayerSources._instance || !mapLayerSource) {\r\n return undefined;\r\n }\r\n MapLayerSources._instance._sources = MapLayerSources._instance._sources.filter((source) => {\r\n return !(source.name === mapLayerSource.name || source.url === mapLayerSource.url);\r\n });\r\n\r\n MapLayerSources._instance._sources.push(mapLayerSource);\r\n MapLayerSources._instance._sources.sort((a: MapLayerSource, b: MapLayerSource) => compareStrings(a.name.toLowerCase(), b.name.toLowerCase()));\r\n return MapLayerSources._instance;\r\n }\r\n\r\n public static removeLayerByName(name: string): boolean {\r\n if (!MapLayerSources._instance) {\r\n return false;\r\n }\r\n\r\n // For now we only rely on the name\r\n const lengthBeforeRemove = MapLayerSources._instance._sources.length;\r\n MapLayerSources._instance._sources = MapLayerSources._instance._sources.filter((source) => {\r\n return (source.name !== name);\r\n });\r\n return (lengthBeforeRemove !== MapLayerSources._instance._sources.length);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"MapLayerSources.js","sourceRoot":"","sources":["../../../../src/tile/map/MapLayerSources.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,qBAAqB,EAAE,iBAAiB,EAAE,oBAAoB,EAAgC,qBAAqB,GACpH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAA2B,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAA4B,MAAM,aAAa,CAAC;AAE3F;;GAEG;AACH,MAAM,CAAN,IAAY,oBAkBX;AAlBD,WAAY,oBAAoB;IAC9B,4BAA4B;IAC5B,iEAAK,CAAA;IACL,iEAAiE;IACjE,2FAAkB,CAAA;IAClB,6EAA6E;IAC7E,iFAAa,CAAA;IACb,uDAAuD;IACvD,qFAAe,CAAA;IACf,oEAAoE;IACpE,2EAAU,CAAA;IACV,iEAAiE;IACjE,6EAAW,CAAA;IACX,mDAAmD;IACnD,qGAAuB,CAAA;IACvB;OACG;IACH,2FAAkB,CAAA;AACpB,CAAC,EAlBW,oBAAoB,KAApB,oBAAoB,QAkB/B;AAmBD;;GAEG;AACH,MAAM,OAAO,cAAc;IASzB,YAAoB,QAAQ,GAAG,KAAK,EAAE,IAAY,EAAE,GAAW,EAAE,OAAO,GAAG,KAAK,EAAE,qBAAqB,GAAG,IAAI;QALvG,YAAO,GAAG,KAAK,CAAC;QAMrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG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AC;QAC9I,OAAO,eAAe,CAAC,SAAS,CAAC;IACnC,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,IAAY;QAC1C,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QAED,mCAAmC;QACnC,MAAM,kBAAkB,GAAG,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrE,eAAe,CAAC,SAAS,CAAC,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;YACxF,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,kBAAkB,KAAK,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MapLayers\r\n */\r\n\r\nimport { compareStrings } from \"@itwin/core-bentley\";\r\nimport {\r\n BackgroundMapProvider, BackgroundMapType, BaseMapLayerSettings, DeprecatedBackgroundMapProps, ImageMapLayerSettings, MapSubLayerProps,\r\n} from \"@itwin/core-common\";\r\nimport { Point2d } from \"@itwin/core-geometry\";\r\nimport { IModelApp } from \"../../IModelApp\";\r\nimport { IModelConnection } from \"../../IModelConnection\";\r\nimport { request, RequestBasicCredentials } from \"../../request/Request\";\r\nimport { ArcGisUtilities, MapCartoRectangle, MapLayerSourceValidation } from \"../internal\";\r\n\r\n/** Values for return codes from [[MapLayerSource.validateSource]]\r\n * @public\r\n */\r\nexport enum MapLayerSourceStatus {\r\n /** Layer source is valid */\r\n Valid,\r\n /** Authorization has failed when accessing this layer source. */\r\n InvalidCredentials,\r\n /** Provided format id could not be resolved in [[MapLayerFormatRegistry]] */\r\n InvalidFormat,\r\n /** The tiling schema of the source is not supported */\r\n InvalidTileTree,\r\n /** Could not not connect to remote server using the provided URL.*/\r\n InvalidUrl,\r\n /** Authorization is required to access this map layer source. */\r\n RequireAuth,\r\n /** Map-layer coordinate system is not supported */\r\n InvalidCoordinateSystem,\r\n /** Format is not compatible with the URL provided.\r\n */\r\n IncompatibleFormat,\r\n}\r\n\r\n/** JSON representation of a map layer source.\r\n * @see [ImageryMapLayerFormatId]($common)\r\n * @public\r\n */\r\nexport interface MapLayerSourceProps {\r\n /** Identifies the map layers source. Defaults to 'WMS'. */\r\n formatId?: string;\r\n /** Name */\r\n name: string;\r\n /** URL */\r\n url: string;\r\n /** True to indicate background is transparent. Defaults to 'true'. */\r\n transparentBackground?: boolean;\r\n /** Indicate if this source definition should be used as a base map. Defaults to false. */\r\n baseMap?: boolean;\r\n}\r\n\r\n/** A source for map layers. These may be catalogued for convenient use by users or applications.\r\n * @public\r\n */\r\nexport class MapLayerSource {\r\n public formatId: string;\r\n public name: string;\r\n public url: string;\r\n public baseMap = false;\r\n public transparentBackground?: boolean;\r\n public userName?: string;\r\n public password?: string;\r\n\r\n private constructor(formatId = \"WMS\", name: string, url: string, baseMap = false, transparentBackground = true) {\r\n this.formatId = formatId;\r\n this.name = name;\r\n this.url = url;\r\n this.baseMap = baseMap;\r\n this.transparentBackground = transparentBackground;\r\n }\r\n\r\n public static fromJSON(json: MapLayerSourceProps): MapLayerSource | undefined {\r\n if (json === undefined)\r\n return undefined;\r\n\r\n return new MapLayerSource(json.formatId, json.name, json.url, json.baseMap, json.transparentBackground);\r\n }\r\n\r\n public async validateSource(ignoreCache?: boolean): Promise<MapLayerSourceValidation> {\r\n return IModelApp.mapLayerFormatRegistry.validateSource(this.formatId, this.url, this.userName, this.password, ignoreCache);\r\n }\r\n\r\n /** @internal*/\r\n public static fromBackgroundMapProps(props: DeprecatedBackgroundMapProps) {\r\n const provider = BackgroundMapProvider.fromBackgroundMapProps(props);\r\n const layerSettings = BaseMapLayerSettings.fromProvider(provider);\r\n if (undefined !== layerSettings) {\r\n const source = MapLayerSource.fromJSON(layerSettings);\r\n if (source) {\r\n source.baseMap = true;\r\n return source;\r\n }\r\n }\r\n\r\n return undefined;\r\n }\r\n public toJSON() {\r\n return { url: this.url, name: this.name, formatId: this.formatId, transparentBackground: this.transparentBackground };\r\n }\r\n\r\n public toLayerSettings(subLayers?: MapSubLayerProps[]): ImageMapLayerSettings | undefined {\r\n // When MapLayerSetting is created from a MapLayerSource, sub-layers and credentials need to be set separately.\r\n const layerSettings = ImageMapLayerSettings.fromJSON({ ...this, subLayers });\r\n if (this.userName !== undefined || this.password !== undefined) {\r\n layerSettings?.setCredentials(this.userName, this.password);\r\n }\r\n\r\n return layerSettings;\r\n }\r\n\r\n private getCredentials(): RequestBasicCredentials | undefined {\r\n return this.userName && this.password ? { user: this.userName, password: this.password } : undefined;\r\n }\r\n}\r\n\r\n/** A collection of [[MapLayerSource]] objects.\r\n * @beta\r\n */\r\nexport class MapLayerSources {\r\n private static _instance?: MapLayerSources;\r\n private constructor(private _sources: MapLayerSource[]) { }\r\n\r\n public static getInstance() { return MapLayerSources._instance; }\r\n\r\n public findByName(name: string, baseMap: boolean = false): MapLayerSource | undefined {\r\n const nameTest = name.toLowerCase();\r\n for (const source of this._sources)\r\n if (source.baseMap === baseMap && source.name.toLowerCase().indexOf(nameTest) !== -1)\r\n return source;\r\n\r\n return undefined;\r\n }\r\n public get layers(): MapLayerSource[] {\r\n const layers = new Array<MapLayerSource>();\r\n this._sources.forEach((source) => {\r\n if (!source.baseMap)\r\n layers.push(source);\r\n });\r\n\r\n return layers;\r\n }\r\n public get allSource() { return this._sources; }\r\n public get bases(): MapLayerSource[] {\r\n const layers = new Array<MapLayerSource>();\r\n this._sources.forEach((source) => {\r\n if (source.baseMap)\r\n layers.push(source);\r\n });\r\n\r\n return layers;\r\n }\r\n\r\n private static getBingMapLayerSource(): MapLayerSource[] {\r\n const mapLayerSources: MapLayerSource[] = [];\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"BingProvider\", providerData: { mapType: BackgroundMapType.Street } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"BingProvider\", providerData: { mapType: BackgroundMapType.Aerial } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"BingProvider\", providerData: { mapType: BackgroundMapType.Hybrid } })!);\r\n return mapLayerSources;\r\n }\r\n\r\n private static getMapBoxLayerSource(): MapLayerSource[] {\r\n const mapLayerSources: MapLayerSource[] = [];\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"MapBoxProvider\", providerData: { mapType: BackgroundMapType.Street } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"MapBoxProvider\", providerData: { mapType: BackgroundMapType.Aerial } })!);\r\n mapLayerSources.push(MapLayerSource.fromBackgroundMapProps({ providerName: \"MapBoxProvider\", providerData: { mapType: BackgroundMapType.Hybrid } })!);\r\n return mapLayerSources;\r\n }\r\n\r\n public static async create(iModel?: IModelConnection, queryForPublicSources = false, addMapBoxSources = false): Promise<MapLayerSources> {\r\n if (!queryForPublicSources && MapLayerSources._instance)\r\n return MapLayerSources._instance;\r\n\r\n if (!iModel)\r\n iModel = IModelApp.viewManager.selectedView ? IModelApp.viewManager.selectedView.iModel : undefined;\r\n\r\n let sourceRange = MapCartoRectangle.createMaximum();\r\n if (iModel) {\r\n const projectCenter = iModel.projectExtents.localXYZToWorld(.5, .5, .5)!;\r\n const cartoCenter = iModel.spatialToCartographicFromEcef(projectCenter);\r\n const globeRange = MapCartoRectangle.createMaximum();\r\n const nearDelta = Point2d.create(globeRange.xLength() / 100, globeRange.yLength() / 100);\r\n sourceRange = MapCartoRectangle.fromRadians(cartoCenter.longitude - nearDelta.x, cartoCenter.latitude - nearDelta.y, cartoCenter.longitude + nearDelta.x, cartoCenter.latitude + nearDelta.y);\r\n }\r\n\r\n const sources = new Array<MapLayerSource>();\r\n const urlSet = new Set<string>();\r\n const addSource = ((source: MapLayerSource) => {\r\n if (!urlSet.has(source.url)) {\r\n sources.push(source);\r\n urlSet.add(source.url);\r\n }\r\n });\r\n\r\n this.getBingMapLayerSource().forEach((source) => {\r\n addSource(source);\r\n });\r\n\r\n if (addMapBoxSources) {\r\n this.getMapBoxLayerSource().forEach((source) => {\r\n addSource(source);\r\n });\r\n }\r\n\r\n if (queryForPublicSources) {\r\n const sourcesJson = await request(`${IModelApp.publicPath}assets/MapLayerSources.json`, \"json\");\r\n\r\n for (const sourceJson of sourcesJson) {\r\n const source = MapLayerSource.fromJSON(sourceJson);\r\n if (source)\r\n addSource(source);\r\n }\r\n\r\n (await ArcGisUtilities.getSourcesFromQuery(sourceRange)).forEach((queriedSource) => addSource(queriedSource));\r\n }\r\n\r\n sources.sort((a: MapLayerSource, b: MapLayerSource) => compareStrings(a.name.toLowerCase(), b.name.toLowerCase()));\r\n\r\n const mapLayerSources = new MapLayerSources(sources);\r\n MapLayerSources._instance = mapLayerSources;\r\n\r\n return mapLayerSources;\r\n }\r\n public static async addSourceToMapLayerSources(mapLayerSource?: MapLayerSource): Promise<MapLayerSources | undefined> {\r\n if (!MapLayerSources._instance || !mapLayerSource) {\r\n return undefined;\r\n }\r\n MapLayerSources._instance._sources = MapLayerSources._instance._sources.filter((source) => {\r\n return !(source.name === mapLayerSource.name || source.url === mapLayerSource.url);\r\n });\r\n\r\n MapLayerSources._instance._sources.push(mapLayerSource);\r\n MapLayerSources._instance._sources.sort((a: MapLayerSource, b: MapLayerSource) => compareStrings(a.name.toLowerCase(), b.name.toLowerCase()));\r\n return MapLayerSources._instance;\r\n }\r\n\r\n public static removeLayerByName(name: string): boolean {\r\n if (!MapLayerSources._instance) {\r\n return false;\r\n }\r\n\r\n // For now we only rely on the name\r\n const lengthBeforeRemove = MapLayerSources._instance._sources.length;\r\n MapLayerSources._instance._sources = MapLayerSources._instance._sources.filter((source) => {\r\n return (source.name !== name);\r\n });\r\n return (lengthBeforeRemove !== MapLayerSources._instance._sources.length);\r\n }\r\n}\r\n"]}