@wenle_2523097/agri-map 2.0.8 → 2.0.10

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