Commit c6b37475 authored by 吕 成东's avatar 吕 成东
Browse files

添加v2x 预警

parent c1f2c7ef
<html> <html lang="zh-CN">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>示例集合</title> <title>示例集合</title>
...@@ -210,7 +210,6 @@ ...@@ -210,7 +210,6 @@
<div> <div>
<input type="button" id="addTrafficIncident" value="交通流中的事件" /> <input type="button" id="addTrafficIncident" value="交通流中的事件" />
<input <input
style="display: none"
type="button" type="button"
id="addTrafficIncident2" id="addTrafficIncident2"
value="不在交通流中的事件" value="不在交通流中的事件"
...@@ -290,8 +289,8 @@ ...@@ -290,8 +289,8 @@
style="width: 100vw; height: 100vh; overflow: hidden" style="width: 100vw; height: 100vh; overflow: hidden"
></div> ></div>
</body> </body>
<!-- <script src="http://192.168.60.110:3000/gis_sdk/js/CMapLoader.map.js"></script> --> <script src="http://192.168.60.110:3000/gis_sdk/js/CMapLoader.map.js"></script>
<script src="http://localhost:3000/gis_sdk/js/CMapLoader.map.js"></script> <!-- <script src="http://localhost:3000/gis_sdk/js/CMapLoader.map.js"></script> -->
<script src="./SignalLines.js"></script> <script src="./SignalLines.js"></script>
<!-- <script src="./data.js"></script> --> <!-- <script src="./data.js"></script> -->
</head> </head>
...@@ -330,8 +329,8 @@ ...@@ -330,8 +329,8 @@
initMap("51world"); initMap("51world");
async function initMap(gis_sdk) { async function initMap(gis_sdk) {
// var url = "http://192.168.60.110:3000/hdmap-platform/gateway/cmap2"; var url = "http://192.168.60.110:3000/hdmap-platform/gateway/cmap2";
var url = "http://localhost:3000/hdmap-platform/gateway/cmap2"; // var url = "http://localhost:3000/hdmap-platform/gateway/cmap2";
var secretKey = "10b79c61bf1b42e2"; var secretKey = "10b79c61bf1b42e2";
var config = { var config = {
...@@ -364,9 +363,11 @@ ...@@ -364,9 +363,11 @@
document.getElementById("setZoomAndCenter").onclick = setZoomAndCenter; document.getElementById("setZoomAndCenter").onclick = setZoomAndCenter;
function setZoomAndCenter() { function setZoomAndCenter() {
var options = { var options = {
longitude: 117.346635, // longitude: 117.346635,
latitude: 38.99408, // latitude: 38.99408,
height: 51.43313, longitude: 117.3470838,
latitude: 39.0009016,
height: 9.10081,
}; };
map.setZoomAndCenter(options); map.setZoomAndCenter(options);
} }
...@@ -1045,7 +1046,7 @@ ...@@ -1045,7 +1046,7 @@
document.getElementById("addTrafficIncident").onclick = addTrafficIncident; document.getElementById("addTrafficIncident").onclick = addTrafficIncident;
async function addTrafficIncident() { async function addTrafficIncident() {
document.getElementById("btn-list").style.display = "none"; // document.getElementById("btn-list").style.display = "none";
let fly = 0; let fly = 0;
// 订阅事件 websocket事件 // 订阅事件 websocket事件
...@@ -1287,104 +1288,8 @@ ...@@ -1287,104 +1288,8 @@
startVehicleV2X(url); startVehicleV2X(url);
} }
// 连接杆V2XGan
document.getElementById("startV2XGan").onclick = startV2XGan;
function startV2XGan() {
const url =
"wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=2&reType=51world&vehicleId=269";
startVehicleV2XGan(url);
}
// 开始车辆V2XGan
function startVehicleV2XGan(url, customId = null) {
v2xArrGan = []; // 记录所有v2x
// 创建一个WebSocket实例
v2xGanSocket = new WebSocket(url);
// 当WebSocket打开时执行
v2xGanSocket.onopen = function (event) {
console.log("V2XGansocket连接成功!");
};
// 当接收到消息时执行
v2xGanSocket.onmessage = function (event) {
let data = JSON.parse(event.data);
let { data_list } = data;
let mainCar = data_list[0];
let poleId = data_list[0].vinfo?.poleId || null;
console.log(
"v2xGanSocket.onmessage",
"mainCar:",
mainCar.vid,
"poleId:",
poleId
);
// 如果id不在v2xArr中,则添加
const find = v2xArrGan.find((item) => item.vid === mainCar.vid);
// 没有找到
if (!find && poleId) {
v2xArrGan.push(mainCar);
// console.log("开始", v2xArrGan, mainCar.vid, poleId, data);
const options2 = {
id: mainCar.vid,
vehicleId: [mainCar.vid, poleId], //车辆ID
color: [255, 255, 0, 1],
};
map.renderCommunication(options2);
return;
}
// 如果找到 并且当前是连接的 而且 当前的poleId也是一样的,什么都不做
if (find) {
// 什么都不做
if (find.vinfo.poleId === poleId) {
return;
} else {
// 先清理之前的连接
v2xArrGan.splice(
v2xArrGan.findIndex(
(item) =>
item.vid === mainCar.vid &&
item.vinfo.poleId === find.vinfo.poleId
),
1
);
const options2 = {
id: mainCar.vid,
vehicleId: [mainCar.vid, find.vinfo.poleId], //车辆ID
};
// console.log("结束通信", mainCar.vid, poleId);
map.stopCommunication(options2);
// 再重新创建连接 但是实际上我们这里删除了之后,就找不到了 其实下一帧就会创建,这一帧不显示 影响不大
}
}
};
}
// 清除V2V
document.getElementById("removeV2XGan").onclick = removeV2XGan;
function removeV2XGan() {
v2xGanSocket.close();
v2xArrGan.forEach((item) => {
const options2 = {
id: item.vid,
vehicleId: [item.vid, item.vinfo.poleId], //车辆ID
};
map.stopCommunication(options2);
});
v2xArrGan = [];
}
// 开始车辆V2X // 开始车辆V2X
function startVehicleV2X(url, customId = null) { function startVehicleV2X(url) {
v2xArr = []; // 记录所有v2x v2xArr = []; // 记录所有v2x
// 创建一个WebSocket实例 // 创建一个WebSocket实例
...@@ -1398,11 +1303,11 @@ ...@@ -1398,11 +1303,11 @@
// 当接收到消息时执行 // 当接收到消息时执行
v2xSocket.onmessage = function (event) { v2xSocket.onmessage = function (event) {
let data = JSON.parse(event.data); let data = JSON.parse(event.data);
let { objects, endTime, typeName, id } = data; let { objects, endTime, typeName, id,type } = data;
// objects 如果只有一项,则是单车预警;如果有两项,则需要有两个车辆的通信效果 // objects 如果只有一项,则是单车预警;如果有两项,则需要有两个车辆的通信效果
let mainCar = objects[0]; let mainCar = objects[0];
let otherCar = customId ? customId : objects[1]; let otherCar = objects[1];
// 如果id不在v2xArr中,则添加 // 如果id不在v2xArr中,则添加
const find = v2xArr.find((item) => item.id === id); const find = v2xArr.find((item) => item.id === id);
...@@ -1415,6 +1320,8 @@ ...@@ -1415,6 +1320,8 @@
color: [255, 0, 0, 1], color: [255, 0, 0, 1],
vehicleId: mainCar.id, vehicleId: mainCar.id,
name: typeName, name: typeName,
AlarmDirect:type,
}; };
map.getVehicle("21e7a9e6d2884122804788dac1e002cc").startV2x(options); map.getVehicle("21e7a9e6d2884122804788dac1e002cc").startV2x(options);
if (objects.length > 1) { if (objects.length > 1) {
...@@ -1425,11 +1332,11 @@ ...@@ -1425,11 +1332,11 @@
}; };
map.renderCommunication(options2); map.renderCommunication(options2);
if (objects.length > 1) { // if (objects.length > 1) {
console.log("开始", mainCar.id, otherCar.id, data); // console.log("开始", mainCar.id, otherCar.id, data);
} else { // } else {
console.log("开始", mainCar.id, data); // console.log("开始", mainCar.id, data);
} // }
} }
if (endTime) { if (endTime) {
...@@ -1459,7 +1366,7 @@ ...@@ -1459,7 +1366,7 @@
id, id,
vehicleId: [mainCar.id, otherCar.id], //车辆ID vehicleId: [mainCar.id, otherCar.id], //车辆ID
}; };
console.log("前端结束通信", id, mainCar.id, otherCar.id); // console.log("前端结束通信", id, mainCar.id, otherCar.id);
map.stopCommunication(options2); map.stopCommunication(options2);
if (objects.length > 1) { if (objects.length > 1) {
...@@ -1492,6 +1399,109 @@ ...@@ -1492,6 +1399,109 @@
v2xArr = []; v2xArr = [];
} }
// 连接杆V2XGan
document.getElementById("startV2XGan").onclick = startV2XGan;
function startV2XGan() {
const url =
"wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=2&reType=51world&vehicleId=269";
startVehicleV2XGan(url);
}
// 开始车辆V2XGan
function startVehicleV2XGan(url) {
v2xArrGan = []; // 记录所有v2x
// 创建一个WebSocket实例
v2xGanSocket = new WebSocket(url);
// 当WebSocket打开时执行
v2xGanSocket.onopen = function (event) {
console.log("V2XGansocket连接成功!");
};
// 当接收到消息时执行
v2xGanSocket.onmessage = function (event) {
let data = JSON.parse(event.data);
let { data_list } = data;
let mainCar = data_list[0];
let poleId = data_list[0].vinfo?.poleId || null;
// console.log(
// "v2xGanSocket.onmessage",
// "mainCar:",
// mainCar.vid,
// "poleId:",
// poleId
// );
data_list?.forEach((item)=>{
if(item.vid==271){
console.log('vid:271',"door:",item.vinfo.door,"light:",item.vinfo.light,"coord:",item.coord)
}
})
console.log('')
// 如果id不在v2xArr中,则添加
const find = v2xArrGan.find((item) => item.vid === mainCar.vid);
// 没有找到
if (!find && poleId) {
v2xArrGan.push(mainCar);
// console.log("开始", v2xArrGan, mainCar.vid, poleId, data);
const options = {
id: mainCar.vid,
vehicleId: [mainCar.vid, poleId], //车辆ID
color: [255, 255, 0, 1],
};
map.renderCommunication(options);
return;
}
// 如果找到 并且当前是连接的 而且 当前的poleId也是一样的,什么都不做
if (find) {
// 什么都不做
if (find.vinfo.poleId === poleId) {
return;
} else {
// 先清理之前的连接
v2xArrGan.splice(
v2xArrGan.findIndex(
(item) =>
item.vid === mainCar.vid &&
item.vinfo.poleId === find.vinfo.poleId
),
1
);
const options = {
id: mainCar.vid,
vehicleId: [mainCar.vid, find.vinfo.poleId], //车辆ID
};
// console.log("结束通信", mainCar.vid, poleId);
map.stopCommunication(options);
// 再重新创建连接 但是实际上我们这里删除了之后,就找不到了 其实下一帧就会创建,这一帧不显示 影响不大
}
}
};
}
// 清除V2V
document.getElementById("removeV2XGan").onclick = removeV2XGan;
function removeV2XGan() {
v2xGanSocket.close();
v2xArrGan.forEach((item) => {
const options2 = {
id: item.vid,
vehicleId: [item.vid, item.vinfo.poleId], //车辆ID
};
map.stopCommunication(options2);
});
v2xArrGan = [];
}
// 绘制感知区域 // 绘制感知区域
document.getElementById("addPolygon").onclick = addPolygon; document.getElementById("addPolygon").onclick = addPolygon;
async function addPolygon() { async function addPolygon() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment