@wenle_2523097/agri-map 2.0.8 → 2.0.9

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
@@ -14799,6 +14799,73 @@ function parseVirtualizationConfig(virtualization) {
14799
14799
  };
14800
14800
  }
14801
14801
 
14802
+ /**
14803
+ * 检测并转换坐标格式
14804
+ * @description 如果第一个坐标值 > 90 且第二个值 <= 90,认为是 [lng, lat] 格式,需要翻转
14805
+ * @param positions 原始坐标数组
14806
+ * @returns 包含坐标顺序和标准化后坐标的结果
14807
+ */
14808
+ function detectAndNormalizeCoordinates(positions) {
14809
+ if (!Array.isArray(positions) || positions.length === 0) {
14810
+ return {
14811
+ normalized: positions,
14812
+ order: 'lat-lng'
14813
+ };
14814
+ }
14815
+ // 获取第一个有效坐标进行格式检测
14816
+ var firstItem = positions[0];
14817
+ if (!Array.isArray(firstItem)) {
14818
+ return {
14819
+ normalized: positions,
14820
+ order: 'lat-lng'
14821
+ };
14822
+ }
14823
+ // 获取第一个坐标点
14824
+ var firstCoord = Array.isArray(firstItem[0]) ? firstItem[0] : firstItem;
14825
+ // 检查是否为有效坐标 [lat, lng] 或 [lng, lat]
14826
+ if (firstCoord.length >= 2) {
14827
+ var a = firstCoord[0];
14828
+ var b = firstCoord[1];
14829
+ // 如果 a > 90 && b <= 90,认为是经度值(经度范围 -180~180,纬度 -90~90)
14830
+ if (typeof a === 'number' && a > 90 && typeof b === 'number' && b <= 90) {
14831
+ var flip = function flip(coord) {
14832
+ return [coord[1], coord[0]];
14833
+ };
14834
+ if (Array.isArray(firstItem[0])) {
14835
+ // 三维数组:翻转所有环
14836
+ return {
14837
+ normalized: positions.map(function (inner) {
14838
+ return inner.map(flip);
14839
+ }),
14840
+ order: 'lng-lat'
14841
+ };
14842
+ }
14843
+ // 二维数组
14844
+ return {
14845
+ normalized: positions.map(flip),
14846
+ order: 'lng-lat'
14847
+ };
14848
+ }
14849
+ }
14850
+ return {
14851
+ normalized: positions,
14852
+ order: 'lat-lng'
14853
+ };
14854
+ }
14855
+ /**
14856
+ * 将坐标转换为原始输入格式
14857
+ * @param coords 内部标准格式坐标 [lat, lng]
14858
+ * @param order 原始输入格式
14859
+ * @returns 原始格式的坐标
14860
+ */
14861
+ function convertToOriginalFormat(coords, order) {
14862
+ if (order === 'lng-lat') {
14863
+ return coords.map(function (coord) {
14864
+ return [coord[1], coord[0]];
14865
+ });
14866
+ }
14867
+ return coords;
14868
+ }
14802
14869
  function usePlotData(_ref) {
14803
14870
  var fieldNames = _ref.fieldNames,
14804
14871
  dataSource = _ref.dataSource,
@@ -14815,9 +14882,13 @@ function usePlotData(_ref) {
14815
14882
  // 映射原始数据到标准 PlotData 格式
14816
14883
  var mapPlotData = React.useCallback(function (rawItem) {
14817
14884
  var id = rawItem[mergedFieldNames.id];
14818
- var positions = rawItem[mergedFieldNames.positions];
14885
+ var rawPositions = rawItem[mergedFieldNames.positions];
14819
14886
  var area = rawItem[mergedFieldNames.area];
14820
14887
  var possessor = rawItem[mergedFieldNames.possessor];
14888
+ // 检测并转换坐标格式
14889
+ var detectResult = detectAndNormalizeCoordinates(rawPositions);
14890
+ var positions = detectResult.normalized;
14891
+ var order = detectResult.order;
14821
14892
  // 二维 positions [[lat,lng],...] → 三维 [[[lat,lng],...]]
14822
14893
  if (Array.isArray(positions) && !is3DPositions(positions)) {
14823
14894
  positions = [positions];
@@ -14841,7 +14912,8 @@ function usePlotData(_ref) {
14841
14912
  positions: positions,
14842
14913
  area: area,
14843
14914
  possessor: possessor,
14844
- customData: Object.keys(customData).length > 0 ? customData : undefined
14915
+ customData: Object.keys(customData).length > 0 ? customData : undefined,
14916
+ _coordinateOrder: order
14845
14917
  }, extensionProps);
14846
14918
  }, [mergedFieldNames]);
14847
14919
  // 标准化数据源
@@ -15485,12 +15557,16 @@ function usePlotEditActions(_ref) {
15485
15557
  * 获取完整的编辑结果数据
15486
15558
  * @param coords - 编辑后的坐标
15487
15559
  * @param area - 编辑后的面积
15488
- * @returns 完整的地块数据(包含原始属性+新坐标)
15560
+ * @returns 完整的地块数据(包含原始属性+新坐标),坐标格式保持与输入一致
15489
15561
  */
15490
15562
  var getFullPlotData = React.useCallback(function (coords, area) {
15491
15563
  if (!localPlotDataRef.current) return null;
15564
+ // 获取输入坐标格式
15565
+ var order = localPlotDataRef.current._coordinateOrder;
15566
+ // 转换为原始格式
15567
+ var originalCoords = convertToOriginalFormat(coords, order);
15492
15568
  return _objectSpread2(_objectSpread2({}, localPlotDataRef.current), {}, {
15493
- positions: [coords],
15569
+ positions: [originalCoords],
15494
15570
  area: area
15495
15571
  });
15496
15572
  }, []);
@@ -15554,6 +15630,7 @@ function usePlotEditActions(_ref) {
15554
15630
  }, [cleanupEditEvents, cleanupFragmentLayers, setEditMode, editingLayerRef, drawingCoordinatesRef, preserveTempLayerRef, map]);
15555
15631
  // ========== 操作处理函数 ==========
15556
15632
  var handleSave = React.useCallback(function () {
15633
+ var _localPlotDataRef$cur;
15557
15634
  var currentEditMode = editModeStateRef.current;
15558
15635
  disableDrawMode(map);
15559
15636
  var coords = drawingCoordinatesRef.current;
@@ -15572,12 +15649,16 @@ function usePlotEditActions(_ref) {
15572
15649
  return;
15573
15650
  }
15574
15651
  var areaSquareMeters = calculatePolygonArea(coords);
15652
+ // 获取输入坐标格式并转换为原始格式
15653
+ var order = (_localPlotDataRef$cur = localPlotDataRef.current) === null || _localPlotDataRef$cur === void 0 ? void 0 : _localPlotDataRef$cur._coordinateOrder;
15654
+ var originalCoords = convertToOriginalFormat(coords, order);
15575
15655
  // 获取完整的地块数据(包含原始属性)
15576
15656
  var fullPlotData = getFullPlotData(coords, areaSquareMeters);
15577
15657
  var result = {
15578
15658
  plotId: selectedPlotId,
15579
15659
  mode: currentEditMode,
15580
- coordinates: coords,
15660
+ coordinates: originalCoords,
15661
+ // 保持与输入一致的坐标格式
15581
15662
  area: areaSquareMeters,
15582
15663
  areaUnit: areaUnit,
15583
15664
  plot: fullPlotData || undefined
@@ -15587,7 +15668,10 @@ function usePlotEditActions(_ref) {
15587
15668
  result.selectedFragment = selectedFragmentRef.current;
15588
15669
  }
15589
15670
  if (currentEditMode === 'clip' && clipHolesRef.current) {
15590
- result.positions = clipHolesRef.current;
15671
+ // 转换孔洞坐标为原始格式
15672
+ result.positions = clipHolesRef.current.map(function (hole) {
15673
+ return convertToOriginalFormat(hole, order);
15674
+ });
15591
15675
  }
15592
15676
  dispatchEditResult(result);
15593
15677
  cleanupAfterSave(currentEditMode);