gis-common 5.1.11 → 5.1.12
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/gis-common.es.js +31 -7
- package/dist/gis-common.umd.js +1 -1
- package/dist/utils/CommUtil.d.ts +2 -2
- package/dist/utils/GeoUtil.d.ts +23 -4
- package/package.json +40 -40
package/dist/gis-common.es.js
CHANGED
|
@@ -1005,18 +1005,18 @@ class GeoUtil {
|
|
|
1005
1005
|
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
|
|
1006
1006
|
}
|
|
1007
1007
|
/**
|
|
1008
|
-
*
|
|
1008
|
+
* 计算两个点之间的距离
|
|
1009
1009
|
*
|
|
1010
|
-
* @param A
|
|
1011
|
-
* @param B
|
|
1010
|
+
* @param A 点A,包含x和y两个属性
|
|
1011
|
+
* @param B 点B,包含x和y两个属性
|
|
1012
1012
|
* @returns 返回两点之间的距离,单位为米
|
|
1013
1013
|
*/
|
|
1014
1014
|
static distanceByPoints(A, B) {
|
|
1015
|
-
const {
|
|
1016
|
-
const {
|
|
1015
|
+
const { x: xa, y: ya } = A;
|
|
1016
|
+
const { x: xb, y: yb } = B;
|
|
1017
1017
|
const earthR = 6371e3;
|
|
1018
|
-
const x = Math.cos(
|
|
1019
|
-
const y = Math.sin(
|
|
1018
|
+
const x = Math.cos(ya * Math.PI / 180) * Math.cos(yb * Math.PI / 180) * Math.cos((xa - xb) * Math.PI / 180);
|
|
1019
|
+
const y = Math.sin(ya * Math.PI / 180) * Math.sin(yb * Math.PI / 180);
|
|
1020
1020
|
let s = x + y;
|
|
1021
1021
|
if (s > 1) s = 1;
|
|
1022
1022
|
if (s < -1) s = -1;
|
|
@@ -1280,6 +1280,28 @@ class GeoUtil {
|
|
|
1280
1280
|
y: ySum / n
|
|
1281
1281
|
};
|
|
1282
1282
|
}
|
|
1283
|
+
/**
|
|
1284
|
+
* 在两点之间的线段上进行插值计算
|
|
1285
|
+
*
|
|
1286
|
+
* @param pA 线段起点,可以是Coordinate类型(包含x,y属性)或LngLat类型(包含lng,lat属性)
|
|
1287
|
+
* @param pB 线段终点,可以是Coordinate类型(包含x,y属性)或LngLat类型(包含lng,lat属性)
|
|
1288
|
+
* @param ratio 插值比例,0表示在起点pA,1表示在终点pB,0-1之间表示两点间的插值点
|
|
1289
|
+
* @returns 返回插值点坐标,类型与输入参数保持一致
|
|
1290
|
+
*/
|
|
1291
|
+
static interpolateOnSegment(pA, pB, ratio) {
|
|
1292
|
+
ratio = MathUtil.clamp(ratio, 0, 1);
|
|
1293
|
+
if ("x" in pA && "y" in pA && "x" in pB && "y" in pB) {
|
|
1294
|
+
return {
|
|
1295
|
+
x: pA.x * (1 - ratio) + ratio * pB.x,
|
|
1296
|
+
y: pA.y * (1 - ratio) + ratio * pB.y
|
|
1297
|
+
};
|
|
1298
|
+
} else if ("lng" in pA && "lat" in pA && "lng" in pB && "lat" in pB) {
|
|
1299
|
+
return {
|
|
1300
|
+
lng: pA.lng * (1 - ratio) + ratio * pB.lng,
|
|
1301
|
+
lat: pA.lat * (1 - ratio) + ratio * pB.lat
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1283
1305
|
}
|
|
1284
1306
|
__publicField(GeoUtil, "toRadian", Math.PI / 180);
|
|
1285
1307
|
__publicField(GeoUtil, "R", 6371393);
|
|
@@ -3387,9 +3409,11 @@ class CanvasDrawer {
|
|
|
3387
3409
|
const canvas = document.createElement("canvas");
|
|
3388
3410
|
if (width) {
|
|
3389
3411
|
canvas.width = width;
|
|
3412
|
+
canvas.style.width = width + "px";
|
|
3390
3413
|
}
|
|
3391
3414
|
if (height) {
|
|
3392
3415
|
canvas.height = height;
|
|
3416
|
+
canvas.style.height = height + "px";
|
|
3393
3417
|
}
|
|
3394
3418
|
return canvas;
|
|
3395
3419
|
}
|