处理地图弹窗层级问题

main
许宏杰 1 month ago
parent 3f7a42710b
commit 662b2fb7f3

@ -39,7 +39,12 @@ export default {
<style lang="scss" scoped>
.map-container {
height: 120%;
position: absolute;
left: 0;
top: 0;
z-index: 50;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>

@ -0,0 +1,146 @@
import { Message } from "element-ui";
import { getToken } from "@/utils/authToken"; // 与后端的协商websocket请求需要带上token参数
let websock = null;
let messageCallback = null;
let errorCallback = null;
let wsUrl = "";
let tryTime = 0;
// 接收ws后端返回的数据
function websocketonmessage(e) {
messageCallback(JSON.parse(e.data));
}
/**
* 发起websocket连接
* @param {Object} agentData 需要向后台传递的参数数据
*/
function websocketSend(agentData) {
// 加延迟是为了尽量让ws连接状态变为OPEN
setTimeout(() => {
// 添加状态判断当为OPEN时发送消息
if (websock.readyState === websock.OPEN) {
// websock.OPEN = 1
// 发给后端的数据需要字符串化
websock.send(JSON.stringify(agentData));
}
if (websock.readyState === websock.CLOSED) {
// websock.CLOSED = 3
console.log("websock.readyState=3");
Message.error("ws连接异常请稍候重试");
errorCallback();
}
}, 500);
}
// 关闭ws连接
function websocketclose(e) {
// e.code === 1000 表示正常关闭。 无论为何目的而创建, 该链接都已成功完成任务。
// e.code !== 1000 表示非正常关闭。
if (e && e.code !== 1000) {
Message.error("ws连接异常请稍候重试");
errorCallback();
// // 如果需要设置异常重连则可替换为下面的代码,自行进行测试
// if (tryTime < 10) {
// setTimeout(function() {
// websock = null
// tryTime++
// initWebSocket()
// console.log(`第${tryTime}次重连`)
// }, 3 * 1000)
//} else {
// Message.error('重连失败!请稍后重试')
//}
}
}
// 建立ws连接
function websocketOpen(e) {
// console.log('ws连接成功')
}
// 初始化weosocket
function initWebSocket() {
if (typeof WebSocket === "undefined") {
Message.error("您的浏览器不支持WebSocket无法获取数据");
return false;
}
const token = "JWT=" + getToken();
// ws请求完整地址
const requstWsUrl = wsUrl + "?" + token;
websock = new WebSocket(requstWsUrl);
websock.onmessage = function (e) {
websocketonmessage(e);
};
websock.onopen = function () {
websocketOpen();
};
websock.onerror = function () {
Message.error("ws连接异常请稍候重试");
errorCallback();
};
websock.onclose = function (e) {
websocketclose(e);
};
}
/**
* 发起websocket请求函数
* @param {string} url ws连接地址
* @param {Object} agentData 传给后台的参数
* @param {function} successCallback 接收到ws数据对数据进行处理的回调函数
* @param {function} errCallback ws连接错误的回调函数
*/
export function sendWebsocket(url, agentData, successCallback, errCallback) {
wsUrl = url;
initWebSocket();
messageCallback = successCallback;
errorCallback = errCallback;
websocketSend(agentData);
}
/**
* 关闭websocket函数
*/
export function closeWebsocket() {
if (websock) {
websock.close(); // 关闭websocket
websock.onclose(); // 关闭websocket
}
}
// 使用
// import { sendWebsocket, closeWebsocket } from '@/utils/websocket.js'
// export default {
// beforeDestroy () {
// // 页面销毁时关闭ws。因为有可能ws连接接收数据尚未完成用户就跳转了页面
// // 在需要主动关闭ws的地方都可以调用该方法
// closeWebsocket()
// },
// methods: {
// // ws连接成功后台返回的ws数据组件要拿数据渲染页面等操作
// wsMessage (data) {
// const dataJson = data
// console.log(dataJson)
// // 这里写拿到数据后的业务代码
// },
// // ws连接失败组件要执行的代码
// wsError () {
// // 比如取消页面的loading
// },
// requstWs () {
// // 防止用户多次连续点击发起请求所以要先关闭上次的ws请求。
// closeWebsocket()
// // 跟后端协商,需要什么参数数据给后台
// const obj = {
// monitorUrl: 'xxxxxxxxxxxxx',
// userName: 'xxxxxxxxxx'
// }
// // 发起ws请求
// sendWebsocket('ws://test.ws.com', obj, this.wsMessage, this.wsError)
// }
// }
// }

@ -105,7 +105,7 @@ export default {
color: "#fff",
horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
distanceDisplayCondition: false,
distanceDisplayCondition: true,
clampToGround: true,
},
attr: {
@ -255,7 +255,7 @@ export default {
top: 23px;
left: 50%;
transform: translateX(-50%);
z-index: 2000;
z-index: 100;
display: flex;
align-items: center;
justify-content: center;
@ -294,7 +294,7 @@ export default {
bottom: 25px;
left: 50%;
transform: translateX(-50%);
z-index: 50;
z-index: 100;
padding: 10px;
display: flex;
align-items: center;
@ -302,47 +302,4 @@ export default {
border-radius: 10px;
background: rgba(28, 31, 34, 0.6);
}
.multiple {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
z-index: 50;
width: 880px;
height: 80px;
display: flex;
align-items: center;
justify-content: space-between;
background: url("../assets/images/multipleList.png");
background-size: 100% 100%;
padding: 0 230px;
.checkbox {
cursor: pointer;
width: 112px;
height: 32px;
line-height: 32px;
text-align: center;
font-size: 14px;
color: #ffffff;
background: linear-gradient(180deg, #072853 0%, #0079ff 100%);
// border-radius: 16px;
border: 1px solid #0084ff;
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
}
.checked {
background: #fd873f;
color: #612500;
border: 0;
font-weight: bold;
border: 1px solid #f7c75d;
}
.btn-icon {
width: 15px;
height: 16px;
margin-right: 10px;
}
}
</style>

@ -76,7 +76,6 @@ export default {
initChina() {
mars3d.Util.fetchJson({ url: this.chinaUrl }).then((res) => {
const arr = mars3d.Util.geoJsonToGraphics(res);
arr.map((item, index) => {
const polygonEntity = new mars3d.graphic.PolygonEntity({
positions: item.positions,
@ -90,9 +89,6 @@ export default {
setHeight: 900009,
},
});
this.mapLayer.china.addGraphic(polygonEntity);
});
arr.map((item, index) => {
const wall = new mars3d.graphic.WallPrimitive({
positions: item.positions,
style: {
@ -106,6 +102,7 @@ export default {
},
},
});
this.mapLayer.china.addGraphic(polygonEntity);
this.mapLayer.china.addGraphic(wall);
});
@ -117,7 +114,6 @@ export default {
const options = this.getEchartsOption();
const echartsLayer = new mars3d.layer.EchartsLayer(options);
this.map.addLayer(echartsLayer);
//
window.addEventListener("resize", function () {
echartsLayer.resize();

Loading…
Cancel
Save