/* eslint-disable no-undef */
import { map, satellite } from './index_old';
import { useToolboxStore } from '@/stores/toolbox';
import { DialogUtil } from '@/utils/map/dialog';
const toolboxStore = useToolboxStore();
/**
* 坐标拾取鼠标点击回调事件
*/
var _locationMarker, _locationText;
function _coorPickListener(e) {
var text = `经度: ${e.lnglat.getLng()}
纬度: ${e.lnglat.getLat()}`;
if (_locationMarker == undefined) {
var textM = new AMap.Text({
style: {
'font-size': '12px'
},
text: text,
position: e.lnglat,
offset: new AMap.Pixel(0, 30)
});
var marker = new AMap.Marker({
position: e.lnglat
// icon: icon,
// anchor: 'top-center',
// content: ''
});
map.add(marker);
map.add(textM);
_locationMarker = marker;
_locationText = textM;
} else {
_locationMarker.setPosition(e.lnglat);
_locationText.setPosition(e.lnglat);
_locationText.setText(text);
}
}
export default {
/**
* 开关地物标注
* @param {boolean} value
*/
toggleFeatures(value) {
value
? map.setFeatures(['bg', 'road', 'point', 'building'])
: map.setFeatures(['bg', 'road']);
toolboxStore.featuresStatus = value;
},
/**
* 开关卫星地图
* @param {boolean} value
*/
toggleSatellite(value) {
value ? satellite.show() : satellite.hide();
toolboxStore.satelliteStatus = value;
},
/**
* 开关控制罗盘
* @param {boolean} value
*/
toggleControlbar(value) {
// value ? controlbar.show() : controlbar.hide();
value ? $('.amap-controlbar').show() : $('.amap-controlbar').hide();
toolboxStore.controlbarStatus = value;
},
/**
* 开关坐标拾取
* @param {boolean} value
*/
toggleCoorPicking(value) {
if (value) {
map.on('click', _coorPickListener);
} else {
map.off('click', _coorPickListener);
map.remove([_locationMarker, _locationText]);
_locationMarker = undefined;
_locationText = undefined;
}
toolboxStore.coorPickStatus = value;
},
/**
* 开关数据弹框
*/
toggleDataDialogStatus(value) {
toolboxStore.dataDialogStatus = value;
if (value) {
DialogUtil.openWindow();
} else {
DialogUtil.closeWindow();
}
},
/**
* 开关溯源清单
*/
toggleSceneSearch(value) {
toolboxStore.sceneSearchStatus = value;
}
};