@hzab/map-combine 0.4.2-alpha.2 → 0.4.2-alpha.3
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.
- package/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/src/amap/AMapEvent.ts +55 -54
- package/src/basic/BasicBusiness.ts +5 -5
- package/src/basic/BasicModel.ts +48 -0
- package/src/basic/MapCombine.ts +4 -0
- package/src/basic/Point.ts +1 -0
- package/src/basic/ReactPopup.tsx +3 -0
- package/src/cesium/CesiumEvent.ts +85 -84
- package/src/cesium/CesiumMap.ts +358 -347
- package/src/cesium/CesiumModel.ts +60 -0
- package/src/cesium/CesiumPoint.ts +1 -0
- package/src/mine/MineEvent.ts +55 -46
- package/src/openlayer/OpenlayerEvent.ts +88 -87
- package/src/utils/turfjs-utils.ts +52 -0
- package/src/utils/types.d.ts +12 -0
package/src/cesium/CesiumMap.ts
CHANGED
|
@@ -1,347 +1,358 @@
|
|
|
1
|
-
import { AMapImageryProvider } from "./cesium-tile-covert";
|
|
2
|
-
|
|
3
|
-
import { MapCombine } from "../basic/MapCombine";
|
|
4
|
-
import { PointOption, Point } from "../basic/Point";
|
|
5
|
-
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
6
|
-
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
7
|
-
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
8
|
-
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
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
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Cesium.Cartesian3.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.viewer.camera.position
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
cartographic.
|
|
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
|
-
// viewer.cesiumWidget.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
map
|
|
147
|
-
|
|
148
|
-
map.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.
|
|
160
|
-
|
|
161
|
-
this.
|
|
162
|
-
this.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return [
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return [
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
1
|
+
import { AMapImageryProvider } from "./cesium-tile-covert";
|
|
2
|
+
|
|
3
|
+
import { MapCombine } from "../basic/MapCombine";
|
|
4
|
+
import { PointOption, Point } from "../basic/Point";
|
|
5
|
+
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
6
|
+
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
7
|
+
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
8
|
+
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
9
|
+
import { type BasicModelOption, type BasicModel } from "../basic/BasicModel";
|
|
10
|
+
|
|
11
|
+
import { bindEvent } from "./CesiumEvent";
|
|
12
|
+
import { drawPoint } from "./CesiumPoint";
|
|
13
|
+
import { drawPolygon } from "./CesiumPolygon";
|
|
14
|
+
import { drawPolyline } from "./CesiumPolyline";
|
|
15
|
+
import { drawTile3D } from "./CesiumTile3D";
|
|
16
|
+
import { CesiumModel } from "./CesiumModel";
|
|
17
|
+
|
|
18
|
+
const $m = 20037508.34278924;
|
|
19
|
+
/**
|
|
20
|
+
* flyToViewer 最小判断半径(米)
|
|
21
|
+
*/
|
|
22
|
+
const MIN_RADIUS = 500;
|
|
23
|
+
/**
|
|
24
|
+
* flyToViewer 最大缩放层级
|
|
25
|
+
*/
|
|
26
|
+
const MAX_ZOOM = 18;
|
|
27
|
+
|
|
28
|
+
export class CesiumMap extends MapCombine {
|
|
29
|
+
viewer: any;
|
|
30
|
+
markers: any;
|
|
31
|
+
option;
|
|
32
|
+
|
|
33
|
+
container: HTMLDivElement;
|
|
34
|
+
|
|
35
|
+
get cursor(): string {
|
|
36
|
+
return this.container.style.cursor;
|
|
37
|
+
}
|
|
38
|
+
set cursor(val: string) {
|
|
39
|
+
this.container.style.cursor = val;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get moveable(): boolean {
|
|
43
|
+
return this.viewer.scene.screenSpaceCameraController.enableRotate;
|
|
44
|
+
}
|
|
45
|
+
set moveable(val: boolean) {
|
|
46
|
+
this.viewer.scene.screenSpaceCameraController.enableRotate = val;
|
|
47
|
+
}
|
|
48
|
+
get center(): number[] {
|
|
49
|
+
const { viewer, container } = this;
|
|
50
|
+
const width = container.offsetWidth;
|
|
51
|
+
const height = container.offsetHeight;
|
|
52
|
+
const position = viewer.scene.camera.pickEllipsoid(
|
|
53
|
+
new Cesium.Cartesian2(width / 2, height / 2),
|
|
54
|
+
viewer.scene.globe.ellipsoid,
|
|
55
|
+
);
|
|
56
|
+
const cartographic = Cesium.Cartographic.fromCartesian(position);
|
|
57
|
+
return [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude)];
|
|
58
|
+
}
|
|
59
|
+
set center(val: number[]) {
|
|
60
|
+
const { viewer, container } = this;
|
|
61
|
+
const width = container.offsetWidth;
|
|
62
|
+
const height = container.offsetHeight;
|
|
63
|
+
const position = viewer.scene.camera.pickEllipsoid(
|
|
64
|
+
new Cesium.Cartesian2(width / 2, height / 2),
|
|
65
|
+
viewer.scene.globe.ellipsoid,
|
|
66
|
+
);
|
|
67
|
+
const target = Cesium.Cartesian3.fromDegrees(...val);
|
|
68
|
+
Cesium.Cartesian3.subtract(target, position, target);
|
|
69
|
+
Cesium.Cartesian3.add(this.viewer.camera.position, target, this.viewer.camera.position);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get zoom(): number {
|
|
73
|
+
const cartographic = Cesium.Cartographic.fromCartesian(this.viewer.camera.position);
|
|
74
|
+
return this.distanceTzoom(cartographic.height);
|
|
75
|
+
}
|
|
76
|
+
set zoom(val: number) {
|
|
77
|
+
const cartographic = Cesium.Cartographic.fromCartesian(this.viewer.camera.position);
|
|
78
|
+
cartographic.height = this.zoomTdistance(val);
|
|
79
|
+
this.viewer.camera.position = Cesium.Cartesian3.fromRadians(
|
|
80
|
+
cartographic.longitude,
|
|
81
|
+
cartographic.latitude,
|
|
82
|
+
cartographic.height,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
fov = 0.9695385667699215;
|
|
87
|
+
distanceTzoom(distance: number) {
|
|
88
|
+
const height = this.container.offsetHeight;
|
|
89
|
+
return Math.log2(($m * height) / (256 * Math.tan(this.fov / 2) * distance));
|
|
90
|
+
}
|
|
91
|
+
zoomTdistance(zoom: number): number {
|
|
92
|
+
const height = this.container.offsetHeight;
|
|
93
|
+
return ($m * height) / (256 * Math.tan(this.fov / 2) * Math.pow(2, zoom));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
constructor(viewer?: any) {
|
|
97
|
+
super();
|
|
98
|
+
this._initParamsEvent(viewer);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
init(opt) {
|
|
102
|
+
this.option = opt;
|
|
103
|
+
const { container, center = [120.2288892, 30.2349677, 0], zoom = 13, url } = opt || {};
|
|
104
|
+
const viewer = new Cesium.Viewer(container, {
|
|
105
|
+
vrButton: false,
|
|
106
|
+
// 检索
|
|
107
|
+
geocoder: false,
|
|
108
|
+
// home
|
|
109
|
+
homeButton: false,
|
|
110
|
+
// 切换3d地图
|
|
111
|
+
sceneModePicker: false,
|
|
112
|
+
// 底图切换按钮
|
|
113
|
+
baseLayerPicker: false,
|
|
114
|
+
// 问号
|
|
115
|
+
navigationHelpButton: false,
|
|
116
|
+
// 动画控制
|
|
117
|
+
animation: false,
|
|
118
|
+
// 版权信息
|
|
119
|
+
creditContainer: document.createElement("div"),
|
|
120
|
+
// 时间轴
|
|
121
|
+
timeline: false,
|
|
122
|
+
// 全屏按钮
|
|
123
|
+
fullscreenButton: false,
|
|
124
|
+
selectionIndicator: false,
|
|
125
|
+
// 打开动画
|
|
126
|
+
shouldAnimate: false,
|
|
127
|
+
infoBox: false,
|
|
128
|
+
// 只进行3d渲染,没有2d,2.5d,提高性能
|
|
129
|
+
scene3DOnly: true,
|
|
130
|
+
// 初始设置一个纯色瓦片,避免报错影响后续瓦片加载
|
|
131
|
+
imageryProvider: new Cesium.SingleTileImageryProvider({
|
|
132
|
+
url: createColorCanvas("#333"),
|
|
133
|
+
rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// viewer.cesiumWidget.creditContainer.remove();
|
|
138
|
+
|
|
139
|
+
// viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
|
140
|
+
|
|
141
|
+
this._initParamsEvent(viewer);
|
|
142
|
+
|
|
143
|
+
// 处理瓦片
|
|
144
|
+
this._createLayer();
|
|
145
|
+
|
|
146
|
+
const map = this;
|
|
147
|
+
const d = Cesium.Cartesian3.fromDegrees(...center);
|
|
148
|
+
map.setView([d.x, d.y, d.z, 6.283185307179586, -1.5691285980481942, 0]);
|
|
149
|
+
map.center = center;
|
|
150
|
+
map.zoom = zoom;
|
|
151
|
+
|
|
152
|
+
return map;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private _initParamsEvent(viewer) {
|
|
156
|
+
if (!viewer) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.viewer = viewer;
|
|
160
|
+
|
|
161
|
+
this.container = viewer?.container;
|
|
162
|
+
this.container.appendChild(this.htmllayer);
|
|
163
|
+
this.cursor = "default";
|
|
164
|
+
this.markers = this.viewer.scene.primitives.add(new Cesium.BillboardCollection());
|
|
165
|
+
|
|
166
|
+
bindEvent(this);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private _createLayer() {
|
|
170
|
+
const { url, subdomains, proj, minZoomLevel, maxZoomLevel } = this.option;
|
|
171
|
+
let layer: any;
|
|
172
|
+
let options = {
|
|
173
|
+
...this.option,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
switch (proj) {
|
|
177
|
+
case "GCJ02->WGS84":
|
|
178
|
+
options = {
|
|
179
|
+
...options,
|
|
180
|
+
crs: "WGS84", // 使用84坐标系,默认为:GCJ02
|
|
181
|
+
};
|
|
182
|
+
layer = this.viewer.imageryLayers.addImageryProvider(new AMapImageryProvider(options));
|
|
183
|
+
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
options = {
|
|
187
|
+
...options,
|
|
188
|
+
tilingScheme: new Cesium.WebMercatorTilingScheme(),
|
|
189
|
+
};
|
|
190
|
+
layer = this.viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider(options));
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
this.viewer.imageryLayers.add(layer);
|
|
195
|
+
|
|
196
|
+
return layer;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
getView() {
|
|
200
|
+
const { camera } = this.viewer;
|
|
201
|
+
return [camera.position.x, camera.position.y, camera.position.z, camera.heading, camera.pitch, camera.roll];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
setView(e: number[]) {
|
|
205
|
+
const { camera } = this.viewer;
|
|
206
|
+
camera.setView({
|
|
207
|
+
destination: new Cesium.Cartesian3(e[0], e[1], e[2]),
|
|
208
|
+
orientation: new Cesium.HeadingPitchRoll(e[3], e[4], e[5]),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
createPoint<K>(option?: Partial<PointOption<K>>): Point<K> {
|
|
213
|
+
const e = new Point(this, option);
|
|
214
|
+
drawPoint(this, e);
|
|
215
|
+
return e;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
createPointAggregation(option?: PointAggregationOption): PointAggregation {
|
|
219
|
+
const e = new PointAggregation(this, option);
|
|
220
|
+
return e;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
|
|
224
|
+
const e = new Polyline(this, option);
|
|
225
|
+
drawPolyline(this, e);
|
|
226
|
+
return e;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K> {
|
|
230
|
+
const e = new Polygon(this, option);
|
|
231
|
+
drawPolygon(this, e);
|
|
232
|
+
return e;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
createTile3D(option?: Partial<Tile3DOption>): Tile3D {
|
|
236
|
+
const e = new Tile3D(this, option);
|
|
237
|
+
drawTile3D(this, e);
|
|
238
|
+
return e;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
createModel(option?: Partial<BasicModelOption> | undefined): BasicModel {
|
|
242
|
+
return new CesiumModel(this, option);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
canvasTgeography(p: number[]): number[] {
|
|
246
|
+
const { viewer } = this;
|
|
247
|
+
const cartesian2 = new Cesium.Cartesian2(...p);
|
|
248
|
+
const ray = viewer.camera.getPickRay(cartesian2);
|
|
249
|
+
const cartesian = viewer.scene.globe.pick(ray, viewer.scene);
|
|
250
|
+
|
|
251
|
+
if (cartesian) {
|
|
252
|
+
const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
|
253
|
+
return [
|
|
254
|
+
Cesium.Math.toDegrees(cartographic.longitude),
|
|
255
|
+
Cesium.Math.toDegrees(cartographic.latitude),
|
|
256
|
+
cartographic.height,
|
|
257
|
+
];
|
|
258
|
+
} else {
|
|
259
|
+
return [0, 0, 0];
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
geographyTcanvas(p: number[]): number[] {
|
|
263
|
+
const res = Cesium.SceneTransforms.wgs84ToWindowCoordinates(this.viewer.scene, Cesium.Cartesian3.fromDegrees(...p));
|
|
264
|
+
if (!res) {
|
|
265
|
+
return [-1, -1];
|
|
266
|
+
}
|
|
267
|
+
return [res.x, res.y];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 所有点位移动至视口,调整位置及层级
|
|
272
|
+
* @param points
|
|
273
|
+
* @param opt
|
|
274
|
+
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
275
|
+
* @param {Array<number> = [0,0,0,0]} opt.minRadius flyToViewer 最小范围(米)
|
|
276
|
+
* @param {Array<number> = [0,0,0,0]} opt.maxZoom flyToViewer 最大缩放层级
|
|
277
|
+
*/
|
|
278
|
+
flyToViewer(
|
|
279
|
+
points,
|
|
280
|
+
opt = {
|
|
281
|
+
avoid: [0, 0, 0, 0],
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* flyToViewer 最小判断半径(米)
|
|
285
|
+
*/
|
|
286
|
+
minRadius: MIN_RADIUS,
|
|
287
|
+
/**
|
|
288
|
+
* flyToViewer 最大缩放层级
|
|
289
|
+
*/
|
|
290
|
+
maxZoom: MAX_ZOOM,
|
|
291
|
+
},
|
|
292
|
+
) {
|
|
293
|
+
if (points?.length === 0) {
|
|
294
|
+
return this.flyTo(points[0], opt);
|
|
295
|
+
}
|
|
296
|
+
// 创建矩形
|
|
297
|
+
const rectangle = Cesium.Rectangle.fromDegrees(
|
|
298
|
+
...this.getBounds(points, { canvas: this.viewer.scene.canvas, ...opt }),
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
// 将经纬度转换为笛卡尔坐标
|
|
302
|
+
const positions = points.map((coord) => {
|
|
303
|
+
return Cesium.Cartesian3.fromDegrees(coord[0], coord[1]);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// 计算所有点位的包围球
|
|
307
|
+
const boundingSphere = Cesium.BoundingSphere.fromPoints(positions);
|
|
308
|
+
|
|
309
|
+
// 计算包围球半径
|
|
310
|
+
const radius = boundingSphere.radius;
|
|
311
|
+
|
|
312
|
+
let destination = rectangle;
|
|
313
|
+
// 点位距离小于指定范围使用固定高度
|
|
314
|
+
if (radius < MIN_RADIUS || (opt?.minRadius && radius < opt.minRadius)) {
|
|
315
|
+
const center = Cesium.Rectangle.center(rectangle);
|
|
316
|
+
destination = Cesium.Cartesian3.fromRadians(
|
|
317
|
+
center.longitude,
|
|
318
|
+
center.latitude,
|
|
319
|
+
this.zoomTdistance(opt?.maxZoom ?? MAX_ZOOM),
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 设置相机视角
|
|
324
|
+
this.viewer.camera.flyTo({
|
|
325
|
+
destination,
|
|
326
|
+
...opt,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 移动点位到中心点
|
|
332
|
+
* @param point
|
|
333
|
+
*/
|
|
334
|
+
flyTo(point, opt = {}) {
|
|
335
|
+
const height = this.zoomTdistance(this.zoom);
|
|
336
|
+
// 取消任何正在进行的飞行,防止排队
|
|
337
|
+
if (this.viewer.camera.cancelFlight) {
|
|
338
|
+
this.viewer.camera.cancelFlight();
|
|
339
|
+
}
|
|
340
|
+
// 设置相机视角
|
|
341
|
+
this.viewer.camera.flyTo({
|
|
342
|
+
destination: Cesium.Cartesian3.fromDegrees(point[0], point[1], height),
|
|
343
|
+
...opt,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function createColorCanvas(color) {
|
|
349
|
+
var width = 1,
|
|
350
|
+
height = 1;
|
|
351
|
+
var canvas = document.createElement("canvas");
|
|
352
|
+
canvas.width = width;
|
|
353
|
+
canvas.height = height;
|
|
354
|
+
var ctx = canvas.getContext("2d");
|
|
355
|
+
ctx.fillStyle = color;
|
|
356
|
+
ctx.fillRect(0, 0, width, height);
|
|
357
|
+
return canvas.toDataURL();
|
|
358
|
+
}
|