@hzab/map-combine 0.4.2-alpha.0 → 0.4.2-alpha.11
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 +7 -0
- package/package.json +5 -5
- package/src/amap/AMap.ts +313 -306
- package/src/amap/AMapEvent.ts +110 -54
- package/src/amap/AMapPoint.ts +140 -143
- package/src/amap/AMapPolygon.ts +214 -195
- package/src/amap/AMapPolyline.ts +199 -185
- package/src/basic/BasicBusiness.ts +5 -5
- package/src/basic/BasicModel.ts +49 -0
- package/src/basic/MapCombine.ts +4 -0
- package/src/basic/MapElement.ts +2 -1
- package/src/basic/MapEvent.ts +5 -0
- package/src/basic/Point.ts +1 -0
- package/src/basic/PointAggregation.tsx +23 -11
- package/src/basic/ReactPopup.tsx +3 -0
- package/src/cesium/CesiumEvent.ts +97 -84
- package/src/cesium/CesiumMap.ts +355 -347
- package/src/cesium/CesiumModel.ts +64 -0
- package/src/cesium/CesiumPoint.ts +3 -0
- package/src/cesium/CesiumPolygon.ts +2 -0
- package/src/cesium/CesiumPolyline.ts +185 -47
- package/src/cesium/CesiumTile3D.ts +222 -225
- package/src/mine/MineEvent.ts +70 -46
- package/src/mine/MineMap.ts +52 -1
- package/src/mine/MinePoint.ts +7 -1
- package/src/mine/MinePolygon.ts +6 -1
- package/src/mine/MinePolyline.ts +6 -1
- package/src/openlayer/OpenlayerEvent.ts +109 -87
- package/src/openlayer/OpenlayerMap.ts +287 -287
- package/src/openlayer/OpenlayerPoint.ts +6 -1
- package/src/openlayer/OpenlayerPolygon.ts +34 -24
- package/src/openlayer/OpenlayerPolyline.ts +10 -3
- package/src/utils/color.ts +49 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/points-viewer.ts +27 -1
- package/src/utils/turfjs-utils.ts +52 -0
- package/src/utils/types.d.ts +12 -0
package/src/amap/AMapEvent.ts
CHANGED
|
@@ -1,54 +1,110 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
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
|
-
|
|
1
|
+
import { pointToLineDistance } from "@turf/turf";
|
|
2
|
+
|
|
3
|
+
import { AMap } from "./AMap";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 高德地图事件
|
|
7
|
+
* 高德地图 元素事件由各自元素处理
|
|
8
|
+
* @param map
|
|
9
|
+
*/
|
|
10
|
+
export function bindEvent(map: AMap) {
|
|
11
|
+
const { event, viewer, container } = map;
|
|
12
|
+
|
|
13
|
+
const frame = () => {
|
|
14
|
+
if (map.isAlive) {
|
|
15
|
+
requestAnimationFrame(frame);
|
|
16
|
+
event.trigger("view-preRender");
|
|
17
|
+
map.bussinesses.forEach((e) => e.show && e.onFrame?.());
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
frame();
|
|
21
|
+
|
|
22
|
+
viewer.on("moveend", (e) => {
|
|
23
|
+
event.trigger("view-moveEnd");
|
|
24
|
+
event.trigger("view-change");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
container.addEventListener("mousedown", (e) => {
|
|
28
|
+
event.trigger("pointer-down");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
container.addEventListener("mouseup", (e) => {
|
|
32
|
+
event.trigger("pointer-up");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// 解决 ReactPoint 点击事件无法触发的问题
|
|
36
|
+
container.addEventListener("click", (e) => {
|
|
37
|
+
event.trigger("left-click");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
viewer.on("mousemove", (e) => {
|
|
41
|
+
event.trigger("pointer-move");
|
|
42
|
+
event.canvas = [e.pixel.x, e.pixel.y];
|
|
43
|
+
event.geography = [e.lnglat.lng, e.lnglat.lat];
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
viewer.on("mapmove", () => {
|
|
47
|
+
event.trigger("view-change");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
viewer.on("click", (e) => {
|
|
51
|
+
event.trigger("left-click");
|
|
52
|
+
|
|
53
|
+
// "drill-pick" 获取点击位置的元素
|
|
54
|
+
const clickPosition = e.lnglat;
|
|
55
|
+
const position = [clickPosition.lng, clickPosition.lat];
|
|
56
|
+
const allOverlays = viewer.getAllOverlays(); // 获取所有覆盖物
|
|
57
|
+
const pickedObjects = [];
|
|
58
|
+
|
|
59
|
+
// 遍历所有覆盖物,检查点击位置是否在覆盖物内
|
|
60
|
+
allOverlays.forEach((overlay) => {
|
|
61
|
+
// 判断是否为多边形
|
|
62
|
+
if (overlay instanceof map.LbsAMap.Polygon) {
|
|
63
|
+
// 使用 contains 方法判断点是否在多边形内
|
|
64
|
+
if (overlay.contains(clickPosition)) {
|
|
65
|
+
pickedObjects.push(overlay);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// 判断是否为折线
|
|
69
|
+
else if (overlay instanceof map.LbsAMap.Polyline) {
|
|
70
|
+
// 使用点线距离计算
|
|
71
|
+
const path = overlay.getPath();
|
|
72
|
+
const coords = path.map((p) => [p.getLng(), p.getLat()]);
|
|
73
|
+
const distance = pointToLineDistance(position, coords, { units: "meters" });
|
|
74
|
+
|
|
75
|
+
// 获取当前地图的分辨率(米/像素) 每像素代表多少米
|
|
76
|
+
const resolution = viewer.getResolution();
|
|
77
|
+
// 计算线宽对应的地理距离(单边)
|
|
78
|
+
const halfWidthInMeters = (overlay.getOptions().strokeWeight / 2) * resolution;
|
|
79
|
+
|
|
80
|
+
// 根据距离判断是否点击
|
|
81
|
+
if (distance < halfWidthInMeters + 2) {
|
|
82
|
+
pickedObjects.push(overlay);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// 判断是否为 Marker
|
|
86
|
+
else if (overlay instanceof map.LbsAMap.Marker) {
|
|
87
|
+
const position = overlay.getPosition();
|
|
88
|
+
const distance = map.LbsAMap.GeometryUtil.distance(position, clickPosition);
|
|
89
|
+
if (distance < 20) {
|
|
90
|
+
// 点击位置距离 Marker 小于 20 像素
|
|
91
|
+
pickedObjects.push(overlay);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// 按 zIndex 从高到低排序
|
|
97
|
+
pickedObjects.sort((a, b) => (b.getzIndex?.() || 0) - (a.getzIndex?.() || 0));
|
|
98
|
+
|
|
99
|
+
event.trigger("drill-pick", {
|
|
100
|
+
event: e,
|
|
101
|
+
pickedTargets: pickedObjects.map((it) => it.getOptions()?.extData?.target),
|
|
102
|
+
sourceObjects: pickedObjects,
|
|
103
|
+
position: position,
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
viewer.on("dblclick", (e) => {
|
|
108
|
+
map.event.trigger("double-click");
|
|
109
|
+
});
|
|
110
|
+
}
|
package/src/amap/AMapPoint.ts
CHANGED
|
@@ -1,143 +1,140 @@
|
|
|
1
|
-
import { Point } from "../basic/Point";
|
|
2
|
-
import { AMap } from "./AMap";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
point.
|
|
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
|
-
marker.
|
|
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
|
-
point.event.off("destroy", onDestroy);
|
|
142
|
-
};
|
|
143
|
-
}
|
|
1
|
+
import { Point } from "../basic/Point";
|
|
2
|
+
import { AMap } from "./AMap";
|
|
3
|
+
|
|
4
|
+
export function drawPoint(map: AMap, point: Point<unknown>) {
|
|
5
|
+
const { viewer, event, LbsAMap } = map;
|
|
6
|
+
let status = 0;
|
|
7
|
+
let skip = 0;
|
|
8
|
+
|
|
9
|
+
const { size, center } = point;
|
|
10
|
+
const pointOffset = [-size[0] * center[0], -size[1] * center[1]];
|
|
11
|
+
const marker = new LbsAMap.Marker({
|
|
12
|
+
position: new LbsAMap.LngLat(0, 0),
|
|
13
|
+
height: point.height,
|
|
14
|
+
title: point._option.name,
|
|
15
|
+
icon: new LbsAMap.Icon({
|
|
16
|
+
image: point.src,
|
|
17
|
+
size: point.size,
|
|
18
|
+
imageSize: point.size,
|
|
19
|
+
}),
|
|
20
|
+
angle: point.rotation,
|
|
21
|
+
anchor: point.center,
|
|
22
|
+
draggable: point.editable,
|
|
23
|
+
bubble: true,
|
|
24
|
+
extData: {
|
|
25
|
+
userdata: point.userdata,
|
|
26
|
+
cursor: point.cursor,
|
|
27
|
+
silent: point.silent,
|
|
28
|
+
target: point,
|
|
29
|
+
},
|
|
30
|
+
offset: pointOffset,
|
|
31
|
+
});
|
|
32
|
+
setIcon();
|
|
33
|
+
viewer.add([marker]);
|
|
34
|
+
|
|
35
|
+
if (point.coordinates) {
|
|
36
|
+
status = 2;
|
|
37
|
+
marker.setPosition(point.coordinates);
|
|
38
|
+
if (point.show) {
|
|
39
|
+
marker.show();
|
|
40
|
+
} else {
|
|
41
|
+
marker.hide();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const onMouseMove = () => {
|
|
46
|
+
switch (status) {
|
|
47
|
+
case 0:
|
|
48
|
+
status = 1;
|
|
49
|
+
marker.setPosition(event.geography);
|
|
50
|
+
if (point.show) {
|
|
51
|
+
marker.show();
|
|
52
|
+
} else {
|
|
53
|
+
marker.hide();
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 1:
|
|
57
|
+
case 3:
|
|
58
|
+
marker.setPosition(event.geography);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const onClick = () => {
|
|
64
|
+
if (status == 1) {
|
|
65
|
+
status = 2;
|
|
66
|
+
skip++;
|
|
67
|
+
point.coordinates = event.geography;
|
|
68
|
+
point.event.trigger("pointer-in");
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const onUpdate = (e: Set<string>) => {
|
|
73
|
+
if (skip) {
|
|
74
|
+
skip--;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
e.forEach((key) => {
|
|
78
|
+
switch (key) {
|
|
79
|
+
case "show":
|
|
80
|
+
if (status) {
|
|
81
|
+
if (point.show) {
|
|
82
|
+
marker.show();
|
|
83
|
+
} else {
|
|
84
|
+
marker.hide();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "editable":
|
|
89
|
+
marker.setDraggable(point.editable);
|
|
90
|
+
break;
|
|
91
|
+
case "coordinates":
|
|
92
|
+
if (point.coordinates) {
|
|
93
|
+
marker.setPosition(point.coordinates);
|
|
94
|
+
marker.setzIndex(point.coordinates[2]);
|
|
95
|
+
marker.show();
|
|
96
|
+
status = 2;
|
|
97
|
+
} else {
|
|
98
|
+
marker.hide();
|
|
99
|
+
status = 0;
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case "src":
|
|
103
|
+
setIcon();
|
|
104
|
+
break;
|
|
105
|
+
case "size":
|
|
106
|
+
setIcon();
|
|
107
|
+
break;
|
|
108
|
+
case "center":
|
|
109
|
+
marker.setAnchor(point.center);
|
|
110
|
+
break;
|
|
111
|
+
case "rotation":
|
|
112
|
+
marker.setAngle(point.rotation);
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
throw new Error(`${key} 还不支持修改`);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
function setIcon() {
|
|
121
|
+
marker.setIcon(
|
|
122
|
+
new LbsAMap.Icon({
|
|
123
|
+
image: point.src,
|
|
124
|
+
size: point.size,
|
|
125
|
+
imageSize: point.size,
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const onDestroy = () => {
|
|
131
|
+
marker.remove();
|
|
132
|
+
point.event.off("update", onUpdate);
|
|
133
|
+
point.event.off("destroy", onDestroy);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
event.on("pointer-move", onMouseMove);
|
|
137
|
+
event.on("left-click", onClick);
|
|
138
|
+
point.event.on("update", onUpdate);
|
|
139
|
+
point.event.on("destroy", onDestroy);
|
|
140
|
+
}
|