@hzab/map-combine 0.2.7 → 0.3.0-beta
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 +53 -44
- package/README.md +83 -67
- package/package.json +4 -2
- package/src/amap/AMap.ts +249 -0
- package/src/amap/AMapEvent.ts +42 -0
- package/src/amap/AMapPoint.ts +143 -0
- package/src/amap/AMapPolygon.ts +196 -0
- package/src/amap/AMapPolyline.ts +186 -0
- package/src/amap/loader.ts +58 -0
- package/src/basic/Point.ts +173 -176
- package/src/basic/ReactPoint.tsx +362 -357
- package/src/cesium/CesiumMap.ts +342 -342
- package/src/cesium/CesiumPolyline.ts +369 -369
- package/src/mine/MineMap.ts +119 -119
- package/src/openlayer/OpenlayerMap.ts +273 -273
- package/src/openlayer/OpenlayerPoint.ts +176 -176
- package/src/openlayer/OpenlayerPolygon.ts +298 -298
- package/src/openlayer/OpenlayerPolyline.ts +288 -288
|
@@ -1,369 +1,369 @@
|
|
|
1
|
-
import { Polyline } from "../basic/Polyline";
|
|
2
|
-
import { ChainNode, PolylineEditor } from "../utils/PolylineEditor";
|
|
3
|
-
import { CesiumMap } from "./CesiumMap";
|
|
4
|
-
import iconPoint from "../assets/point.png";
|
|
5
|
-
import iconAdd from "../assets/add.png";
|
|
6
|
-
|
|
7
|
-
const source = `
|
|
8
|
-
czm_material czm_getMaterial(czm_materialInput materialInput){
|
|
9
|
-
czm_material material = czm_getDefaultMaterial(materialInput);
|
|
10
|
-
vec2 st = vec2(fract(materialInput.st.x * k), materialInput.st.y);
|
|
11
|
-
vec4 colorImage = texture2D(image, vec2(fract((st.s - speed * czm_frameNumber * 0.005)), st.t));
|
|
12
|
-
vec3 tintedColor = color.rgb;
|
|
13
|
-
material.diffuse = tintedColor;
|
|
14
|
-
material.alpha = colorImage.a * color.a;
|
|
15
|
-
return material;
|
|
16
|
-
}`;
|
|
17
|
-
function createLineMaterial(e: Polyline<unknown>) {
|
|
18
|
-
if (e.icon || e.flow) {
|
|
19
|
-
const material = new Cesium.Material({
|
|
20
|
-
fabric: {
|
|
21
|
-
type: "PolylineFlowIcon",
|
|
22
|
-
uniforms: {
|
|
23
|
-
color: Cesium.Color.fromCssColorString(e.stroke),
|
|
24
|
-
image:
|
|
25
|
-
e.icon ||
|
|
26
|
-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIQAAABQCAYAAADY692eAAAACXBIWXMAACxLAAAsSwGlPZapAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAL7SURBVHgB7ZjBbRpBFIZnB4mzS4ALiGM6SDqJK0g6iNxBUoHTSdKBj0hwgBJ8RgI8Y3mtAQye2X2r1b73/QcjvLv+bOnXP5+pVqvVv+Px+NVl5nA4fFssFv+dUOD3yz+P3+/39+H1OfsB7x83m82dEwr8fvkXPz+0bRte/xQ8M9ntdj+dUOD3yz+Pj1/G4/Hv8LIteO7HcrmcOKHA75ef5rUQ0+n0OZxN9wXP3Y1Go0cnFPj98tNU6RsED8H06RsED8E8KQSCh2D6828geLb5F4VA8Gzzq2sXEDybfH/tAoJnk3+1EAieTb6/dRHBs8e/WQgEzx6/yrkJwbPD9zk3IXh2+FmFQPDs8LMKEYPg2eBnFwLBs8HPkso0CJ5ufvZC1EHwdPOLC4Hg6eYXFyIGwdPLb1QIBE8vv1gq0yB4+viNFqIOgqeP36oQCJ4+fqtCxCB4uvitC4Hg6eK3kso0CJ4OfuuFqIPg6eCLFQLB08EXK0QMgjd8vmghELzh88WkMg2CN1y+6ELUQfCGy++kEAjecPmdHBkxsXEB8hRhmY/E8+/L2x8Dvyd+JwsRg+ANk99ZIWICYOLKsnWCgV/O77QQwXR/ldwfZOjBCQZ+Ob+zQqzX6/jLTHLvD/P2IHV+wm/O70Qq46df4V+ZTcEj2/l8PnVCgd+c38lChLOraKpiO51g4Dfniy9E+JTsezi7sm25qqq/s9msxIbhd8gXXwhEbth80UIgcsPnix0ZiJwOvthCIHI6+CILgcjp4YssBCKnh9+6EIicLn6rIwOR08dvtRCInD5+44VA5HTyGy8EIqeT36gQiJxefvGRgcjp5hcvBCKnm1+0EIicfn7RQiBy+vnZhUDkbPCzjgxEzg4/ayEQOTv8TxcCkbPF/3QhEDlb/JuFQOTs8a8eGYicTf7VhUDkbPI/XAhEzi7/w4VA5OzyLwqByNnmnxwZiJxtfszJQiBytvkx7wuByNnm13lfCETONr/OayEQOdv8NBUih0im8YgcIpnmBTnnQRKFAYSqAAAAAElFTkSuQmCC",
|
|
27
|
-
speed: 1,
|
|
28
|
-
k: 20,
|
|
29
|
-
},
|
|
30
|
-
source,
|
|
31
|
-
},
|
|
32
|
-
translucent() {
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
return material;
|
|
37
|
-
} else {
|
|
38
|
-
return e.dash
|
|
39
|
-
? Cesium.Material.fromType("PolylineDash", {
|
|
40
|
-
color: Cesium.Color.fromCssColorString(e.stroke),
|
|
41
|
-
dashLength: 10,
|
|
42
|
-
})
|
|
43
|
-
: Cesium.Material.fromType("Color", {
|
|
44
|
-
color: Cesium.Color.fromCssColorString(e.stroke),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function cartesian3Tgeography(e: any): number[] {
|
|
50
|
-
const r = Cesium.Cartographic.fromCartesian(e);
|
|
51
|
-
return [Cesium.Math.toDegrees(r.longitude), Cesium.Math.toDegrees(r.latitude), r.height];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function geographyTcartesian3(e: number[]) {
|
|
55
|
-
return Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const eyeOffset = new Cesium.Cartesian3(0, 0, -1);
|
|
59
|
-
|
|
60
|
-
export function drawPolyline(map: CesiumMap, polyline: Polyline<unknown>) {
|
|
61
|
-
const { event, viewer } = map;
|
|
62
|
-
let status = 0;
|
|
63
|
-
let skip = 0;
|
|
64
|
-
|
|
65
|
-
let material = createLineMaterial(polyline);
|
|
66
|
-
const appearance = new Cesium.PolylineMaterialAppearance({
|
|
67
|
-
material,
|
|
68
|
-
});
|
|
69
|
-
const markers = viewer.scene.primitives.add(
|
|
70
|
-
new Cesium.BillboardCollection({
|
|
71
|
-
show: polyline.show,
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const _event = {
|
|
76
|
-
cursor: polyline.cursor,
|
|
77
|
-
silent: polyline.silent,
|
|
78
|
-
onPointerIn() {
|
|
79
|
-
status == 2 && polyline.event.trigger("pointer-in");
|
|
80
|
-
},
|
|
81
|
-
onPointerOut() {
|
|
82
|
-
status == 2 && polyline.event.trigger("pointer-out");
|
|
83
|
-
},
|
|
84
|
-
onLClick() {
|
|
85
|
-
status == 2 && polyline.event.trigger("left-click");
|
|
86
|
-
},
|
|
87
|
-
onRClick() {
|
|
88
|
-
if (polyline.menu) {
|
|
89
|
-
map.menu.show(polyline.menu);
|
|
90
|
-
}
|
|
91
|
-
status == 2 && polyline.event.trigger("right-click");
|
|
92
|
-
},
|
|
93
|
-
onDbClick() {
|
|
94
|
-
polyline.editable &&
|
|
95
|
-
status == 2 &&
|
|
96
|
-
setTimeout(() => {
|
|
97
|
-
polyline.event.trigger("start-edit");
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
let primitive: any;
|
|
103
|
-
let cache: any[];
|
|
104
|
-
let activeNode: ChainNode<any, any>;
|
|
105
|
-
if (polyline.coordinates) {
|
|
106
|
-
status = 2;
|
|
107
|
-
cache = polyline.coordinates.map((e) => Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]));
|
|
108
|
-
primitive = new Cesium.Primitive({
|
|
109
|
-
show: polyline.show,
|
|
110
|
-
geometryInstances: new Cesium.GeometryInstance({
|
|
111
|
-
geometry: new Cesium.PolylineGeometry({
|
|
112
|
-
positions: cache,
|
|
113
|
-
width: polyline.lineWidth,
|
|
114
|
-
vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
|
|
115
|
-
}),
|
|
116
|
-
id: _event,
|
|
117
|
-
}),
|
|
118
|
-
appearance,
|
|
119
|
-
});
|
|
120
|
-
viewer.scene.primitives.add(primitive);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const editor = new PolylineEditor<any, any>();
|
|
124
|
-
|
|
125
|
-
editor.on("create-node", (n) => {
|
|
126
|
-
if (n.type == "node") {
|
|
127
|
-
const feature = markers.add({
|
|
128
|
-
position: new Cesium.Cartesian3(...n.position),
|
|
129
|
-
width: 16,
|
|
130
|
-
height: 16,
|
|
131
|
-
image: iconPoint,
|
|
132
|
-
eyeOffset,
|
|
133
|
-
id: {
|
|
134
|
-
cursor: "move",
|
|
135
|
-
onPointerDown() {
|
|
136
|
-
status = 4;
|
|
137
|
-
activeNode = n;
|
|
138
|
-
map.moveable = false;
|
|
139
|
-
},
|
|
140
|
-
onPointerUp() {
|
|
141
|
-
if (status == 4) {
|
|
142
|
-
status = 3;
|
|
143
|
-
map.moveable = true;
|
|
144
|
-
activeNode = undefined;
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
onDbClick() {
|
|
148
|
-
n.destroy();
|
|
149
|
-
cache = editor.getCoordinates().map((e) => new Cesium.Cartesian3(...e));
|
|
150
|
-
initPrimitive();
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
n.shape = feature;
|
|
155
|
-
} else {
|
|
156
|
-
const feature = markers.add({
|
|
157
|
-
position: new Cesium.Cartesian3(...n.position),
|
|
158
|
-
width: 16,
|
|
159
|
-
height: 16,
|
|
160
|
-
image: iconAdd,
|
|
161
|
-
eyeOffset,
|
|
162
|
-
id: {
|
|
163
|
-
cursor: "pointer",
|
|
164
|
-
onPointerDown() {
|
|
165
|
-
status = 4;
|
|
166
|
-
activeNode = n.insert();
|
|
167
|
-
map.cursor = "move";
|
|
168
|
-
map.moveable = false;
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
n.shape = feature;
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
editor.on("update-node", (n) => {
|
|
177
|
-
n.shape.position = new Cesium.Cartesian3(...n.position);
|
|
178
|
-
});
|
|
179
|
-
editor.on("remove-node", (n) => {
|
|
180
|
-
markers.remove(n.shape);
|
|
181
|
-
});
|
|
182
|
-
editor.on("empty", () => {
|
|
183
|
-
// markers.removeAll()
|
|
184
|
-
viewer.scene.primitives.remove(primitive);
|
|
185
|
-
status = 0;
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
const onUpdate = (e: Set<string>) => {
|
|
189
|
-
if (skip) {
|
|
190
|
-
skip--;
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const keys = new Set();
|
|
194
|
-
e.forEach((key) => {
|
|
195
|
-
switch (key) {
|
|
196
|
-
case "show":
|
|
197
|
-
if (primitive) {
|
|
198
|
-
primitive.show = polyline.show;
|
|
199
|
-
markers.show = polyline.show;
|
|
200
|
-
}
|
|
201
|
-
break;
|
|
202
|
-
case "editable":
|
|
203
|
-
break;
|
|
204
|
-
case "coordinates":
|
|
205
|
-
keys.add("Primitive");
|
|
206
|
-
break;
|
|
207
|
-
case "lineWidth":
|
|
208
|
-
keys.add("Primitive");
|
|
209
|
-
break;
|
|
210
|
-
case "icon":
|
|
211
|
-
keys.add("Material");
|
|
212
|
-
break;
|
|
213
|
-
case "flow":
|
|
214
|
-
keys.add("Material");
|
|
215
|
-
break;
|
|
216
|
-
case "stroke":
|
|
217
|
-
material.uniforms.color = Cesium.Color.fromCssColorString(polyline.stroke);
|
|
218
|
-
break;
|
|
219
|
-
case "dash":
|
|
220
|
-
keys.add("Material");
|
|
221
|
-
|
|
222
|
-
break;
|
|
223
|
-
default:
|
|
224
|
-
throw new Error(`${key} 还不支持修改`);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
keys.forEach((key) => {
|
|
228
|
-
switch (key) {
|
|
229
|
-
case "Primitive":
|
|
230
|
-
if (polyline.coordinates) {
|
|
231
|
-
cache = polyline.coordinates.map((e) => geographyTcartesian3(e));
|
|
232
|
-
} else {
|
|
233
|
-
cache = [];
|
|
234
|
-
markers.removeAll();
|
|
235
|
-
status = 0;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
initPrimitive();
|
|
239
|
-
|
|
240
|
-
break;
|
|
241
|
-
case "Material":
|
|
242
|
-
material = createLineMaterial(polyline);
|
|
243
|
-
appearance.material = material;
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const onStartEdit = () => {
|
|
250
|
-
switch (status) {
|
|
251
|
-
case 2:
|
|
252
|
-
status = 3;
|
|
253
|
-
editor.setCoordinates(cache.map((e) => [e.x, e.y, e.z]));
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
let temp: any;
|
|
258
|
-
const onMouseMove = () => {
|
|
259
|
-
const e = event.geography;
|
|
260
|
-
|
|
261
|
-
switch (status) {
|
|
262
|
-
case 1:
|
|
263
|
-
cache.pop();
|
|
264
|
-
cache.push(Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]));
|
|
265
|
-
initPrimitive();
|
|
266
|
-
break;
|
|
267
|
-
case 4:
|
|
268
|
-
temp = Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]);
|
|
269
|
-
activeNode.update([temp.x, temp.y, temp.z]);
|
|
270
|
-
cache = editor.getCoordinates().map((e) => new Cesium.Cartesian3(...e));
|
|
271
|
-
initPrimitive();
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
const onClick = () => {
|
|
277
|
-
const e = event.geography;
|
|
278
|
-
switch (status) {
|
|
279
|
-
case 0:
|
|
280
|
-
status = 1;
|
|
281
|
-
cache = [Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2])];
|
|
282
|
-
cache.push(cache[0]);
|
|
283
|
-
initPrimitive();
|
|
284
|
-
break;
|
|
285
|
-
case 1:
|
|
286
|
-
cache.push(cache[cache.length - 1]);
|
|
287
|
-
// geometry.setCoordinates(cache)
|
|
288
|
-
initPrimitive();
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
const initPrimitive = () => {
|
|
294
|
-
primitive && viewer.scene.primitives.remove(primitive);
|
|
295
|
-
if (cache.length > 1) {
|
|
296
|
-
const geometry = Cesium.PolylineGeometry.createGeometry(
|
|
297
|
-
new Cesium.PolylineGeometry({
|
|
298
|
-
positions: cache,
|
|
299
|
-
width: polyline.lineWidth,
|
|
300
|
-
vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
|
|
301
|
-
}),
|
|
302
|
-
);
|
|
303
|
-
if (geometry) {
|
|
304
|
-
primitive = new Cesium.Primitive({
|
|
305
|
-
show: polyline.show,
|
|
306
|
-
asynchronous: false,
|
|
307
|
-
geometryInstances: new Cesium.GeometryInstance({
|
|
308
|
-
geometry,
|
|
309
|
-
id: _event,
|
|
310
|
-
}),
|
|
311
|
-
appearance,
|
|
312
|
-
});
|
|
313
|
-
viewer.scene.primitives.add(primitive);
|
|
314
|
-
} else {
|
|
315
|
-
primitive = undefined;
|
|
316
|
-
}
|
|
317
|
-
} else {
|
|
318
|
-
primitive = undefined;
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
const onDbClick = () => {
|
|
323
|
-
switch (status) {
|
|
324
|
-
case 1:
|
|
325
|
-
status = 2;
|
|
326
|
-
skip++;
|
|
327
|
-
cache.pop();
|
|
328
|
-
cache.pop();
|
|
329
|
-
// geometry.setCoordinates(cache)
|
|
330
|
-
polyline.coordinates = cache.map((e) => cartesian3Tgeography(e));
|
|
331
|
-
polyline.event.trigger("data-loaded");
|
|
332
|
-
polyline.event.trigger("pointer-in");
|
|
333
|
-
break;
|
|
334
|
-
case 3:
|
|
335
|
-
polyline.stopEdit();
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const onStopEdit = () => {
|
|
341
|
-
if (status == 3) {
|
|
342
|
-
status = 2;
|
|
343
|
-
skip++;
|
|
344
|
-
polyline.coordinates = editor.getCoordinates().map((e) => cartesian3Tgeography(e));
|
|
345
|
-
editor.setCoordinates([]);
|
|
346
|
-
polyline.event.trigger("pointer-in");
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
const onDestroy = () => {
|
|
351
|
-
primitive && viewer.scene.primitives.remove(primitive);
|
|
352
|
-
viewer.scene.primitives.remove(markers);
|
|
353
|
-
event.off("pointer-move", onMouseMove);
|
|
354
|
-
event.off("left-click", onClick);
|
|
355
|
-
event.off("double-click", onDbClick);
|
|
356
|
-
polyline.event.off("update", onUpdate);
|
|
357
|
-
polyline.event.off("start-edit", onStartEdit);
|
|
358
|
-
polyline.event.off("stop-edit", onStopEdit);
|
|
359
|
-
polyline.event.off("destroy", onDestroy);
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
event.on("pointer-move", onMouseMove);
|
|
363
|
-
event.on("left-click", onClick);
|
|
364
|
-
event.on("double-click", onDbClick);
|
|
365
|
-
polyline.event.on("update", onUpdate);
|
|
366
|
-
polyline.event.on("start-edit", onStartEdit);
|
|
367
|
-
polyline.event.on("stop-edit", onStopEdit);
|
|
368
|
-
polyline.event.on("destroy", onDestroy);
|
|
369
|
-
}
|
|
1
|
+
import { Polyline } from "../basic/Polyline";
|
|
2
|
+
import { ChainNode, PolylineEditor } from "../utils/PolylineEditor";
|
|
3
|
+
import { CesiumMap } from "./CesiumMap";
|
|
4
|
+
import iconPoint from "../assets/point.png";
|
|
5
|
+
import iconAdd from "../assets/add.png";
|
|
6
|
+
|
|
7
|
+
const source = `
|
|
8
|
+
czm_material czm_getMaterial(czm_materialInput materialInput){
|
|
9
|
+
czm_material material = czm_getDefaultMaterial(materialInput);
|
|
10
|
+
vec2 st = vec2(fract(materialInput.st.x * k), materialInput.st.y);
|
|
11
|
+
vec4 colorImage = texture2D(image, vec2(fract((st.s - speed * czm_frameNumber * 0.005)), st.t));
|
|
12
|
+
vec3 tintedColor = color.rgb;
|
|
13
|
+
material.diffuse = tintedColor;
|
|
14
|
+
material.alpha = colorImage.a * color.a;
|
|
15
|
+
return material;
|
|
16
|
+
}`;
|
|
17
|
+
function createLineMaterial(e: Polyline<unknown>) {
|
|
18
|
+
if (e.icon || e.flow) {
|
|
19
|
+
const material = new Cesium.Material({
|
|
20
|
+
fabric: {
|
|
21
|
+
type: "PolylineFlowIcon",
|
|
22
|
+
uniforms: {
|
|
23
|
+
color: Cesium.Color.fromCssColorString(e.stroke),
|
|
24
|
+
image:
|
|
25
|
+
e.icon ||
|
|
26
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIQAAABQCAYAAADY692eAAAACXBIWXMAACxLAAAsSwGlPZapAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAL7SURBVHgB7ZjBbRpBFIZnB4mzS4ALiGM6SDqJK0g6iNxBUoHTSdKBj0hwgBJ8RgI8Y3mtAQye2X2r1b73/QcjvLv+bOnXP5+pVqvVv+Px+NVl5nA4fFssFv+dUOD3yz+P3+/39+H1OfsB7x83m82dEwr8fvkXPz+0bRte/xQ8M9ntdj+dUOD3yz+Pj1/G4/Hv8LIteO7HcrmcOKHA75ef5rUQ0+n0OZxN9wXP3Y1Go0cnFPj98tNU6RsED8H06RsED8E8KQSCh2D6828geLb5F4VA8Gzzq2sXEDybfH/tAoJnk3+1EAieTb6/dRHBs8e/WQgEzx6/yrkJwbPD9zk3IXh2+FmFQPDs8LMKEYPg2eBnFwLBs8HPkso0CJ5ufvZC1EHwdPOLC4Hg6eYXFyIGwdPLb1QIBE8vv1gq0yB4+viNFqIOgqeP36oQCJ4+fqtCxCB4uvitC4Hg6eK3kso0CJ4OfuuFqIPg6eCLFQLB08EXK0QMgjd8vmghELzh88WkMg2CN1y+6ELUQfCGy++kEAjecPmdHBkxsXEB8hRhmY/E8+/L2x8Dvyd+JwsRg+ANk99ZIWICYOLKsnWCgV/O77QQwXR/ldwfZOjBCQZ+Ob+zQqzX6/jLTHLvD/P2IHV+wm/O70Qq46df4V+ZTcEj2/l8PnVCgd+c38lChLOraKpiO51g4Dfniy9E+JTsezi7sm25qqq/s9msxIbhd8gXXwhEbth80UIgcsPnix0ZiJwOvthCIHI6+CILgcjp4YssBCKnh9+6EIicLn6rIwOR08dvtRCInD5+44VA5HTyGy8EIqeT36gQiJxefvGRgcjp5hcvBCKnm1+0EIicfn7RQiBy+vnZhUDkbPCzjgxEzg4/ayEQOTv8TxcCkbPF/3QhEDlb/JuFQOTs8a8eGYicTf7VhUDkbPI/XAhEzi7/w4VA5OzyLwqByNnmnxwZiJxtfszJQiBytvkx7wuByNnm13lfCETONr/OayEQOdv8NBUih0im8YgcIpnmBTnnQRKFAYSqAAAAAElFTkSuQmCC",
|
|
27
|
+
speed: 1,
|
|
28
|
+
k: 20,
|
|
29
|
+
},
|
|
30
|
+
source,
|
|
31
|
+
},
|
|
32
|
+
translucent() {
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return material;
|
|
37
|
+
} else {
|
|
38
|
+
return e.dash
|
|
39
|
+
? Cesium.Material.fromType("PolylineDash", {
|
|
40
|
+
color: Cesium.Color.fromCssColorString(e.stroke),
|
|
41
|
+
dashLength: 10,
|
|
42
|
+
})
|
|
43
|
+
: Cesium.Material.fromType("Color", {
|
|
44
|
+
color: Cesium.Color.fromCssColorString(e.stroke),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function cartesian3Tgeography(e: any): number[] {
|
|
50
|
+
const r = Cesium.Cartographic.fromCartesian(e);
|
|
51
|
+
return [Cesium.Math.toDegrees(r.longitude), Cesium.Math.toDegrees(r.latitude), r.height];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function geographyTcartesian3(e: number[]) {
|
|
55
|
+
return Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const eyeOffset = new Cesium.Cartesian3(0, 0, -1);
|
|
59
|
+
|
|
60
|
+
export function drawPolyline(map: CesiumMap, polyline: Polyline<unknown>) {
|
|
61
|
+
const { event, viewer } = map;
|
|
62
|
+
let status = 0;
|
|
63
|
+
let skip = 0;
|
|
64
|
+
|
|
65
|
+
let material = createLineMaterial(polyline);
|
|
66
|
+
const appearance = new Cesium.PolylineMaterialAppearance({
|
|
67
|
+
material,
|
|
68
|
+
});
|
|
69
|
+
const markers = viewer.scene.primitives.add(
|
|
70
|
+
new Cesium.BillboardCollection({
|
|
71
|
+
show: polyline.show,
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const _event = {
|
|
76
|
+
cursor: polyline.cursor,
|
|
77
|
+
silent: polyline.silent,
|
|
78
|
+
onPointerIn() {
|
|
79
|
+
status == 2 && polyline.event.trigger("pointer-in");
|
|
80
|
+
},
|
|
81
|
+
onPointerOut() {
|
|
82
|
+
status == 2 && polyline.event.trigger("pointer-out");
|
|
83
|
+
},
|
|
84
|
+
onLClick() {
|
|
85
|
+
status == 2 && polyline.event.trigger("left-click");
|
|
86
|
+
},
|
|
87
|
+
onRClick() {
|
|
88
|
+
if (polyline.menu) {
|
|
89
|
+
map.menu.show(polyline.menu);
|
|
90
|
+
}
|
|
91
|
+
status == 2 && polyline.event.trigger("right-click");
|
|
92
|
+
},
|
|
93
|
+
onDbClick() {
|
|
94
|
+
polyline.editable &&
|
|
95
|
+
status == 2 &&
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
polyline.event.trigger("start-edit");
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
let primitive: any;
|
|
103
|
+
let cache: any[];
|
|
104
|
+
let activeNode: ChainNode<any, any>;
|
|
105
|
+
if (polyline.coordinates) {
|
|
106
|
+
status = 2;
|
|
107
|
+
cache = polyline.coordinates.map((e) => Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]));
|
|
108
|
+
primitive = new Cesium.Primitive({
|
|
109
|
+
show: polyline.show,
|
|
110
|
+
geometryInstances: new Cesium.GeometryInstance({
|
|
111
|
+
geometry: new Cesium.PolylineGeometry({
|
|
112
|
+
positions: cache,
|
|
113
|
+
width: polyline.lineWidth,
|
|
114
|
+
vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
|
|
115
|
+
}),
|
|
116
|
+
id: _event,
|
|
117
|
+
}),
|
|
118
|
+
appearance,
|
|
119
|
+
});
|
|
120
|
+
viewer.scene.primitives.add(primitive);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const editor = new PolylineEditor<any, any>();
|
|
124
|
+
|
|
125
|
+
editor.on("create-node", (n) => {
|
|
126
|
+
if (n.type == "node") {
|
|
127
|
+
const feature = markers.add({
|
|
128
|
+
position: new Cesium.Cartesian3(...n.position),
|
|
129
|
+
width: 16,
|
|
130
|
+
height: 16,
|
|
131
|
+
image: iconPoint,
|
|
132
|
+
eyeOffset,
|
|
133
|
+
id: {
|
|
134
|
+
cursor: "move",
|
|
135
|
+
onPointerDown() {
|
|
136
|
+
status = 4;
|
|
137
|
+
activeNode = n;
|
|
138
|
+
map.moveable = false;
|
|
139
|
+
},
|
|
140
|
+
onPointerUp() {
|
|
141
|
+
if (status == 4) {
|
|
142
|
+
status = 3;
|
|
143
|
+
map.moveable = true;
|
|
144
|
+
activeNode = undefined;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
onDbClick() {
|
|
148
|
+
n.destroy();
|
|
149
|
+
cache = editor.getCoordinates().map((e) => new Cesium.Cartesian3(...e));
|
|
150
|
+
initPrimitive();
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
n.shape = feature;
|
|
155
|
+
} else {
|
|
156
|
+
const feature = markers.add({
|
|
157
|
+
position: new Cesium.Cartesian3(...n.position),
|
|
158
|
+
width: 16,
|
|
159
|
+
height: 16,
|
|
160
|
+
image: iconAdd,
|
|
161
|
+
eyeOffset,
|
|
162
|
+
id: {
|
|
163
|
+
cursor: "pointer",
|
|
164
|
+
onPointerDown() {
|
|
165
|
+
status = 4;
|
|
166
|
+
activeNode = n.insert();
|
|
167
|
+
map.cursor = "move";
|
|
168
|
+
map.moveable = false;
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
n.shape = feature;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
editor.on("update-node", (n) => {
|
|
177
|
+
n.shape.position = new Cesium.Cartesian3(...n.position);
|
|
178
|
+
});
|
|
179
|
+
editor.on("remove-node", (n) => {
|
|
180
|
+
markers.remove(n.shape);
|
|
181
|
+
});
|
|
182
|
+
editor.on("empty", () => {
|
|
183
|
+
// markers.removeAll()
|
|
184
|
+
viewer.scene.primitives.remove(primitive);
|
|
185
|
+
status = 0;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const onUpdate = (e: Set<string>) => {
|
|
189
|
+
if (skip) {
|
|
190
|
+
skip--;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const keys = new Set();
|
|
194
|
+
e.forEach((key) => {
|
|
195
|
+
switch (key) {
|
|
196
|
+
case "show":
|
|
197
|
+
if (primitive) {
|
|
198
|
+
primitive.show = polyline.show;
|
|
199
|
+
markers.show = polyline.show;
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
case "editable":
|
|
203
|
+
break;
|
|
204
|
+
case "coordinates":
|
|
205
|
+
keys.add("Primitive");
|
|
206
|
+
break;
|
|
207
|
+
case "lineWidth":
|
|
208
|
+
keys.add("Primitive");
|
|
209
|
+
break;
|
|
210
|
+
case "icon":
|
|
211
|
+
keys.add("Material");
|
|
212
|
+
break;
|
|
213
|
+
case "flow":
|
|
214
|
+
keys.add("Material");
|
|
215
|
+
break;
|
|
216
|
+
case "stroke":
|
|
217
|
+
material.uniforms.color = Cesium.Color.fromCssColorString(polyline.stroke);
|
|
218
|
+
break;
|
|
219
|
+
case "dash":
|
|
220
|
+
keys.add("Material");
|
|
221
|
+
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
throw new Error(`${key} 还不支持修改`);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
keys.forEach((key) => {
|
|
228
|
+
switch (key) {
|
|
229
|
+
case "Primitive":
|
|
230
|
+
if (polyline.coordinates) {
|
|
231
|
+
cache = polyline.coordinates.map((e) => geographyTcartesian3(e));
|
|
232
|
+
} else {
|
|
233
|
+
cache = [];
|
|
234
|
+
markers.removeAll();
|
|
235
|
+
status = 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
initPrimitive();
|
|
239
|
+
|
|
240
|
+
break;
|
|
241
|
+
case "Material":
|
|
242
|
+
material = createLineMaterial(polyline);
|
|
243
|
+
appearance.material = material;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const onStartEdit = () => {
|
|
250
|
+
switch (status) {
|
|
251
|
+
case 2:
|
|
252
|
+
status = 3;
|
|
253
|
+
editor.setCoordinates(cache.map((e) => [e.x, e.y, e.z]));
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
let temp: any;
|
|
258
|
+
const onMouseMove = () => {
|
|
259
|
+
const e = event.geography;
|
|
260
|
+
|
|
261
|
+
switch (status) {
|
|
262
|
+
case 1:
|
|
263
|
+
cache.pop();
|
|
264
|
+
cache.push(Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]));
|
|
265
|
+
initPrimitive();
|
|
266
|
+
break;
|
|
267
|
+
case 4:
|
|
268
|
+
temp = Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2]);
|
|
269
|
+
activeNode.update([temp.x, temp.y, temp.z]);
|
|
270
|
+
cache = editor.getCoordinates().map((e) => new Cesium.Cartesian3(...e));
|
|
271
|
+
initPrimitive();
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const onClick = () => {
|
|
277
|
+
const e = event.geography;
|
|
278
|
+
switch (status) {
|
|
279
|
+
case 0:
|
|
280
|
+
status = 1;
|
|
281
|
+
cache = [Cesium.Cartesian3.fromDegrees(e[0], e[1], e[2])];
|
|
282
|
+
cache.push(cache[0]);
|
|
283
|
+
initPrimitive();
|
|
284
|
+
break;
|
|
285
|
+
case 1:
|
|
286
|
+
cache.push(cache[cache.length - 1]);
|
|
287
|
+
// geometry.setCoordinates(cache)
|
|
288
|
+
initPrimitive();
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const initPrimitive = () => {
|
|
294
|
+
primitive && viewer.scene.primitives.remove(primitive);
|
|
295
|
+
if (cache.length > 1) {
|
|
296
|
+
const geometry = Cesium.PolylineGeometry.createGeometry(
|
|
297
|
+
new Cesium.PolylineGeometry({
|
|
298
|
+
positions: cache,
|
|
299
|
+
width: polyline.lineWidth,
|
|
300
|
+
vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
|
|
301
|
+
}),
|
|
302
|
+
);
|
|
303
|
+
if (geometry) {
|
|
304
|
+
primitive = new Cesium.Primitive({
|
|
305
|
+
show: polyline.show,
|
|
306
|
+
asynchronous: false,
|
|
307
|
+
geometryInstances: new Cesium.GeometryInstance({
|
|
308
|
+
geometry,
|
|
309
|
+
id: _event,
|
|
310
|
+
}),
|
|
311
|
+
appearance,
|
|
312
|
+
});
|
|
313
|
+
viewer.scene.primitives.add(primitive);
|
|
314
|
+
} else {
|
|
315
|
+
primitive = undefined;
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
primitive = undefined;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const onDbClick = () => {
|
|
323
|
+
switch (status) {
|
|
324
|
+
case 1:
|
|
325
|
+
status = 2;
|
|
326
|
+
skip++;
|
|
327
|
+
cache.pop();
|
|
328
|
+
cache.pop();
|
|
329
|
+
// geometry.setCoordinates(cache)
|
|
330
|
+
polyline.coordinates = cache.map((e) => cartesian3Tgeography(e));
|
|
331
|
+
polyline.event.trigger("data-loaded");
|
|
332
|
+
polyline.event.trigger("pointer-in");
|
|
333
|
+
break;
|
|
334
|
+
case 3:
|
|
335
|
+
polyline.stopEdit();
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const onStopEdit = () => {
|
|
341
|
+
if (status == 3) {
|
|
342
|
+
status = 2;
|
|
343
|
+
skip++;
|
|
344
|
+
polyline.coordinates = editor.getCoordinates().map((e) => cartesian3Tgeography(e));
|
|
345
|
+
editor.setCoordinates([]);
|
|
346
|
+
polyline.event.trigger("pointer-in");
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const onDestroy = () => {
|
|
351
|
+
primitive && viewer.scene.primitives.remove(primitive);
|
|
352
|
+
viewer.scene.primitives.remove(markers);
|
|
353
|
+
event.off("pointer-move", onMouseMove);
|
|
354
|
+
event.off("left-click", onClick);
|
|
355
|
+
event.off("double-click", onDbClick);
|
|
356
|
+
polyline.event.off("update", onUpdate);
|
|
357
|
+
polyline.event.off("start-edit", onStartEdit);
|
|
358
|
+
polyline.event.off("stop-edit", onStopEdit);
|
|
359
|
+
polyline.event.off("destroy", onDestroy);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
event.on("pointer-move", onMouseMove);
|
|
363
|
+
event.on("left-click", onClick);
|
|
364
|
+
event.on("double-click", onDbClick);
|
|
365
|
+
polyline.event.on("update", onUpdate);
|
|
366
|
+
polyline.event.on("start-edit", onStartEdit);
|
|
367
|
+
polyline.event.on("stop-edit", onStopEdit);
|
|
368
|
+
polyline.event.on("destroy", onDestroy);
|
|
369
|
+
}
|