@fleet-frontend/mower-maps 0.2.5-beta.23 → 0.2.5-beta.25

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.
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * 地图渲染相关常量配置
3
3
  */
4
+ /** 无效 GPS 时的兜底中心点 [lng, lat] */
5
+ export declare const DEFAULT_GPS_CENTER: [number, number];
6
+ /** 无 map_width/map_height 时的默认 GPS 边界 [lng, lat](中心约 (0,0)) */
4
7
  export declare const DEFAULT_COORDINATES: {
5
8
  sw: number[];
6
9
  ne: number[];
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/config/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,eAAO,MAAM,mBAAmB;;;CAG/B,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,YAAY,KAAK,CAAC;AAE/B;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;CAUtB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;CAOpB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;CAMhB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;CAUf,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAYrB,CAAC;AAGX,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEjF,eAAO,MAAM,qBAAqB,sqUAqB3B,CAAC;AAER;;GAEG;AACH,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B;;GAEG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC;;GAEG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC;;GAEG;AACH,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C;;GAEG;AACH,eAAO,MAAM,uBAAuB,IAA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,mBAAmB,IAAI,CAAC;AACrC;;GAEG;AACH,eAAO,MAAM,eAAe,IAAI,CAAC;AACjC;;GAEG;AACH,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAC9C;;GAEG;AACH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC;;GAEG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC;;GAEG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC;;GAEG;AACH,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAChD;;GAEG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC;;GAEG;AACH,eAAO,MAAM,UAAU,KAAK,CAAC;AAE7B,eAAO,MAAM,eAAe,4BAA4B,CAAC;AAEzD,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,mBAAmB,MAAM,CAAC;AACvC,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAGtC,eAAO,MAAM,wBAAwB,WAAW,CAAC"}
package/dist/index.esm.js CHANGED
@@ -10617,9 +10617,12 @@ var SvgMapOpacity;
10617
10617
  // sw: [116.071044, 40.102099],
10618
10618
  // ne: [116.0734, 40.103901],
10619
10619
  // };
10620
+ /** 无效 GPS 时的兜底中心点 [lng, lat] */
10621
+ const DEFAULT_GPS_CENTER = [0, 0];
10622
+ /** 无 map_width/map_height 时的默认 GPS 边界 [lng, lat](中心约 (0,0)) */
10620
10623
  const DEFAULT_COORDINATES = {
10621
- sw: [-1178e-6, -901e-6],
10622
- ne: [0.001178, 0.000901],
10624
+ sw: [-225e-6, -225e-6],
10625
+ ne: [0.000225, 0.000225],
10623
10626
  };
10624
10627
  /**
10625
10628
  * 缩放因子 - 将米转换为像素
@@ -18560,6 +18563,38 @@ function calculateBoundaryBoundsCenter(mapData) {
18560
18563
  boundaryBounds.minY + (boundaryBounds.maxY - boundaryBounds.minY) / 2,
18561
18564
  ];
18562
18565
  }
18566
+ /**
18567
+ * 由中心点与物理尺寸(米)计算 GPS 边界 [lng, lat]
18568
+ */
18569
+ function computeGpsBoundsFromCenterAndSize(centerLng, centerLat, mapWidthMeters, mapHeightMeters) {
18570
+ const METERS_PER_DEGREE_LAT = EQUATORIAL_CIRCUMFERENCE / 360;
18571
+ const METERS_PER_DEGREE_LNG = METERS_PER_DEGREE_LAT * Math.cos((centerLat * Math.PI) / 180);
18572
+ const swLat = centerLat - mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18573
+ const swLng = centerLng - mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18574
+ const neLat = centerLat + mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18575
+ const neLng = centerLng + mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18576
+ return {
18577
+ sw: [swLng, swLat],
18578
+ ne: [neLng, neLat],
18579
+ };
18580
+ }
18581
+ /**
18582
+ * GPS 无效时:中心 (0,0) + JSON 的 map_width/map_height;无尺寸则用 DEFAULT_COORDINATES
18583
+ */
18584
+ function getFallbackGpsBounds(mapData) {
18585
+ const [centerLng, centerLat] = DEFAULT_GPS_CENTER;
18586
+ const hasMapSize = typeof mapData.map_width === 'number' &&
18587
+ typeof mapData.map_height === 'number' &&
18588
+ mapData.map_width > 0 &&
18589
+ mapData.map_height > 0;
18590
+ if (hasMapSize) {
18591
+ return computeGpsBoundsFromCenterAndSize(centerLng, centerLat, mapData.map_width, mapData.map_height);
18592
+ }
18593
+ return {
18594
+ sw: [...DEFAULT_COORDINATES.sw],
18595
+ ne: [...DEFAULT_COORDINATES.ne],
18596
+ };
18597
+ }
18563
18598
  /**
18564
18599
  * 检查GPS坐标是否有效
18565
18600
  */
@@ -18664,39 +18699,44 @@ function calculateMapGpsCenter(mapData) {
18664
18699
  }
18665
18700
  }
