gis-common 5.1.11 → 5.1.13

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.
@@ -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 经纬度点A,包含lng(经度)和lat(纬度)两个属性
1011
- * @param B 经纬度点B,包含lng(经度)和lat(纬度)两个属性
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 { lng: lngA, lat: latA } = A;
1016
- const { lng: lngB, lat: latB } = B;
1015
+ const { x: xa, y: ya } = A;
1016
+ const { x: xb, y: yb } = B;
1017
1017
  const earthR = 6371e3;
1018
- const x = Math.cos(latA * Math.PI / 180) * Math.cos(latB * Math.PI / 180) * Math.cos((lngA - lngB) * Math.PI / 180);
1019
- const y = Math.sin(latA * Math.PI / 180) * Math.sin(latB * Math.PI / 180);
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;
@@ -1223,18 +1223,6 @@ class GeoUtil {
1223
1223
  const y = earthRad / 2 * Math.log((1 + Math.sin(a)) / (1 - Math.sin(a)));
1224
1224
  return { x, y };
1225
1225
  }
1226
- /**
1227
- * 根据百分比获取坐标
1228
- *
1229
- * @param start 起点坐标
1230
- * @param end 终点坐标
1231
- * @param percent 百分比,取值范围0-1
1232
- * @returns 返回插值后的坐标
1233
- */
1234
- static interpolate({ x: x1, y: y1, z: z1 = 0 }, { x: x2, y: y2, z: z2 = 0 }, percent) {
1235
- const dx = x2 - x1, dy = y2 - y1, dz = z2 - z1;
1236
- return { x: x1 + dx * percent, y: y1 + dy * percent, z: z1 + dz * percent };
1237
- }
1238
1226
  /**
1239
1227
  * 计算三角形面积
1240
1228
  *
@@ -1280,6 +1268,25 @@ class GeoUtil {
1280
1268
  y: ySum / n
1281
1269
  };
1282
1270
  }
1271
+ /**
1272
+ * 根据百分比获取坐标
1273
+ *
1274
+ * @param pA 线段起点,可以是Coordinate类型(包含x,y属性)或LngLat类型(包含lng,lat属性)
1275
+ * @param pB 线段终点,可以是Coordinate类型(包含x,y属性)或LngLat类型(包含lng,lat属性)
1276
+ * @param ratio 插值比例,0表示在起点pA,1表示在终点pB,0-1之间表示两点间的插值点
1277
+ * @returns 返回插值点坐标,类型与输入参数保持一致
1278
+ */
1279
+ static interpolate(pA, pB, ratio) {
1280
+ if ("x" in pA && "y" in pA && "x" in pB && "y" in pB) {
1281
+ const dx = pB.x - pA.x;
1282
+ const dy = pB.y - pA.y;
1283
+ return { x: pA.x + dx * ratio, y: pA.y + dy * ratio };
1284
+ } else if ("lng" in pA && "lat" in pA && "lng" in pB && "lat" in pB) {
1285
+ const dx = pB.lng - pA.lng;
1286
+ const dy = pB.lat - pA.lat;
1287
+ return { x: pA.lng + dx * ratio, y: pA.lat + dy * ratio };
1288
+ }
1289
+ }
1283
1290
  }
1284
1291
  __publicField(GeoUtil, "toRadian", Math.PI / 180);
1285
1292
  __publicField(GeoUtil, "R", 6371393);
@@ -1447,7 +1454,7 @@ class Color {
1447
1454
  this._r = r;
1448
1455
  this._g = g;
1449
1456
  this._b = b;
1450
- this._alpha = MathUtil.clamp(a || 1, 0, 1);
1457
+ this._alpha = MathUtil.clamp(a ?? 1, 0, 1);
1451
1458
  }
1452
1459
  _validateColorChannel(channel) {
1453
1460
  if (channel < 0 || channel > 255) {
@@ -1470,7 +1477,7 @@ class Color {
1470
1477
  return Color.rgb2hex(this._r, this._g, this._b, this._alpha);
1471
1478
  }
1472
1479
  setAlpha(a) {
1473
- this._alpha = MathUtil.clamp(a, 0, 1);
1480
+ this._alpha = MathUtil.clamp(a ?? 1, 0, 1);
1474
1481
  return this;
1475
1482
  }
1476
1483
  // 设置颜色的RGB值
@@ -3387,9 +3394,11 @@ class CanvasDrawer {
3387
3394
  const canvas = document.createElement("canvas");
3388
3395
  if (width) {
3389
3396
  canvas.width = width;
3397
+ canvas.style.width = width + "px";
3390
3398
  }
3391
3399
  if (height) {
3392
3400
  canvas.height = height;
3401
+ canvas.style.height = height + "px";
3393
3402
  }
3394
3403
  return canvas;
3395
3404
  }