Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
方 梦梦
world51tocmap
Commits
c1f2c7ef
Commit
c1f2c7ef
authored
May 20, 2025
by
吕 成东
Browse files
灯杆效果
parent
a62b30ae
Changes
1
Show whitespace changes
Inline
Side-by-side
index.html
View file @
c1f2c7ef
...
...
@@ -237,6 +237,12 @@
<input
type=
"button"
id=
"startV2X7"
value=
"7号车V2X"
/>
<input
type=
"button"
id=
"removeV2X"
value=
"清除V2X"
/>
</div>
<div>
<input
type=
"button"
id=
"startV2XGan"
value=
"连接杆V2X-269"
/>
<input
type=
"button"
id=
"removeV2XGan"
value=
"清除V2X-269"
/>
</div>
<div>
<input
type=
"button"
id=
"addPolygon"
value=
"绘制感知区域"
/>
<input
type=
"button"
id=
"showPolygon"
value=
"显示感知区域"
/>
...
...
@@ -284,8 +290,8 @@
style=
"width: 100vw; height: 100vh; overflow: hidden"
></div>
</body>
<!-- <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="./data.js"></script> -->
</head>
...
...
@@ -308,6 +314,12 @@
var
v2xSocket
=
null
;
var
v2xArr
=
[];
// 记录所有v2x
var
v2xGanSocket
=
null
;
var
v2xArrGan
=
[];
// 记录所有v2x
var
v2xGanSocket
=
null
;
var
v2xGanArr
=
[];
// 记录所有v2x
var
trafficEventSocket
=
null
;
var
trafficEventArr
=
[];
// 记录所有的交通事件
//高亮模型Id
...
...
@@ -318,6 +330,7 @@
initMap
(
"
51world
"
);
async
function
initMap
(
gis_sdk
)
{
// var url = "http://192.168.60.110:3000/hdmap-platform/gateway/cmap2";
var
url
=
"
http://localhost:3000/hdmap-platform/gateway/cmap2
"
;
var
secretKey
=
"
10b79c61bf1b42e2
"
;
...
...
@@ -1274,38 +1287,104 @@
startVehicleV2X
(
url
);
}
// 开始车辆V2X
function
startVehicleV2X
(
url
)
{
// let options = {
// color: [255, 255, 0, 1],
// vehicleId: "仿AYZQS001", //鄂A17U5N
// // vehicleId: "测试车辆001", //鄂A17U5N
// name: '注意行人'
// };
// map.getVehicle("21e7a9e6d2884122804788dac1e002cc").startV2x(options);
// 连接杆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
);
}
// const options2 = {
// vehicleId: ['1200001992', 'sxt000045'],//车辆ID
// color: [255, 0, 0, 1],
// }
// map.renderCommunication(options2)
// setTimeout(() => {
// map.stopCommunication(options2)
// }, 200)
// return
// 257 XM140001
// 259 XM140002
// 261 XM140003
// 263 XM140004
// 265 XM140005
// 267 XM140006
// 269 XM140007
// 271 XM140008
// 219 仿AYZQS001
// 221 仿A-0234DA
// 开始车辆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
function
startVehicleV2X
(
url
,
customId
=
null
)
{
v2xArr
=
[];
// 记录所有v2x
// 创建一个WebSocket实例
...
...
@@ -1323,6 +1402,7 @@
// objects 如果只有一项,则是单车预警;如果有两项,则需要有两个车辆的通信效果
let
mainCar
=
objects
[
0
];
let
otherCar
=
customId
?
customId
:
objects
[
1
];
// 如果id不在v2xArr中,则添加
const
find
=
v2xArr
.
find
((
item
)
=>
item
.
id
===
id
);
...
...
@@ -1337,17 +1417,16 @@
name
:
typeName
,
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
startV2x
(
options
);
if
(
objects
.
length
>
1
)
{
const
options2
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
o
bjects
[
1
]
.
id
],
//车辆ID
vehicleId
:
[
mainCar
.
id
,
o
therCar
.
id
],
//车辆ID
color
:
[
255
,
255
,
0
,
1
],
};
map
.
renderCommunication
(
options2
);
if
(
objects
.
length
>
1
)
{
console
.
log
(
"
开始
"
,
mainCar
.
id
,
o
bjects
[
1
]
.
id
,
data
);
console
.
log
(
"
开始
"
,
mainCar
.
id
,
o
therCar
.
id
,
data
);
}
else
{
console
.
log
(
"
开始
"
,
mainCar
.
id
,
data
);
}
...
...
@@ -1378,9 +1457,9 @@
const
options2
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
o
bjects
[
1
]
.
id
],
//车辆ID
vehicleId
:
[
mainCar
.
id
,
o
therCar
.
id
],
//车辆ID
};
console
.
log
(
"
前端结束通信
"
,
id
,
mainCar
.
id
,
o
bjects
[
1
]
.
id
);
console
.
log
(
"
前端结束通信
"
,
id
,
mainCar
.
id
,
o
therCar
.
id
);
map
.
stopCommunication
(
options2
);
if
(
objects
.
length
>
1
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment