import AMapLoader from '@amap/amap-jsapi-loader'; var mapInitDone = false; var onMapMountedEvents = []; var AMap; // 地图对象 var map; // 卫星图层 var satellite; // 鼠标绘图 var mouseTool; // 地图加载完成触发 function onMapMounted(...events) { if (mapInitDone) { events.forEach((e) => { e(); }); } else { onMapMountedEvents = onMapMountedEvents.concat(events); } } function createMap(id) { AMapLoader.load({ key: 'c55f27799afbfa69dc5a3fad90cafe51', // 申请好的Web端开发者Key,首次调用 load 时必填 version: '2.0', // 指定要加载的 JS API 的版本,缺省时默认为 1.4.15 plugins: [ 'Map3D', 'ElasticMarker', 'AMap.ControlBar', 'AMap.ToolBar', 'AMap.Scale', 'AMap.DragRoute', 'AMap.MouseTool', 'AMap.PolygonEditor' ] // 需要使用的的插件列表,如比例尺'AMap.Scale'等 }) .then((_AMap) => { AMap = _AMap; initMap(id); mapInitDone = true; onMapMountedEvents.forEach((e) => { e(); }); onMapMountedEvents = []; }) .catch((e) => { console.log(e); }); } function initMap(elementId) { map = new AMap.Map(elementId, { rotateEnable: true, pitchEnable: true, alwaysRender: false, showLabel: true, showBuildingBlock: true, // mapStyle: 'amap://styles/e1e78509de64ddcd2efb4cb34c6fae2a', // features: ['bg', 'road'], pitch: 0, // 地图俯仰角度,有效范围 0 度- 83 度 viewMode: '3D', // 地图模式 resizeEnable: true, center: [121.6039283, 31.25295567], zooms: [3, 18], zoom: 14 }); // 添加卫星地图 satellite = new AMap.TileLayer.Satellite(); satellite.hide(); map.add([satellite]); // const rPx = 100; // const tPx = 110; // 添加地图控制工具 // map.addControl( // new AMap.ControlBar({ // position: { // right: rPx + 'px', // top: tPx + 'px' // } // }) // ); // map.addControl( // new AMap.ToolBar({ // position: { // right: rPx + 30 + 'px', // top: tPx + 90 + 'px' // } // }) // ); // mouseTool = new AMap.MouseTool(map); } export { createMap, onMapMounted, map, AMap, mouseTool };