18666
18701
  // 如果有西南角和东北角坐标,检查其有效性并计算中心点
18667
- if (mapData.sw_gps &&
18668
- mapData.ne_gps &&
18669
- mapData.sw_gps.length >= 2 &&
18670
- mapData.ne_gps.length >= 2) {
18671
- const swLat = mapData.sw_gps[1];
18672
- const swLng = mapData.sw_gps[0];
18673
- const neLat = mapData.ne_gps[1];
18674
- const neLng = mapData.ne_gps[0];
18675
- // 检查边界坐标的有效性
18676
- if (isValidGpsCoordinate(swLat, swLng) && isValidGpsCoordinate(neLat, neLng)) {
18677
- return {
18678
- lat: (swLat + neLat) / 2,
18679
- lng: (swLng + neLng) / 2,
18680
- };
18681
- }
18682
- else {
18683
- console.warn('sw_gps或ne_gps坐标无效:', {
18684
- sw: { lat: swLat, lng: swLng },
18685
- ne: { lat: neLat, lng: neLng },
18686
- });
18687
- }
18688
- }
18702
+ // if (
18703
+ // mapData.sw_gps &&
18704
+ // mapData.ne_gps &&
18705
+ // mapData.sw_gps.length >= 2 &&
18706
+ // mapData.ne_gps.length >= 2
18707
+ // ) {
18708
+ // const swLat = mapData.sw_gps[1];
18709
+ // const swLng = mapData.sw_gps[0];
18710
+ // const neLat = mapData.ne_gps[1];
18711
+ // const neLng = mapData.ne_gps[0];
18712
+ // // 检查边界坐标的有效性
18713
+ // if (isValidGpsCoordinate(swLat, swLng) && isValidGpsCoordinate(neLat, neLng)) {
18714
+ // return {
18715
+ // lat: (swLat + neLat) / 2,
18716
+ // lng: (swLng + neLng) / 2,
18717
+ // };
18718
+ // } else {
18719
+ // console.warn('sw_gps或ne_gps坐标无效:', {
18720
+ // sw: { lat: swLat, lng: swLng },
18721
+ // ne: { lat: neLat, lng: neLng },
18722
+ // });
18723
+ // }
18724
+ // }
18689
18725
  // 尝试从地图几何边界估算GPS坐标
18690
- const estimatedBounds = estimateGpsFromMapBounds(mapData);
18691
- if (estimatedBounds) {
18692
- // 从估算的边界计算中心点
18693
- const centerLat = (estimatedBounds.sw[1] + estimatedBounds.ne[1]) / 2;
18694
- const centerLng = (estimatedBounds.sw[0] + estimatedBounds.ne[0]) / 2;
18695
- return { lat: centerLat, lng: centerLng };
18696
- }
18726
+ // const estimatedBounds = estimateGpsFromMapBounds(mapData);
18727
+ // if (estimatedBounds) {
18728
+ // // 从估算的边界计算中心点
18729
+ // const centerLat = (estimatedBounds.sw[1] + estimatedBounds.ne[1]) / 2;
18730
+ // const centerLng = (estimatedBounds.sw[0] + estimatedBounds.ne[0]) / 2;
18731
+ // return { lat: centerLat, lng: centerLng };
18732
+ // }
18733
+ // return {
18734
+ // lat: 39.9042, // 北京纬度
18735
+ // lng: 116.4074, // 北京经度
18736
+ // };
18697
18737
  return {
18698
- lat: 39.9042, // 北京纬度
18699
- lng: 116.4074, // 北京经度
18738
+ lat: DEFAULT_GPS_CENTER[1],
18739
+ lng: DEFAULT_GPS_CENTER[0],
18700
18740
  };
