export function getValues(arr,key) { let ids = []; arr.forEach(item => { ids.push(item[key]); }) return ids; } export function getMethodValues(arr,method,key) { let ids = []; arr.forEach(item => { ids.push(item[method](key)); }) return ids; } export function cleanArrayUndefined(arr) { let nr = []; arr.forEach(v => { if(v){ nr.push(v) } }) return nr; } export function splitDate(time) { let date = new Date(time); let YY = date.getFullYear(); let MM = date.getMonth() + 1; let DD = date.getDate(); let hh = date.getHours(); let mm = date.getMinutes(); let ss = date.getSeconds(); return {year:YY,month:MM,day:DD,hour:hh,minute:mm,second:ss} } /** * 获取文件名后缀 * @param filePath * @returns {string} */ export function getFileExt(filePath) { let index= filePath.lastIndexOf("."); //获取后缀 let ext = filePath.substring(index+1); return ext; } //point 字符串格式转成数组 export function parsePointToArray(pointString) { // 移除字符串两端的空格(虽然这里可能不是必需的,但为了保险起见还是加上) pointString = pointString.trim(); // 正则表达式匹配POINT后面的括号和坐标 let regex = /POINT\s*\(([\d.]+)\s+([\d.]+)\)/; let match = pointString.match(regex); if (!match) { throw new Error('Invalid POINT format'); } // 提取匹配到的坐标字符串,并转换为浮点数 let x = parseFloat(match[1]); let y = parseFloat(match[2]); // 返回包含x和y的数组 return [x, y]; } //POLYGON 字符串格式转成二维数组 export function parsePolygon(polygonString) { const text = polygonString.slice(0,12) if(text==='MULTIPOLYGON'){ // 使用正则表达式提取所有坐标点 const coordinates = polygonString.match(/[\d\.]+ [\d\.]+/g); // 将坐标点转换为二维数组 const result = coordinates.map(coord => coord.split(' ').map(Number)); return result }else{ // 提取坐标部分 const coordinatesString = polygonString.replace("POLYGON Z ((", "").replace("))", ""); // 将坐标字符串拆分为数组 const coordinatesArray = coordinatesString.split(","); //高度集合 const numbers = [] // 将每个坐标字符串转换为数组,并对第三项向上取整 const result = coordinatesArray.map(coord => { const [x, y, z] = coord.trim().split(" ").map(Number); numbers.push(Math.ceil(z)) return [x, y, Math.ceil(z)]; // 对 z 值向上取整 }); const max = Math.max(...numbers); // 获取高度最大值 const updateList = result.map(item =>{ item[2] = max + 12 return item }) return updateList; } } //通过经纬度查处对应的地址 const MAP_KEY = "CZLBZ-LJICQ-R4A5J-BN62X-YXCRJ-GNBUT"; export async function getLocation (point){ const type = typeof point let arr = point if(type==='string'){ arr = parsePointToArray(point) } const locationParams = { key: MAP_KEY, location: `${arr[1]},${arr[0]}`, }; let obj = {} await VE_API.old_mini_map.location(locationParams).then(({ result }) => { obj.street = result.address_component?.street obj.address = result.formatted_addresses?.recommend ? result.formatted_addresses.recommend : result.address + ""; }); return obj }