cesium-alpha-earth 1.0.76 → 1.0.78
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.js
CHANGED
|
@@ -321624,13 +321624,9 @@ function cartesianToWindow(viewer, cartesian32) {
|
|
|
321624
321624
|
return void 0;
|
|
321625
321625
|
}
|
|
321626
321626
|
}
|
|
321627
|
-
function createMyWorker() {
|
|
321627
|
+
function createMyWorker(options = {}) {
|
|
321628
321628
|
let worker;
|
|
321629
|
-
worker = new Worker(
|
|
321630
|
-
/* @vite-ignore */
|
|
321631
|
-
"/assets/geojson2Line-D52oeUm7.js",
|
|
321632
|
-
import.meta.url
|
|
321633
|
-
));
|
|
321629
|
+
worker = new Worker("/worker/geojson2Line.ts");
|
|
321634
321630
|
return worker;
|
|
321635
321631
|
}
|
|
321636
321632
|
class PositionInfoStatusBar {
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @param {Object} options - 可选配置(如 Worker 路径自定义)
|
|
5
5
|
* @returns {Worker} 实例化的 Worker 对象
|
|
6
6
|
*/
|
|
7
|
-
function createMyWorker() {
|
|
7
|
+
function createMyWorker(options = {}) {
|
|
8
8
|
// 处理模块化场景(如 Webpack 等打包工具)
|
|
9
9
|
let worker;
|
|
10
10
|
// 方案1:适配打包工具(如 Webpack 的 worker-loader)
|
|
11
|
-
worker = new Worker(
|
|
11
|
+
worker = new Worker('/worker/geojson2Line.ts');
|
|
12
12
|
return worker;
|
|
13
13
|
}
|
|
14
14
|
// 导出方式1:ES 模块导出(兼容 import/export)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/worker/geojson2Line/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;GAIG;AACH,SAAS,cAAc;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/worker/geojson2Line/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC;;;;GAIG;AACH,SAAS,cAAc,CAAC,OAAO,GAAG,EAAE;IAChC,2BAA2B;IAC3B,IAAI,MAAM,CAAC;IAEX,wCAAwC;IACxC,MAAM,GAAG,IAAI,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAG/C,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,kCAAkC;AAClC,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
"use strict";
|
|
3
|
-
var earthRadius = 63710088e-1;
|
|
4
|
-
var factors = {
|
|
5
|
-
centimeters: earthRadius * 100,
|
|
6
|
-
centimetres: earthRadius * 100,
|
|
7
|
-
degrees: 360 / (2 * Math.PI),
|
|
8
|
-
feet: earthRadius * 3.28084,
|
|
9
|
-
inches: earthRadius * 39.37,
|
|
10
|
-
kilometers: earthRadius / 1e3,
|
|
11
|
-
kilometres: earthRadius / 1e3,
|
|
12
|
-
meters: earthRadius,
|
|
13
|
-
metres: earthRadius,
|
|
14
|
-
miles: earthRadius / 1609.344,
|
|
15
|
-
millimeters: earthRadius * 1e3,
|
|
16
|
-
millimetres: earthRadius * 1e3,
|
|
17
|
-
nauticalmiles: earthRadius / 1852,
|
|
18
|
-
radians: 1,
|
|
19
|
-
yards: earthRadius * 1.0936
|
|
20
|
-
};
|
|
21
|
-
function feature(geom, properties, options = {}) {
|
|
22
|
-
const feat = { type: "Feature" };
|
|
23
|
-
if (options.id === 0 || options.id) {
|
|
24
|
-
feat.id = options.id;
|
|
25
|
-
}
|
|
26
|
-
if (options.bbox) {
|
|
27
|
-
feat.bbox = options.bbox;
|
|
28
|
-
}
|
|
29
|
-
feat.properties = {};
|
|
30
|
-
feat.geometry = geom;
|
|
31
|
-
return feat;
|
|
32
|
-
}
|
|
33
|
-
function point(coordinates, properties, options = {}) {
|
|
34
|
-
if (!coordinates) {
|
|
35
|
-
throw new Error("coordinates is required");
|
|
36
|
-
}
|
|
37
|
-
if (!Array.isArray(coordinates)) {
|
|
38
|
-
throw new Error("coordinates must be an Array");
|
|
39
|
-
}
|
|
40
|
-
if (coordinates.length < 2) {
|
|
41
|
-
throw new Error("coordinates must be at least 2 numbers long");
|
|
42
|
-
}
|
|
43
|
-
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
|
|
44
|
-
throw new Error("coordinates must contain numbers");
|
|
45
|
-
}
|
|
46
|
-
const geom = {
|
|
47
|
-
type: "Point",
|
|
48
|
-
coordinates
|
|
49
|
-
};
|
|
50
|
-
return feature(geom, properties, options);
|
|
51
|
-
}
|
|
52
|
-
function radiansToLength(radians, units = "kilometers") {
|
|
53
|
-
const factor = factors[units];
|
|
54
|
-
if (!factor) {
|
|
55
|
-
throw new Error(units + " units is invalid");
|
|
56
|
-
}
|
|
57
|
-
return radians * factor;
|
|
58
|
-
}
|
|
59
|
-
function degreesToRadians(degrees) {
|
|
60
|
-
const normalisedDegrees = degrees % 360;
|
|
61
|
-
return normalisedDegrees * Math.PI / 180;
|
|
62
|
-
}
|
|
63
|
-
function isNumber(num) {
|
|
64
|
-
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
65
|
-
}
|
|
66
|
-
function getCoord(coord) {
|
|
67
|
-
if (!coord) {
|
|
68
|
-
throw new Error("coord is required");
|
|
69
|
-
}
|
|
70
|
-
if (!Array.isArray(coord)) {
|
|
71
|
-
if (coord.type === "Feature" && coord.geometry !== null && coord.geometry.type === "Point") {
|
|
72
|
-
return [...coord.geometry.coordinates];
|
|
73
|
-
}
|
|
74
|
-
if (coord.type === "Point") {
|
|
75
|
-
return [...coord.coordinates];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (Array.isArray(coord) && coord.length >= 2 && !Array.isArray(coord[0]) && !Array.isArray(coord[1])) {
|
|
79
|
-
return [...coord];
|
|
80
|
-
}
|
|
81
|
-
throw new Error("coord must be GeoJSON Point or an Array of numbers");
|
|
82
|
-
}
|
|
83
|
-
function distance(from, to, options = {}) {
|
|
84
|
-
var coordinates1 = getCoord(from);
|
|
85
|
-
var coordinates2 = getCoord(to);
|
|
86
|
-
var dLat = degreesToRadians(coordinates2[1] - coordinates1[1]);
|
|
87
|
-
var dLon = degreesToRadians(coordinates2[0] - coordinates1[0]);
|
|
88
|
-
var lat1 = degreesToRadians(coordinates1[1]);
|
|
89
|
-
var lat2 = degreesToRadians(coordinates2[1]);
|
|
90
|
-
var a = Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
|
|
91
|
-
return radiansToLength(
|
|
92
|
-
2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)),
|
|
93
|
-
options.units
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
self.onmessage = (e) => {
|
|
97
|
-
let data = convertGeoJsonToGraph(e.data.geoJson, e.data.snapThreshold);
|
|
98
|
-
self.postMessage(data);
|
|
99
|
-
};
|
|
100
|
-
function convertGeoJsonToGraph(geoJson, snapThreshold) {
|
|
101
|
-
var _a;
|
|
102
|
-
let projectedFeatureCollection = {
|
|
103
|
-
features: [],
|
|
104
|
-
type: "FeatureCollection"
|
|
105
|
-
};
|
|
106
|
-
const nodes = /* @__PURE__ */ new Map();
|
|
107
|
-
let featureIndex = 0;
|
|
108
|
-
for (let feature2 of geoJson.features) {
|
|
109
|
-
if (!["LineString", "MultiLineString"].includes((_a = feature2.geometry) == null ? void 0 : _a.type)) {
|
|
110
|
-
console.warn(`Feature ${featureIndex} 不是线数据,跳过`);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
let coordinates = [];
|
|
114
|
-
if (feature2.geometry.type === "LineString") {
|
|
115
|
-
coordinates = [feature2.geometry.coordinates];
|
|
116
|
-
} else if (feature2.geometry.type === "MultiLineString") {
|
|
117
|
-
coordinates = feature2.geometry.coordinates;
|
|
118
|
-
}
|
|
119
|
-
for (const line of coordinates) {
|
|
120
|
-
let currentNodesLine = [];
|
|
121
|
-
for (const [index, position] of line.entries()) {
|
|
122
|
-
const [lng, lat] = position;
|
|
123
|
-
let currentNodeId = null;
|
|
124
|
-
let longitude = lng;
|
|
125
|
-
let latitude = lat;
|
|
126
|
-
if (index === 0 || index === line.length - 1) {
|
|
127
|
-
currentNodeId = findMatchedNode(nodes, [lng, lat], snapThreshold);
|
|
128
|
-
if (currentNodeId) {
|
|
129
|
-
let positionCoord = currentNodeId.split(",");
|
|
130
|
-
longitude = positionCoord[0];
|
|
131
|
-
latitude = positionCoord[1];
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
currentNodesLine.push([parseFloat(longitude), parseFloat(latitude)]);
|
|
135
|
-
projectedFeatureCollection.features.push({
|
|
136
|
-
type: "Feature",
|
|
137
|
-
geometry: {
|
|
138
|
-
type: "LineString",
|
|
139
|
-
coordinates: currentNodesLine
|
|
140
|
-
},
|
|
141
|
-
properties: {}
|
|
142
|
-
});
|
|
143
|
-
nodes.set(`${longitude},${latitude}`, {
|
|
144
|
-
id: `${longitude},${latitude}`,
|
|
145
|
-
coord: [longitude, latitude],
|
|
146
|
-
properties: feature2.properties
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
featureIndex += 1;
|
|
151
|
-
}
|
|
152
|
-
return projectedFeatureCollection;
|
|
153
|
-
}
|
|
154
|
-
function findMatchedNode(nodeCoordMap, coord, snapThreshold) {
|
|
155
|
-
let nearestNodeId = null;
|
|
156
|
-
nodeCoordMap.forEach((nodeId, coordKey) => {
|
|
157
|
-
const [lng, lat] = coordKey.split(",").map(Number);
|
|
158
|
-
const distance$1 = distance(point([lng, lat]), point(coord)) * 1e3;
|
|
159
|
-
if (distance$1 < snapThreshold) {
|
|
160
|
-
nearestNodeId = coordKey;
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
return nearestNodeId;
|
|
164
|
-
}
|
|
165
|
-
})();
|