gps.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import countryGPS from '@/utils/country_gps';
  2. import { transform } from '@/utils/coordinate';
  3. export function getGPSOfBDCountries() {
  4. return new Promise((resolve) => {
  5. const allGPS = {};
  6. const countries = Object.keys(countryGPS);
  7. let transNum = 0;
  8. const convertor = new BMap.Convertor();
  9. let times = 0;
  10. const inst = setInterval(() => {
  11. const country = countries[times];
  12. const gps = countryGPS[country];
  13. console.log('gps', gps);
  14. const gpsPoint = new BMap.Point(gps[0], gps[1]);
  15. // 这个地方的参数估计有问题
  16. convertor.translate([gpsPoint], 1, 5, ({status, points}) => {
  17. transNum += 1;
  18. if (status === 0) {
  19. const [bdPoint] = points;
  20. allGPS[country] = {
  21. gps: gpsPoint,
  22. bd: bdPoint,
  23. }
  24. }
  25. console.log(country, points, transNum);
  26. if (transNum >= countries.length) {
  27. console.log(JSON.stringify(allGPS))
  28. resolve(allGPS);
  29. }
  30. });
  31. times ++;
  32. if (times >= countries.length) {
  33. clearInterval(inst);
  34. }
  35. }, 1000);
  36. });
  37. }
  38. export function getGPSOfGD() {
  39. const countries = Object.keys(countryGPS);
  40. const allGPS = countries.reduce((acc, country) => {
  41. const gps = countryGPS[country];
  42. const gd = transform(gps.join(','));
  43. return {
  44. ...acc,
  45. [country]: {
  46. gps,
  47. gd
  48. }
  49. }
  50. }, {});
  51. console.log(JSON.stringify(allGPS));
  52. }