@hzab/map-combine 0.0.1 → 0.1.0
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 +4 -0
- package/package.json +2 -2
- package/src/basic/MapElement.ts +15 -17
- package/src/basic/Tile3D.ts +76 -41
- package/src/cesium/CesiumEvent.ts +18 -29
- package/src/cesium/CesiumMap.ts +148 -53
- package/src/cesium/CesiumTile3D.ts +184 -55
- package/src/cesium/cesium-tile-covert/index.js +48 -0
- package/src/cesium/cesium-tile-covert/modules/index.js +12 -0
- package/src/cesium/cesium-tile-covert/modules/projection/BD09Projection.js +377 -0
- package/src/cesium/cesium-tile-covert/modules/provider/AMapImageryProvider.js +27 -0
- package/src/cesium/cesium-tile-covert/modules/provider/BaiduImageryProvider.js +58 -0
- package/src/cesium/cesium-tile-covert/modules/provider/GeoVisImageryProvider.js +25 -0
- package/src/cesium/cesium-tile-covert/modules/provider/GoogleImageryProvider.js +27 -0
- package/src/cesium/cesium-tile-covert/modules/provider/TdtImageryProvider.js +23 -0
- package/src/cesium/cesium-tile-covert/modules/provider/TencentImageryProvider.js +41 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/BD09TilingScheme.js +100 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/CustomGeographicTilingScheme.js +60 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/CustomMercatorTilingScheme.js +70 -0
- package/src/cesium/cesium-tile-covert/modules/tiling-scheme/GCJ02TilingScheme.js +33 -0
- package/src/cesium/cesium-tile-covert/modules/transform/CoordTransform.js +148 -0
- package/src/utils/index.ts +15 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzab/map-combine",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "地图组件",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"scripts": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"axios": "^1.4.0",
|
|
30
30
|
"eslint": "^8.30.0",
|
|
31
31
|
"less": "^4.1.3",
|
|
32
|
+
"lil-gui": "^0.19.2",
|
|
32
33
|
"mobx": "^6.7.0",
|
|
33
34
|
"mobx-react": "^7.6.0",
|
|
34
35
|
"react": "^17.0.2",
|
|
@@ -41,7 +42,6 @@
|
|
|
41
42
|
"lib": "lib"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
|
-
"@dvgis/cesium-map": "^3.1.0",
|
|
45
45
|
"coordtransform": "^2.1.2",
|
|
46
46
|
"lodash": ">=4.17.21",
|
|
47
47
|
"ol": "^7.4.0",
|
package/src/basic/MapElement.ts
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
import { MapCombine } from "./MapCombine"
|
|
1
|
+
import { MapCombine } from "./MapCombine";
|
|
2
2
|
|
|
3
3
|
export interface MapElementOption {
|
|
4
|
-
name: string
|
|
4
|
+
name: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export abstract class MapElement<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
readonly map: MapCombine
|
|
12
|
-
protected readonly _option: T
|
|
7
|
+
export abstract class MapElement<T extends MapElementOption = MapElementOption> {
|
|
8
|
+
abstract type: string;
|
|
9
|
+
readonly map: MapCombine;
|
|
10
|
+
readonly _option: T;
|
|
13
11
|
get name() {
|
|
14
|
-
return this._option.name
|
|
12
|
+
return this._option.name;
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
constructor(map: MapCombine, option: T) {
|
|
18
|
-
this.map = map
|
|
19
|
-
this._option = option
|
|
16
|
+
this.map = map;
|
|
17
|
+
this._option = option;
|
|
20
18
|
if (map.elements.has(option.name)) {
|
|
21
|
-
throw new Error(`已存在同名元素 ${option.name}`)
|
|
19
|
+
throw new Error(`已存在同名元素 ${option.name}`);
|
|
22
20
|
}
|
|
23
|
-
map.elements.set(option.name, this)
|
|
21
|
+
map.elements.set(option.name, this);
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
destroy() {
|
|
27
|
-
this.map.elements.delete(this.name)
|
|
28
|
-
this._onDestroy()
|
|
25
|
+
this.map.elements.delete(this.name);
|
|
26
|
+
this._onDestroy();
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
protected abstract _onDestroy(): void
|
|
32
|
-
}
|
|
29
|
+
protected abstract _onDestroy(): void;
|
|
30
|
+
}
|
package/src/basic/Tile3D.ts
CHANGED
|
@@ -1,99 +1,134 @@
|
|
|
1
|
-
import Eventful from "zrender/lib/core/Eventful"
|
|
1
|
+
import Eventful from "zrender/lib/core/Eventful";
|
|
2
2
|
|
|
3
|
-
import { MapElement, MapElementOption } from "./MapElement"
|
|
4
|
-
import { MapCombine } from "./MapCombine"
|
|
3
|
+
import { MapElement, MapElementOption } from "./MapElement";
|
|
4
|
+
import { MapCombine } from "./MapCombine";
|
|
5
5
|
|
|
6
6
|
export interface Tile3DOption extends MapElementOption {
|
|
7
|
-
show: boolean
|
|
8
|
-
src: string
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
show: boolean;
|
|
8
|
+
src: string;
|
|
9
|
+
/** 中心点坐标 [lng, lat, height] */
|
|
10
|
+
coordinates?: number[];
|
|
11
|
+
/** 移动 [x, y, z] */
|
|
12
|
+
translates?: number[];
|
|
13
|
+
/** 旋转 [x, y, z] */
|
|
14
|
+
rotates?: number[];
|
|
15
|
+
/** 缩放 [x, y, z] */
|
|
16
|
+
scales?: number[];
|
|
17
|
+
quality: number;
|
|
11
18
|
}
|
|
12
19
|
|
|
13
|
-
export class Tile3D extends MapElement<Tile3DOption>{
|
|
14
|
-
type =
|
|
20
|
+
export class Tile3D extends MapElement<Tile3DOption> {
|
|
21
|
+
type = "Tile3D";
|
|
22
|
+
tileset;
|
|
15
23
|
event = new Eventful<{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}>()
|
|
24
|
+
ready: () => void;
|
|
25
|
+
update: (keys: Set<string>) => void;
|
|
26
|
+
destroy: () => void;
|
|
27
|
+
focus: () => void;
|
|
28
|
+
}>();
|
|
21
29
|
|
|
22
30
|
get show() {
|
|
23
|
-
return this._option.show
|
|
31
|
+
return this._option.show;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
set show(val) {
|
|
27
35
|
if (this._option.show != val) {
|
|
28
|
-
this._option.show = val
|
|
29
|
-
this._update(
|
|
36
|
+
this._option.show = val;
|
|
37
|
+
this._update("show");
|
|
30
38
|
}
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
get src() {
|
|
34
|
-
return this._option.src
|
|
42
|
+
return this._option.src;
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
set src(val) {
|
|
38
46
|
if (this._option.src != val) {
|
|
39
|
-
this._option.src = val
|
|
40
|
-
this._update(
|
|
47
|
+
this._option.src = val;
|
|
48
|
+
this._update("src");
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
get coordinates() {
|
|
45
|
-
return this._option.coordinates
|
|
53
|
+
return this._option.coordinates;
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
set coordinates(val) {
|
|
49
57
|
if (this._option.coordinates != val) {
|
|
50
|
-
this._option.coordinates = val
|
|
51
|
-
this._update(
|
|
58
|
+
this._option.coordinates = val;
|
|
59
|
+
this._update("coordinates");
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
get quality() {
|
|
56
|
-
return this._option.quality
|
|
64
|
+
return this._option.quality;
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
set quality(val) {
|
|
60
68
|
if (this._option.quality != val) {
|
|
61
|
-
this._option.quality = val
|
|
62
|
-
this._update(
|
|
69
|
+
this._option.quality = val;
|
|
70
|
+
this._update("quality");
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
|
|
66
|
-
|
|
67
|
-
|
|
68
74
|
constructor(map: MapCombine, option: Partial<Tile3DOption> = {}) {
|
|
69
|
-
super(map, Object.assign({ ...Tile3D.option }, option))
|
|
75
|
+
super(map, Object.assign({ ...Tile3D.option }, option));
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
static option: Tile3DOption = {
|
|
73
|
-
name:
|
|
79
|
+
name: "3D瓦片",
|
|
74
80
|
show: true,
|
|
75
|
-
src:
|
|
76
|
-
quality: 0.5
|
|
77
|
-
}
|
|
81
|
+
src: "",
|
|
82
|
+
quality: 0.5,
|
|
83
|
+
};
|
|
78
84
|
|
|
79
|
-
private _needUpdate?: Set<string
|
|
85
|
+
private _needUpdate?: Set<string>;
|
|
80
86
|
private _update(key: string) {
|
|
81
87
|
if (this._needUpdate) {
|
|
82
|
-
this._needUpdate.add(key)
|
|
88
|
+
this._needUpdate.add(key);
|
|
83
89
|
} else {
|
|
84
|
-
this._needUpdate = new Set([key])
|
|
90
|
+
this._needUpdate = new Set([key]);
|
|
85
91
|
setTimeout(() => {
|
|
86
|
-
this.event.trigger(
|
|
87
|
-
this._needUpdate = undefined
|
|
92
|
+
this.event.trigger("update", this._needUpdate);
|
|
93
|
+
this._needUpdate = undefined;
|
|
88
94
|
});
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
|
|
98
|
+
/** 基于本地的 ENU 坐标系的偏移,也就是垂直于地表向上为 Z,东为 X,北为 Y
|
|
99
|
+
* @param dx x轴偏移量。单位:米
|
|
100
|
+
* @param dy y轴偏移量。单位:米
|
|
101
|
+
* @param dz z轴偏移量。单位:米
|
|
102
|
+
* @param tileset Cesium3DTileset
|
|
103
|
+
*/
|
|
104
|
+
translate(dx: number, dy: number, dz: number, tileset: any = this.tileset) {
|
|
105
|
+
console.info("TileD translate");
|
|
106
|
+
}
|
|
107
|
+
/** 基于本地的 ENU 坐标系的旋转,也就是垂直于地表向上为 Z,东为 X,北为 Y
|
|
108
|
+
* https://blog.csdn.net/weixin_70945905/article/details/142419968
|
|
109
|
+
* @param rx 绕X轴旋转的角度。单位:度
|
|
110
|
+
* @param ry 绕Y轴旋转的角度。单位:度
|
|
111
|
+
* @param rz 绕Z轴旋转的角度。单位:度
|
|
112
|
+
* @param tileset Cesium3DTileset
|
|
113
|
+
*/
|
|
114
|
+
rotate(rx: number, ry: number, rz: number, tileset = this.tileset) {
|
|
115
|
+
console.info("TileD rotate");
|
|
116
|
+
}
|
|
117
|
+
/** 基于本地的 ENU 坐标系的缩放,也就是垂直于地表向上为 Z,东为 X,北为 Y
|
|
118
|
+
* @param sx x 轴缩放倍数
|
|
119
|
+
* @param sy y 轴缩放倍数
|
|
120
|
+
* @param sz z 轴缩放倍数
|
|
121
|
+
* @param tileset Cesium3DTileset
|
|
122
|
+
*/
|
|
123
|
+
scale(sx: number, sy: number, sz: number, tileset = this.tileset) {
|
|
124
|
+
console.info("TileD scale");
|
|
125
|
+
}
|
|
126
|
+
|
|
92
127
|
protected _onDestroy(): void {
|
|
93
|
-
this.event.trigger(
|
|
128
|
+
this.event.trigger("destroy");
|
|
94
129
|
}
|
|
95
130
|
|
|
96
131
|
focus() {
|
|
97
|
-
this.event.trigger(
|
|
132
|
+
this.event.trigger("focus");
|
|
98
133
|
}
|
|
99
|
-
}
|
|
134
|
+
}
|
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
import { CesiumMap } from "./CesiumMap"
|
|
1
|
+
import { CesiumMap } from "./CesiumMap";
|
|
2
2
|
|
|
3
3
|
export function bindEvent(map: CesiumMap) {
|
|
4
|
-
const { event, viewer, container } = map
|
|
4
|
+
const { event, viewer, container } = map;
|
|
5
5
|
viewer.camera.percentageChanged = 0.0001;
|
|
6
6
|
viewer.camera.changed.addEventListener(() => {
|
|
7
|
-
event.trigger(
|
|
7
|
+
event.trigger("view-change");
|
|
8
8
|
});
|
|
9
9
|
viewer.camera.moveEnd.addEventListener(() => {
|
|
10
|
-
event.trigger(
|
|
10
|
+
event.trigger("view-moveEnd");
|
|
11
11
|
});
|
|
12
12
|
const handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
|
|
13
13
|
let target: any;
|
|
14
14
|
handler.setInputAction((e: any) => {
|
|
15
15
|
event.canvas = [e.endPosition.x, e.endPosition.y];
|
|
16
16
|
event.geography = map.canvasTgeography(event.canvas);
|
|
17
|
-
let _target: any = undefined
|
|
17
|
+
let _target: any = undefined;
|
|
18
18
|
const res = viewer.scene.pick(e.endPosition);
|
|
19
|
-
const a = res
|
|
20
|
-
? res.id
|
|
21
|
-
? res.id
|
|
22
|
-
: res.primitive
|
|
23
|
-
? res.primitive
|
|
24
|
-
: undefined
|
|
25
|
-
: undefined;
|
|
19
|
+
const a = res ? (res.id ? res.id : res.primitive ? res.primitive : undefined) : undefined;
|
|
26
20
|
|
|
27
21
|
if (a && !a.silent) {
|
|
28
22
|
_target = a;
|
|
@@ -38,49 +32,44 @@ export function bindEvent(map: CesiumMap) {
|
|
|
38
32
|
} else {
|
|
39
33
|
map.cursor = "";
|
|
40
34
|
}
|
|
41
|
-
event.trigger(
|
|
35
|
+
event.trigger("pointer-move");
|
|
42
36
|
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
|
|
43
37
|
|
|
44
38
|
handler.setInputAction(() => {
|
|
45
39
|
if (target) {
|
|
46
40
|
target.onPointerDown?.();
|
|
47
41
|
}
|
|
48
|
-
event.trigger(
|
|
42
|
+
event.trigger("pointer-down");
|
|
49
43
|
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
container.addEventListener('pointerup', () => {
|
|
45
|
+
container.addEventListener("pointerup", () => {
|
|
53
46
|
if (target) {
|
|
54
47
|
target.onPointerUp?.();
|
|
55
48
|
}
|
|
56
|
-
event.trigger(
|
|
57
|
-
})
|
|
58
|
-
|
|
49
|
+
event.trigger("pointer-up");
|
|
50
|
+
});
|
|
59
51
|
|
|
60
52
|
handler.setInputAction((e) => {
|
|
61
|
-
console.log('e', e);
|
|
62
|
-
|
|
63
53
|
if (target) {
|
|
64
54
|
target.onLClick?.();
|
|
65
55
|
}
|
|
66
|
-
event.trigger(
|
|
56
|
+
event.trigger("left-click");
|
|
67
57
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
68
58
|
handler.setInputAction(() => {
|
|
69
59
|
if (target) {
|
|
70
60
|
target.onRClick?.();
|
|
71
61
|
}
|
|
72
|
-
event.trigger(
|
|
62
|
+
event.trigger("right-click");
|
|
73
63
|
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
|
|
74
64
|
|
|
75
65
|
handler.setInputAction(() => {
|
|
76
66
|
if (target) {
|
|
77
67
|
target.onDbClick?.();
|
|
78
68
|
}
|
|
79
|
-
event.trigger(
|
|
69
|
+
event.trigger("double-click");
|
|
80
70
|
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
|
81
71
|
|
|
82
|
-
event.on(
|
|
83
|
-
viewer.destroy()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
}
|
|
72
|
+
event.on("destroy", () => {
|
|
73
|
+
viewer.destroy();
|
|
74
|
+
});
|
|
75
|
+
}
|
package/src/cesium/CesiumMap.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { AMapImageryProvider } from "./cesium-tile-covert";
|
|
1
2
|
|
|
2
3
|
import { MapCombine } from "../basic/MapCombine";
|
|
3
4
|
import { PointOption, Point } from "../basic/Point";
|
|
4
5
|
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
5
6
|
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
6
7
|
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
8
|
+
|
|
7
9
|
import { bindEvent } from "./CesiumEvent";
|
|
8
10
|
import { drawPoint } from "./CesiumPoint";
|
|
9
11
|
import { drawPolygon } from "./CesiumPolygon";
|
|
@@ -13,19 +15,17 @@ import { drawTile3D } from "./CesiumTile3D";
|
|
|
13
15
|
const $m = 20037508.34278924;
|
|
14
16
|
|
|
15
17
|
export class CesiumMap extends MapCombine {
|
|
16
|
-
|
|
17
18
|
viewer: any;
|
|
18
19
|
markers: any;
|
|
20
|
+
option;
|
|
19
21
|
|
|
20
22
|
container: HTMLDivElement;
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
24
|
get cursor(): string {
|
|
25
|
-
return
|
|
25
|
+
return this.container.style.cursor;
|
|
26
26
|
}
|
|
27
27
|
set cursor(val: string) {
|
|
28
|
-
|
|
28
|
+
this.container.style.cursor = val;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
get moveable(): boolean {
|
|
@@ -40,13 +40,10 @@ export class CesiumMap extends MapCombine {
|
|
|
40
40
|
const height = container.offsetHeight;
|
|
41
41
|
const position = viewer.scene.camera.pickEllipsoid(
|
|
42
42
|
new Cesium.Cartesian2(width / 2, height / 2),
|
|
43
|
-
viewer.scene.globe.ellipsoid
|
|
43
|
+
viewer.scene.globe.ellipsoid,
|
|
44
44
|
);
|
|
45
45
|
const cartographic = Cesium.Cartographic.fromCartesian(position);
|
|
46
|
-
return [
|
|
47
|
-
Cesium.Math.toDegrees(cartographic.longitude),
|
|
48
|
-
Cesium.Math.toDegrees(cartographic.latitude),
|
|
49
|
-
]
|
|
46
|
+
return [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude)];
|
|
50
47
|
}
|
|
51
48
|
set center(val: number[]) {
|
|
52
49
|
const { viewer, container } = this;
|
|
@@ -54,22 +51,25 @@ export class CesiumMap extends MapCombine {
|
|
|
54
51
|
const height = container.offsetHeight;
|
|
55
52
|
const position = viewer.scene.camera.pickEllipsoid(
|
|
56
53
|
new Cesium.Cartesian2(width / 2, height / 2),
|
|
57
|
-
viewer.scene.globe.ellipsoid
|
|
54
|
+
viewer.scene.globe.ellipsoid,
|
|
58
55
|
);
|
|
59
|
-
const target = Cesium.Cartesian3.fromDegrees(...val)
|
|
60
|
-
Cesium.Cartesian3.subtract(target, position, target)
|
|
61
|
-
Cesium.Cartesian3.add(this.viewer.camera.position, target, this.viewer.camera.position)
|
|
56
|
+
const target = Cesium.Cartesian3.fromDegrees(...val);
|
|
57
|
+
Cesium.Cartesian3.subtract(target, position, target);
|
|
58
|
+
Cesium.Cartesian3.add(this.viewer.camera.position, target, this.viewer.camera.position);
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
get zoom(): number {
|
|
65
|
-
const cartographic = Cesium.Cartographic.fromCartesian(this.viewer.camera.position)
|
|
66
|
-
return this.distanceTzoom(cartographic.height)
|
|
62
|
+
const cartographic = Cesium.Cartographic.fromCartesian(this.viewer.camera.position);
|
|
63
|
+
return this.distanceTzoom(cartographic.height);
|
|
67
64
|
}
|
|
68
65
|
set zoom(val: number) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
const cartographic = Cesium.Cartographic.fromCartesian(this.viewer.camera.position);
|
|
67
|
+
cartographic.height = this.zoomTdistance(val);
|
|
68
|
+
this.viewer.camera.position = Cesium.Cartesian3.fromRadians(
|
|
69
|
+
cartographic.longitude,
|
|
70
|
+
cartographic.latitude,
|
|
71
|
+
cartographic.height,
|
|
72
|
+
);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
fov = 0.9695385667699215;
|
|
@@ -82,57 +82,145 @@ export class CesiumMap extends MapCombine {
|
|
|
82
82
|
return ($m * height) / (256 * Math.tan(this.fov / 2) * Math.pow(2, zoom));
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
constructor(viewer
|
|
86
|
-
super()
|
|
87
|
-
this.viewer
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
constructor(viewer?: any) {
|
|
86
|
+
super();
|
|
87
|
+
this._initParamsEvent(viewer);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
init(opt) {
|
|
91
|
+
this.option = opt;
|
|
92
|
+
const { container, center = [120.2288892, 30.2349677, 0], zoom = 13, url } = opt || {};
|
|
93
|
+
const viewer = new Cesium.Viewer(container, {
|
|
94
|
+
vrButton: false,
|
|
95
|
+
// 检索
|
|
96
|
+
geocoder: false,
|
|
97
|
+
// home
|
|
98
|
+
homeButton: false,
|
|
99
|
+
// 切换3d地图
|
|
100
|
+
sceneModePicker: false,
|
|
101
|
+
// 底图切换按钮
|
|
102
|
+
baseLayerPicker: false,
|
|
103
|
+
// 问号
|
|
104
|
+
navigationHelpButton: false,
|
|
105
|
+
// 动画控制
|
|
106
|
+
animation: false,
|
|
107
|
+
// 版权信息
|
|
108
|
+
creditContainer: document.createElement("div"),
|
|
109
|
+
// 时间轴
|
|
110
|
+
timeline: false,
|
|
111
|
+
// 全屏按钮
|
|
112
|
+
fullscreenButton: false,
|
|
113
|
+
selectionIndicator: false,
|
|
114
|
+
// 打开动画
|
|
115
|
+
shouldAnimate: false,
|
|
116
|
+
infoBox: false,
|
|
117
|
+
// 只进行3d渲染,没有2d,2.5d,提高性能
|
|
118
|
+
scene3DOnly: true,
|
|
119
|
+
// 初始设置一个纯色瓦片,避免报错影响后续瓦片加载
|
|
120
|
+
imageryProvider: new Cesium.SingleTileImageryProvider({
|
|
121
|
+
url: createColorCanvas("#333"),
|
|
122
|
+
rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// viewer.cesiumWidget.creditContainer.remove();
|
|
127
|
+
|
|
128
|
+
// viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
|
|
129
|
+
|
|
130
|
+
this._initParamsEvent(viewer);
|
|
131
|
+
|
|
132
|
+
// 处理瓦片
|
|
133
|
+
this._createLayer();
|
|
134
|
+
|
|
135
|
+
const map = this;
|
|
136
|
+
const d = Cesium.Cartesian3.fromDegrees(...center);
|
|
137
|
+
map.setView([d.x, d.y, d.z, 6.283185307179586, -1.5691285980481942, 0]);
|
|
138
|
+
map.center = center;
|
|
139
|
+
map.zoom = zoom;
|
|
140
|
+
|
|
141
|
+
return map;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private _initParamsEvent(viewer) {
|
|
145
|
+
if (!viewer) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.viewer = viewer;
|
|
149
|
+
|
|
150
|
+
this.container = viewer?.container;
|
|
151
|
+
this.container.appendChild(this.htmllayer);
|
|
152
|
+
this.cursor = "default";
|
|
153
|
+
this.markers = this.viewer.scene.primitives.add(new Cesium.BillboardCollection());
|
|
154
|
+
|
|
155
|
+
bindEvent(this);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private _createLayer() {
|
|
159
|
+
const { url, subdomains, proj, minZoomLevel, maxZoomLevel } = this.option;
|
|
160
|
+
let layer: any;
|
|
161
|
+
console.log("url", url);
|
|
162
|
+
let options = {
|
|
163
|
+
...this.option,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
switch (proj) {
|
|
167
|
+
case "GCJ02->WGS84":
|
|
168
|
+
options = {
|
|
169
|
+
...options,
|
|
170
|
+
crs: "WGS84", // 使用84坐标系,默认为:GCJ02
|
|
171
|
+
};
|
|
172
|
+
layer = this.viewer.imageryLayers.addImageryProvider(new AMapImageryProvider(options));
|
|
95
173
|
|
|
174
|
+
break;
|
|
175
|
+
default:
|
|
176
|
+
options = {
|
|
177
|
+
...options,
|
|
178
|
+
tilingScheme: new Cesium.WebMercatorTilingScheme(),
|
|
179
|
+
};
|
|
180
|
+
layer = this.viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider(options));
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
this.viewer.imageryLayers.add(layer);
|
|
185
|
+
|
|
186
|
+
return layer;
|
|
96
187
|
}
|
|
97
188
|
|
|
98
189
|
getView() {
|
|
99
|
-
const { camera } = this.viewer
|
|
100
|
-
return [
|
|
101
|
-
camera.position.x, camera.position.y, camera.position.z,
|
|
102
|
-
camera.heading, camera.pitch, camera.roll,
|
|
103
|
-
]
|
|
190
|
+
const { camera } = this.viewer;
|
|
191
|
+
return [camera.position.x, camera.position.y, camera.position.z, camera.heading, camera.pitch, camera.roll];
|
|
104
192
|
}
|
|
105
193
|
|
|
106
194
|
setView(e: number[]) {
|
|
107
|
-
const { camera } = this.viewer
|
|
195
|
+
const { camera } = this.viewer;
|
|
108
196
|
camera.setView({
|
|
109
197
|
destination: new Cesium.Cartesian3(e[0], e[1], e[2]),
|
|
110
|
-
orientation: new Cesium.HeadingPitchRoll(e[3], e[4], e[5])
|
|
198
|
+
orientation: new Cesium.HeadingPitchRoll(e[3], e[4], e[5]),
|
|
111
199
|
});
|
|
112
200
|
}
|
|
113
201
|
|
|
114
202
|
createPoint<K>(option?: Partial<PointOption<K>>): Point<K> {
|
|
115
|
-
const e = new Point(this, option)
|
|
116
|
-
drawPoint(this, e)
|
|
117
|
-
return e
|
|
203
|
+
const e = new Point(this, option);
|
|
204
|
+
drawPoint(this, e);
|
|
205
|
+
return e;
|
|
118
206
|
}
|
|
119
207
|
|
|
120
208
|
createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
|
|
121
|
-
const e = new Polyline(this, option)
|
|
122
|
-
drawPolyline(this, e)
|
|
123
|
-
return e
|
|
209
|
+
const e = new Polyline(this, option);
|
|
210
|
+
drawPolyline(this, e);
|
|
211
|
+
return e;
|
|
124
212
|
}
|
|
125
213
|
|
|
126
214
|
createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K> {
|
|
127
|
-
const e = new Polygon(this, option)
|
|
128
|
-
drawPolygon(this, e)
|
|
129
|
-
return e
|
|
215
|
+
const e = new Polygon(this, option);
|
|
216
|
+
drawPolygon(this, e);
|
|
217
|
+
return e;
|
|
130
218
|
}
|
|
131
219
|
|
|
132
220
|
createTile3D(option?: Partial<Tile3DOption>): Tile3D {
|
|
133
|
-
const e = new Tile3D(this, option)
|
|
134
|
-
drawTile3D(this, e)
|
|
135
|
-
return e
|
|
221
|
+
const e = new Tile3D(this, option);
|
|
222
|
+
drawTile3D(this, e);
|
|
223
|
+
return e;
|
|
136
224
|
}
|
|
137
225
|
|
|
138
226
|
canvasTgeography(p: number[]): number[] {
|
|
@@ -159,9 +247,16 @@ export class CesiumMap extends MapCombine {
|
|
|
159
247
|
}
|
|
160
248
|
return [res.x, res.y];
|
|
161
249
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
250
|
}
|
|
167
251
|
|
|
252
|
+
function createColorCanvas(color) {
|
|
253
|
+
var width = 1,
|
|
254
|
+
height = 1;
|
|
255
|
+
var canvas = document.createElement("canvas");
|
|
256
|
+
canvas.width = width;
|
|
257
|
+
canvas.height = height;
|
|
258
|
+
var ctx = canvas.getContext("2d");
|
|
259
|
+
ctx.fillStyle = color;
|
|
260
|
+
ctx.fillRect(0, 0, width, height);
|
|
261
|
+
return canvas.toDataURL();
|
|
262
|
+
}
|