18701
18741
  }
18702
18742
  // 旋转坐标点
@@ -18726,50 +18766,22 @@ const getValidGpsBounds = (mapData, rotation = 0) => {
18726
18766
  mapData.map_width > 0 &&
18727
18767
  mapData.map_height > 0) {
18728
18768
  const [centerLng, centerLat] = mapData.center_gps;
18729
- const mapWidthMeters = mapData.map_width;
18730
- const mapHeightMeters = mapData.map_height;
18731
- // 精确的坐标转换常数(基于 WGS84 标准 - GPS 国际标准)
18732
- // WGS84 赤道半径 = 6,378,137 米
18733
- // 地球赤道周长 = 2 × π × 6,378,137 ≈ 40,075,017 米
18734
- // 1度纬度 = 40075017 / 360 ≈ 111,319.49 米(在地球上任何地方都基本相同)
18735
- // 1度经度 = (40075017 / 360) * cos(纬度) 米(随纬度变化)
18736
- const METERS_PER_DEGREE_LAT = EQUATORIAL_CIRCUMFERENCE / 360;
18737
- const METERS_PER_DEGREE_LNG = METERS_PER_DEGREE_LAT * Math.cos((centerLat * Math.PI) / 180);
18738
- // 计算SW(西南角)GPS坐标:从中心点减去半个地图的宽度和高度
18739
- const swLat = centerLat - mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18740
- const swLng = centerLng - mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18741
- // 计算NE(东北角)GPS坐标:从中心点加上半个地图的宽度和高度
18742
- const neLat = centerLat + mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18743
- const neLng = centerLng + mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18744
- bounds = {
18745
- sw: [swLng, swLat],
18746
- ne: [neLng, neLat],
18747
- };
18748
- }
18749
- else if (isValidGpsCoordinate(mapData.sw_gps?.[1], mapData.sw_gps?.[0]) &&
18750
- isValidGpsCoordinate(mapData.ne_gps?.[1], mapData.ne_gps?.[0])) {
18751
- // 降级方案:使用地图数据中的GPS坐标
18752
- console.warn('center_gps 或 map_width/map_height 不可用,使用 sw_gps 和 ne_gps');
18753
- bounds = {
18754
- sw: mapData.sw_gps,
18755
- ne: mapData.ne_gps,
18756
- };
18757
- }
18769
+ bounds = computeGpsBoundsFromCenterAndSize(centerLng, centerLat, mapData.map_width, mapData.map_height);
18770
+ }
18771
+ // else if (
18772
+ // isValidGpsCoordinate(mapData.sw_gps?.[1], mapData.sw_gps?.[0]) &&
18773
+ // isValidGpsCoordinate(mapData.ne_gps?.[1], mapData.ne_gps?.[0])
18774
+ // ) {
18775
+ // // 降级方案:使用地图数据中的GPS坐标
18776
+ // console.warn('center_gps map_width/map_height 不可用,使用 sw_gps 和 ne_gps');
18777
+ // bounds = {
18778
+ // sw: mapData.sw_gps,
18779
+ // ne: mapData.ne_gps,
18780
+ // };
18781
+ // }
18758
18782
  else {
18759
- // 如果GPS坐标无效,尝试从地图几何数据估算
18760
- const { sw, ne } = estimateGpsFromMapBounds(mapData);
18761
- if (sw && ne) {
18762
- console.warn('GPS坐标无效,使用地图几何数据估算边界:', sw, ne);
18763
- bounds = {
18764
- sw: [sw[0], sw[1]],
18765
- ne: [ne[0], ne[1]],
18766
- };
18767
- }
18768
- else {
18769
- // 最后的fallback:使用默认坐标
18770
- console.warn('无法获取有效的GPS边界,使用默认坐标');
18771
- bounds = DEFAULT_COORDINATES;
18772
- }
18783
+ console.warn('无法获取有效的GPS边界,使用 (0,0) 中心 + map_width/map_height 或 DEFAULT_COORDINATES');
18784
+ bounds = getFallbackGpsBounds(mapData);
18773
18785
  }
18774
18786
  // 如果有旋转角度,计算旋转后的边界
