@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
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { BasicModel, type BasicModelOption } from "../basic/BasicModel";
|
|
2
|
+
import { objHasKeys } from "../utils";
|
|
3
|
+
import { type CesiumMap } from "./CesiumMap";
|
|
4
|
+
|
|
5
|
+
export class CesiumModel extends BasicModel {
|
|
6
|
+
private readonly _map: CesiumMap;
|
|
7
|
+
private _shape: any;
|
|
8
|
+
constructor(map: CesiumMap, option?: Partial<BasicModelOption>) {
|
|
9
|
+
super(option);
|
|
10
|
+
this._map = map;
|
|
11
|
+
|
|
12
|
+
this._shape = map.viewer.scene.primitives.add(
|
|
13
|
+
Cesium.Model.fromGltf({
|
|
14
|
+
show: this.option.show,
|
|
15
|
+
url: this.option.model,
|
|
16
|
+
modelMatrix: this._initMatrix(),
|
|
17
|
+
scale: this.option.scale,
|
|
18
|
+
allowPicking: !this.option.silent,
|
|
19
|
+
minimumPixelSize: this.option.minSize,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private _initMatrix() {
|
|
25
|
+
const { lon, lat, alt, heading, pitch, roll } = this.option;
|
|
26
|
+
const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
|
|
27
|
+
const origin = Cesium.Cartesian3.fromDegrees(lon, lat, alt);
|
|
28
|
+
const modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, hpr);
|
|
29
|
+
return modelMatrix;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected _onUpdate(option: Partial<BasicModelOption>): void {
|
|
33
|
+
const { _shape } = this;
|
|
34
|
+
if (objHasKeys(option, ["model"])) {
|
|
35
|
+
this._map.viewer.scene.primitives.remove(this._shape, true);
|
|
36
|
+
this._shape = this._map.viewer.scene.primitives.add(
|
|
37
|
+
Cesium.Model.fromGltf({
|
|
38
|
+
url: this.option.model,
|
|
39
|
+
modelMatrix: this._initMatrix(),
|
|
40
|
+
scale: this.option.scale,
|
|
41
|
+
minimumPixelSize: this.option.minSize,
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
} else {
|
|
45
|
+
if (objHasKeys(option, ["show"])) {
|
|
46
|
+
_shape.show = option.show;
|
|
47
|
+
}
|
|
48
|
+
if (objHasKeys(option, ["lon", "lat", "alt", "heading", "pitch", "roll"])) {
|
|
49
|
+
this._shape.modelMatrix = this._initMatrix();
|
|
50
|
+
}
|
|
51
|
+
if (objHasKeys(option, ["scale"])) {
|
|
52
|
+
this._shape.scale = option.scale;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
destroy(): void {
|
|
58
|
+
this._map.viewer.scene.primitives.remove(this._shape, true);
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/mine/MineEvent.ts
CHANGED
|
@@ -1,46 +1,55 @@
|
|
|
1
|
-
import { MineMap } from "./MineMap";
|
|
2
|
-
|
|
3
|
-
export function bindEvent(map: MineMap) {
|
|
4
|
-
const { event, viewer, container } = map;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
container.addEventListener("
|
|
20
|
-
event.trigger("
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
event.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
event.
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
event.trigger("pointer-
|
|
38
|
-
});
|
|
39
|
-
viewer.on("
|
|
40
|
-
event.trigger("
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
import { MineMap } from "./MineMap";
|
|
2
|
+
|
|
3
|
+
export function bindEvent(map: MineMap) {
|
|
4
|
+
const { event, viewer, container } = map;
|
|
5
|
+
|
|
6
|
+
const frame = () => {
|
|
7
|
+
if (map.isAlive) {
|
|
8
|
+
requestAnimationFrame(frame);
|
|
9
|
+
event.trigger("view-preRender");
|
|
10
|
+
map.bussinesses.forEach((e) => e.show && e.onFrame?.());
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
frame();
|
|
14
|
+
|
|
15
|
+
viewer.on("moveend", (e) => {
|
|
16
|
+
event.trigger("view-moveEnd");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
container.addEventListener("mousedown", (e) => {
|
|
20
|
+
event.trigger("pointer-down");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
container.addEventListener("mouseup", (e) => {
|
|
24
|
+
event.trigger("pointer-up");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// 解决 ReactPoint 点击事件无法触发的问题
|
|
28
|
+
container.addEventListener("click", (e) => {
|
|
29
|
+
event.trigger("left-click");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
viewer.on("mousemove", (e) => {
|
|
33
|
+
event.canvas = [e.point.x, e.point.y];
|
|
34
|
+
event.geography = [e.lngLat.lng, e.lngLat.lat, 0];
|
|
35
|
+
});
|
|
36
|
+
container.addEventListener("pointermove", (e) => {
|
|
37
|
+
event.trigger("pointer-move");
|
|
38
|
+
});
|
|
39
|
+
viewer.on("move", () => {
|
|
40
|
+
event.trigger("view-change");
|
|
41
|
+
});
|
|
42
|
+
viewer.on("mouseup", () => {
|
|
43
|
+
event.trigger("pointer-up");
|
|
44
|
+
});
|
|
45
|
+
viewer.on("mousedown", () => {
|
|
46
|
+
event.trigger("pointer-down");
|
|
47
|
+
});
|
|
48
|
+
viewer.on("click", () => {
|
|
49
|
+
event.trigger("left-click");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
event.on("destroy", () => {
|
|
53
|
+
viewer.remove();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -1,87 +1,88 @@
|
|
|
1
|
-
import { OpenlayerMap } from "./OpenlayerMap";
|
|
2
|
-
|
|
3
|
-
export function bindEvent(map: OpenlayerMap) {
|
|
4
|
-
const { event, viewer, container } = map;
|
|
5
|
-
let target: any;
|
|
6
|
-
let moving = false;
|
|
7
|
-
|
|
8
|
-
const frame = () => {
|
|
9
|
-
if (map.isAlive) {
|
|
10
|
-
requestAnimationFrame(frame);
|
|
11
|
-
event.trigger("view-preRender");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
event.
|
|
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
|
-
}
|
|
1
|
+
import { OpenlayerMap } from "./OpenlayerMap";
|
|
2
|
+
|
|
3
|
+
export function bindEvent(map: OpenlayerMap) {
|
|
4
|
+
const { event, viewer, container } = map;
|
|
5
|
+
let target: any;
|
|
6
|
+
let moving = false;
|
|
7
|
+
|
|
8
|
+
const frame = () => {
|
|
9
|
+
if (map.isAlive) {
|
|
10
|
+
requestAnimationFrame(frame);
|
|
11
|
+
event.trigger("view-preRender");
|
|
12
|
+
map.bussinesses.forEach((e) => e.show && e.onFrame?.());
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
frame();
|
|
16
|
+
|
|
17
|
+
viewer.on("moveend", (e) => {
|
|
18
|
+
event.trigger("view-moveEnd");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
viewer.on("pointermove", (e) => {
|
|
22
|
+
event.canvas = e.pixel;
|
|
23
|
+
event.geography = map.canvasTgeography(event.canvas);
|
|
24
|
+
let _target: any;
|
|
25
|
+
if (moving) {
|
|
26
|
+
event.trigger("pointer-move");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const res = viewer.getFeaturesAtPixel(event.canvas)[0];
|
|
30
|
+
_target = res ? res.get("event") : undefined;
|
|
31
|
+
if (_target?.silent) {
|
|
32
|
+
_target = undefined;
|
|
33
|
+
}
|
|
34
|
+
if (_target !== target) {
|
|
35
|
+
target?.onPointerOut?.();
|
|
36
|
+
_target?.onPointerIn?.();
|
|
37
|
+
target = _target;
|
|
38
|
+
}
|
|
39
|
+
event.trigger("pointer-move");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
container.addEventListener("mousedown", () => {
|
|
43
|
+
if (target) {
|
|
44
|
+
moving = true;
|
|
45
|
+
target.onPointerDown?.();
|
|
46
|
+
}
|
|
47
|
+
event.trigger("pointer-down");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
container.addEventListener("mouseup", () => {
|
|
51
|
+
if (target) {
|
|
52
|
+
moving = false;
|
|
53
|
+
target.onPointerUp?.();
|
|
54
|
+
}
|
|
55
|
+
event.trigger("pointer-up");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
container.addEventListener("contextmenu", (e) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
if (target) {
|
|
61
|
+
target.onRClick?.();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
viewer.on("click", () => {
|
|
66
|
+
if (target) {
|
|
67
|
+
target.onLClick?.();
|
|
68
|
+
}
|
|
69
|
+
event.trigger("left-click");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
viewer.on("dblclick", () => {
|
|
73
|
+
if (target) {
|
|
74
|
+
target.onDbClick?.();
|
|
75
|
+
}
|
|
76
|
+
map.event.trigger("double-click");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
let key = 0;
|
|
80
|
+
|
|
81
|
+
viewer.on("precompose", () => {
|
|
82
|
+
const _key = map.center.reduce((a, b) => a + b, map.zoom);
|
|
83
|
+
if (key != _key) {
|
|
84
|
+
key = _key;
|
|
85
|
+
event.trigger("view-change");
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用函数:提取所有坐标并扁平化为普通数组
|
|
3
|
+
* @param geojsonFeature
|
|
4
|
+
* @param geomType
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export function extractCoordinatesToArr(coords, geomType) {
|
|
8
|
+
if (geomType === "Polygon") {
|
|
9
|
+
// 多边形:三维数组 [环1[点1,点2...], 环2[...]] -> 转为二维数组
|
|
10
|
+
return coords.map(
|
|
11
|
+
(ring) => ring.map((coord) => [coord[0], coord[1]]), // 提取经度、纬度
|
|
12
|
+
);
|
|
13
|
+
} else if (geomType === "MultiPolygon") {
|
|
14
|
+
// 多部件多边形:四维数组 -> 转为三维数组
|
|
15
|
+
return coords.map((polygon) => polygon.map((ring) => ring.map((coord) => [coord[0], coord[1]])));
|
|
16
|
+
} else if (geomType === "Point") {
|
|
17
|
+
// 点:返回一维数组
|
|
18
|
+
return [coords[0], coords[1]];
|
|
19
|
+
} else if (geomType === "LineString") {
|
|
20
|
+
// 线:返回二维数组
|
|
21
|
+
return coords.map((coord) => [coord[0], coord[1]]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return coords;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 通用函数:提取所有坐标并扁平化为普通数组
|
|
29
|
+
* @param geojsonFeature
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export function extractGeojsonCoordinatesToArr(geojsonFeature) {
|
|
33
|
+
const coords = geojsonFeature.geometry.coordinates;
|
|
34
|
+
const geomType = geojsonFeature.geometry.type;
|
|
35
|
+
if (geomType === "Polygon") {
|
|
36
|
+
// 多边形:三维数组 [环1[点1,点2...], 环2[...]] -> 转为二维数组
|
|
37
|
+
return coords.map(
|
|
38
|
+
(ring) => ring.map((coord) => [coord[0], coord[1]]), // 提取经度、纬度
|
|
39
|
+
);
|
|
40
|
+
} else if (geomType === "MultiPolygon") {
|
|
41
|
+
// 多部件多边形:四维数组 -> 转为三维数组
|
|
42
|
+
return coords.map((polygon) => polygon.map((ring) => ring.map((coord) => [coord[0], coord[1]])));
|
|
43
|
+
} else if (geomType === "Point") {
|
|
44
|
+
// 点:返回一维数组
|
|
45
|
+
return [coords[0], coords[1]];
|
|
46
|
+
} else if (geomType === "LineString") {
|
|
47
|
+
// 线:返回二维数组
|
|
48
|
+
return coords.map((coord) => [coord[0], coord[1]]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return coords;
|
|
52
|
+
}
|