import countryGPS from '@/utils/country_gps'; import { transform } from '@/utils/coordinate'; export function getGPSOfBDCountries() { return new Promise((resolve) => { const allGPS = {}; const countries = Object.keys(countryGPS); let transNum = 0; const convertor = new BMap.Convertor(); let times = 0; const inst = setInterval(() => { const country = countries[times]; const gps = countryGPS[country]; console.log('gps', gps); const gpsPoint = new BMap.Point(gps[0], gps[1]); // 这个地方的参数估计有问题 convertor.translate([gpsPoint], 1, 5, ({status, points}) => { transNum += 1; if (status === 0) { const [bdPoint] = points; allGPS[country] = { gps: gpsPoint, bd: bdPoint, } } console.log(country, points, transNum); if (transNum >= countries.length) { console.log(JSON.stringify(allGPS)) resolve(allGPS); } }); times ++; if (times >= countries.length) { clearInterval(inst); } }, 1000); }); } export function getGPSOfGD() { const countries = Object.keys(countryGPS); const allGPS = countries.reduce((acc, country) => { const gps = countryGPS[country]; const gd = transform(gps.join(',')); return { ...acc, [country]: { gps, gd } } }, {}); console.log(JSON.stringify(allGPS)); }