18775
18787
  if (rotation !== 0) {
@@ -19202,7 +19214,7 @@ function getMowerImage(positonConfig, mowerIconConfig, modelType, hasEdger) {
19202
19214
  const mowerImage = mowerIconConfig?.mapImgUrl || getMowerImageByModal(model, hasEdger);
19203
19215
  const disabledImage = mowerIconConfig?.mapDisabledUrl || getDisabledMowerImageByModal(model);
19204
19216
  const noPositionImage = mowerIconConfig?.mapNoPositionUrl || getNoPositionMowerImageByModal(model);
19205
- const positonOutOfRange = isOutOfRange(positonConfig);
19217
+ // const positonOutOfRange = isOutOfRange(positonConfig);
19206
19218
  const positionValid = isInvalidPosition(positonConfig);
19207
19219
  const isOffLine = state === RobotStatus.DISCONNECTED;
19208
19220
  const isInPark = state === RobotStatus.CHARGING || state === RobotStatus.PARKED;
@@ -19212,7 +19224,7 @@ function getMowerImage(positonConfig, mowerIconConfig, modelType, hasEdger) {
19212
19224
  if (isInPark) {
19213
19225
  return mowerImage;
19214
19226
  }
19215
- if (positionValid || positonOutOfRange) {
19227
+ if (positionValid) {
19216
19228
  return noPositionImage;
19217
19229
  }
19218
19230
  else {
@@ -19236,12 +19248,6 @@ function isInvalidPosition(positonConfig) {
19236
19248
  isNoPosture(positonConfig.postureY) &&
19237
19249
  isNoPosture(positonConfig.postureTheta));
19238
19250
  }
19239
- function isOutOfRange(positonConfig) {
19240
- return (positonConfig.postureX != null &&
19241
- Math.abs(positonConfig.postureX) > 1000 &&
19242
- positonConfig.postureY != null &&
19243
- Math.abs(positonConfig.postureY) > 1000);
19244
- }
19245
19251
  function getMindistanceByModel(modelType) {
19246
19252
  if (isIModel(modelType)) {
19247
19253
  return I_MIN_DISTANCE;
@@ -27934,10 +27940,10 @@ const usePosition = ({ mowerPositionData, viewBox, modelType, hasEdger, mapData,
27934
27940
  }
27935
27941
  else {
27936
27942
  // 检查位置是否有效
27937
- const positionOutOfRange = isOutOfRange(mowerPositionData);
27943
+ // const positionOutOfRange = isOutOfRange(mowerPositionData);
27938
27944
  const positionInvalid = isInvalidPosition(mowerPositionData);
27939
27945
  const isStandby = mowerPositionData.vehicleState === RobotStatus.STANDBY;
27940
- if (positionOutOfRange || positionInvalid || isOffLine) {
27946
+ if (positionInvalid || isOffLine) {
27941
27947
  // 位置无效时,尝试使用上次位置或充电桩位置
27942
27948
  updatePositionByLastPosition(mowerPositionData);
27943
27949
  }
package/dist/index.js CHANGED
@@ -10637,9 +10637,12 @@ var SvgMapOpacity;
10637
10637
  // sw: [116.071044, 40.102099],
10638
10638
  // ne: [116.0734, 40.103901],
10639
10639
  // };
10640
+ /** 无效 GPS 时的兜底中心点 [lng, lat] */
10641
+ const DEFAULT_GPS_CENTER = [0, 0];
10642
+ /** 无 map_width/map_height 时的默认 GPS 边界 [lng, lat](中心约 (0,0)) */
10640
10643
  const DEFAULT_COORDINATES = {
10641
- sw: [-1178e-6, -901e-6],
10642
- ne: [0.001178, 0.000901],
10644
+ sw: [-225e-6, -225e-6],
10645
+ ne: [0.000225, 0.000225],
10643
10646
  };
10644
10647
  /**
10645
10648
  * 缩放因子 - 将米转换为像素
@@ -18580,6 +18583,38 @@ function calculateBoundaryBoundsCenter(mapData) {
18580
18583
  boundaryBounds.minY + (boundaryBounds.maxY - boundaryBounds.minY) / 2,
18581
18584
  ];
18582
18585
  }
18586
+ /**
18587
+ * 由中心点与物理尺寸(米)计算 GPS 边界 [lng, lat]
18588
+ */
18589
+ function computeGpsBoundsFromCenterAndSize(centerLng, centerLat, mapWidthMeters, mapHeightMeters) {
18590
+ const METERS_PER_DEGREE_LAT = EQUATORIAL_CIRCUMFERENCE / 360;
18591
+ const METERS_PER_DEGREE_LNG = METERS_PER_DEGREE_LAT * Math.cos((centerLat * Math.PI) / 180);
18592
+ const swLat = centerLat - mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18593
+ const swLng = centerLng - mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18594
+ const neLat = centerLat + mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18595
+ const neLng = centerLng + mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18596
+ return {
18597
+ sw: [swLng, swLat],
18598
+ ne: [neLng, neLat],
18599
+ };
18600
+ }
18601
+ /**
18602
+ * GPS 无效时:中心 (0,0) + JSON 的 map_width/map_height;无尺寸则用 DEFAULT_COORDINATES
18603
+ */
18604
+ function getFallbackGpsBounds(mapData) {
18605
+ const [centerLng, centerLat] = DEFAULT_GPS_CENTER;
18606
+ const hasMapSize = typeof mapData.map_width === 'number' &&
18607
+ typeof mapData.map_height === 'number' &&
18608
+ mapData.map_width > 0 &&
18609
+ mapData.map_height > 0;
18610
+ if (hasMapSize) {
18611
+ return computeGpsBoundsFromCenterAndSize(centerLng, centerLat, mapData.map_width, mapData.map_height);
18612
+ }
18613
+ return {
18614
+ sw: [...DEFAULT_COORDINATES.sw],
18615
+ ne: [...DEFAULT_COORDINATES.ne],
18616
+ };
18617
+ }
18583
18618
  /**
18584
18619
  * 检查GPS坐标是否有效
18585
18620
  */
@@ -18684,39 +18719,44 @@ function calculateMapGpsCenter(mapData) {
18684
18719
  }
18685
18720
  }
18686
18721
  // 如果有西南角和东北角坐标,检查其有效性并计算中心点
18687
- if (mapData.sw_gps &&
18688
- mapData.ne_gps &&
18689
- mapData.sw_gps.length >= 2 &&
18690
- mapData.ne_gps.length >= 2) {
18691
- const swLat = mapData.sw_gps[1];
18692
- const swLng = mapData.sw_gps[0];
18693
- const neLat = mapData.ne_gps[1];
18694
- const neLng = mapData.ne_gps[0];
18695
- // 检查边界坐标的有效性
18696
- if (isValidGpsCoordinate(swLat, swLng) && isValidGpsCoordinate(neLat, neLng)) {
18697
- return {
18698
- lat: (swLat + neLat) / 2,
18699
- lng: (swLng + neLng) / 2,
18700
- };
18701
- }
18702
- else {
18703
- console.warn('sw_gps或ne_gps坐标无效:', {
18704
- sw: { lat: swLat, lng: swLng },
18705
- ne: { lat: neLat, lng: neLng },
18706
- });
18707
- }
18708
- }
18722
+ // if (
18723
+ // mapData.sw_gps &&
18724
+ // mapData.ne_gps &&
18725
+ // mapData.sw_gps.length >= 2 &&
18726
+ // mapData.ne_gps.length >= 2
18727
+ // ) {
18728
+ // const swLat = mapData.sw_gps[1];
18729
+ // const swLng = mapData.sw_gps[0];
18730
+ // const neLat = mapData.ne_gps[1];
18731
+ // const neLng = mapData.ne_gps[0];
18732
+ // // 检查边界坐标的有效性
18733
+ // if (isValidGpsCoordinate(swLat, swLng) && isValidGpsCoordinate(neLat, neLng)) {
18734
+ // return {
18735
+ // lat: (swLat + neLat) / 2,
18736
+ // lng: (swLng + neLng) / 2,
18737
+ // };
18738
+ // } else {
18739
+ // console.warn('sw_gps或ne_gps坐标无效:', {
18740
+ // sw: { lat: swLat, lng: swLng },
18741
+ // ne: { lat: neLat, lng: neLng },
18742
+ // });
18743
+ // }
18744
+ // }
18709
18745
  // 尝试从地图几何边界估算GPS坐标
18710
- const estimatedBounds = estimateGpsFromMapBounds(mapData);
18711
- if (estimatedBounds) {
18712
- // 从估算的边界计算中心点
18713
- const centerLat = (estimatedBounds.sw[1] + estimatedBounds.ne[1]) / 2;
18714
- const centerLng = (estimatedBounds.sw[0] + estimatedBounds.ne[0]) / 2;
18715
- return { lat: centerLat, lng: centerLng };
18716
- }
18746
+ // const estimatedBounds = estimateGpsFromMapBounds(mapData);
18747
+ // if (estimatedBounds) {
18748
+ // // 从估算的边界计算中心点
18749
+ // const centerLat = (estimatedBounds.sw[1] + estimatedBounds.ne[1]) / 2;
18750
+ // const centerLng = (estimatedBounds.sw[0] + estimatedBounds.ne[0]) / 2;
18751
+ // return { lat: centerLat, lng: centerLng };
18752
+ // }
18753
+ // return {
18754
+ // lat: 39.9042, // 北京纬度
18755
+ // lng: 116.4074, // 北京经度
18756
+ // };
18717
18757
  return {
18718
- lat: 39.9042, // 北京纬度
18719
- lng: 116.4074, // 北京经度
18758
+ lat: DEFAULT_GPS_CENTER[1],
18759
+ lng: DEFAULT_GPS_CENTER[0],
18720
18760
  };
18721
18761
  }
18722
18762
  // 旋转坐标点
@@ -18746,50 +18786,22 @@ const getValidGpsBounds = (mapData, rotation = 0) => {
18746
18786
  mapData.map_width > 0 &&
18747
18787
  mapData.map_height > 0) {
18748
18788
  const [centerLng, centerLat] = mapData.center_gps;
18749
- const mapWidthMeters = mapData.map_width;
18750
- const mapHeightMeters = mapData.map_height;
18751
- // 精确的坐标转换常数(基于 WGS84 标准 - GPS 国际标准)
18752
- // WGS84 赤道半径 = 6,378,137 米
18753
- // 地球赤道周长 = 2 × π × 6,378,137 ≈ 40,075,017 米
18754
- // 1度纬度 = 40075017 / 360 ≈ 111,319.49 米(在地球上任何地方都基本相同)
18755
- // 1度经度 = (40075017 / 360) * cos(纬度) 米(随纬度变化)
18756
- const METERS_PER_DEGREE_LAT = EQUATORIAL_CIRCUMFERENCE / 360;
18757
- const METERS_PER_DEGREE_LNG = METERS_PER_DEGREE_LAT * Math.cos((centerLat * Math.PI) / 180);
18758
- // 计算SW(西南角)GPS坐标:从中心点减去半个地图的宽度和高度
18759
- const swLat = centerLat - mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18760
- const swLng = centerLng - mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18761
- // 计算NE(东北角)GPS坐标:从中心点加上半个地图的宽度和高度
18762
- const neLat = centerLat + mapHeightMeters / 2 / METERS_PER_DEGREE_LAT;
18763
- const neLng = centerLng + mapWidthMeters / 2 / METERS_PER_DEGREE_LNG;
18764
- bounds = {
18765
- sw: [swLng, swLat],
18766
- ne: [neLng, neLat],
18767
- };
18768
- }
18769
- else if (isValidGpsCoordinate(mapData.sw_gps?.[1], mapData.sw_gps?.[0]) &&
18770
- isValidGpsCoordinate(mapData.ne_gps?.[1], mapData.ne_gps?.[0])) {
18771
- // 降级方案:使用地图数据中的GPS坐标
18772
- console.warn('center_gps 或 map_width/map_height 不可用,使用 sw_gps 和 ne_gps');
18773
- bounds = {
18774
- sw: mapData.sw_gps,
18775
- ne: mapData.ne_gps,
18776
- };
18777
- }
18789
+ bounds = computeGpsBoundsFromCenterAndSize(centerLng, centerLat, mapData.map_width, mapData.map_height);
18790
+ }
18791
+ // else if (
18792
+ // isValidGpsCoordinate(mapData.sw_gps?.[1], mapData.sw_gps?.[0]) &&
18793
+ // isValidGpsCoordinate(mapData.ne_gps?.[1], mapData.ne_gps?.[0])
18794
+ // ) {
18795
+ // // 降级方案:使用地图数据中的GPS坐标
18796
+ // console.warn('center_gps map_width/map_height 不可用,使用 sw_gps 和 ne_gps');
18797
+ // bounds = {
18798
+ // sw: mapData.sw_gps,
18799
+ // ne: mapData.ne_gps,
18800
+ // };
18801
+ // }
18778
18802
  else {
18779
- // 如果GPS坐标无效,尝试从地图几何数据估算
18780
- const { sw, ne } = estimateGpsFromMapBounds(mapData);
18781
- if (sw && ne) {
18782
- console.warn('GPS坐标无效,使用地图几何数据估算边界:', sw, ne);
18783
- bounds = {
18784
- sw: [sw[0], sw[1]],
18785
- ne: [ne[0], ne[1]],
18786
- };
18787
- }
18788
- else {
18789
- // 最后的fallback:使用默认坐标
18790
- console.warn('无法获取有效的GPS边界,使用默认坐标');
18791
- bounds = DEFAULT_COORDINATES;
18792
- }
18803
+ console.warn('无法获取有效的GPS边界,使用 (0,0) 中心 + map_width/map_height 或 DEFAULT_COORDINATES');
18804
+ bounds = getFallbackGpsBounds(mapData);
18793
18805
  }
18794
18806
  // 如果有旋转角度,计算旋转后的边界
18795
18807
  if (rotation !== 0) {
@@ -19222,7 +19234,7 @@ function getMowerImage(positonConfig, mowerIconConfig, modelType, hasEdger) {
19222
19234
  const mowerImage = mowerIconConfig?.mapImgUrl || getMowerImageByModal(model, hasEdger);
19223
19235
  const disabledImage = mowerIconConfig?.mapDisabledUrl || getDisabledMowerImageByModal(model);
19224
19236
  const noPositionImage = mowerIconConfig?.mapNoPositionUrl || getNoPositionMowerImageByModal(model);
19225
- const positonOutOfRange = isOutOfRange(positonConfig);
19237
+ // const positonOutOfRange = isOutOfRange(positonConfig);
19226
19238
  const positionValid = isInvalidPosition(positonConfig);
19227
19239
  const isOffLine = state === RobotStatus.DISCONNECTED;
19228
19240
  const isInPark = state === RobotStatus.CHARGING || state === RobotStatus.PARKED;
@@ -19232,7 +19244,7 @@ function getMowerImage(positonConfig, mowerIconConfig, modelType, hasEdger) {
19232
19244
  if (isInPark) {
19233
19245
  return mowerImage;
19234
19246
  }
19235
- if (positionValid || positonOutOfRange) {
19247
+ if (positionValid) {
19236
19248
  return noPositionImage;
19237
19249
  }
19238
19250
  else {
@@ -19256,12 +19268,6 @@ function isInvalidPosition(positonConfig) {
19256
19268
  isNoPosture(positonConfig.postureY) &&
19257
19269
  isNoPosture(positonConfig.postureTheta));
19258
19270
  }
19259
- function isOutOfRange(positonConfig) {
19260
- return (positonConfig.postureX != null &&
19261
- Math.abs(positonConfig.postureX) > 1000 &&
19262
- positonConfig.postureY != null &&
19263
- Math.abs(positonConfig.postureY) > 1000);
19264
- }
19265
19271
  function getMindistanceByModel(modelType) {
19266
19272
  if (isIModel(modelType)) {
19267
19273
  return I_MIN_DISTANCE;
@@ -27954,10 +27960,10 @@ const usePosition = ({ mowerPositionData, viewBox, modelType, hasEdger, mapData,
27954
27960
  }
27955
27961
  else {
27956
27962
  // 检查位置是否有效
27957
- const positionOutOfRange = isOutOfRange(mowerPositionData);
27963
+ // const positionOutOfRange = isOutOfRange(mowerPositionData);
27958
27964
  const positionInvalid = isInvalidPosition(mowerPositionData);
27959
27965
  const isStandby = mowerPositionData.vehicleState === RobotStatus.STANDBY;
27960
- if (positionOutOfRange || positionInvalid || isOffLine) {
27966
+ if (positionInvalid || isOffLine) {
27961
27967
  // 位置无效时,尝试使用上次位置或充电桩位置
27962
27968
  updatePositionByLastPosition(mowerPositionData);
27963
27969
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mapBounds.d.ts","sourceRoot":"","sources":["../../src/utils/mapBounds.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAElD,OA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ower-maps",
3
- "version": "0.2.5-beta.23",
3
+ "version": "0.2.5-beta.25",
4
4
  "type": "module",
5
5
  "description": "a mower maps in google maps",
6
6
  "main": "dist/index.js",