@vesium/plot 1.0.1-beta.51 → 1.0.1-beta.52
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/dist/index.cjs +1651 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -54
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +102 -54
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +1653 -110
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.cjs.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +1631 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -10
package/dist/index.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(exports, cesium, vesium, __vueuse_core, vue) {
|
|
1
|
+
(function(exports, cesium, vesium, __vueuse_core, vue, __turf_turf) {
|
|
2
2
|
|
|
3
3
|
//#region rolldown:runtime
|
|
4
4
|
var __create = Object.create;
|
|
@@ -27,6 +27,7 @@ cesium = __toESM(cesium);
|
|
|
27
27
|
vesium = __toESM(vesium);
|
|
28
28
|
__vueuse_core = __toESM(__vueuse_core);
|
|
29
29
|
vue = __toESM(vue);
|
|
30
|
+
__turf_turf = __toESM(__turf_turf);
|
|
30
31
|
|
|
31
32
|
//#region usePlot/PlotScheme.ts
|
|
32
33
|
var PlotScheme = class PlotScheme {
|
|
@@ -36,9 +37,7 @@ var PlotScheme = class PlotScheme {
|
|
|
36
37
|
this.allowManualComplete = options.allowManualComplete;
|
|
37
38
|
this.definingCursor = options.definingCursor ?? "crosshair";
|
|
38
39
|
this.skeletons = options.skeletons?.map((item) => item()) ?? [];
|
|
39
|
-
this.
|
|
40
|
-
this.initPrimitives = options.initPrimitives;
|
|
41
|
-
this.initGroundPrimitives = options.initGroundPrimitives;
|
|
40
|
+
this.initRender = options.initRender;
|
|
42
41
|
this.render = options.render;
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
@@ -65,17 +64,9 @@ var PlotScheme = class PlotScheme {
|
|
|
65
64
|
*/
|
|
66
65
|
skeletons;
|
|
67
66
|
/**
|
|
68
|
-
* 初始化时创建`Entity`的函数,创建后的`Entity`会作为配置项传入`render`中
|
|
69
|
-
*/
|
|
70
|
-
initEntites;
|
|
71
|
-
/**
|
|
72
|
-
* 初始化时创建`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
|
|
73
|
-
*/
|
|
74
|
-
initPrimitives;
|
|
75
|
-
/**
|
|
76
67
|
* 初始化时创建贴地`Primitive`的函数,创建后的`Primitive`会作为配置项传入`render`中
|
|
77
68
|
*/
|
|
78
|
-
|
|
69
|
+
initRender;
|
|
79
70
|
/**
|
|
80
71
|
* 当标绘数据变化时,会触发`render`回调,返回的数据会被添加到cesium中
|
|
81
72
|
*/
|
|
@@ -250,10 +241,13 @@ var SampledPlotProperty = class SampledPlotProperty {
|
|
|
250
241
|
* @template D 数据类型。
|
|
251
242
|
*/
|
|
252
243
|
getValue(time, result) {
|
|
253
|
-
result ??= {
|
|
244
|
+
result ??= {
|
|
245
|
+
time,
|
|
246
|
+
positions: []
|
|
247
|
+
};
|
|
254
248
|
Object.assign(result, {
|
|
255
249
|
time: time?.clone(),
|
|
256
|
-
positions:
|
|
250
|
+
positions: [],
|
|
257
251
|
derivative: void 0
|
|
258
252
|
});
|
|
259
253
|
if (!time) {
|
|
@@ -369,9 +363,10 @@ var PlotFeature = class {
|
|
|
369
363
|
this._disabled = disabled;
|
|
370
364
|
this._sampled = sampled instanceof SampledPlotProperty ? sampled : new SampledPlotProperty(sampled);
|
|
371
365
|
this._sampled.definitionChanged.addEventListener((property) => this._definitionChanged.raiseEvent(this, "sampled", property, property), this);
|
|
372
|
-
|
|
373
|
-
this.
|
|
374
|
-
this.
|
|
366
|
+
const init = this._scheme.initRender?.() ?? {};
|
|
367
|
+
this._entities = [...init.entities ?? []];
|
|
368
|
+
this._primitives = [...init.primitives ?? []];
|
|
369
|
+
this._groundPrimitives = [...init.groundPrimitives ?? []];
|
|
375
370
|
this._skeletons = [];
|
|
376
371
|
}
|
|
377
372
|
/**
|
|
@@ -942,9 +937,9 @@ function control() {
|
|
|
942
937
|
const positions = [...packable.positions ?? []];
|
|
943
938
|
const cartographic = (0, vesium.toCartographic)(positions[index]);
|
|
944
939
|
const r = height / 1e5;
|
|
945
|
-
const distance = r * Math.PI / 180 / 1e3;
|
|
946
|
-
cartographic.latitude += distance * Math.cos(newHeading);
|
|
947
|
-
cartographic.longitude += distance * Math.sin(newHeading);
|
|
940
|
+
const distance$1 = r * Math.PI / 180 / 1e3;
|
|
941
|
+
cartographic.latitude += distance$1 * Math.cos(newHeading);
|
|
942
|
+
cartographic.longitude += distance$1 * Math.sin(newHeading);
|
|
948
943
|
positions[index] = (0, vesium.toCartesian3)(cartographic);
|
|
949
944
|
sampled.setSample({
|
|
950
945
|
time: packable.time,
|
|
@@ -1207,7 +1202,7 @@ async function clampToHeightMostDetailedByTilesetOrTerrain(options) {
|
|
|
1207
1202
|
|
|
1208
1203
|
//#endregion
|
|
1209
1204
|
//#region measure/utils/triangleGrid.ts
|
|
1210
|
-
function defaultOptions$
|
|
1205
|
+
function defaultOptions$2(original) {
|
|
1211
1206
|
const clampToGround = original?.clampToGround ?? false;
|
|
1212
1207
|
const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
|
|
1213
1208
|
const density = Math.floor(original?.density ?? 10);
|
|
@@ -1226,7 +1221,7 @@ function defaultOptions$1(original) {
|
|
|
1226
1221
|
*/
|
|
1227
1222
|
async function triangleGrid(positions, options) {
|
|
1228
1223
|
if (positions.length < 3) throw new Error("positions must >= 3");
|
|
1229
|
-
const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$
|
|
1224
|
+
const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$2(options);
|
|
1230
1225
|
if (density <= 0) throw new Error("options.density must > 0");
|
|
1231
1226
|
const bbox = cesium.Rectangle.fromCartesianArray(positions);
|
|
1232
1227
|
const vertical = bbox.north - bbox.south;
|
|
@@ -1285,7 +1280,7 @@ function triangleArea(p0, p1, p2) {
|
|
|
1285
1280
|
const cross = cesium.Cartesian3.cross(v0, v1, v0);
|
|
1286
1281
|
return cesium.Cartesian3.magnitude(cross) * .5;
|
|
1287
1282
|
}
|
|
1288
|
-
function defaultOptions(original) {
|
|
1283
|
+
function defaultOptions$1(original) {
|
|
1289
1284
|
const clampToGround = original?.clampToGround ?? false;
|
|
1290
1285
|
const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
|
|
1291
1286
|
const density = Math.floor(original?.density ?? 10);
|
|
@@ -1303,7 +1298,7 @@ function defaultOptions(original) {
|
|
|
1303
1298
|
*/
|
|
1304
1299
|
async function area(positions, options) {
|
|
1305
1300
|
if (positions.length < 2) throw new Error("positions.length must >= 2");
|
|
1306
|
-
const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions(options);
|
|
1301
|
+
const { density, scene, clampToGround, classificationType, terrainProvider } = defaultOptions$1(options);
|
|
1307
1302
|
if (density <= 0) throw new Error("options.density must > 0");
|
|
1308
1303
|
if (!clampToGround) {
|
|
1309
1304
|
const triangles$1 = tesselate(positions);
|
|
@@ -1319,24 +1314,111 @@ async function area(positions, options) {
|
|
|
1319
1314
|
return triangles.reduce((count, current) => count += triangleArea(...current), 0);
|
|
1320
1315
|
}
|
|
1321
1316
|
|
|
1317
|
+
//#endregion
|
|
1318
|
+
//#region measure/utils/lerpArray.ts
|
|
1319
|
+
/**
|
|
1320
|
+
* 在起点和终点间进行插值, 返回的数组包括起点和终点,数组长度为 count+1
|
|
1321
|
+
*/
|
|
1322
|
+
async function lerpArray(options) {
|
|
1323
|
+
const { start, end, count, scene, clampToGround, classificationType, terrainProvider } = options;
|
|
1324
|
+
const result = [];
|
|
1325
|
+
for (let i = 0; i < count; i++) {
|
|
1326
|
+
const position = cesium.Cartesian3.lerp(start, end, 1 / count, new cesium.Cartesian3());
|
|
1327
|
+
result.push(position);
|
|
1328
|
+
}
|
|
1329
|
+
result.push(end.clone());
|
|
1330
|
+
if (!clampToGround) return result;
|
|
1331
|
+
if (!scene) throw new Error("scene is required on `clampToGround == true`.");
|
|
1332
|
+
const detaileds = await clampToHeightMostDetailedByTilesetOrTerrain({
|
|
1333
|
+
scene,
|
|
1334
|
+
terrainProvider,
|
|
1335
|
+
positions: result,
|
|
1336
|
+
classificationType
|
|
1337
|
+
});
|
|
1338
|
+
return detaileds;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region measure/utils/distance.ts
|
|
1343
|
+
function defaultOptions(original) {
|
|
1344
|
+
const clampToGround = original?.clampToGround ?? false;
|
|
1345
|
+
const classificationType = original?.classificationType ?? cesium.ClassificationType.BOTH;
|
|
1346
|
+
const density = Math.floor(original?.density ?? 50);
|
|
1347
|
+
return {
|
|
1348
|
+
scene: original?.scene,
|
|
1349
|
+
clampToGround,
|
|
1350
|
+
classificationType,
|
|
1351
|
+
terrainProvider: original?.terrainProvider,
|
|
1352
|
+
density
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* 计算多点位之间的距离
|
|
1357
|
+
* @param positions
|
|
1358
|
+
*/
|
|
1359
|
+
async function distance(positions, options) {
|
|
1360
|
+
if (positions.length < 2) throw new Error("positions.length must >= 2");
|
|
1361
|
+
const _options = defaultOptions(options);
|
|
1362
|
+
const stages = [];
|
|
1363
|
+
let count = 0;
|
|
1364
|
+
positions.forEach((position, index) => {
|
|
1365
|
+
if (index !== positions.length - 1) {
|
|
1366
|
+
const next = positions[index + 1];
|
|
1367
|
+
const distance$1 = cesium.Cartesian3.distance(position, next);
|
|
1368
|
+
stages.push(distance$1);
|
|
1369
|
+
count += distance$1;
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
if (!_options.clampToGround) return {
|
|
1373
|
+
stages,
|
|
1374
|
+
count
|
|
1375
|
+
};
|
|
1376
|
+
const density = _options.density;
|
|
1377
|
+
if (density <= 0) throw new Error("options.density must > 0");
|
|
1378
|
+
const densities = stages.map((stage) => {
|
|
1379
|
+
return Math.floor(stage / count * density);
|
|
1380
|
+
});
|
|
1381
|
+
const diff = density - densities.reduce((count$1, current) => count$1 += current, 0);
|
|
1382
|
+
if (diff) densities[densities.length - 1] += diff;
|
|
1383
|
+
const positionListPromises = densities.map((density$1, i) => {
|
|
1384
|
+
return lerpArray({
|
|
1385
|
+
scene: _options.scene,
|
|
1386
|
+
start: positions[i],
|
|
1387
|
+
end: positions[i + 1],
|
|
1388
|
+
count: density$1,
|
|
1389
|
+
clampToGround: true,
|
|
1390
|
+
classificationType: _options.classificationType,
|
|
1391
|
+
terrainProvider: _options.terrainProvider
|
|
1392
|
+
});
|
|
1393
|
+
});
|
|
1394
|
+
const detaileds = await Promise.all(positionListPromises);
|
|
1395
|
+
const stagePromises = detaileds.map(async (positions$1) => {
|
|
1396
|
+
const { count: count$1 } = await distance(positions$1);
|
|
1397
|
+
return count$1;
|
|
1398
|
+
});
|
|
1399
|
+
const groundStages = await Promise.all(stagePromises);
|
|
1400
|
+
return {
|
|
1401
|
+
stages: groundStages,
|
|
1402
|
+
count: groundStages.reduce((count$1, current) => count$1 += current, 0)
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1322
1406
|
//#endregion
|
|
1323
1407
|
//#region measure/measureArea.ts
|
|
1324
1408
|
const schemeMeasureArea = new PlotScheme({
|
|
1325
|
-
type: "
|
|
1409
|
+
type: "MeasureArea",
|
|
1326
1410
|
allowManualComplete: (packable) => packable.positions.length >= 3,
|
|
1327
1411
|
skeletons: [control, interval],
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
|
|
1331
|
-
polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
|
|
1332
|
-
})],
|
|
1333
|
-
render(options) {
|
|
1334
|
-
const { mouse, packable } = options;
|
|
1335
|
-
const entity = options.previous.entities?.[0] ?? new cesium.Entity({
|
|
1412
|
+
initRender() {
|
|
1413
|
+
return { entities: [new cesium.Entity({
|
|
1336
1414
|
label: { font: "14pt" },
|
|
1337
1415
|
polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
|
|
1338
1416
|
polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
|
|
1339
|
-
});
|
|
1417
|
+
})] };
|
|
1418
|
+
},
|
|
1419
|
+
render(context) {
|
|
1420
|
+
const entity = context.previous.entities[0];
|
|
1421
|
+
const { mouse, packable } = context;
|
|
1340
1422
|
const positions = [...packable.positions ?? []];
|
|
1341
1423
|
mouse && positions.push(mouse);
|
|
1342
1424
|
if (positions.length === 2) {
|
|
@@ -1368,19 +1450,67 @@ const schemeMeasureArea = new PlotScheme({
|
|
|
1368
1450
|
});
|
|
1369
1451
|
|
|
1370
1452
|
//#endregion
|
|
1371
|
-
//#region
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1453
|
+
//#region measure/measureDistance.ts
|
|
1454
|
+
const schemeMeasureDistance = new PlotScheme({
|
|
1455
|
+
type: "MeasureDistance",
|
|
1456
|
+
allowManualComplete: (packable) => packable.positions.length >= 2,
|
|
1457
|
+
skeletons: [control],
|
|
1458
|
+
initRender() {
|
|
1459
|
+
return { entities: [new cesium.Entity({ polyline: {
|
|
1460
|
+
width: 2,
|
|
1461
|
+
material: cesium.Color.YELLOW.withAlpha(.5)
|
|
1462
|
+
} })] };
|
|
1463
|
+
},
|
|
1464
|
+
render(context) {
|
|
1465
|
+
const entity = context.previous.entities[0];
|
|
1466
|
+
const { mouse, packable, previous } = context;
|
|
1467
|
+
const entities = previous.entities;
|
|
1468
|
+
const positions = [...packable.positions ?? []];
|
|
1469
|
+
mouse && positions.push(mouse);
|
|
1470
|
+
if (positions.length < 2) return { entities };
|
|
1471
|
+
const pl = entities[0];
|
|
1472
|
+
pl.polyline ??= new cesium.PolylineGraphics();
|
|
1473
|
+
pl.polyline.positions = new cesium.CallbackProperty(() => positions, false);
|
|
1474
|
+
positions.forEach((item, index) => {
|
|
1475
|
+
if (!entities[index + 1]) entities[index + 1] = new cesium.Entity({
|
|
1476
|
+
position: item,
|
|
1477
|
+
label: new cesium.LabelGraphics({
|
|
1478
|
+
backgroundColor: cesium.Color.fromCssColorString("#fff"),
|
|
1479
|
+
font: "12pt sans-serif"
|
|
1480
|
+
})
|
|
1481
|
+
});
|
|
1482
|
+
});
|
|
1483
|
+
entities.splice(positions.length, entities.length - positions.length - 1);
|
|
1484
|
+
distance(positions).then(({ count, stages }) => {
|
|
1485
|
+
stages.forEach((stage, index) => {
|
|
1486
|
+
entities[index + 1].position = new cesium.CallbackPositionProperty(() => cesium.Cartesian3.midpoint(positions[index], positions[index + 1], new cesium.Cartesian3()), false);
|
|
1487
|
+
entities[index + 1].label.text = new cesium.CallbackProperty(() => `${stage.toFixed(2)} m`, false);
|
|
1488
|
+
});
|
|
1489
|
+
if (stages.length > 1) {
|
|
1490
|
+
entities[entities.length - 1].position = new cesium.CallbackPositionProperty(() => positions[positions.length - 1], false);
|
|
1491
|
+
entities[entities.length - 1].label.text = new cesium.CallbackProperty(() => `${count.toFixed(2)} m`, false);
|
|
1492
|
+
} else {
|
|
1493
|
+
entities[entities.length - 1].position = void 0;
|
|
1494
|
+
entities[entities.length - 1].label.text = void 0;
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
return { entities };
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
|
|
1501
|
+
//#endregion
|
|
1502
|
+
//#region scheme/Billboard.ts
|
|
1503
|
+
const PlotSchemeBillboard = new PlotScheme({
|
|
1504
|
+
type: "Billboard",
|
|
1377
1505
|
complete: (packable) => packable.positions.length >= 1,
|
|
1378
1506
|
skeletons: [moved],
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1507
|
+
initRender: () => {
|
|
1508
|
+
return { entities: [new cesium.Entity({ billboard: {
|
|
1509
|
+
image: "/favicon.svg",
|
|
1510
|
+
width: 32,
|
|
1511
|
+
height: 32
|
|
1512
|
+
} })] };
|
|
1513
|
+
},
|
|
1384
1514
|
render(options) {
|
|
1385
1515
|
const { mouse, packable } = options;
|
|
1386
1516
|
const entity = options.previous.entities?.[0] ?? new cesium.Entity({ billboard: {} });
|
|
@@ -1391,47 +1521,130 @@ const schemeBillboard = new PlotScheme({
|
|
|
1391
1521
|
});
|
|
1392
1522
|
|
|
1393
1523
|
//#endregion
|
|
1394
|
-
//#region scheme/
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
*/
|
|
1398
|
-
const schemeLabel = new PlotScheme({
|
|
1399
|
-
type: "label",
|
|
1524
|
+
//#region scheme/BillboardPinBuilder.ts
|
|
1525
|
+
const PlotSchemeBillboardPinBuilder = new PlotScheme({
|
|
1526
|
+
type: "BillboardPinBuilder",
|
|
1400
1527
|
complete: (packable) => packable.positions.length >= 1,
|
|
1401
1528
|
skeletons: [moved],
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
const
|
|
1529
|
+
initRender() {
|
|
1530
|
+
return { entities: [new cesium.Entity({ billboard: {} })] };
|
|
1531
|
+
},
|
|
1532
|
+
render(context) {
|
|
1533
|
+
const entity = context.previous.entities[0];
|
|
1534
|
+
const position = context.packable.positions[0] ?? context.mouse;
|
|
1407
1535
|
entity.position = new cesium.CallbackPositionProperty(() => position, true);
|
|
1408
1536
|
return { entities: [entity] };
|
|
1409
1537
|
}
|
|
1410
1538
|
});
|
|
1411
1539
|
|
|
1412
1540
|
//#endregion
|
|
1413
|
-
//#region scheme/
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1541
|
+
//#region scheme/Cylinder.ts
|
|
1542
|
+
const PlotSchemeCylinder = new PlotScheme({
|
|
1543
|
+
type: "Cylinder",
|
|
1544
|
+
complete: (packable) => packable.positions.length >= 2,
|
|
1545
|
+
skeletons: [moved, control],
|
|
1546
|
+
initRender() {
|
|
1547
|
+
return { entities: [new cesium.Entity({ cylinder: {} })] };
|
|
1548
|
+
},
|
|
1549
|
+
render(context) {
|
|
1550
|
+
const entity = context.previous.entities[0];
|
|
1551
|
+
const positions = [...context.packable.positions];
|
|
1552
|
+
if (positions.length === 0) return context.previous;
|
|
1553
|
+
if (positions.length === 1) {
|
|
1554
|
+
const position = context.mouse;
|
|
1555
|
+
position && positions.push(position);
|
|
1556
|
+
}
|
|
1557
|
+
if (positions.length < 2) return context.previous;
|
|
1558
|
+
entity.position = new cesium.ConstantPositionProperty(positions[0]);
|
|
1559
|
+
const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
|
|
1560
|
+
entity.cylinder.bottomRadius = new cesium.CallbackProperty(() => radius, false);
|
|
1561
|
+
if (context.defining || !(0, vesium.toPropertyValue)(entity.cylinder.length)) entity.cylinder.length = (0, vesium.toProperty)(radius * 2);
|
|
1562
|
+
return { entities: [entity] };
|
|
1563
|
+
}
|
|
1564
|
+
});
|
|
1565
|
+
|
|
1566
|
+
//#endregion
|
|
1567
|
+
//#region scheme/Ellipse.ts
|
|
1568
|
+
const PlotSchemeEllipse = new PlotScheme({
|
|
1569
|
+
type: "Ellipse",
|
|
1570
|
+
complete: (packable) => packable.positions.length >= 2,
|
|
1571
|
+
skeletons: [moved, control],
|
|
1572
|
+
initRender() {
|
|
1573
|
+
return { entities: [new cesium.Entity({ ellipse: {} })] };
|
|
1574
|
+
},
|
|
1575
|
+
render(context) {
|
|
1576
|
+
const entity = context.previous.entities[0];
|
|
1577
|
+
const positions = [...context.packable.positions];
|
|
1578
|
+
if (positions.length === 0) return context.previous;
|
|
1579
|
+
if (positions.length === 1) {
|
|
1580
|
+
const position = context.mouse;
|
|
1581
|
+
position && positions.push(position);
|
|
1582
|
+
}
|
|
1583
|
+
if (positions.length < 2) return context.previous;
|
|
1584
|
+
entity.position = new cesium.ConstantPositionProperty(positions[0]);
|
|
1585
|
+
const radius = cesium.Cartesian3.distance(positions[0], positions[1]);
|
|
1586
|
+
entity.ellipse.semiMinorAxis = new cesium.CallbackProperty(() => radius || 1, false);
|
|
1587
|
+
entity.ellipse.semiMajorAxis = entity.ellipse.semiMinorAxis;
|
|
1588
|
+
return { entities: [entity] };
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
//#endregion
|
|
1593
|
+
//#region scheme/Label.ts
|
|
1594
|
+
const PlotSchemeLabel = new PlotScheme({
|
|
1595
|
+
type: "Label",
|
|
1596
|
+
complete: (packable) => packable.positions.length >= 1,
|
|
1597
|
+
skeletons: [moved],
|
|
1598
|
+
initRender() {
|
|
1599
|
+
return { entities: [new cesium.Entity({ label: { text: "Label" } })] };
|
|
1600
|
+
},
|
|
1601
|
+
render(context) {
|
|
1602
|
+
const entity = context.previous.entities[0];
|
|
1603
|
+
const position = context.packable.positions[0] ?? context.mouse;
|
|
1604
|
+
entity.position = new cesium.CallbackPositionProperty(() => position, true);
|
|
1605
|
+
return { entities: [entity] };
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
//#endregion
|
|
1610
|
+
//#region scheme/Point.ts
|
|
1611
|
+
const PlotSchemePoint = new PlotScheme({
|
|
1612
|
+
type: "Point",
|
|
1613
|
+
complete: (packable) => packable.positions.length >= 1,
|
|
1614
|
+
skeletons: [moved],
|
|
1615
|
+
initRender() {
|
|
1616
|
+
return { entities: [new cesium.Entity({ point: {
|
|
1617
|
+
pixelSize: 10,
|
|
1618
|
+
color: cesium.Color.RED
|
|
1619
|
+
} })] };
|
|
1620
|
+
},
|
|
1621
|
+
render(context) {
|
|
1622
|
+
const entity = context.previous.entities[0];
|
|
1623
|
+
const position = context.packable.positions[0] ?? context.mouse;
|
|
1624
|
+
entity.position = new cesium.CallbackPositionProperty(() => position, true);
|
|
1625
|
+
return { entities: [entity] };
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
|
|
1629
|
+
//#endregion
|
|
1630
|
+
//#region scheme/Polygon.ts
|
|
1631
|
+
const PlotSchemePolygon = new PlotScheme({
|
|
1632
|
+
type: "Polygon",
|
|
1633
|
+
allowManualComplete: (packable) => packable.positions.length >= 2,
|
|
1420
1634
|
skeletons: [
|
|
1635
|
+
moved,
|
|
1421
1636
|
control,
|
|
1422
|
-
interval
|
|
1423
|
-
moved
|
|
1637
|
+
interval
|
|
1424
1638
|
],
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1639
|
+
initRender: () => {
|
|
1640
|
+
return { entities: [new cesium.Entity({
|
|
1641
|
+
polyline: {},
|
|
1642
|
+
polygon: {}
|
|
1643
|
+
})] };
|
|
1644
|
+
},
|
|
1429
1645
|
render(options) {
|
|
1430
1646
|
const { mouse, packable } = options;
|
|
1431
|
-
const entity = options.previous.entities
|
|
1432
|
-
polyline: { material: cesium.Color.YELLOW.withAlpha(.5) },
|
|
1433
|
-
polygon: { material: cesium.Color.YELLOW.withAlpha(.5) }
|
|
1434
|
-
});
|
|
1647
|
+
const entity = options.previous.entities[0];
|
|
1435
1648
|
const positions = [...packable.positions ?? []];
|
|
1436
1649
|
mouse && positions.push(mouse);
|
|
1437
1650
|
if (positions.length === 2) {
|
|
@@ -1452,51 +1665,1362 @@ const schemePolygon = new PlotScheme({
|
|
|
1452
1665
|
});
|
|
1453
1666
|
|
|
1454
1667
|
//#endregion
|
|
1455
|
-
//#region
|
|
1668
|
+
//#region geom/helper.ts
|
|
1669
|
+
const FITTING_COUNT = 100;
|
|
1670
|
+
const HALF_PI = Math.PI / 2;
|
|
1671
|
+
const ZERO_TOLERANCE = 1e-4;
|
|
1672
|
+
const TWO_PI = Math.PI * 2;
|
|
1673
|
+
/**
|
|
1674
|
+
* 计算两个坐标之间的距离
|
|
1675
|
+
* @param coord1
|
|
1676
|
+
* @param coord2
|
|
1677
|
+
*/
|
|
1678
|
+
function mathDistance(coord1, coord2) {
|
|
1679
|
+
return Math.hypot(coord1[0] - coord2[0], coord1[1] - coord2[1]);
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* 计算点集合的总距离
|
|
1683
|
+
* @param points
|
|
1684
|
+
*/
|
|
1685
|
+
function wholeDistance(points) {
|
|
1686
|
+
let distance$1 = 0;
|
|
1687
|
+
if (points && Array.isArray(points) && points.length > 0) points.forEach((item, index) => {
|
|
1688
|
+
if (index < points.length - 1) distance$1 += mathDistance(item, points[index + 1]);
|
|
1689
|
+
});
|
|
1690
|
+
return distance$1;
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* 获取基础长度
|
|
1694
|
+
* @param points
|
|
1695
|
+
*/
|
|
1696
|
+
const getBaseLength = (points) => wholeDistance(points) ** .99;
|
|
1697
|
+
/**
|
|
1698
|
+
* 求取两个坐标的中间坐标
|
|
1699
|
+
* @param coord1
|
|
1700
|
+
* @param coord2
|
|
1701
|
+
*/
|
|
1702
|
+
function mid(coord1, coord2) {
|
|
1703
|
+
return [(coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2];
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* 通过三个点确定一个圆的中心点
|
|
1707
|
+
* @param coord1
|
|
1708
|
+
* @param coord2
|
|
1709
|
+
* @param coord3
|
|
1710
|
+
*/
|
|
1711
|
+
function getCircleCenterOfThreeCoords(coord1, coord2, coord3) {
|
|
1712
|
+
const coordA = [(coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2];
|
|
1713
|
+
const coordB = [coordA[0] - coord1[1] + coord2[1], coordA[1] + coord1[0] - coord2[0]];
|
|
1714
|
+
const coordC = [(coord1[0] + coord3[0]) / 2, (coord1[1] + coord3[1]) / 2];
|
|
1715
|
+
const coordD = [coordC[0] - coord1[1] + coord3[1], coordC[1] + coord1[0] - coord3[0]];
|
|
1716
|
+
return getIntersectCoord(coordA, coordB, coordC, coordD);
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* 获取交集的点
|
|
1720
|
+
* @param coordA
|
|
1721
|
+
* @param coordB
|
|
1722
|
+
* @param coordC
|
|
1723
|
+
* @param coordD
|
|
1724
|
+
*/
|
|
1725
|
+
function getIntersectCoord(coordA, coordB, coordC, coordD) {
|
|
1726
|
+
if (coordA[1] === coordB[1]) {
|
|
1727
|
+
const f$1 = (coordD[0] - coordC[0]) / (coordD[1] - coordC[1]);
|
|
1728
|
+
const x$1 = f$1 * (coordA[1] - coordC[1]) + coordC[0];
|
|
1729
|
+
const y$1 = coordA[1];
|
|
1730
|
+
return [x$1, y$1];
|
|
1731
|
+
}
|
|
1732
|
+
if (coordC[1] === coordD[1]) {
|
|
1733
|
+
const e$1 = (coordB[0] - coordA[0]) / (coordB[1] - coordA[1]);
|
|
1734
|
+
const x$1 = e$1 * (coordC[1] - coordA[1]) + coordA[0];
|
|
1735
|
+
const y$1 = coordC[1];
|
|
1736
|
+
return [x$1, y$1];
|
|
1737
|
+
}
|
|
1738
|
+
const e = (coordB[0] - coordA[0]) / (coordB[1] - coordA[1]);
|
|
1739
|
+
const f = (coordD[0] - coordC[0]) / (coordD[1] - coordC[1]);
|
|
1740
|
+
const y = (e * coordA[1] - coordA[0] - f * coordC[1] + coordC[0]) / (e - f);
|
|
1741
|
+
const x = e * y - e * coordA[1] + coordA[0];
|
|
1742
|
+
return [x, y];
|
|
1743
|
+
}
|
|
1744
|
+
/**
|
|
1745
|
+
* 获取方位角(地平经度)
|
|
1746
|
+
* @param startCoord
|
|
1747
|
+
* @param endCoord
|
|
1748
|
+
*/
|
|
1749
|
+
function getAzimuth(startCoord, endCoord) {
|
|
1750
|
+
let azimuth = 0;
|
|
1751
|
+
const angle = Math.asin(Math.abs(endCoord[1] - startCoord[1]) / mathDistance(startCoord, endCoord));
|
|
1752
|
+
if (endCoord[1] >= startCoord[1] && endCoord[0] >= startCoord[0]) azimuth = angle + Math.PI;
|
|
1753
|
+
else if (endCoord[1] >= startCoord[1] && endCoord[0] < startCoord[0]) azimuth = Math.PI * 2 - angle;
|
|
1754
|
+
else if (endCoord[1] < startCoord[1] && endCoord[0] < startCoord[0]) azimuth = angle;
|
|
1755
|
+
else if (endCoord[1] < startCoord[1] && endCoord[0] >= startCoord[0]) azimuth = Math.PI - angle;
|
|
1756
|
+
return azimuth;
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* 通过三个点获取方位角
|
|
1760
|
+
* @param coordA
|
|
1761
|
+
* @param coordB
|
|
1762
|
+
* @param coordC
|
|
1763
|
+
*/
|
|
1764
|
+
function getAngleOfThreeCoords(coordA, coordB, coordC) {
|
|
1765
|
+
const angle = getAzimuth(coordB, coordA) - getAzimuth(coordB, coordC);
|
|
1766
|
+
return angle < 0 ? angle + Math.PI * 2 : angle;
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* 判断是否是顺时针
|
|
1770
|
+
* @param coord1
|
|
1771
|
+
* @param coord2
|
|
1772
|
+
* @param coord3
|
|
1773
|
+
*/
|
|
1774
|
+
function isClockWise(coord1, coord2, coord3) {
|
|
1775
|
+
return (coord3[1] - coord1[1]) * (coord2[0] - coord1[0]) > (coord2[1] - coord1[1]) * (coord3[0] - coord1[0]);
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* 获取立方值
|
|
1779
|
+
*/
|
|
1780
|
+
function getCubicValue(t, startCoord, coord1, coord2, endCoord) {
|
|
1781
|
+
t = Math.max(Math.min(t, 1), 0);
|
|
1782
|
+
const [tp, t2] = [1 - t, t * t];
|
|
1783
|
+
const t3 = t2 * t;
|
|
1784
|
+
const tp2 = tp * tp;
|
|
1785
|
+
const tp3 = tp2 * tp;
|
|
1786
|
+
const x = tp3 * startCoord[0] + 3 * tp2 * t * coord1[0] + 3 * tp * t2 * coord2[0] + t3 * endCoord[0];
|
|
1787
|
+
const y = tp3 * startCoord[1] + 3 * tp2 * t * coord1[1] + 3 * tp * t2 * coord2[1] + t3 * endCoord[1];
|
|
1788
|
+
return [x, y];
|
|
1789
|
+
}
|
|
1790
|
+
/**
|
|
1791
|
+
* 根据起止点和旋转方向求取第三个点
|
|
1792
|
+
* @param startCoord
|
|
1793
|
+
* @param endCoord
|
|
1794
|
+
* @param angle
|
|
1795
|
+
* @param distance
|
|
1796
|
+
* @param clockWise
|
|
1797
|
+
*/
|
|
1798
|
+
function getThirdCoord(startCoord, endCoord, angle, distance$1, clockWise) {
|
|
1799
|
+
const azimuth = getAzimuth(startCoord, endCoord);
|
|
1800
|
+
const alpha = clockWise ? azimuth + angle : azimuth - angle;
|
|
1801
|
+
const dx = distance$1 * Math.cos(alpha);
|
|
1802
|
+
const dy = distance$1 * Math.sin(alpha);
|
|
1803
|
+
return [endCoord[0] + dx, endCoord[1] + dy];
|
|
1804
|
+
}
|
|
1805
|
+
/**
|
|
1806
|
+
* 插值弓形线段点
|
|
1807
|
+
* @param center
|
|
1808
|
+
* @param radius
|
|
1809
|
+
* @param startAngle
|
|
1810
|
+
* @param endAngle
|
|
1811
|
+
*/
|
|
1812
|
+
function getArcCoords(center, radius, startAngle, endAngle) {
|
|
1813
|
+
let [x, y, coords, angleDiff] = [
|
|
1814
|
+
0,
|
|
1815
|
+
0,
|
|
1816
|
+
[],
|
|
1817
|
+
endAngle - startAngle
|
|
1818
|
+
];
|
|
1819
|
+
angleDiff = angleDiff < 0 ? angleDiff + Math.PI * 2 : angleDiff;
|
|
1820
|
+
for (let i = 0; i <= 100; i++) {
|
|
1821
|
+
const angle = startAngle + angleDiff * i / 100;
|
|
1822
|
+
x = center[0] + radius * Math.cos(angle);
|
|
1823
|
+
y = center[1] + radius * Math.sin(angle);
|
|
1824
|
+
coords.push([x, y]);
|
|
1825
|
+
}
|
|
1826
|
+
return coords;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* getBisectorNormals
|
|
1830
|
+
* @param t
|
|
1831
|
+
* @param coord1
|
|
1832
|
+
* @param coord2
|
|
1833
|
+
* @param coord3
|
|
1834
|
+
*/
|
|
1835
|
+
function getBisectorNormals(t, coord1, coord2, coord3) {
|
|
1836
|
+
const normal = getNormal(coord1, coord2, coord3);
|
|
1837
|
+
let [bisectorNormalRight, bisectorNormalLeft, dt, x, y] = [
|
|
1838
|
+
[0, 0],
|
|
1839
|
+
[0, 0],
|
|
1840
|
+
0,
|
|
1841
|
+
0,
|
|
1842
|
+
0
|
|
1843
|
+
];
|
|
1844
|
+
const dist = Math.hypot(normal[0], normal[1]);
|
|
1845
|
+
const uX = normal[0] / dist;
|
|
1846
|
+
const uY = normal[1] / dist;
|
|
1847
|
+
const d1 = mathDistance(coord1, coord2);
|
|
1848
|
+
const d2 = mathDistance(coord2, coord3);
|
|
1849
|
+
if (dist > ZERO_TOLERANCE) if (isClockWise(coord1, coord2, coord3)) {
|
|
1850
|
+
dt = t * d1;
|
|
1851
|
+
x = coord2[0] - dt * uY;
|
|
1852
|
+
y = coord2[1] + dt * uX;
|
|
1853
|
+
bisectorNormalRight = [x, y];
|
|
1854
|
+
dt = t * d2;
|
|
1855
|
+
x = coord2[0] + dt * uY;
|
|
1856
|
+
y = coord2[1] - dt * uX;
|
|
1857
|
+
bisectorNormalLeft = [x, y];
|
|
1858
|
+
} else {
|
|
1859
|
+
dt = t * d1;
|
|
1860
|
+
x = coord2[0] + dt * uY;
|
|
1861
|
+
y = coord2[1] - dt * uX;
|
|
1862
|
+
bisectorNormalRight = [x, y];
|
|
1863
|
+
dt = t * d2;
|
|
1864
|
+
x = coord2[0] - dt * uY;
|
|
1865
|
+
y = coord2[1] + dt * uX;
|
|
1866
|
+
bisectorNormalLeft = [x, y];
|
|
1867
|
+
}
|
|
1868
|
+
else {
|
|
1869
|
+
x = coord2[0] + t * (coord1[0] - coord2[0]);
|
|
1870
|
+
y = coord2[1] + t * (coord1[1] - coord2[1]);
|
|
1871
|
+
bisectorNormalRight = [x, y];
|
|
1872
|
+
x = coord2[0] + t * (coord3[0] - coord2[0]);
|
|
1873
|
+
y = coord2[1] + t * (coord3[1] - coord2[1]);
|
|
1874
|
+
bisectorNormalLeft = [x, y];
|
|
1875
|
+
}
|
|
1876
|
+
return [bisectorNormalRight, bisectorNormalLeft];
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* 获取默认三点的内切圆
|
|
1880
|
+
* @param coord1
|
|
1881
|
+
* @param coord2
|
|
1882
|
+
* @param coord3
|
|
1883
|
+
*/
|
|
1884
|
+
function getNormal(coord1, coord2, coord3) {
|
|
1885
|
+
let dX1 = coord1[0] - coord2[0];
|
|
1886
|
+
let dY1 = coord1[1] - coord2[1];
|
|
1887
|
+
const d1 = Math.hypot(dX1, dY1);
|
|
1888
|
+
dX1 /= d1;
|
|
1889
|
+
dY1 /= d1;
|
|
1890
|
+
let dX2 = coord3[0] - coord2[0];
|
|
1891
|
+
let dY2 = coord3[1] - coord2[1];
|
|
1892
|
+
const d2 = Math.hypot(dX2, dY2);
|
|
1893
|
+
dX2 /= d2;
|
|
1894
|
+
dY2 /= d2;
|
|
1895
|
+
const uX = dX1 + dX2;
|
|
1896
|
+
const uY = dY1 + dY2;
|
|
1897
|
+
return [uX, uY];
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* 贝塞尔曲线
|
|
1901
|
+
* @param points
|
|
1902
|
+
*/
|
|
1903
|
+
function getBezierCoords(points) {
|
|
1904
|
+
if (points.length <= 2) return points;
|
|
1905
|
+
const bezierCoords = [];
|
|
1906
|
+
const n = points.length - 1;
|
|
1907
|
+
for (let t = 0; t <= 1; t += .01) {
|
|
1908
|
+
let [x, y] = [0, 0];
|
|
1909
|
+
for (let index = 0; index <= n; index++) {
|
|
1910
|
+
const factor = getBinomialFactor(n, index);
|
|
1911
|
+
const a = t ** index;
|
|
1912
|
+
const b = (1 - t) ** (n - index);
|
|
1913
|
+
x += factor * a * b * points[index][0];
|
|
1914
|
+
y += factor * a * b * points[index][1];
|
|
1915
|
+
}
|
|
1916
|
+
bezierCoords.push([x, y]);
|
|
1917
|
+
}
|
|
1918
|
+
bezierCoords.push(points[n]);
|
|
1919
|
+
return bezierCoords;
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* 获取阶乘数据
|
|
1923
|
+
* @param n
|
|
1924
|
+
*/
|
|
1925
|
+
function getFactorial(n) {
|
|
1926
|
+
let result = 1;
|
|
1927
|
+
switch (true) {
|
|
1928
|
+
case n <= 1:
|
|
1929
|
+
result = 1;
|
|
1930
|
+
break;
|
|
1931
|
+
case n === 2:
|
|
1932
|
+
result = 2;
|
|
1933
|
+
break;
|
|
1934
|
+
case n === 3:
|
|
1935
|
+
result = 6;
|
|
1936
|
+
break;
|
|
1937
|
+
case n === 24:
|
|
1938
|
+
result = 24;
|
|
1939
|
+
break;
|
|
1940
|
+
case n === 5:
|
|
1941
|
+
result = 120;
|
|
1942
|
+
break;
|
|
1943
|
+
default:
|
|
1944
|
+
for (let i = 1; i <= n; i++) result *= i;
|
|
1945
|
+
break;
|
|
1946
|
+
}
|
|
1947
|
+
return result;
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* 获取二项分布
|
|
1951
|
+
* @param n
|
|
1952
|
+
* @param index
|
|
1953
|
+
*/
|
|
1954
|
+
function getBinomialFactor(n, index) {
|
|
1955
|
+
return getFactorial(n) / (getFactorial(index) * getFactorial(n - index));
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* 插值线性点
|
|
1959
|
+
* @param points
|
|
1960
|
+
*/
|
|
1961
|
+
function getQBSplineCoords(points) {
|
|
1962
|
+
if (points.length <= 2) return points;
|
|
1963
|
+
const [n, bSplineCoords] = [2, []];
|
|
1964
|
+
const m = points.length - n - 1;
|
|
1965
|
+
bSplineCoords.push(points[0]);
|
|
1966
|
+
for (let i = 0; i <= m; i++) for (let t = 0; t <= 1; t += .05) {
|
|
1967
|
+
let [x, y] = [0, 0];
|
|
1968
|
+
for (let k = 0; k <= n; k++) {
|
|
1969
|
+
const factor = getQuadricBSplineFactor(k, t);
|
|
1970
|
+
x += factor * points[i + k][0];
|
|
1971
|
+
y += factor * points[i + k][1];
|
|
1972
|
+
}
|
|
1973
|
+
bSplineCoords.push([x, y]);
|
|
1974
|
+
}
|
|
1975
|
+
bSplineCoords.push(points.at(-1));
|
|
1976
|
+
return bSplineCoords;
|
|
1977
|
+
}
|
|
1978
|
+
/**
|
|
1979
|
+
* 得到二次线性因子
|
|
1980
|
+
* @param k
|
|
1981
|
+
* @param t
|
|
1982
|
+
*/
|
|
1983
|
+
function getQuadricBSplineFactor(k, t) {
|
|
1984
|
+
let res = 0;
|
|
1985
|
+
if (k === 0) res = (t - 1) ** 2 / 2;
|
|
1986
|
+
else if (k === 1) res = (-2 * t ** 2 + 2 * t + 1) / 2;
|
|
1987
|
+
else if (k === 2) res = t ** 2 / 2;
|
|
1988
|
+
return res;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
//#endregion
|
|
1992
|
+
//#region geom/arc.ts
|
|
1993
|
+
/**
|
|
1994
|
+
* 标绘画弓形算法,继承线要素相关方法和属性
|
|
1995
|
+
*/
|
|
1996
|
+
function arc(coords) {
|
|
1997
|
+
const coordlength = coords.length;
|
|
1998
|
+
if (coordlength <= 2) throw new Error("coords.length must >= 3");
|
|
1999
|
+
else {
|
|
2000
|
+
let [coord1, coord2, coord3, startAngle, endAngle] = [
|
|
2001
|
+
coords[0],
|
|
2002
|
+
coords[1],
|
|
2003
|
+
coords[2],
|
|
2004
|
+
0,
|
|
2005
|
+
0
|
|
2006
|
+
];
|
|
2007
|
+
const center = getCircleCenterOfThreeCoords(coord1, coord2, coord3);
|
|
2008
|
+
const radius = mathDistance(coord1, center);
|
|
2009
|
+
const angle1 = getAzimuth(coord1, center);
|
|
2010
|
+
const angle2 = getAzimuth(coord2, center);
|
|
2011
|
+
if (isClockWise(coord1, coord2, coord3)) {
|
|
2012
|
+
startAngle = angle2;
|
|
2013
|
+
endAngle = angle1;
|
|
2014
|
+
} else {
|
|
2015
|
+
startAngle = angle1;
|
|
2016
|
+
endAngle = angle2;
|
|
2017
|
+
}
|
|
2018
|
+
return getArcCoords(center, radius, startAngle, endAngle);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
//#endregion
|
|
2023
|
+
//#region geom/arrowAttackDirection.ts
|
|
2024
|
+
/**
|
|
2025
|
+
* 尖曲箭头
|
|
2026
|
+
*/
|
|
2027
|
+
function arrowAttackDirection(coords, options = {}) {
|
|
2028
|
+
const coordLength = coords.length;
|
|
2029
|
+
if (coordLength < 3) throw new Error("coords.length must >= 3");
|
|
2030
|
+
else {
|
|
2031
|
+
let [tailLeft, tailRight] = [coords[0], coords[1]];
|
|
2032
|
+
if (isClockWise(coords[0], coords[1], coords[2])) {
|
|
2033
|
+
tailLeft = coords[1];
|
|
2034
|
+
tailRight = coords[0];
|
|
2035
|
+
}
|
|
2036
|
+
const midTail = mid(tailLeft, tailRight);
|
|
2037
|
+
const boneCoords = [midTail].concat(coords.slice(2));
|
|
2038
|
+
const headCoords = getArrowHeadCoords(boneCoords, {
|
|
2039
|
+
tailLeft,
|
|
2040
|
+
tailRight,
|
|
2041
|
+
...options
|
|
2042
|
+
});
|
|
2043
|
+
if (headCoords && headCoords.length > 4) {
|
|
2044
|
+
const [neckLeft, neckRight] = [headCoords[0], headCoords[4]];
|
|
2045
|
+
const tailWidthFactor = mathDistance(tailLeft, tailRight) / getBaseLength(boneCoords);
|
|
2046
|
+
const bodyCoords = getArrowBodyCoords(boneCoords, neckLeft, neckRight, tailWidthFactor);
|
|
2047
|
+
const coordlength = bodyCoords.length;
|
|
2048
|
+
let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength / 2));
|
|
2049
|
+
leftCoords.push(neckLeft);
|
|
2050
|
+
let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength / 2, coordlength));
|
|
2051
|
+
rightCoords.push(neckRight);
|
|
2052
|
+
leftCoords = getQBSplineCoords(leftCoords);
|
|
2053
|
+
rightCoords = getQBSplineCoords(rightCoords);
|
|
2054
|
+
return leftCoords.concat(headCoords, rightCoords.reverse());
|
|
2055
|
+
} else return [];
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* 插值头部点
|
|
2060
|
+
*/
|
|
2061
|
+
function getArrowHeadCoords(points, options) {
|
|
2062
|
+
const { tailLeft, tailRight, headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, headTailFactor = .8 } = options;
|
|
2063
|
+
let len = getBaseLength(points);
|
|
2064
|
+
let headHeight = len * headHeightFactor;
|
|
2065
|
+
const headCoord = points.at(-1);
|
|
2066
|
+
len = mathDistance(headCoord, points.at(-2));
|
|
2067
|
+
let tailWidth = 0;
|
|
2068
|
+
if (tailLeft && tailRight) tailWidth = mathDistance(tailLeft, tailRight);
|
|
2069
|
+
if (headHeight > tailWidth * headTailFactor) headHeight = tailWidth * headTailFactor;
|
|
2070
|
+
const headWidth = headHeight * headWidthFactor;
|
|
2071
|
+
const neckWidth = headHeight * neckWidthFactor;
|
|
2072
|
+
headHeight = Math.min(headHeight, len);
|
|
2073
|
+
const neckHeight = headHeight * neckHeightFactor;
|
|
2074
|
+
const headEndCoord = getThirdCoord(points.at(-2), headCoord, 0, headHeight, true);
|
|
2075
|
+
const neckEndCoord = getThirdCoord(points.at(-2), headCoord, 0, neckHeight, true);
|
|
2076
|
+
const headLeft = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, false);
|
|
2077
|
+
const headRight = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, true);
|
|
2078
|
+
const neckLeft = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, false);
|
|
2079
|
+
const neckRight = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, true);
|
|
2080
|
+
return [
|
|
2081
|
+
neckLeft,
|
|
2082
|
+
headLeft,
|
|
2083
|
+
headCoord,
|
|
2084
|
+
headRight,
|
|
2085
|
+
neckRight
|
|
2086
|
+
];
|
|
2087
|
+
}
|
|
2088
|
+
/**
|
|
2089
|
+
* 插值面部分数据
|
|
2090
|
+
* @param points
|
|
2091
|
+
* @param neckLeft
|
|
2092
|
+
* @param neckRight
|
|
2093
|
+
* @param tailWidthFactor
|
|
2094
|
+
*/
|
|
2095
|
+
function getArrowBodyCoords(points, neckLeft, neckRight, tailWidthFactor) {
|
|
2096
|
+
const allLen = wholeDistance(points);
|
|
2097
|
+
const len = getBaseLength(points);
|
|
2098
|
+
const tailWidth = len * tailWidthFactor;
|
|
2099
|
+
const neckWidth = mathDistance(neckLeft, neckRight);
|
|
2100
|
+
const widthDif = (tailWidth - neckWidth) / 2;
|
|
2101
|
+
let tempLen = 0;
|
|
2102
|
+
const leftBodyCoords = [];
|
|
2103
|
+
const rightBodyCoords = [];
|
|
2104
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
2105
|
+
const angle = getAngleOfThreeCoords(points[i - 1], points[i], points[i + 1]) / 2;
|
|
2106
|
+
tempLen += mathDistance(points[i - 1], points[i]);
|
|
2107
|
+
const w = (tailWidth / 2 - tempLen / allLen * widthDif) / Math.sin(angle);
|
|
2108
|
+
const left = getThirdCoord(points[i - 1], points[i], Math.PI - angle, w, true);
|
|
2109
|
+
const right = getThirdCoord(points[i - 1], points[i], angle, w, false);
|
|
2110
|
+
leftBodyCoords.push(left);
|
|
2111
|
+
rightBodyCoords.push(right);
|
|
2112
|
+
}
|
|
2113
|
+
return leftBodyCoords.concat(rightBodyCoords);
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
//#endregion
|
|
2117
|
+
//#region geom/arrowAttackDirectionTailed.ts
|
|
2118
|
+
/**
|
|
2119
|
+
* 燕尾尖曲箭头
|
|
2120
|
+
*/
|
|
2121
|
+
function arrowAttackDirectionTailed(coords, options = {}) {
|
|
2122
|
+
const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1, swallowTailFactor = 1 } = options;
|
|
2123
|
+
const coordLength = coords.length;
|
|
2124
|
+
if (coordLength < 3) throw new Error("coords.length must >= 3");
|
|
2125
|
+
let [tailLeft, tailRight] = [coords[0], coords[1]];
|
|
2126
|
+
if (isClockWise(coords[0], coords[1], coords[2])) {
|
|
2127
|
+
tailLeft = coords[1];
|
|
2128
|
+
tailRight = coords[0];
|
|
2129
|
+
}
|
|
2130
|
+
const midTail = mid(tailLeft, tailRight);
|
|
2131
|
+
const boneCoords = [midTail].concat(coords.slice(2));
|
|
2132
|
+
const headCoords = getArrowHeadCoords(boneCoords, {
|
|
2133
|
+
tailLeft,
|
|
2134
|
+
tailRight,
|
|
2135
|
+
headHeightFactor,
|
|
2136
|
+
headWidthFactor,
|
|
2137
|
+
neckWidthFactor,
|
|
2138
|
+
neckHeightFactor
|
|
2139
|
+
});
|
|
2140
|
+
if (headCoords && headCoords.length > 4) {
|
|
2141
|
+
const [neckLeft, neckRight] = [headCoords[0], headCoords[4]];
|
|
2142
|
+
const tailWidth = mathDistance(tailLeft, tailRight);
|
|
2143
|
+
const allLen = getBaseLength(boneCoords);
|
|
2144
|
+
const len = allLen * tailWidthFactor * swallowTailFactor;
|
|
2145
|
+
const swallowTailCoord = getThirdCoord(boneCoords[1], boneCoords[0], 0, len, true);
|
|
2146
|
+
const factor = tailWidth / allLen;
|
|
2147
|
+
const bodyCoords = getArrowBodyCoords(boneCoords, neckLeft, neckRight, factor);
|
|
2148
|
+
const coordlength = bodyCoords.length;
|
|
2149
|
+
let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength / 2));
|
|
2150
|
+
leftCoords.push(neckLeft);
|
|
2151
|
+
let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength / 2, coordlength));
|
|
2152
|
+
rightCoords.push(neckRight);
|
|
2153
|
+
leftCoords = getQBSplineCoords(leftCoords);
|
|
2154
|
+
rightCoords = getQBSplineCoords(rightCoords);
|
|
2155
|
+
return leftCoords.concat(headCoords, rightCoords.reverse(), [swallowTailCoord, leftCoords[0]]);
|
|
2156
|
+
} else return [];
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
//#endregion
|
|
2160
|
+
//#region geom/arrowClamped.ts
|
|
1456
2161
|
/**
|
|
1457
|
-
*
|
|
2162
|
+
* 钳击箭头 有效点位长度3,4,5
|
|
1458
2163
|
*/
|
|
1459
|
-
|
|
1460
|
-
|
|
2164
|
+
function arrowClamped(coords) {
|
|
2165
|
+
const options = {
|
|
2166
|
+
headHeightFactor: .25,
|
|
2167
|
+
headWidthFactor: .3,
|
|
2168
|
+
neckHeightFactor: .85,
|
|
2169
|
+
neckWidthFactor: .15
|
|
2170
|
+
};
|
|
2171
|
+
if (coords.length < 3) throw new Error(`coords.length must >= 3`);
|
|
2172
|
+
const [coord1, coord2, coord3] = coords;
|
|
2173
|
+
let tempCoord4, connCoord;
|
|
2174
|
+
if (coords.length === 3) {
|
|
2175
|
+
tempCoord4 = getTempCoord4(coord1, coord2, coord3);
|
|
2176
|
+
connCoord = mid(coord1, coord2);
|
|
2177
|
+
} else if (coords.length === 4) {
|
|
2178
|
+
tempCoord4 = coords[3];
|
|
2179
|
+
connCoord = mid(coord1, coord2);
|
|
2180
|
+
} else {
|
|
2181
|
+
tempCoord4 = coords[3];
|
|
2182
|
+
connCoord = coords[4];
|
|
2183
|
+
}
|
|
2184
|
+
let leftArrowCoords;
|
|
2185
|
+
let rightArrowCoords;
|
|
2186
|
+
if (isClockWise(coord1, coord2, coord3)) {
|
|
2187
|
+
leftArrowCoords = getArrowCoords(coord1, connCoord, tempCoord4, false, options);
|
|
2188
|
+
rightArrowCoords = getArrowCoords(connCoord, coord2, coord3, true, options);
|
|
2189
|
+
} else {
|
|
2190
|
+
leftArrowCoords = getArrowCoords(coord2, connCoord, coord3, false, options);
|
|
2191
|
+
rightArrowCoords = getArrowCoords(connCoord, coord1, tempCoord4, true, options);
|
|
2192
|
+
}
|
|
2193
|
+
const m = leftArrowCoords.length;
|
|
2194
|
+
const t = (m - 5) / 2;
|
|
2195
|
+
const llBodyCoords = leftArrowCoords.slice(0, t);
|
|
2196
|
+
const lArrowCoords = leftArrowCoords.slice(t, t + 5);
|
|
2197
|
+
let lrBodyCoords = leftArrowCoords.slice(t + 5, m);
|
|
2198
|
+
let rlBodyCoords = rightArrowCoords.slice(0, t);
|
|
2199
|
+
const rArrowCoords = rightArrowCoords.slice(t, t + 5);
|
|
2200
|
+
const rrBodyCoords = rightArrowCoords.slice(t + 5, m);
|
|
2201
|
+
rlBodyCoords = getBezierCoords(rlBodyCoords);
|
|
2202
|
+
const bodyCoords = getBezierCoords(rrBodyCoords.concat(llBodyCoords.slice(1)));
|
|
2203
|
+
lrBodyCoords = getBezierCoords(lrBodyCoords);
|
|
2204
|
+
return rlBodyCoords.concat(rArrowCoords, bodyCoords, lArrowCoords, lrBodyCoords);
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* 插值箭形上的点
|
|
2208
|
+
* @param coord1 - Wgs84坐标
|
|
2209
|
+
* @param coord2 - Wgs84坐标
|
|
2210
|
+
* @param coord3 - Wgs84坐标
|
|
2211
|
+
* @param clockWise - 是否顺时针
|
|
2212
|
+
*/
|
|
2213
|
+
function getArrowCoords(coord1, coord2, coord3, clockWise, options) {
|
|
2214
|
+
const midCoord = mid(coord1, coord2);
|
|
2215
|
+
const len = mathDistance(midCoord, coord3);
|
|
2216
|
+
let midCoord1 = getThirdCoord(coord3, midCoord, 0, len * .3, true);
|
|
2217
|
+
let midCoord2 = getThirdCoord(coord3, midCoord, 0, len * .5, true);
|
|
2218
|
+
midCoord1 = getThirdCoord(midCoord, midCoord1, HALF_PI, len / 5, clockWise);
|
|
2219
|
+
midCoord2 = getThirdCoord(midCoord, midCoord2, HALF_PI, len / 4, clockWise);
|
|
2220
|
+
const coords = [
|
|
2221
|
+
midCoord,
|
|
2222
|
+
midCoord1,
|
|
2223
|
+
midCoord2,
|
|
2224
|
+
coord3
|
|
2225
|
+
];
|
|
2226
|
+
const arrowCoords = getArrowHeadCoords$1(coords, options);
|
|
2227
|
+
if (arrowCoords && Array.isArray(arrowCoords) && arrowCoords.length > 0) {
|
|
2228
|
+
const [neckLeftCoord, neckRightCoord] = [arrowCoords[0], arrowCoords[4]];
|
|
2229
|
+
const tailWidthFactor = mathDistance(coord1, coord2) / getBaseLength(coords) / 2;
|
|
2230
|
+
const bodyCoords = getArrowBodyCoords$1(coords, neckLeftCoord, neckRightCoord, tailWidthFactor);
|
|
2231
|
+
const n = bodyCoords.length;
|
|
2232
|
+
let lCoords = bodyCoords.slice(0, n / 2);
|
|
2233
|
+
let rCoords = bodyCoords.slice(n / 2, n);
|
|
2234
|
+
lCoords.push(neckLeftCoord);
|
|
2235
|
+
rCoords.push(neckRightCoord);
|
|
2236
|
+
lCoords = lCoords.reverse();
|
|
2237
|
+
lCoords.push(coord2);
|
|
2238
|
+
rCoords = rCoords.reverse();
|
|
2239
|
+
rCoords.push(coord1);
|
|
2240
|
+
return lCoords.reverse().concat(arrowCoords, rCoords);
|
|
2241
|
+
} else throw new Error("插值出错");
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* 插值头部点
|
|
2245
|
+
* @param coords
|
|
2246
|
+
*/
|
|
2247
|
+
function getArrowHeadCoords$1(coords, options) {
|
|
2248
|
+
const { headHeightFactor, headWidthFactor, neckWidthFactor, neckHeightFactor } = options;
|
|
2249
|
+
const len = getBaseLength(coords);
|
|
2250
|
+
const headHeight = len * headHeightFactor;
|
|
2251
|
+
const headCoord = coords.at(-1);
|
|
2252
|
+
const headWidth = headHeight * headWidthFactor;
|
|
2253
|
+
const neckWidth = headHeight * neckWidthFactor;
|
|
2254
|
+
const neckHeight = headHeight * neckHeightFactor;
|
|
2255
|
+
const headEndCoord = getThirdCoord(coords.at(-2), headCoord, 0, headHeight, true);
|
|
2256
|
+
const neckEndCoord = getThirdCoord(coords.at(-2), headCoord, 0, neckHeight, true);
|
|
2257
|
+
const headLeft = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, false);
|
|
2258
|
+
const headRight = getThirdCoord(headCoord, headEndCoord, HALF_PI, headWidth, true);
|
|
2259
|
+
const neckLeft = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, false);
|
|
2260
|
+
const neckRight = getThirdCoord(headCoord, neckEndCoord, HALF_PI, neckWidth, true);
|
|
2261
|
+
return [
|
|
2262
|
+
neckLeft,
|
|
2263
|
+
headLeft,
|
|
2264
|
+
headCoord,
|
|
2265
|
+
headRight,
|
|
2266
|
+
neckRight
|
|
2267
|
+
];
|
|
2268
|
+
}
|
|
2269
|
+
/**
|
|
2270
|
+
* 插值面部分数据
|
|
2271
|
+
* @param coords
|
|
2272
|
+
* @param neckLeft
|
|
2273
|
+
* @param neckRight
|
|
2274
|
+
* @param tailWidthFactor
|
|
2275
|
+
*/
|
|
2276
|
+
function getArrowBodyCoords$1(coords, neckLeft, neckRight, tailWidthFactor) {
|
|
2277
|
+
const allLen = wholeDistance(coords);
|
|
2278
|
+
const len = getBaseLength(coords);
|
|
2279
|
+
const tailWidth = len * tailWidthFactor;
|
|
2280
|
+
const neckWidth = mathDistance(neckLeft, neckRight);
|
|
2281
|
+
const widthDif = (tailWidth - neckWidth) / 2;
|
|
2282
|
+
let tempLen = 0;
|
|
2283
|
+
const leftBodyCoords = [];
|
|
2284
|
+
const rightBodyCoords = [];
|
|
2285
|
+
for (let i = 1; i < coords.length - 1; i++) {
|
|
2286
|
+
const angle = getAngleOfThreeCoords(coords[i - 1], coords[i], coords[i + 1]) / 2;
|
|
2287
|
+
tempLen += mathDistance(coords[i - 1], coords[i]);
|
|
2288
|
+
const w = (tailWidth / 2 - tempLen / allLen * widthDif) / Math.sin(angle);
|
|
2289
|
+
const left = getThirdCoord(coords[i - 1], coords[i], Math.PI - angle, w, true);
|
|
2290
|
+
const right = getThirdCoord(coords[i - 1], coords[i], angle, w, false);
|
|
2291
|
+
leftBodyCoords.push(left);
|
|
2292
|
+
rightBodyCoords.push(right);
|
|
2293
|
+
}
|
|
2294
|
+
return leftBodyCoords.concat(rightBodyCoords);
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* 获取对称点
|
|
2298
|
+
* @param lineCoord1
|
|
2299
|
+
* @param lineCoord2
|
|
2300
|
+
* @param coord
|
|
2301
|
+
*/
|
|
2302
|
+
function getTempCoord4(lineCoord1, lineCoord2, coord) {
|
|
2303
|
+
const midCoord = mid(lineCoord1, lineCoord2);
|
|
2304
|
+
const len = mathDistance(midCoord, coord);
|
|
2305
|
+
const angle = getAngleOfThreeCoords(lineCoord1, midCoord, coord);
|
|
2306
|
+
if (angle < HALF_PI) {
|
|
2307
|
+
const distance1 = len * Math.sin(angle);
|
|
2308
|
+
const distance2 = len * Math.cos(angle);
|
|
2309
|
+
const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, false);
|
|
2310
|
+
return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, true);
|
|
2311
|
+
} else if (angle >= HALF_PI && angle < Math.PI) {
|
|
2312
|
+
const distance1 = len * Math.sin(Math.PI - angle);
|
|
2313
|
+
const distance2 = len * Math.cos(Math.PI - angle);
|
|
2314
|
+
const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, false);
|
|
2315
|
+
return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, false);
|
|
2316
|
+
} else if (angle >= Math.PI && angle < Math.PI * 1.5) {
|
|
2317
|
+
const distance1 = len * Math.sin(angle - Math.PI);
|
|
2318
|
+
const distance2 = len * Math.cos(angle - Math.PI);
|
|
2319
|
+
const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true);
|
|
2320
|
+
return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, true);
|
|
2321
|
+
} else {
|
|
2322
|
+
const distance1 = len * Math.sin(Math.PI * 2 - angle);
|
|
2323
|
+
const distance2 = len * Math.cos(Math.PI * 2 - angle);
|
|
2324
|
+
const mid$1 = getThirdCoord(lineCoord1, midCoord, HALF_PI, distance1, true);
|
|
2325
|
+
return getThirdCoord(midCoord, mid$1, HALF_PI, distance2, false);
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
//#endregion
|
|
2330
|
+
//#region geom/arrowStraightSharp.ts
|
|
2331
|
+
/**
|
|
2332
|
+
* 尖箭头
|
|
2333
|
+
*
|
|
2334
|
+
*/
|
|
2335
|
+
function arrowStraightSharp(coords, options = {}) {
|
|
2336
|
+
const { tailWidthFactor = .1, neckWidthFactor = .2, headWidthFactor = .25, headAngle = Math.PI / 8.5, neckAngle = Math.PI / 13 } = options;
|
|
2337
|
+
const coordlength = coords.length;
|
|
2338
|
+
if (coordlength < 2) throw new Error("coords.length must >= 2");
|
|
2339
|
+
const [coord1, coord2] = [coords[0], coords[1]];
|
|
2340
|
+
const len = getBaseLength(coords);
|
|
2341
|
+
const tailWidth = len * tailWidthFactor;
|
|
2342
|
+
const neckWidth = len * neckWidthFactor;
|
|
2343
|
+
const headWidth = len * headWidthFactor;
|
|
2344
|
+
const tailLeft = getThirdCoord(coord2, coord1, HALF_PI, tailWidth, true);
|
|
2345
|
+
const tailRight = getThirdCoord(coord2, coord1, HALF_PI, tailWidth, false);
|
|
2346
|
+
const headLeft = getThirdCoord(coord1, coord2, headAngle, headWidth, false);
|
|
2347
|
+
const headRight = getThirdCoord(coord1, coord2, headAngle, headWidth, true);
|
|
2348
|
+
const neckLeft = getThirdCoord(coord1, coord2, neckAngle, neckWidth, false);
|
|
2349
|
+
const neckRight = getThirdCoord(coord1, coord2, neckAngle, neckWidth, true);
|
|
2350
|
+
const pList = [
|
|
2351
|
+
tailLeft,
|
|
2352
|
+
neckLeft,
|
|
2353
|
+
headLeft,
|
|
2354
|
+
coord2,
|
|
2355
|
+
headRight,
|
|
2356
|
+
neckRight,
|
|
2357
|
+
tailRight
|
|
2358
|
+
];
|
|
2359
|
+
return pList;
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
//#endregion
|
|
2363
|
+
//#region geom/arrowStraight.ts
|
|
2364
|
+
/**
|
|
2365
|
+
* 直箭头
|
|
2366
|
+
*/
|
|
2367
|
+
function arrowStraight(coords) {
|
|
2368
|
+
const tailWidthFactor = .05;
|
|
2369
|
+
const neckWidthFactor = .1;
|
|
2370
|
+
const headWidthFactor = .15;
|
|
2371
|
+
const headAngle = Math.PI / 4;
|
|
2372
|
+
const neckAngle = Math.PI * .17741;
|
|
2373
|
+
return arrowStraightSharp(coords, {
|
|
2374
|
+
tailWidthFactor,
|
|
2375
|
+
neckWidthFactor,
|
|
2376
|
+
headWidthFactor,
|
|
2377
|
+
headAngle,
|
|
2378
|
+
neckAngle
|
|
2379
|
+
});
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
//#endregion
|
|
2383
|
+
//#region geom/arrowUnitCombatOperation.ts
|
|
2384
|
+
/**
|
|
2385
|
+
* 分队战斗行动(尖曲箭头)
|
|
2386
|
+
*/
|
|
2387
|
+
function arrowUnitCombatOperation(coords, options = {}) {
|
|
2388
|
+
const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1 } = options;
|
|
2389
|
+
const coordlength = coords.length;
|
|
2390
|
+
if (coordlength < 2) throw new Error("coords.length must >= 2");
|
|
2391
|
+
else {
|
|
2392
|
+
const allLen = getBaseLength(coords);
|
|
2393
|
+
const tailWidth = allLen * tailWidthFactor;
|
|
2394
|
+
const tailLeft = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, false);
|
|
2395
|
+
const tailRight = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, true);
|
|
2396
|
+
const headCoords = getArrowHeadCoords(coords, {
|
|
2397
|
+
tailLeft,
|
|
2398
|
+
tailRight,
|
|
2399
|
+
headHeightFactor,
|
|
2400
|
+
headWidthFactor,
|
|
2401
|
+
neckWidthFactor,
|
|
2402
|
+
neckHeightFactor
|
|
2403
|
+
});
|
|
2404
|
+
if (headCoords && headCoords.length > 4) {
|
|
2405
|
+
const neckLeft = headCoords[0];
|
|
2406
|
+
const neckRight = headCoords[4];
|
|
2407
|
+
const bodyCoords = getArrowBodyCoords(coords, neckLeft, neckRight, tailWidthFactor);
|
|
2408
|
+
const coordlength$1 = bodyCoords.length;
|
|
2409
|
+
let leftCoords = [tailLeft].concat(bodyCoords.slice(0, coordlength$1 / 2));
|
|
2410
|
+
leftCoords.push(neckLeft);
|
|
2411
|
+
let rightCoords = [tailRight].concat(bodyCoords.slice(coordlength$1 / 2, coordlength$1));
|
|
2412
|
+
rightCoords.push(neckRight);
|
|
2413
|
+
leftCoords = getQBSplineCoords(leftCoords);
|
|
2414
|
+
rightCoords = getQBSplineCoords(rightCoords);
|
|
2415
|
+
return leftCoords.concat(headCoords, rightCoords.reverse());
|
|
2416
|
+
} else return [];
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
//#endregion
|
|
2421
|
+
//#region geom/arrowUnitCombatOperationTailed.ts
|
|
2422
|
+
/**
|
|
2423
|
+
* 燕尾尖箭头
|
|
2424
|
+
*/
|
|
2425
|
+
function arrowUnitCombatOperationTailed(coords, options = {}) {
|
|
2426
|
+
const { headHeightFactor = .18, headWidthFactor = .3, neckHeightFactor = .85, neckWidthFactor = .15, tailWidthFactor = .1, swallowTailFactor = 1 } = options;
|
|
2427
|
+
const coordlength = coords.length;
|
|
2428
|
+
if (coordlength < 2) throw new Error("coords.length must >= 2");
|
|
2429
|
+
const allLen = getBaseLength(coords);
|
|
2430
|
+
const tailWidth = allLen * tailWidthFactor;
|
|
2431
|
+
const tailLeft = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, false);
|
|
2432
|
+
const tailRight = getThirdCoord(coords[1], coords[0], HALF_PI, tailWidth, true);
|
|
2433
|
+
const len = tailWidth * swallowTailFactor;
|
|
2434
|
+
const swallowTailCoord = getThirdCoord(coords[1], coords[0], 0, len, true);
|
|
2435
|
+
const tailCoords = [
|
|
2436
|
+
tailLeft,
|
|
2437
|
+
swallowTailCoord,
|
|
2438
|
+
tailRight
|
|
2439
|
+
];
|
|
2440
|
+
const headCoords = getArrowHeadCoords(coords, {
|
|
2441
|
+
tailLeft: tailCoords[0],
|
|
2442
|
+
tailRight: tailCoords[2],
|
|
2443
|
+
headHeightFactor,
|
|
2444
|
+
headWidthFactor,
|
|
2445
|
+
neckWidthFactor,
|
|
2446
|
+
neckHeightFactor
|
|
2447
|
+
});
|
|
2448
|
+
if (headCoords && headCoords.length > 4) {
|
|
2449
|
+
const neckLeft = headCoords[0];
|
|
2450
|
+
const neckRight = headCoords[4];
|
|
2451
|
+
const bodyCoords = getArrowBodyCoords(coords, neckLeft, neckRight, tailWidthFactor);
|
|
2452
|
+
const coordlength$1 = bodyCoords.length;
|
|
2453
|
+
let leftCoords = [tailCoords[0]].concat(bodyCoords.slice(0, coordlength$1 / 2));
|
|
2454
|
+
leftCoords.push(neckLeft);
|
|
2455
|
+
let rightCoords = [tailCoords[2]].concat(bodyCoords.slice(coordlength$1 / 2, coordlength$1));
|
|
2456
|
+
rightCoords.push(neckRight);
|
|
2457
|
+
leftCoords = getQBSplineCoords(leftCoords);
|
|
2458
|
+
rightCoords = getQBSplineCoords(rightCoords);
|
|
2459
|
+
return leftCoords.concat(headCoords, rightCoords.reverse(), [tailCoords[1], leftCoords[0]]);
|
|
2460
|
+
}
|
|
2461
|
+
return [];
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
//#endregion
|
|
2465
|
+
//#region geom/assemblingPlace.ts
|
|
2466
|
+
/**
|
|
2467
|
+
* 集结地
|
|
2468
|
+
*
|
|
2469
|
+
*/
|
|
2470
|
+
function assemblingPlace(coords) {
|
|
2471
|
+
if (coords.length < 3) throw new Error(`coords.length must >= 3`);
|
|
2472
|
+
const t = .4;
|
|
2473
|
+
const midCoord = mid(coords[0], coords[2]);
|
|
2474
|
+
coords.push(midCoord, coords[0], coords[1]);
|
|
2475
|
+
let normals = [];
|
|
2476
|
+
const pList = [];
|
|
2477
|
+
for (let i = 0; i < coords.length - 2; i++) {
|
|
2478
|
+
const coord1 = coords[i];
|
|
2479
|
+
const coord2 = coords[i + 1];
|
|
2480
|
+
const coord3 = coords[i + 2];
|
|
2481
|
+
const normalCoords = getBisectorNormals(t, coord1, coord2, coord3);
|
|
2482
|
+
normals = normals.concat(normalCoords);
|
|
2483
|
+
}
|
|
2484
|
+
const count = normals.length;
|
|
2485
|
+
normals = [normals[count - 1]].concat(normals.slice(0, count - 1));
|
|
2486
|
+
for (let i = 0; i < coords.length - 2; i++) {
|
|
2487
|
+
const coord1 = coords[i];
|
|
2488
|
+
const coord2 = coords[i + 1];
|
|
2489
|
+
pList.push(coord1);
|
|
2490
|
+
for (let t$1 = 0; t$1 <= FITTING_COUNT; t$1++) {
|
|
2491
|
+
const coord = getCubicValue(t$1 / FITTING_COUNT, coord1, normals[i * 2], normals[i * 2 + 1], coord2);
|
|
2492
|
+
pList.push(coord);
|
|
2493
|
+
}
|
|
2494
|
+
pList.push(coord2);
|
|
2495
|
+
}
|
|
2496
|
+
return pList;
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
//#endregion
|
|
2500
|
+
//#region geom/flagCurve.ts
|
|
2501
|
+
/**
|
|
2502
|
+
* 曲线旗标
|
|
2503
|
+
*/
|
|
2504
|
+
function flagCurve(coords) {
|
|
2505
|
+
const coordlength = coords.length;
|
|
2506
|
+
if (coordlength < 2) throw new Error("coords.length must >= 2");
|
|
2507
|
+
return calculatePonits(coords);
|
|
2508
|
+
}
|
|
2509
|
+
/**
|
|
2510
|
+
* 插值点数据
|
|
2511
|
+
* @param coords
|
|
2512
|
+
*/
|
|
2513
|
+
function calculatePonits(coords) {
|
|
2514
|
+
let components = [];
|
|
2515
|
+
if (coords.length > 1) {
|
|
2516
|
+
const startCoord = coords[0];
|
|
2517
|
+
const endCoord = coords.at(-1);
|
|
2518
|
+
const coord1 = startCoord;
|
|
2519
|
+
const coord2 = [(endCoord[0] - startCoord[0]) / 4 + startCoord[0], (endCoord[1] - startCoord[1]) / 8 + startCoord[1]];
|
|
2520
|
+
const coord3 = [(startCoord[0] + endCoord[0]) / 2, startCoord[1]];
|
|
2521
|
+
const coord4 = [(endCoord[0] - startCoord[0]) * 3 / 4 + startCoord[0], -(endCoord[1] - startCoord[1]) / 8 + startCoord[1]];
|
|
2522
|
+
const coord5 = [endCoord[0], startCoord[1]];
|
|
2523
|
+
const coord6 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
|
|
2524
|
+
const coord7 = [(endCoord[0] - startCoord[0]) * 3 / 4 + startCoord[0], (endCoord[1] - startCoord[1]) * 3 / 8 + startCoord[1]];
|
|
2525
|
+
const coord8 = [(startCoord[0] + endCoord[0]) / 2, (startCoord[1] + endCoord[1]) / 2];
|
|
2526
|
+
const coord9 = [(endCoord[0] - startCoord[0]) / 4 + startCoord[0], (endCoord[1] - startCoord[1]) * 5 / 8 + startCoord[1]];
|
|
2527
|
+
const coord10 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
|
|
2528
|
+
const coord11 = [startCoord[0], endCoord[1]];
|
|
2529
|
+
const curve1 = getBezierCoords([
|
|
2530
|
+
coord1,
|
|
2531
|
+
coord2,
|
|
2532
|
+
coord3,
|
|
2533
|
+
coord4,
|
|
2534
|
+
coord5
|
|
2535
|
+
]);
|
|
2536
|
+
const curve2 = getBezierCoords([
|
|
2537
|
+
coord6,
|
|
2538
|
+
coord7,
|
|
2539
|
+
coord8,
|
|
2540
|
+
coord9,
|
|
2541
|
+
coord10
|
|
2542
|
+
]);
|
|
2543
|
+
components = curve1.concat(curve2);
|
|
2544
|
+
components.push(coord11);
|
|
2545
|
+
}
|
|
2546
|
+
return components;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
//#endregion
|
|
2550
|
+
//#region geom/flagRect.ts
|
|
2551
|
+
/**
|
|
2552
|
+
* 直角旗标(使用两个控制点直接创建直角旗标)
|
|
2553
|
+
*/
|
|
2554
|
+
function flagRect(coords) {
|
|
2555
|
+
if (coords.length < 2) throw new Error("coords.length must >= 2");
|
|
2556
|
+
const [startCoord, endCoord] = coords;
|
|
2557
|
+
const coord1 = [endCoord[0], startCoord[1]];
|
|
2558
|
+
const coord2 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
|
|
2559
|
+
const coord3 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
|
|
2560
|
+
const coord4 = [startCoord[0], endCoord[1]];
|
|
2561
|
+
return [
|
|
2562
|
+
startCoord,
|
|
2563
|
+
coord1,
|
|
2564
|
+
coord2,
|
|
2565
|
+
coord3,
|
|
2566
|
+
coord4
|
|
2567
|
+
];
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
//#endregion
|
|
2571
|
+
//#region geom/flagTriangle.ts
|
|
2572
|
+
/**
|
|
2573
|
+
* 三角旗标(使用两个控制点直接创建三角旗标)
|
|
2574
|
+
*/
|
|
2575
|
+
function flagTriangle(coords) {
|
|
2576
|
+
const coordlength = coords.length;
|
|
2577
|
+
if (coordlength < 2) throw new Error("coords.length must >= 2");
|
|
2578
|
+
const [startCoord, endCoord] = coords;
|
|
2579
|
+
const coord1 = [endCoord[0], (startCoord[1] + endCoord[1]) / 2];
|
|
2580
|
+
const coord2 = [startCoord[0], (startCoord[1] + endCoord[1]) / 2];
|
|
2581
|
+
const coord3 = [startCoord[0], endCoord[1]];
|
|
2582
|
+
return [
|
|
2583
|
+
startCoord,
|
|
2584
|
+
coord1,
|
|
2585
|
+
coord2,
|
|
2586
|
+
coord3
|
|
2587
|
+
];
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
//#endregion
|
|
2591
|
+
//#region scheme/PolygonArc.ts
|
|
2592
|
+
const PlotSchemePolygonArc = new PlotScheme({
|
|
2593
|
+
type: "PolygonArc",
|
|
2594
|
+
complete: (packable) => packable.positions.length >= 3,
|
|
2595
|
+
skeletons: [moved, control],
|
|
2596
|
+
initRender() {
|
|
2597
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2598
|
+
},
|
|
2599
|
+
render(context) {
|
|
2600
|
+
const entity = context.previous.entities[0];
|
|
2601
|
+
const points = context.packable.positions;
|
|
2602
|
+
if (points.length < 3) context.mouse && points.push(context.mouse.clone());
|
|
2603
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2604
|
+
if (coords.length < 3) {
|
|
2605
|
+
entity.polygon.hierarchy = void 0;
|
|
2606
|
+
return context.previous;
|
|
2607
|
+
}
|
|
2608
|
+
const positions = arc(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2609
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2610
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2611
|
+
return { entities: [entity] };
|
|
2612
|
+
}
|
|
2613
|
+
});
|
|
2614
|
+
|
|
2615
|
+
//#endregion
|
|
2616
|
+
//#region scheme/PolygonArrowAttackDirection.ts
|
|
2617
|
+
const PlotSchemePolygonArrowAttackDirection = new PlotScheme({
|
|
2618
|
+
type: "PolygonArrowAttackDirection",
|
|
2619
|
+
allowManualComplete: (packable) => packable.positions.length >= 3,
|
|
2620
|
+
skeletons: [
|
|
2621
|
+
moved,
|
|
2622
|
+
control,
|
|
2623
|
+
intervalNonclosed
|
|
2624
|
+
],
|
|
2625
|
+
initRender() {
|
|
2626
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2627
|
+
},
|
|
2628
|
+
render(context) {
|
|
2629
|
+
const entity = context.previous.entities[0];
|
|
2630
|
+
const points = context.packable.positions;
|
|
2631
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2632
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2633
|
+
if (coords.length < 3) {
|
|
2634
|
+
entity.polygon.hierarchy = void 0;
|
|
2635
|
+
return context.previous;
|
|
2636
|
+
}
|
|
2637
|
+
const positions = arrowAttackDirection(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2638
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2639
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2640
|
+
return { entities: [entity] };
|
|
2641
|
+
}
|
|
2642
|
+
});
|
|
2643
|
+
|
|
2644
|
+
//#endregion
|
|
2645
|
+
//#region scheme/PolygonArrowAttackDirectionTailed.ts
|
|
2646
|
+
const PlotSchemePolygonArrowAttackDirectionTailed = new PlotScheme({
|
|
2647
|
+
type: "PolygonArrowAttackDirectionTailed",
|
|
2648
|
+
allowManualComplete: (packable) => packable.positions.length >= 3,
|
|
2649
|
+
skeletons: [
|
|
2650
|
+
moved,
|
|
2651
|
+
control,
|
|
2652
|
+
intervalNonclosed
|
|
2653
|
+
],
|
|
2654
|
+
initRender() {
|
|
2655
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2656
|
+
},
|
|
2657
|
+
render(context) {
|
|
2658
|
+
const entity = context.previous.entities[0];
|
|
2659
|
+
const points = context.packable.positions;
|
|
2660
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2661
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2662
|
+
if (coords.length < 3) {
|
|
2663
|
+
entity.polygon.hierarchy = void 0;
|
|
2664
|
+
return context.previous;
|
|
2665
|
+
}
|
|
2666
|
+
const positions = arrowAttackDirectionTailed(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2667
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2668
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2669
|
+
return { entities: [entity] };
|
|
2670
|
+
}
|
|
2671
|
+
});
|
|
2672
|
+
|
|
2673
|
+
//#endregion
|
|
2674
|
+
//#region scheme/PolygonArrowClamped.ts
|
|
2675
|
+
const PlotSchemePolygonArrowClamped = new PlotScheme({
|
|
2676
|
+
type: "PolygonArrowClamped",
|
|
2677
|
+
complete: (packable) => packable.positions.length >= 5,
|
|
2678
|
+
skeletons: [moved, control],
|
|
2679
|
+
initRender() {
|
|
2680
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2681
|
+
},
|
|
2682
|
+
render(context) {
|
|
2683
|
+
const entity = context.previous.entities[0];
|
|
2684
|
+
const points = context.packable.positions;
|
|
2685
|
+
if (points.length < 5) {
|
|
2686
|
+
const mouse = context.mouse;
|
|
2687
|
+
mouse && points.push(mouse.clone());
|
|
2688
|
+
}
|
|
2689
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2690
|
+
if (coords.length >= 3) {
|
|
2691
|
+
const positions = arrowClamped(coords);
|
|
2692
|
+
const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
|
|
2693
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2694
|
+
} else entity.polygon.hierarchy = void 0;
|
|
2695
|
+
return { entities: [entity] };
|
|
2696
|
+
}
|
|
2697
|
+
});
|
|
2698
|
+
|
|
2699
|
+
//#endregion
|
|
2700
|
+
//#region scheme/PolygonArrowStraight.ts
|
|
2701
|
+
const PlotSchemePolygonArrowStraight = new PlotScheme({
|
|
2702
|
+
type: "PolygonArrowStraight",
|
|
2703
|
+
complete: (packable) => packable.positions.length >= 2,
|
|
2704
|
+
skeletons: [moved, control],
|
|
2705
|
+
initRender() {
|
|
2706
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2707
|
+
},
|
|
2708
|
+
render(context) {
|
|
2709
|
+
const entity = context.previous.entities[0];
|
|
2710
|
+
const points = context.packable.positions;
|
|
2711
|
+
if (points.length < 2) {
|
|
2712
|
+
const mouse = context.mouse;
|
|
2713
|
+
mouse && points.push(mouse.clone());
|
|
2714
|
+
}
|
|
2715
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2716
|
+
if (coords.length >= 2) {
|
|
2717
|
+
const positions = arrowStraight(coords);
|
|
2718
|
+
const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
|
|
2719
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2720
|
+
} else entity.polygon.hierarchy = void 0;
|
|
2721
|
+
return { entities: [entity] };
|
|
2722
|
+
}
|
|
2723
|
+
});
|
|
2724
|
+
|
|
2725
|
+
//#endregion
|
|
2726
|
+
//#region scheme/PolygonArrowStraightSharp.ts
|
|
2727
|
+
const PlotSchemePolygonArrowStraightSharp = new PlotScheme({
|
|
2728
|
+
type: "PolygonArrowStraightSharp",
|
|
2729
|
+
complete: (packable) => packable.positions.length >= 2,
|
|
2730
|
+
skeletons: [moved, control],
|
|
2731
|
+
initRender() {
|
|
2732
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2733
|
+
},
|
|
2734
|
+
render(context) {
|
|
2735
|
+
const entity = context.previous.entities[0];
|
|
2736
|
+
const points = context.packable.positions;
|
|
2737
|
+
if (points.length < 2) {
|
|
2738
|
+
const mouse = context.mouse;
|
|
2739
|
+
mouse && points.push(mouse.clone());
|
|
2740
|
+
}
|
|
2741
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2742
|
+
if (coords.length >= 2) {
|
|
2743
|
+
const positions = arrowStraightSharp(coords);
|
|
2744
|
+
const hierarchy = new cesium.PolygonHierarchy(positions.map((item) => (0, vesium.toCartesian3)(item)));
|
|
2745
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2746
|
+
} else entity.polygon.hierarchy = void 0;
|
|
2747
|
+
return { entities: [entity] };
|
|
2748
|
+
}
|
|
2749
|
+
});
|
|
2750
|
+
|
|
2751
|
+
//#endregion
|
|
2752
|
+
//#region scheme/PolygonArrowUnitCombatOperation.ts
|
|
2753
|
+
const PlotSchemePolygonArrowUnitCombatOperation = new PlotScheme({
|
|
2754
|
+
type: "PolygonArrowUnitCombatOperation",
|
|
1461
2755
|
allowManualComplete: (packable) => packable.positions.length >= 2,
|
|
1462
2756
|
skeletons: [
|
|
2757
|
+
moved,
|
|
1463
2758
|
control,
|
|
1464
|
-
intervalNonclosed
|
|
1465
|
-
moved
|
|
2759
|
+
intervalNonclosed
|
|
1466
2760
|
],
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
entity
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
2761
|
+
initRender() {
|
|
2762
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2763
|
+
},
|
|
2764
|
+
render(context) {
|
|
2765
|
+
const entity = context.previous.entities[0];
|
|
2766
|
+
const points = context.packable.positions;
|
|
2767
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2768
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2769
|
+
if (coords.length < 2) {
|
|
2770
|
+
entity.polygon.hierarchy = void 0;
|
|
2771
|
+
return context.previous;
|
|
2772
|
+
}
|
|
2773
|
+
const positions = arrowUnitCombatOperation(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2774
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2775
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
1475
2776
|
return { entities: [entity] };
|
|
1476
2777
|
}
|
|
1477
2778
|
});
|
|
1478
2779
|
|
|
1479
2780
|
//#endregion
|
|
1480
|
-
//#region scheme/
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
2781
|
+
//#region scheme/PolygonArrowUnitCombatOperationTailed.ts
|
|
2782
|
+
const PlotSchemePolygonArrowUnitCombatOperationTailed = new PlotScheme({
|
|
2783
|
+
type: "PolygonArrowUnitCombatOperationTailed",
|
|
2784
|
+
allowManualComplete: (packable) => packable.positions.length >= 2,
|
|
2785
|
+
skeletons: [
|
|
2786
|
+
moved,
|
|
2787
|
+
control,
|
|
2788
|
+
interval
|
|
2789
|
+
],
|
|
2790
|
+
initRender() {
|
|
2791
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2792
|
+
},
|
|
2793
|
+
render(context) {
|
|
2794
|
+
const entity = context.previous.entities[0];
|
|
2795
|
+
const points = context.packable.positions;
|
|
2796
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2797
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2798
|
+
if (coords.length < 2) {
|
|
2799
|
+
entity.polygon.hierarchy = void 0;
|
|
2800
|
+
return context.previous;
|
|
2801
|
+
}
|
|
2802
|
+
const positions = arrowUnitCombatOperationTailed(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2803
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2804
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2805
|
+
return { entities: [entity] };
|
|
2806
|
+
}
|
|
2807
|
+
});
|
|
2808
|
+
|
|
2809
|
+
//#endregion
|
|
2810
|
+
//#region scheme/PolygonAssemblingPlace.ts
|
|
2811
|
+
const PlotSchemePolygonAssemblingPlace = new PlotScheme({
|
|
2812
|
+
type: "PolygonAssemblingPlace",
|
|
2813
|
+
complete: (packable) => packable.positions.length >= 3,
|
|
2814
|
+
skeletons: [
|
|
2815
|
+
moved,
|
|
2816
|
+
control,
|
|
2817
|
+
interval
|
|
2818
|
+
],
|
|
2819
|
+
initRender() {
|
|
2820
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2821
|
+
},
|
|
2822
|
+
render(context) {
|
|
2823
|
+
const entity = context.previous.entities[0];
|
|
2824
|
+
const points = context.packable.positions;
|
|
2825
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2826
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2827
|
+
if (coords.length < 2) {
|
|
2828
|
+
entity.polygon.hierarchy = void 0;
|
|
2829
|
+
return context.previous;
|
|
2830
|
+
}
|
|
2831
|
+
const positions = assemblingPlace(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2832
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2833
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2834
|
+
return { entities: [entity] };
|
|
2835
|
+
}
|
|
2836
|
+
});
|
|
2837
|
+
|
|
2838
|
+
//#endregion
|
|
2839
|
+
//#region scheme/PolygonFlagCurve.ts
|
|
2840
|
+
const PlotSchemePolygonFlagCurve = new PlotScheme({
|
|
2841
|
+
type: "PolygonFlagCurve",
|
|
1486
2842
|
complete: (packable) => packable.positions.length >= 2,
|
|
2843
|
+
skeletons: [moved, control],
|
|
2844
|
+
initRender() {
|
|
2845
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2846
|
+
},
|
|
2847
|
+
render(context) {
|
|
2848
|
+
const entity = context.previous.entities[0];
|
|
2849
|
+
const points = context.packable.positions;
|
|
2850
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2851
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2852
|
+
if (coords.length < 2) {
|
|
2853
|
+
entity.polygon.hierarchy = void 0;
|
|
2854
|
+
return context.previous;
|
|
2855
|
+
}
|
|
2856
|
+
const positions = flagCurve(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2857
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2858
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2859
|
+
return { entities: [entity] };
|
|
2860
|
+
}
|
|
2861
|
+
});
|
|
2862
|
+
|
|
2863
|
+
//#endregion
|
|
2864
|
+
//#region scheme/PolygonFlagRect.ts
|
|
2865
|
+
const PlotSchemePolygonFlagRect = new PlotScheme({
|
|
2866
|
+
type: "PolygonFlagRect",
|
|
2867
|
+
complete: (packable) => packable.positions.length >= 2,
|
|
2868
|
+
skeletons: [moved, control],
|
|
2869
|
+
initRender() {
|
|
2870
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2871
|
+
},
|
|
2872
|
+
render(context) {
|
|
2873
|
+
const entity = context.previous.entities[0];
|
|
2874
|
+
const points = context.packable.positions;
|
|
2875
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2876
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2877
|
+
if (coords.length < 2) {
|
|
2878
|
+
entity.polygon.hierarchy = void 0;
|
|
2879
|
+
return context.previous;
|
|
2880
|
+
}
|
|
2881
|
+
const positions = flagRect(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2882
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2883
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2884
|
+
return { entities: [entity] };
|
|
2885
|
+
}
|
|
2886
|
+
});
|
|
2887
|
+
|
|
2888
|
+
//#endregion
|
|
2889
|
+
//#region scheme/PolygonFlagTriangle.ts
|
|
2890
|
+
const PlotSchemePolygonFlagTriangle = new PlotScheme({
|
|
2891
|
+
type: "PolygonFlagTriangle",
|
|
2892
|
+
complete: (packable) => packable.positions.length >= 2,
|
|
2893
|
+
skeletons: [moved, control],
|
|
2894
|
+
initRender() {
|
|
2895
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2896
|
+
},
|
|
2897
|
+
render(context) {
|
|
2898
|
+
const entity = context.previous.entities[0];
|
|
2899
|
+
const points = context.packable.positions;
|
|
2900
|
+
context.mouse && points.push(context.mouse.clone());
|
|
2901
|
+
const coords = points.map((e) => (0, vesium.toCoord)(e));
|
|
2902
|
+
if (coords.length < 2) {
|
|
2903
|
+
entity.polygon.hierarchy = void 0;
|
|
2904
|
+
return context.previous;
|
|
2905
|
+
}
|
|
2906
|
+
const positions = flagTriangle(coords).map((item) => (0, vesium.toCartesian3)(item));
|
|
2907
|
+
const hierarchy = new cesium.PolygonHierarchy(positions);
|
|
2908
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2909
|
+
return { entities: [entity] };
|
|
2910
|
+
}
|
|
2911
|
+
});
|
|
2912
|
+
|
|
2913
|
+
//#endregion
|
|
2914
|
+
//#region scheme/PolygonSmooth.ts
|
|
2915
|
+
const PlotSchemePolygonSmooth = new PlotScheme({
|
|
2916
|
+
type: "PolygonSmooth",
|
|
2917
|
+
allowManualComplete: (packable) => packable.positions.length >= 3,
|
|
1487
2918
|
skeletons: [
|
|
2919
|
+
moved,
|
|
1488
2920
|
control,
|
|
1489
|
-
|
|
1490
|
-
moved
|
|
2921
|
+
intervalNonclosed
|
|
1491
2922
|
],
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
const
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
2923
|
+
initRender() {
|
|
2924
|
+
return { entities: [new cesium.Entity({ polygon: {} })] };
|
|
2925
|
+
},
|
|
2926
|
+
render(context) {
|
|
2927
|
+
const entity = context.previous.entities[0];
|
|
2928
|
+
const positions = context.packable.positions;
|
|
2929
|
+
const mousePosition = context.mouse;
|
|
2930
|
+
mousePosition && positions.push(mousePosition.clone());
|
|
2931
|
+
if (positions.length <= 2) {
|
|
2932
|
+
entity.polygon.hierarchy = void 0;
|
|
2933
|
+
return context.previous;
|
|
2934
|
+
}
|
|
2935
|
+
const wgs84s = positions.map((e) => (0, vesium.toCoord)(e));
|
|
2936
|
+
wgs84s.push(wgs84s[0]);
|
|
2937
|
+
const { features } = __turf_turf.polygonSmooth(__turf_turf.polygon([wgs84s]), { iterations: 3 });
|
|
2938
|
+
const cartesians = features[0].geometry.coordinates[0].map((item) => (0, vesium.toCartesian3)(item)).filter((e) => !!e);
|
|
2939
|
+
const hierarchy = new cesium.PolygonHierarchy(cartesians);
|
|
2940
|
+
entity.polygon.hierarchy = new cesium.CallbackProperty(() => hierarchy, false);
|
|
2941
|
+
return { entities: [entity] };
|
|
2942
|
+
}
|
|
2943
|
+
});
|
|
2944
|
+
|
|
2945
|
+
//#endregion
|
|
2946
|
+
//#region scheme/Polyline.ts
|
|
2947
|
+
const PlotSchemePolyline = new PlotScheme({
|
|
2948
|
+
type: "Polyline",
|
|
2949
|
+
allowManualComplete: (packable) => packable.positions.length > 1,
|
|
2950
|
+
skeletons: [
|
|
2951
|
+
moved,
|
|
2952
|
+
control,
|
|
2953
|
+
intervalNonclosed
|
|
2954
|
+
],
|
|
2955
|
+
initRender() {
|
|
2956
|
+
return { entities: [new cesium.Entity({ polyline: {
|
|
2957
|
+
material: cesium.Color.RED,
|
|
2958
|
+
width: 2
|
|
2959
|
+
} })] };
|
|
2960
|
+
},
|
|
2961
|
+
render(context) {
|
|
2962
|
+
const entity = context.previous.entities[0];
|
|
2963
|
+
const positions = [...context.packable.positions];
|
|
2964
|
+
const mouse = context.mouse;
|
|
2965
|
+
mouse && positions.push(mouse.clone());
|
|
2966
|
+
const cache = positions.length >= 2 ? positions : [];
|
|
2967
|
+
entity.polyline.positions = new cesium.CallbackProperty(() => cache, false);
|
|
2968
|
+
return { entities: [entity] };
|
|
2969
|
+
}
|
|
2970
|
+
});
|
|
2971
|
+
|
|
2972
|
+
//#endregion
|
|
2973
|
+
//#region scheme/PolylineCurve.ts
|
|
2974
|
+
const PlotSchemePolylineCurve = new PlotScheme({
|
|
2975
|
+
type: "PolylineCurve",
|
|
2976
|
+
allowManualComplete: (packable) => packable.positions.length > 1,
|
|
2977
|
+
skeletons: [
|
|
2978
|
+
moved,
|
|
2979
|
+
control,
|
|
2980
|
+
intervalNonclosed
|
|
2981
|
+
],
|
|
2982
|
+
initRender() {
|
|
2983
|
+
return { entities: [new cesium.Entity({ polyline: {
|
|
2984
|
+
material: cesium.Color.RED,
|
|
2985
|
+
width: 2
|
|
2986
|
+
} })] };
|
|
2987
|
+
},
|
|
2988
|
+
render(context) {
|
|
2989
|
+
const entity = context.previous.entities[0];
|
|
2990
|
+
const positions = [...context.packable.positions];
|
|
2991
|
+
const mouse = context.mouse;
|
|
2992
|
+
mouse && positions.push(mouse.clone());
|
|
2993
|
+
if (positions.length < 2) {
|
|
2994
|
+
entity.polyline.positions = void 0;
|
|
2995
|
+
return context.previous;
|
|
2996
|
+
}
|
|
2997
|
+
const coords = positions.map((position) => (0, vesium.toCoord)(position));
|
|
2998
|
+
const { geometry: { coordinates } } = __turf_turf.bezierSpline(__turf_turf.lineString(coords));
|
|
2999
|
+
entity.polyline.positions = new cesium.CallbackProperty(() => coordinates.map(vesium.toCartesian3), false);
|
|
3000
|
+
return { entities: [entity] };
|
|
3001
|
+
}
|
|
3002
|
+
});
|
|
3003
|
+
|
|
3004
|
+
//#endregion
|
|
3005
|
+
//#region scheme/Rectangle.ts
|
|
3006
|
+
const PlotSchemeRectangle = new PlotScheme({
|
|
3007
|
+
type: "Rectangle",
|
|
3008
|
+
complete: (packable) => packable.positions.length >= 2,
|
|
3009
|
+
skeletons: [moved, control],
|
|
3010
|
+
initRender() {
|
|
3011
|
+
return { entities: [new cesium.Entity({ rectangle: {} })] };
|
|
3012
|
+
},
|
|
3013
|
+
render(context) {
|
|
3014
|
+
const entity = context.previous.entities[0];
|
|
3015
|
+
const positions = [...context.packable.positions];
|
|
3016
|
+
const mouse = context.mouse;
|
|
3017
|
+
mouse && positions.push(mouse.clone());
|
|
3018
|
+
if (positions.length < 2) {
|
|
3019
|
+
entity.rectangle.coordinates = void 0;
|
|
3020
|
+
return context.previous;
|
|
3021
|
+
}
|
|
3022
|
+
const coordinates = cesium.Rectangle.fromCartesianArray(positions ?? []);
|
|
3023
|
+
entity.rectangle.coordinates = new cesium.CallbackProperty(() => coordinates, false);
|
|
1500
3024
|
return { entities: [entity] };
|
|
1501
3025
|
}
|
|
1502
3026
|
});
|
|
@@ -1505,6 +3029,29 @@ const schemeRectangle = new PlotScheme({
|
|
|
1505
3029
|
exports.PlotAction = PlotAction;
|
|
1506
3030
|
exports.PlotFeature = PlotFeature;
|
|
1507
3031
|
exports.PlotScheme = PlotScheme;
|
|
3032
|
+
exports.PlotSchemeBillboard = PlotSchemeBillboard;
|
|
3033
|
+
exports.PlotSchemeBillboardPinBuilder = PlotSchemeBillboardPinBuilder;
|
|
3034
|
+
exports.PlotSchemeCylinder = PlotSchemeCylinder;
|
|
3035
|
+
exports.PlotSchemeEllipse = PlotSchemeEllipse;
|
|
3036
|
+
exports.PlotSchemeLabel = PlotSchemeLabel;
|
|
3037
|
+
exports.PlotSchemePoint = PlotSchemePoint;
|
|
3038
|
+
exports.PlotSchemePolygon = PlotSchemePolygon;
|
|
3039
|
+
exports.PlotSchemePolygonArc = PlotSchemePolygonArc;
|
|
3040
|
+
exports.PlotSchemePolygonArrowAttackDirection = PlotSchemePolygonArrowAttackDirection;
|
|
3041
|
+
exports.PlotSchemePolygonArrowAttackDirectionTailed = PlotSchemePolygonArrowAttackDirectionTailed;
|
|
3042
|
+
exports.PlotSchemePolygonArrowClamped = PlotSchemePolygonArrowClamped;
|
|
3043
|
+
exports.PlotSchemePolygonArrowStraight = PlotSchemePolygonArrowStraight;
|
|
3044
|
+
exports.PlotSchemePolygonArrowStraightSharp = PlotSchemePolygonArrowStraightSharp;
|
|
3045
|
+
exports.PlotSchemePolygonArrowUnitCombatOperation = PlotSchemePolygonArrowUnitCombatOperation;
|
|
3046
|
+
exports.PlotSchemePolygonArrowUnitCombatOperationTailed = PlotSchemePolygonArrowUnitCombatOperationTailed;
|
|
3047
|
+
exports.PlotSchemePolygonAssemblingPlace = PlotSchemePolygonAssemblingPlace;
|
|
3048
|
+
exports.PlotSchemePolygonFlagCurve = PlotSchemePolygonFlagCurve;
|
|
3049
|
+
exports.PlotSchemePolygonFlagRect = PlotSchemePolygonFlagRect;
|
|
3050
|
+
exports.PlotSchemePolygonFlagTriangle = PlotSchemePolygonFlagTriangle;
|
|
3051
|
+
exports.PlotSchemePolygonSmooth = PlotSchemePolygonSmooth;
|
|
3052
|
+
exports.PlotSchemePolyline = PlotSchemePolyline;
|
|
3053
|
+
exports.PlotSchemePolylineCurve = PlotSchemePolylineCurve;
|
|
3054
|
+
exports.PlotSchemeRectangle = PlotSchemeRectangle;
|
|
1508
3055
|
exports.PlotSkeletonEntity = PlotSkeletonEntity;
|
|
1509
3056
|
exports.SampledPlotProperty = SampledPlotProperty;
|
|
1510
3057
|
exports.SampledPlotStrategy = SampledPlotStrategy;
|
|
@@ -1512,12 +3059,8 @@ exports.control = control;
|
|
|
1512
3059
|
exports.interval = interval;
|
|
1513
3060
|
exports.intervalNonclosed = intervalNonclosed;
|
|
1514
3061
|
exports.moved = moved;
|
|
1515
|
-
exports.schemeBillboard = schemeBillboard;
|
|
1516
|
-
exports.schemeLabel = schemeLabel;
|
|
1517
3062
|
exports.schemeMeasureArea = schemeMeasureArea;
|
|
1518
|
-
exports.
|
|
1519
|
-
exports.schemePolyline = schemePolyline;
|
|
1520
|
-
exports.schemeRectangle = schemeRectangle;
|
|
3063
|
+
exports.schemeMeasureDistance = schemeMeasureDistance;
|
|
1521
3064
|
exports.usePlot = usePlot;
|
|
1522
|
-
})(this.Vesium = this.Vesium || {}, Cesium, Vesium, VueUse, Vue);
|
|
3065
|
+
})(this.Vesium = this.Vesium || {}, Cesium, Vesium, VueUse, Vue, turf);
|
|
1523
3066
|
//# sourceMappingURL=index.iife.js.map
|