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
79a65e8e
Commit
79a65e8e
authored
Apr 10, 2025
by
heng.zhang3@inzymeits.com
Browse files
v2x使用ws方式
parent
71ad822f
Changes
1
Show whitespace changes
Inline
Side-by-side
index.html
View file @
79a65e8e
...
@@ -161,10 +161,9 @@
...
@@ -161,10 +161,9 @@
<input
type=
"button"
id=
"resumeHistoryVehicle"
value=
"重新开始历史轨迹"
/>
<input
type=
"button"
id=
"resumeHistoryVehicle"
value=
"重新开始历史轨迹"
/>
</div>
</div>
<div>
<div>
<input
type=
"button"
id=
"startV2X"
value=
"开始V2X"
/>
<input
type=
"button"
id=
"startV2X"
value=
"全部车辆V2X"
/>
<input
type=
"button"
id=
"startV2X6"
value=
"6号车V2X"
/>
<input
type=
"button"
id=
"removeV2X"
value=
"清除V2X"
/>
<input
type=
"button"
id=
"removeV2X"
value=
"清除V2X"
/>
<input
type=
"button"
id=
"startCommunication"
value=
"开始通信效果"
/>
<input
type=
"button"
id=
"removeCommunication"
value=
"清除通信效果"
/>
</div>
</div>
<div>
<div>
<input
type=
"button"
id=
"addPolygon"
value=
"绘制感知区域"
/>
<input
type=
"button"
id=
"addPolygon"
value=
"绘制感知区域"
/>
...
@@ -203,6 +202,8 @@
...
@@ -203,6 +202,8 @@
var
trafficIncidentArr
=
[];
//热力图否显示
var
trafficIncidentArr
=
[];
//热力图否显示
var
polygon
=
null
;
// 感知区域
var
polygon
=
null
;
// 感知区域
var
v2xSocket
=
null
;
var
v2xArr
=
[];
// 记录所有v2x
//高亮模型Id
//高亮模型Id
var
highlightModelId
=
null
;
var
highlightModelId
=
null
;
var
handler
=
(
e
)
=>
{
var
handler
=
(
e
)
=>
{
...
@@ -242,12 +243,7 @@
...
@@ -242,12 +243,7 @@
// 设置地图中心点和级别
// 设置地图中心点和级别
document
.
getElementById
(
"
setZoomAndCenter
"
).
onclick
=
setZoomAndCenter
;
document
.
getElementById
(
"
setZoomAndCenter
"
).
onclick
=
setZoomAndCenter
;
function
setZoomAndCenter
()
{
function
setZoomAndCenter
()
{
var
options
=
{
var
options
=
{
"
longitude
"
:
117.346635
,
"
latitude
"
:
38.99408
,
"
height
"
:
51.43313
}
longitude
:
117.31884370955275
,
latitude
:
38.989795506281467
,
height
:
527.966445
,
zoom
:
16
,
};
map
.
setZoomAndCenter
(
options
);
map
.
setZoomAndCenter
(
options
);
}
}
...
@@ -297,7 +293,7 @@
...
@@ -297,7 +293,7 @@
document
.
getElementById
(
"
flyTo
"
).
onclick
=
flyTo
;
document
.
getElementById
(
"
flyTo
"
).
onclick
=
flyTo
;
function
flyTo
()
{
function
flyTo
()
{
var
options
=
{
var
options
=
{
position
:
[
117.3
670360408276
,
39.00412281044355
,
276.84
],
position
:
[
117.3
4584096
,
38.99557144
,
276.84
],
orientation
:
[
0
,
-
90
],
orientation
:
[
0
,
-
90
],
};
};
camera
.
flyTo
(
options
);
camera
.
flyTo
(
options
);
...
@@ -1156,15 +1152,40 @@
...
@@ -1156,15 +1152,40 @@
// 开始V2V
// 开始V2V
document
.
getElementById
(
"
startV2X
"
).
onclick
=
startV2X
;
document
.
getElementById
(
"
startV2X
"
).
onclick
=
startV2X
;
function
startV2X
()
{
function
startV2X
()
{
const
url
=
'
wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=4&reType=51world
'
startVehicleV2X
(
url
)
}
// 6号车V2X
document
.
getElementById
(
"
startV2X6
"
).
onclick
=
startV2X6
;
function
startV2X6
()
{
const
url
=
'
wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=4&reType=51world&vehicleId=267
'
startVehicleV2X
(
url
)
}
// 开始车辆V2X
function
startVehicleV2X
(
url
)
{
// let options = {
// let options = {
// color: [255, 255, 0, 1],
// color: [255, 255, 0, 1],
// vehicleId: "仿AYZQS001", //鄂A17U5N
// vehicleId: "仿AYZQS001", //鄂A17U5N
// objectId: "1200000479", // 连接车辆的效果
// // vehicleId: "测试车辆001", //鄂A17U5N
// // vehicleId: "测试车辆001", //鄂A17U5N
// name: '注意行人'
// name: '注意行人'
// };
// };
// map.getVehicle("21e7a9e6d2884122804788dac1e002cc").startV2x(options);
// map.getVehicle("21e7a9e6d2884122804788dac1e002cc").startV2x(options);
// const options2 = {
// vehicleId: ['1200001992', 'sxt000045'],//车辆ID
// color: [255, 0, 0, 1],
// }
// map.renderCommunication(options2)
// setTimeout(() => {
// map.stopCommunication(options2)
// }, 200)
// return
// 257 XM140001
// 257 XM140001
// 259 XM140002
// 259 XM140002
// 261 XM140003
// 261 XM140003
...
@@ -1176,23 +1197,30 @@
...
@@ -1176,23 +1197,30 @@
// 219 仿AYZQS001
// 219 仿AYZQS001
// 221 仿A-0234DA
// 221 仿A-0234DA
const
url
=
'
wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=4&reType=51world&vehicleId=267
'
v2xArr
=
[];
// 记录所有v2x
// 创建一个WebSocket实例
// 创建一个WebSocket实例
s
ocket
=
new
WebSocket
(
url
);
v2xS
ocket
=
new
WebSocket
(
url
);
// 当WebSocket打开时执行
// 当WebSocket打开时执行
s
ocket
.
onopen
=
function
(
event
)
{
v2xS
ocket
.
onopen
=
function
(
event
)
{
console
.
log
(
"
socket连接成功!
"
);
console
.
log
(
"
socket连接成功!
"
);
};
};
// 当接收到消息时执行
// 当接收到消息时执行
s
ocket
.
onmessage
=
function
(
event
)
{
v2xS
ocket
.
onmessage
=
function
(
event
)
{
cons
t
data
=
JSON
.
parse
(
event
.
data
)
le
t
data
=
JSON
.
parse
(
event
.
data
)
cons
t
{
objects
,
endTime
,
typeName
,
id
}
=
data
le
t
{
objects
,
endTime
,
typeName
,
id
}
=
data
// objects 如果只有一项,则是单车预警;如果有两项,则需要有两个车辆的通信效果
// objects 如果只有一项,则是单车预警;如果有两项,则需要有两个车辆的通信效果
const
mainCar
=
objects
[
0
]
let
mainCar
=
objects
[
0
]
// 如果id不在v2xArr中,则添加
const
find
=
v2xArr
.
find
(
item
=>
item
.
id
===
id
)
if
(
!
find
)
{
v2xArr
.
push
(
data
)
}
let
options
=
{
let
options
=
{
id
:
id
,
id
:
id
,
color
:
[
255
,
255
,
0
,
1
],
color
:
[
255
,
255
,
0
,
1
],
...
@@ -1203,6 +1231,7 @@
...
@@ -1203,6 +1231,7 @@
if
(
objects
.
length
>
1
)
{
if
(
objects
.
length
>
1
)
{
const
options2
=
{
const
options2
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
color
:
[
255
,
0
,
0
,
1
],
color
:
[
255
,
0
,
0
,
1
],
}
}
...
@@ -1217,48 +1246,53 @@
...
@@ -1217,48 +1246,53 @@
if
(
endTime
)
{
if
(
endTime
)
{
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
stopV2x
(
mainCar
.
id
)
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
stopV2x
(
mainCar
.
id
)
v2xArr
.
splice
(
v2xArr
.
findIndex
(
item
=>
item
.
id
===
id
),
1
)
// v2x的效果只能添加一个,但车辆能同时存在多个v2x
const
lastV2x
=
v2xArr
[
v2xArr
.
length
-
1
]
if
(
lastV2x
)
{
const
options
=
{
id
:
lastV2x
.
id
,
color
:
[
255
,
255
,
0
,
1
],
vehicleId
:
lastV2x
.
objects
[
0
].
id
,
name
:
lastV2x
.
name
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
startV2x
(
options
);
}
const
options2
=
{
const
options2
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
}
}
console
.
log
(
'
前端结束通信
'
,
id
,
mainCar
.
id
,
objects
[
1
].
id
)
map
.
stopCommunication
(
options2
)
map
.
stopCommunication
(
options2
)
if
(
objects
.
length
>
1
)
{
if
(
objects
.
length
>
1
)
{
console
.
log
(
'
结束结束结束
'
,
mainCar
.
id
,
objects
[
1
].
id
)
//
console.log('结束结束结束', mainCar.id, objects[1].id)
}
else
{
}
else
{
console
.
log
(
'
结束结束结束
'
,
mainCar
.
id
)
//
console.log('结束结束结束', mainCar.id)
}
}
};
};
}
}
}
}
// 开始通信效果
document
.
getElementById
(
"
startCommunication
"
).
onclick
=
startCommunication
;
function
startCommunication
()
{
map
.
renderCommunication
(
options2
)
}
// 清除通信效果
document
.
getElementById
(
"
removeCommunication
"
).
onclick
=
removeCommunication
;
function
removeCommunication
()
{
map
.
removeCommunication
()
}
// 隐藏V2V
// document.getElementById("hideV2X").onclick = hideV2X;
// function hideV2X() {
// let options = {
// color: [255, 255, 0, 1],
// vehicleId: "仿AYZQS001", //鄂A17U5N
// };
// map.getVehicle("21e7a9e6d2884122804788dac1e002cc").hideV2x(options);
// }
// 清除V2V
// 清除V2V
document
.
getElementById
(
"
removeV2X
"
).
onclick
=
removeV2X
;
document
.
getElementById
(
"
removeV2X
"
).
onclick
=
removeV2X
;
function
removeV2X
()
{
function
removeV2X
()
{
let
vehicleId
=
"
仿AYZQS001
"
;
v2xSocket
.
close
()
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
stopV2x
(
vehicleId
);
v2xArr
.
forEach
(
item
=>
{
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
stopV2x
(
item
.
objects
[
0
].
id
)
if
(
item
.
objects
.
length
>
1
)
{
const
options2
=
{
id
,
vehicleId
:
[
item
.
objects
[
0
].
id
,
item
.
objects
[
1
].
id
],
//车辆ID
}
map
.
stopCommunication
(
options2
)
}
})
v2xArr
=
[]
}
}
// 绘制感知区域
// 绘制感知区域
...
...
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