-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathInitSource.ts
More file actions
153 lines (137 loc) · 4.17 KB
/
InitSource.ts
File metadata and controls
153 lines (137 loc) · 4.17 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { JsonObject } from "../Core/Json";
import Result from "../Core/Result";
import { TerriaErrorSeverity } from "../Core/TerriaError";
import { ProviderCoordsMap } from "../Map/PickedFeatures/PickedFeatures";
import { BaseMapsJson } from "./BaseMaps/BaseMapsModel";
import IElementConfig from "./IElementConfig";
export interface InitSourcePickedFeatures {
providerCoords?: ProviderCoordsMap;
pickCoords?: {
lat: number;
lng: number;
height: number;
};
current?: {
name?: string;
hash?: number;
};
entities?: {
name?: string;
hash?: number;
}[];
}
export type ViewModeJson = "3d" | "3dSmooth" | "2d";
/** Provides loose type hints for ModelJson */
export interface ModelJson extends JsonObject {
localId?: string;
name?: string;
id?: string;
type?: string;
shareKeys?: string[];
members?: (string | JsonObject)[];
}
export interface StoryData {
title: string;
text: string;
id: string;
shareData: ShareInitSourceData;
}
export interface ShareInitSourceData {
version: string;
/** Share data initSources can be a mix of initUrls (string) and initData (InitDataSource/JsonObject) */
initSources: (InitSourceData | string)[];
}
export interface InitSourceData {
stratum?: string;
corsDomains?: string[];
parameters?: {
brandBarElements?: string[];
brandBarSmallElements?: string[];
displayOneBrand?: number;
};
catalog?: JsonObject[];
elements?: Map<string, IElementConfig>;
stories?: StoryData[];
viewerMode?: ViewModeJson;
baseMaps?: BaseMapsJson;
homeCamera?: JsonObject;
/* Either a `CameraView` instance or a flag for focusing the camera on the workbench items */
initialCamera?: JsonObject | { focusWorkbenchItems: boolean };
showSplitter?: boolean;
splitPosition?: number;
workbench?: string[];
timeline?: string[];
models?: { [key: string]: ModelJson };
previewedItemId?: string;
pickedFeatures?: InitSourcePickedFeatures;
/** These settings will override localStorage persistent settings. They are used for shares/stories */
settings?: {
baseMaximumScreenSpaceError?: number;
useNativeResolution?: boolean;
alwaysShowTimeline?: boolean;
/** This is used to save basemap for shares/stories. Please use `InitSource.baseMaps.defaultBaseMapId` instead. */
baseMapId?: string;
terrainSplitDirection?: number;
depthTestAgainstTerrainEnabled?: boolean;
/** Check or uncheck "Share/Print -> Advanced options -> Shorten the share URL using a web service".
* See https://github.com/TerriaJS/terriajs/discussions/6848#discussioncomment-6798623 for a typical use case.
* To disable the shortening url service, set it to false.
*/
shortenShareUrls?: boolean;
};
}
/**
* An absolute or relative URL.
*/
interface InitSourceFromUrl extends InitSourceBase {
initUrl: string;
}
export interface InitSourceFromData extends InitSourceBase {
data: InitSourceData;
}
interface InitSourceFromDataPromise extends InitSourceBase {
data: Promise<Result<InitSourceFromData | undefined>>;
}
interface InitSourceFromOptions extends InitSourceBase {
options: InitSource[];
}
interface InitSourceBase {
/** Name is only used for debugging purposes */
name?: string;
/** Severity to use for errors caught while loading/applying this initSource */
errorSeverity?: TerriaErrorSeverity;
}
export type InitSource =
| InitSourceFromUrl
| InitSourceFromData
| InitSourceFromOptions
| InitSourceFromDataPromise;
export function isInitFromUrl(
initSource: InitSource
): initSource is InitSourceFromUrl {
return "initUrl" in initSource;
}
export function isInitFromData(
initSource: InitSource
): initSource is InitSourceFromData {
return (
initSource &&
"data" in initSource &&
Object.prototype.toString.call(initSource.data) !== "[object Promise]"
);
}
export function isInitFromDataPromise(
initSource: any
): initSource is InitSourceFromDataPromise {
return (
initSource &&
"data" in initSource &&
Object.prototype.toString.call(initSource.data) === "[object Promise]"
);
}
export function isInitFromOptions(
initSource: InitSource
): initSource is InitSourceFromOptions {
return "options" in initSource;
}
export default InitSource;