@hzab/map-combine 0.4.1 → 0.4.2-alpha.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 +5 -0
- package/package.json +1 -1
- package/src/basic/BasicElement.ts +14 -14
- package/src/basic/BasicMarker.ts +32 -26
- package/src/basic/BasicMouseHandler.ts +4 -4
- package/src/basic/Point.ts +173 -173
- package/src/basic/Polygon.ts +81 -70
- package/src/basic/Polyline.ts +85 -75
- package/src/basic/ReactPopup.tsx +12 -10
- package/src/cesium/CesiumPoint.ts +69 -69
- package/src/cesium/CesiumPolygon.ts +181 -190
- package/src/cesium/CesiumPolyline.ts +369 -369
- package/src/mine/MinePoint.ts +70 -78
- package/src/mine/MinePolygon.ts +206 -216
- package/src/mine/MinePolyline.ts +193 -203
- package/src/mine/MineTile3D.ts +7 -11
- package/src/openlayer/OpenlayerPoint.ts +185 -177
- package/src/openlayer/OpenlayerPolygon.ts +302 -299
- package/src/openlayer/OpenlayerPolyline.ts +303 -289
- package/src/utils/Image.ts +16 -20
- package/src/utils/PolygonEditor.ts +78 -99
- package/src/utils/PolylineEditor.ts +75 -90
- package/src/utils/static.ts +3 -3
|
@@ -1,177 +1,185 @@
|
|
|
1
|
-
import { Point } from "../basic/Point";
|
|
2
|
-
import { OpenlayerMap } from "./OpenlayerMap";
|
|
3
|
-
import Feature from
|
|
4
|
-
import OlPoint from
|
|
5
|
-
import { Icon, Style } from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
viewer
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
point.event.trigger(
|
|
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
|
-
layer.
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
1
|
+
import { Point } from "../basic/Point";
|
|
2
|
+
import { OpenlayerMap } from "./OpenlayerMap";
|
|
3
|
+
import Feature from "ol/Feature.js";
|
|
4
|
+
import OlPoint from "ol/geom/Point.js";
|
|
5
|
+
import { Icon, Style } from "ol/style.js";
|
|
6
|
+
import VectorSource from "ol/source/Vector";
|
|
7
|
+
import VectorLayer from "ol/layer/Vector";
|
|
8
|
+
const RD = 0.017453292519943295;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 获取点位的 zIndex/height 值
|
|
12
|
+
* @param point
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
function getPointZIndex(point) {
|
|
16
|
+
return point?.coordinates?.[2] ?? point.height ?? 3;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function drawPoint(map: OpenlayerMap, point: Point<unknown>) {
|
|
20
|
+
const { viewer, event, getFromLonLat, isFromLonLat } = map;
|
|
21
|
+
let status = 0;
|
|
22
|
+
|
|
23
|
+
const source = new VectorSource();
|
|
24
|
+
const layer = new VectorLayer({
|
|
25
|
+
source,
|
|
26
|
+
visible: point.show,
|
|
27
|
+
});
|
|
28
|
+
viewer.addLayer(layer);
|
|
29
|
+
const feature = new Feature();
|
|
30
|
+
const geometry = new OlPoint([0, 0]);
|
|
31
|
+
const style = new Style({
|
|
32
|
+
image: new Icon({
|
|
33
|
+
width: point.size[0],
|
|
34
|
+
height: point.size[1],
|
|
35
|
+
src: point.src,
|
|
36
|
+
rotation: point.rotation * RD,
|
|
37
|
+
anchor: point.center,
|
|
38
|
+
crossOrigin: "anonymous",
|
|
39
|
+
}),
|
|
40
|
+
zIndex: 3,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const _event = {
|
|
44
|
+
cursor: point.cursor,
|
|
45
|
+
silent: point.silent,
|
|
46
|
+
onPointerIn() {
|
|
47
|
+
point.event.trigger("pointer-in");
|
|
48
|
+
},
|
|
49
|
+
onPointerOut() {
|
|
50
|
+
point.event.trigger("pointer-out");
|
|
51
|
+
},
|
|
52
|
+
onLClick() {
|
|
53
|
+
point.event.trigger("left-click");
|
|
54
|
+
},
|
|
55
|
+
onRClick() {
|
|
56
|
+
point.event.trigger("right-click");
|
|
57
|
+
},
|
|
58
|
+
onPointerDown() {
|
|
59
|
+
if (point.editable && status == 2) {
|
|
60
|
+
status = 3;
|
|
61
|
+
map.moveable = false;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
onPointerUp() {
|
|
65
|
+
if (point.editable && status == 3) {
|
|
66
|
+
status = 2;
|
|
67
|
+
map.moveable = true;
|
|
68
|
+
point.coordinates = [event.geography[0], event.geography[1], getPointZIndex(point)];
|
|
69
|
+
point.event.trigger("data-update");
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
feature.setGeometry(geometry);
|
|
75
|
+
feature.setStyle(style);
|
|
76
|
+
feature.set("event", _event, true);
|
|
77
|
+
if (point.coordinates) {
|
|
78
|
+
status = 2;
|
|
79
|
+
geometry.setCoordinates(getFromLonLat(point.coordinates, isFromLonLat));
|
|
80
|
+
layer.setZIndex(getPointZIndex(point));
|
|
81
|
+
point.event.trigger("data-loaded");
|
|
82
|
+
source.addFeature(feature);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const onUpdate = (e: Set<string>) => {
|
|
86
|
+
const keys = new Set();
|
|
87
|
+
e.forEach((key) => {
|
|
88
|
+
switch (key) {
|
|
89
|
+
case "show":
|
|
90
|
+
if (status) {
|
|
91
|
+
layer.setVisible(point.show);
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case "editable":
|
|
95
|
+
break;
|
|
96
|
+
case "coordinates":
|
|
97
|
+
if (point.coordinates) {
|
|
98
|
+
geometry.setCoordinates(getFromLonLat(point.coordinates, isFromLonLat));
|
|
99
|
+
layer.setZIndex(getPointZIndex(point));
|
|
100
|
+
switch (status) {
|
|
101
|
+
case 0:
|
|
102
|
+
source.addFeature(feature);
|
|
103
|
+
status = 2;
|
|
104
|
+
break;
|
|
105
|
+
case 1:
|
|
106
|
+
status = 2;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
source.removeFeature(feature);
|
|
111
|
+
status = 0;
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case "src":
|
|
115
|
+
keys.add("icon");
|
|
116
|
+
break;
|
|
117
|
+
case "size":
|
|
118
|
+
keys.add("icon");
|
|
119
|
+
break;
|
|
120
|
+
case "center":
|
|
121
|
+
keys.add("icon");
|
|
122
|
+
break;
|
|
123
|
+
case "rotation":
|
|
124
|
+
keys.add("icon");
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
throw new Error(`${key} 还不支持修改`);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
keys.forEach((e) => {
|
|
132
|
+
switch (e) {
|
|
133
|
+
case "icon":
|
|
134
|
+
style.setImage(
|
|
135
|
+
new Icon({
|
|
136
|
+
width: point.size[0],
|
|
137
|
+
height: point.size[1],
|
|
138
|
+
src: point.src,
|
|
139
|
+
rotation: point.rotation * RD,
|
|
140
|
+
anchor: point.center,
|
|
141
|
+
crossOrigin: "anonymous",
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
feature.changed();
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const onMouseMove = () => {
|
|
151
|
+
const coordinates = [event.geography[0], event.geography[1], getPointZIndex(point)];
|
|
152
|
+
switch (status) {
|
|
153
|
+
case 0:
|
|
154
|
+
status = 1;
|
|
155
|
+
geometry.setCoordinates(getFromLonLat(coordinates, isFromLonLat));
|
|
156
|
+
source.addFeature(feature);
|
|
157
|
+
break;
|
|
158
|
+
case 1:
|
|
159
|
+
case 3:
|
|
160
|
+
geometry.setCoordinates(getFromLonLat(coordinates, isFromLonLat));
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const onClick = () => {
|
|
166
|
+
if (status == 1) {
|
|
167
|
+
status = 2;
|
|
168
|
+
point.coordinates = [event.geography[0], event.geography[1], getPointZIndex(point)];
|
|
169
|
+
point.event.trigger("pointer-in");
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const onDestroy = () => {
|
|
174
|
+
source.removeFeature(feature);
|
|
175
|
+
event.off("pointer-move", onMouseMove);
|
|
176
|
+
event.off("left-click", onClick);
|
|
177
|
+
point.event.off("update", onUpdate);
|
|
178
|
+
point.event.off("destroy", onDestroy);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
event.on("pointer-move", onMouseMove);
|
|
182
|
+
event.on("left-click", onClick);
|
|
183
|
+
point.event.on("update", onUpdate);
|
|
184
|
+
point.event.on("destroy", onDestroy);
|
|
185
|
+
}
|