Skip to content

Commit 3383a26

Browse files
committed
feat: hai-ari-posture file add handle
1 parent 02d3461 commit 3383a26

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

src/pages/Feature/.DS_Store

0 Bytes
Binary file not shown.

src/pages/Feature/Map/Cesium/HaiAirPosture.tsx

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import thermal from '@/utils/MapCompute/ThermalMapData.json';
22
import { iconData } from '@/utils/MapCompute/dataEnd';
33
import { ProCard } from '@ant-design/pro-components';
4-
import { message } from 'antd';
4+
import { Button, message } from 'antd';
55
import * as Cesium from 'cesium';
66
import 'cesium/Build/Cesium/Widgets/widgets.css';
77
import { useEffect, useState } from 'react';
@@ -140,10 +140,79 @@ const HaiAirPosture = () => {
140140
};
141141
}, []);
142142

143+
const handleLonLat = () => {
144+
function convertDMSToDD(dmsStr: string) {
145+
try {
146+
// 移除空格,保留数字、正负号和度分秒符号
147+
const cleanStr = dmsStr.trim();
148+
149+
// 获取正负号
150+
const sign = cleanStr.startsWith('-') ? -1 : 1;
151+
152+
// 提取数字部分
153+
const matches = cleanStr.match(/([+-]?\d+)˚(\d+)'(\d+)''/);
154+
if (!matches) {
155+
console.error('Invalid DMS format:', dmsStr);
156+
return null;
157+
}
158+
159+
// 解析度分秒
160+
const degrees = parseFloat(matches[1]);
161+
const minutes = parseFloat(matches[2]);
162+
const seconds = parseFloat(matches[3]);
163+
164+
// 验证数值
165+
console.log('Parsed values:', {
166+
degrees,
167+
minutes,
168+
seconds,
169+
sign,
170+
});
171+
172+
// 转换为十进制度数
173+
const decimal = sign * (Math.abs(degrees) + minutes / 60 + seconds / 3600);
174+
175+
console.log('Converted decimal:', decimal);
176+
177+
return decimal;
178+
} catch (error) {
179+
console.error('Conversion error:', error);
180+
return null;
181+
}
182+
}
183+
184+
let longitude = "+115˚12'266''";
185+
let latitude = "-29˚33'123''";
186+
187+
const lonDD = convertDMSToDD(longitude);
188+
const latDD = convertDMSToDD(latitude);
189+
190+
console.log('Final coordinates:', { lonDD, latDD });
191+
192+
// 确保坐标有效再创建位置
193+
if (lonDD !== null && latDD !== null && !isNaN(lonDD) && !isNaN(latDD)) {
194+
const position = Cesium.Cartesian3.fromDegrees(lonDD, latDD);
195+
196+
viewer.entities.add({
197+
position: position,
198+
billboard: {
199+
image: require('@/assets/Detection.png'),
200+
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
201+
scale: 0.6,
202+
},
203+
});
204+
} else {
205+
console.error('Invalid coordinates calculated');
206+
}
207+
};
208+
143209
return (
144210
<>
145211
<ProCard>
146212
{contextHolder}
213+
<Button className="mb-2" onClick={() => handleLonLat()}>
214+
经纬度
215+
</Button>
147216
<div id="cesiumContainer" />
148217
</ProCard>
149218
</>

0 commit comments

Comments
 (0)