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