@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/components/PlotLayer/usePlotData.d.ts +7 -0
- package/dist/components/plotgrouplayer.esm.js +90 -6
- package/dist/components/plotgrouplayer.esm.js.map +1 -1
- package/dist/components/plotlayer.esm.js +90 -6
- package/dist/components/plotlayer.esm.js.map +1 -1
- package/dist/index.esm.js +90 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +90 -6
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +90 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/types/plot.d.ts +7 -0
- package/package.json +1 -1
|
@@ -7581,6 +7581,73 @@ function parseVirtualizationConfig(virtualization) {
|
|
|
7581
7581
|
};
|
|
7582
7582
|
}
|
|
7583
7583
|
|
|
7584
|
+
/**
|
|
7585
|
+
* 检测并转换坐标格式
|
|
7586
|
+
* @description 如果第一个坐标值 > 90 且第二个值 <= 90,认为是 [lng, lat] 格式,需要翻转
|
|
7587
|
+
* @param positions 原始坐标数组
|
|
7588
|
+
* @returns 包含坐标顺序和标准化后坐标的结果
|
|
7589
|
+
*/
|
|
7590
|
+
function detectAndNormalizeCoordinates(positions) {
|
|
7591
|
+
if (!Array.isArray(positions) || positions.length === 0) {
|
|
7592
|
+
return {
|
|
7593
|
+
normalized: positions,
|
|
7594
|
+
order: 'lat-lng'
|
|
7595
|
+
};
|
|
7596
|
+
}
|
|
7597
|
+
// 获取第一个有效坐标进行格式检测
|
|
7598
|
+
var firstItem = positions[0];
|
|
7599
|
+
if (!Array.isArray(firstItem)) {
|
|
7600
|
+
return {
|
|
7601
|
+
normalized: positions,
|
|
7602
|
+
order: 'lat-lng'
|
|
7603
|
+
};
|
|
7604
|
+
}
|
|
7605
|
+
// 获取第一个坐标点
|
|
7606
|
+
var firstCoord = Array.isArray(firstItem[0]) ? firstItem[0] : firstItem;
|
|
7607
|
+
// 检查是否为有效坐标 [lat, lng] 或 [lng, lat]
|
|
7608
|
+
if (firstCoord.length >= 2) {
|
|
7609
|
+
var a = firstCoord[0];
|
|
7610
|
+
var b = firstCoord[1];
|
|
7611
|
+
// 如果 a > 90 && b <= 90,认为是经度值(经度范围 -180~180,纬度 -90~90)
|
|
7612
|
+
if (typeof a === 'number' && a > 90 && typeof b === 'number' && b <= 90) {
|
|
7613
|
+
var flip = function flip(coord) {
|
|
7614
|
+
return [coord[1], coord[0]];
|
|
7615
|
+
};
|
|
7616
|
+
if (Array.isArray(firstItem[0])) {
|
|
7617
|
+
// 三维数组:翻转所有环
|
|
7618
|
+
return {
|
|
7619
|
+
normalized: positions.map(function (inner) {
|
|
7620
|
+
return inner.map(flip);
|
|
7621
|
+
}),
|
|
7622
|
+
order: 'lng-lat'
|
|
7623
|
+
};
|
|
7624
|
+
}
|
|
7625
|
+
// 二维数组
|
|
7626
|
+
return {
|
|
7627
|
+
normalized: positions.map(flip),
|
|
7628
|
+
order: 'lng-lat'
|
|
7629
|
+
};
|
|
7630
|
+
}
|
|
7631
|
+
}
|
|
7632
|
+
return {
|
|
7633
|
+
normalized: positions,
|
|
7634
|
+
order: 'lat-lng'
|
|
7635
|
+
};
|
|
7636
|
+
}
|
|
7637
|
+
/**
|
|
7638
|
+
* 将坐标转换为原始输入格式
|
|
7639
|
+
* @param coords 内部标准格式坐标 [lat, lng]
|
|
7640
|
+
* @param order 原始输入格式
|
|
7641
|
+
* @returns 原始格式的坐标
|
|
7642
|
+
*/
|
|
7643
|
+
function convertToOriginalFormat(coords, order) {
|
|
7644
|
+
if (order === 'lng-lat') {
|
|
7645
|
+
return coords.map(function (coord) {
|
|
7646
|
+
return [coord[1], coord[0]];
|
|
7647
|
+
});
|
|
7648
|
+
}
|
|
7649
|
+
return coords;
|
|
7650
|
+
}
|
|
7584
7651
|
function usePlotData(_ref) {
|
|
7585
7652
|
var fieldNames = _ref.fieldNames,
|
|
7586
7653
|
dataSource = _ref.dataSource,
|
|
@@ -7597,9 +7664,13 @@ function usePlotData(_ref) {
|
|
|
7597
7664
|
// 映射原始数据到标准 PlotData 格式
|
|
7598
7665
|
var mapPlotData = useCallback(function (rawItem) {
|
|
7599
7666
|
var id = rawItem[mergedFieldNames.id];
|
|
7600
|
-
var
|
|
7667
|
+
var rawPositions = rawItem[mergedFieldNames.positions];
|
|
7601
7668
|
var area = rawItem[mergedFieldNames.area];
|
|
7602
7669
|
var possessor = rawItem[mergedFieldNames.possessor];
|
|
7670
|
+
// 检测并转换坐标格式
|
|
7671
|
+
var detectResult = detectAndNormalizeCoordinates(rawPositions);
|
|
7672
|
+
var positions = detectResult.normalized;
|
|
7673
|
+
var order = detectResult.order;
|
|
7603
7674
|
// 二维 positions [[lat,lng],...] → 三维 [[[lat,lng],...]]
|
|
7604
7675
|
if (Array.isArray(positions) && !is3DPositions(positions)) {
|
|
7605
7676
|
positions = [positions];
|
|
@@ -7623,7 +7694,8 @@ function usePlotData(_ref) {
|
|
|
7623
7694
|
positions: positions,
|
|
7624
7695
|
area: area,
|
|
7625
7696
|
possessor: possessor,
|
|
7626
|
-
customData: Object.keys(customData).length > 0 ? customData : undefined
|
|
7697
|
+
customData: Object.keys(customData).length > 0 ? customData : undefined,
|
|
7698
|
+
_coordinateOrder: order
|
|
7627
7699
|
}, extensionProps);
|
|
7628
7700
|
}, [mergedFieldNames]);
|
|
7629
7701
|
// 标准化数据源
|
|
@@ -8267,12 +8339,16 @@ function usePlotEditActions(_ref) {
|
|
|
8267
8339
|
* 获取完整的编辑结果数据
|
|
8268
8340
|
* @param coords - 编辑后的坐标
|
|
8269
8341
|
* @param area - 编辑后的面积
|
|
8270
|
-
* @returns
|
|
8342
|
+
* @returns 完整的地块数据(包含原始属性+新坐标),坐标格式保持与输入一致
|
|
8271
8343
|
*/
|
|
8272
8344
|
var getFullPlotData = useCallback(function (coords, area) {
|
|
8273
8345
|
if (!localPlotDataRef.current) return null;
|
|
8346
|
+
// 获取输入坐标格式
|
|
8347
|
+
var order = localPlotDataRef.current._coordinateOrder;
|
|
8348
|
+
// 转换为原始格式
|
|
8349
|
+
var originalCoords = convertToOriginalFormat(coords, order);
|
|
8274
8350
|
return _objectSpread2(_objectSpread2({}, localPlotDataRef.current), {}, {
|
|
8275
|
-
positions: [
|
|
8351
|
+
positions: [originalCoords],
|
|
8276
8352
|
area: area
|
|
8277
8353
|
});
|
|
8278
8354
|
}, []);
|
|
@@ -8336,6 +8412,7 @@ function usePlotEditActions(_ref) {
|
|
|
8336
8412
|
}, [cleanupEditEvents, cleanupFragmentLayers, setEditMode, editingLayerRef, drawingCoordinatesRef, preserveTempLayerRef, map]);
|
|
8337
8413
|
// ========== 操作处理函数 ==========
|
|
8338
8414
|
var handleSave = useCallback(function () {
|
|
8415
|
+
var _localPlotDataRef$cur;
|
|
8339
8416
|
var currentEditMode = editModeStateRef.current;
|
|
8340
8417
|
disableDrawMode(map);
|
|
8341
8418
|
var coords = drawingCoordinatesRef.current;
|
|
@@ -8354,12 +8431,16 @@ function usePlotEditActions(_ref) {
|
|
|
8354
8431
|
return;
|
|
8355
8432
|
}
|
|
8356
8433
|
var areaSquareMeters = calculatePolygonArea(coords);
|
|
8434
|
+
// 获取输入坐标格式并转换为原始格式
|
|
8435
|
+
var order = (_localPlotDataRef$cur = localPlotDataRef.current) === null || _localPlotDataRef$cur === void 0 ? void 0 : _localPlotDataRef$cur._coordinateOrder;
|
|
8436
|
+
var originalCoords = convertToOriginalFormat(coords, order);
|
|
8357
8437
|
// 获取完整的地块数据(包含原始属性)
|
|
8358
8438
|
var fullPlotData = getFullPlotData(coords, areaSquareMeters);
|
|
8359
8439
|
var result = {
|
|
8360
8440
|
plotId: selectedPlotId,
|
|
8361
8441
|
mode: currentEditMode,
|
|
8362
|
-
coordinates:
|
|
8442
|
+
coordinates: originalCoords,
|
|
8443
|
+
// 保持与输入一致的坐标格式
|
|
8363
8444
|
area: areaSquareMeters,
|
|
8364
8445
|
areaUnit: areaUnit,
|
|
8365
8446
|
plot: fullPlotData || undefined
|
|
@@ -8369,7 +8450,10 @@ function usePlotEditActions(_ref) {
|
|
|
8369
8450
|
result.selectedFragment = selectedFragmentRef.current;
|
|
8370
8451
|
}
|
|
8371
8452
|
if (currentEditMode === 'clip' && clipHolesRef.current) {
|
|
8372
|
-
|
|
8453
|
+
// 转换孔洞坐标为原始格式
|
|
8454
|
+
result.positions = clipHolesRef.current.map(function (hole) {
|
|
8455
|
+
return convertToOriginalFormat(hole, order);
|
|
8456
|
+
});
|
|
8373
8457
|
}
|
|
8374
8458
|
dispatchEditResult(result);
|
|
8375
8459
|
cleanupAfterSave(currentEditMode);
|