/
BackgroundMapProvider.ts
95 lines (83 loc) · 3.35 KB
/
BackgroundMapProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module DisplayStyles
*/
import { DeprecatedBackgroundMapProps } from "./BackgroundMapSettings";
/** Enumerates the types of map imagery that can be supplied by a [[BackgroundMapProvider]].
* @public
* @extensions
*/
export enum BackgroundMapType {
Street = 1,
Aerial = 2,
Hybrid = 3,
}
/** Enumerates a set of supported [[BackgroundMapProvider]]s that can provide map imagery.
* @note To access imagery from such a provider, an API key must be supplied via [IModelAppOptions.mapLayerOptions]($frontend).
* @public
* @extensions
*/
export type BackgroundMapProviderName = "BingProvider" | "MapBoxProvider";
/** JSON representation of a [[BackgroundMapProvider]].
* @see [[BaseMapLayerProps.provider]].
* @public
*/
export interface BackgroundMapProviderProps {
/** The name of the provider. Default: "BingProvider" */
name?: BackgroundMapProviderName;
/** The type of imagery to display. Default: Hybrid. */
type?: BackgroundMapType;
}
/** Describes one of a small set of standard, known suppliers of background map imagery as part of a [[BaseMapLayerSettings]].
* @public
*/
export class BackgroundMapProvider {
/** The name of the provider. */
public readonly name: BackgroundMapProviderName;
/** The type of map imagery provided. */
public readonly type: BackgroundMapType;
private constructor(name: BackgroundMapProviderName, type: BackgroundMapType) {
this.name = name;
this.type = type;
}
/** Create a provider from its JSON representation. */
public static fromJSON(props: BackgroundMapProviderProps): BackgroundMapProvider {
const name: BackgroundMapProviderName = props.name === "MapBoxProvider" ? props.name : "BingProvider";
let type;
switch (props.type) {
case BackgroundMapType.Street:
case BackgroundMapType.Aerial:
type = props.type;
break;
default:
type = BackgroundMapType.Hybrid;
break;
}
return new BackgroundMapProvider(name, type);
}
/** Convert this provider to its JSON representation. */
public toJSON(): BackgroundMapProviderProps {
return { name: this.name, type: this.type };
}
/** @internal */
public static fromBackgroundMapProps(props: DeprecatedBackgroundMapProps): BackgroundMapProvider {
// eslint-disable-next-line deprecation/deprecation
return this.fromJSON({ name: props.providerName as BackgroundMapProviderName, type: props.providerData?.mapType });
}
/** Return true if this provider is equivalent to `other`. */
public equals(other: BackgroundMapProvider): boolean {
return this.name === other.name && this.type === other.type;
}
/** Produce a copy of this provider with identical properties except for those explicitly specified by `changedProps`.
* Any properties explicitly set to `undefined` in `changedProps` will be reset to their default values.
*/
public clone(changedProps: BackgroundMapProviderProps): BackgroundMapProvider {
return BackgroundMapProvider.fromJSON({
...this.toJSON(),
...changedProps,
});
}
}