/* eslint-disable no-undef */
|
// import '@/lib/AMap';
|
import { useToolboxStore } from '@/stores/toolbox';
|
|
const toolboxStore = useToolboxStore();
|
|
var mapInitDone = false;
|
var onMapMountedEvents = [];
|
|
// 地图对象
|
var map;
|
// 卫星图层
|
var satellite;
|
// 地图拖动控制
|
var controlbar;
|
// 鼠标绘图
|
var mouseTool;
|
// 3D图层
|
var object3Dlayer;
|
// 地图拖动状态
|
var isDragging = false;
|
|
// 地图加载完成触发
|
function onMapMounted(...events) {
|
if (mapInitDone) {
|
events.forEach((e) => {
|
e();
|
});
|
} else {
|
onMapMountedEvents = onMapMountedEvents.concat(events);
|
}
|
}
|
|
function createMap(id) {
|
_initMap(id);
|
mapInitDone = true;
|
onMapMountedEvents.forEach((e) => {
|
e();
|
});
|
onMapMountedEvents = [];
|
}
|
|
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: 45, // 地图俯仰角度,有效范围 0 度- 83 度
|
viewMode: '3D', // 地图模式
|
resizeEnable: true,
|
center: [121.6039283, 31.25295567],
|
zooms: [0, 18],
|
zoom: 14
|
});
|
|
// 添加卫星地图
|
satellite = new AMap.TileLayer.Satellite();
|
satellite.show();
|
map.add([satellite]);
|
toolboxStore.featuresStatus = true;
|
|
_initControlbar();
|
// _initMouseTool();
|
_init3DLayer();
|
_initDragEvent();
|
}
|
|
function _initControlbar() {
|
controlbar = new AMap.ControlBar({
|
position: {
|
right: '300px',
|
top: '260px'
|
}
|
});
|
map.addControl(controlbar);
|
toolboxStore.controlbarStatus = true;
|
}
|
|
// 鼠标绘图初始化
|
// function _initMouseTool() {
|
// mouseTool = new AMap.MouseTool(map);
|
// }
|
|
// 3D图层初始化
|
function _init3DLayer() {
|
object3Dlayer = new AMap.Object3DLayer();
|
map.add(object3Dlayer);
|
}
|
|
// 设置地图拖拽监听事件
|
function _initDragEvent() {
|
let dragEndEvent;
|
map.on('dragstart', () => {
|
clearTimeout(dragEndEvent);
|
isDragging = true;
|
});
|
map.on('dragend', function () {
|
dragEndEvent = setTimeout(() => {
|
isDragging = false;
|
}, 8000);
|
});
|
}
|
|
export {
|
createMap,
|
onMapMounted,
|
map,
|
controlbar,
|
mouseTool,
|
satellite,
|
object3Dlayer,
|
isDragging
|
};
|