无人机管理后台前端(已迁走)
rain
2025-04-08 9fcf4ce4911eb76b73d487e60024edbc79bd941e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
window._AMapSecurityConfig = {
  securityJsCode: '', // 替换为高德平台生成的安全密钥
};
 
export const loadAMap = () => {
  return new Promise((resolve, reject) => {
    if (window.AMap) {
      resolve(window.AMap);
      return;
    }
 
    const script = document.createElement('script');
    script.src = `https://webapi.amap.com/maps?v=1.4.11&key=7873666321486813e3eedad751bb9608&plugin=AMap.PlaceSearch,AMap.Geocoder`; // 替换为你的 API Key
    script.onerror = () => reject(new Error('Failed to load AMap script'));
    script.onload = () => {
      if (window.AMap) {
        resolve(window.AMap);
      } else {
        reject(new Error('AMap failed to initialize'));
      }
    };
 
    document.body.appendChild(script);
  });
};
 
export const loadAMapUI = () => {
  return new Promise((resolve, reject) => {
    if (window.AMapUI) {
      resolve(window.AMapUI);
      return;
    }
 
    const script = document.createElement('script');
    script.src = 'https://webapi.amap.com/ui/1.0/main.js?v=1.0.11';
    script.onerror = () => reject(new Error('Failed to load AMap UI script'));
    script.onload = () => {
      if (window.AMapUI) {
        resolve(window.AMapUI);
      } else {
        reject(new Error('AMap UI failed to initialize'));
      }
    };
 
    document.body.appendChild(script);
  });
};
 
export const initPoiPicker = () => {
  return new Promise((resolve, reject) => {
    loadAMap()
      .then(() => loadAMapUI())
      .then((AMapUI) => {
        AMapUI.loadUI(['misc/PoiPicker'], (PoiPicker) => {
          if (!PoiPicker) {
            reject(new Error('PoiPicker failed to load'));
            return;
          }
          const poiPicker = new PoiPicker();
          resolve(poiPicker);
        });
      })
      .catch((error) => {
        console.error('Error initializing PoiPicker:', error);
        reject(error);
      });
  });
};
 
export const initGeocoder = () => {
  return new Promise((resolve, reject) => {
    loadAMap()
      .then((AMap) => {
        try {
          const geocoder = new AMap.Geocoder();
          resolve(geocoder);
        } catch (error) {
          reject(new Error('Failed to initialize Geocoder'));
        }
      })
      .catch((error) => {
        console.error('Error initializing Geocoder:', error);
        reject(error);
      });
  });
};