| | |
| | | activeType.value = clickedTab.type; |
| | | activeName.value = clickedTab.name; |
| | | }; |
| | | // 解析 geo_data 并转换为 DrawPolygon 所需的坐标格式 |
| | | |
| | | // 解析 geo_data 并转换为坐标格式(兼容 Polygon 和 LineString) |
| | | const parseGeoDataToPositions = (geoDataStr, altitude) => { |
| | | try { |
| | | const geoData = JSON.parse(geoDataStr); |
| | | if (geoData.type !== 'Polygon') return []; |
| | | const coordinates = geoData.coordinates[0]; |
| | | let coordinates = []; |
| | | |
| | | |
| | | if (geoData.type === 'Polygon') { |
| | | // Polygon 坐标格式:[[[lng, lat], ...]] → 取第一个多边形的顶点 |
| | | coordinates = geoData.coordinates[0] || []; |
| | | } else if (geoData.type === 'LineString') { |
| | | // LineString 坐标格式:[[lng, lat], ...] → 直接取顶点 |
| | | coordinates = geoData.coordinates || []; |
| | | } else { |
| | | console.warn(`不支持的地理数据类型:${geoData.type}`); |
| | | return []; |
| | | } |
| | | |
| | | // 转换为 {lng, lat, height} 格式 |
| | | return coordinates.map(([lng, lat]) => ({ |
| | | lng: Number(lng), |
| | | lat: Number(lat), |
| | | height: Number(altitude) || 0, |
| | | height: Number(altitude) || 0, |
| | | })); |
| | | } catch (error) { |
| | | console.error('解析 geo_data 失败:', error); |