-
-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathImageryLayer.ts
130 lines (106 loc) Β· 3.53 KB
/
ImageryLayer.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
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
import { ImageryLayer as CesiumImageryLayer, ImageryProvider } from "cesium";
import {
createCesiumComponent,
PickCesiumProps,
Merge,
ConstructorOptions2,
isPromise,
} from "../core";
/*
@summary
`ImageryLayer` is a imargery layer on the globe.
Layers are added in order of JSX from the top.
```jsx
// Back layer
<ImageryLayer imageryProvider={provider1} />
<ImageryLayer imageryProvider={provider2} />
<ImageryLayer imageryProvider={provider3} />
// Front layer
```
is equivalent to:
```js
viewer.imageryLayers.add(provider1);
viewer.imageryLayers.add(provider2);
viewer.imageryLayers.add(provider3);
```
As a result, the layer added at the very end is the frontmost when actually displayed.
Note: `imageryProvider` property is read only. See also [guide](/guide#cesium-read-only-properties).
*/
/*
@scope
Either:
- Inside [Viewer](/components/Viewer) or [CesiumWidget](/components/CesiumWidget) component: the imargery layer will be attached to the ImageryLayerCollection of the Viewer or CesiumWidget.
- Inside [ImageryLayerCollection](/components/ImageryLayerCollection) component: same as above
*/
export type Target = Merge<CesiumImageryLayer, ConstructorOptions2<typeof CesiumImageryLayer>> & {
index?: number;
};
export type ImageryLayerCesiumProps = PickCesiumProps<Target, typeof cesiumProps>;
export type ImageryLayerCesiumReadonlyProps = Omit<
PickCesiumProps<Target, typeof cesiumReadonlyProps>,
"imageryProvider"
> & {
imageryProvider: ImageryProvider | Promise<ImageryProvider>;
};
export type ImageryLayerProps = ImageryLayerCesiumProps & ImageryLayerCesiumReadonlyProps;
const cesiumProps = [
"alpha",
"brightness",
"contrast",
"hue",
"saturation",
"gamma",
"splitDirection",
"minificationFilter",
"magnificationFilter",
"cutoutRectangle",
"show",
"nightAlpha",
"dayAlpha",
"colorToAlpha",
"colorToAlphaThreshold",
"index",
] as const;
const cesiumReadonlyProps = [
"rectangle",
"maximumAnisotropy",
"minimumTerrainLevel",
"maximumTerrainLevel",
"readyEvent",
"imageryProvider",
] as const;
const ImageryLayer = createCesiumComponent<CesiumImageryLayer, ImageryLayerProps>({
name: "ImageryLayer",
async create(context, props) {
if (!context.imageryLayerCollection) return;
const imageryProvider = isPromise(props.imageryProvider)
? props.imageryProvider
: new Promise<ImageryProvider>(r => queueMicrotask(() => r(props.imageryProvider)));
const imageryLayerWaitingList = context.__$internal?.imageryLayerWaitingList?.slice();
context.__$internal?.imageryLayerWaitingList
? context.__$internal.imageryLayerWaitingList.push(imageryProvider)
: undefined;
// Make sure keeping the order of imagery layer to specify the index correctly.
if (imageryLayerWaitingList) {
await Promise.all(imageryLayerWaitingList.filter(v => isPromise(v)));
}
const result: ImageryProvider = await imageryProvider;
// Remove the awaited result from the waiting list.
if (context.__$internal?.imageryLayerWaitingList) {
const index = context.__$internal.imageryLayerWaitingList.indexOf(imageryProvider);
context.__$internal.imageryLayerWaitingList.splice(index, 1);
}
if (!result) return;
const element = new CesiumImageryLayer(result, props);
context.imageryLayerCollection.add(element, props.index);
return element;
},
destroy(element, context) {
if (context.imageryLayerCollection) {
context.imageryLayerCollection.remove(element);
}
},
cesiumProps,
cesiumReadonlyProps,
});
export default ImageryLayer;