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
1347d4d5
Commit
1347d4d5
authored
Apr 10, 2025
by
chengdong.lv@inzymeits.com
Browse files
提交
parent
79a65e8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
1347d4d5
<html>
<head>
<head>
<meta
charset=
"utf-8"
/>
<title>
示例集合
</title>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<style>
html
{
margin
:
0
;
padding
:
0
;
}
body
{
margin
:
0
;
padding
:
0
;
}
div
{
margin
:
0
;
padding
:
0
;
}
#btn-list
{
position
:
fixed
;
right
:
0
;
top
:
0
;
z-index
:
1
;
padding
:
14px
;
line-height
:
40px
;
overflow
:
auto
;
height
:
100%
;
margin-bottom
:
20px
;
}
#btn-list
>
div
>
[
type
=
"button"
]
{
background
:
rgb
(
59
,
98
,
226
);
color
:
#fff
;
border
:
0
;
padding
:
4px
6px
;
border-radius
:
4px
;
cursor
:
pointer
;
}
#btn-list
>
div
:last-child
{
margin-bottom
:
20px
;
}
html
{
margin
:
0
;
padding
:
0
;
}
body
{
margin
:
0
;
padding
:
0
;
}
div
{
margin
:
0
;
padding
:
0
;
}
#btn-list
{
position
:
fixed
;
right
:
0
;
top
:
0
;
z-index
:
1
;
padding
:
14px
;
line-height
:
40px
;
overflow
:
auto
;
height
:
100%
;
margin-bottom
:
20px
;
}
#btn-list
>
div
>
[
type
=
"button"
]
{
background
:
rgb
(
59
,
98
,
226
);
color
:
#fff
;
border
:
0
;
padding
:
4px
6px
;
border-radius
:
4px
;
cursor
:
pointer
;
}
#btn-list
>
div
:last-child
{
margin-bottom
:
20px
;
}
</style>
<body>
<div
id=
"btn-list"
>
<body>
<div
id=
"btn-list"
>
<div>
<input
type=
"button"
id=
"getZoomAndCenter"
value=
"获取地图中心点和级别"
/>
<input
type=
"button"
id=
"setZoomAndCenter"
value=
"设置地图中心点和级别"
/>
<input
type=
"button"
id=
"getZoomAndCenter"
value=
"获取地图中心点和级别"
/>
<input
type=
"button"
id=
"setZoomAndCenter"
value=
"设置地图中心点和级别"
/>
</div>
<div>
<input
type=
"button"
id=
"lockMap"
value=
"限制地图显示范围和级别"
/>
<input
type=
"button"
id=
"unlockMap"
value=
"解锁地图显示范围和级别"
/>
<input
type=
"button"
id=
"lockMap"
value=
"限制地图显示范围和级别"
/>
<input
type=
"button"
id=
"unlockMap"
value=
"解锁地图显示范围和级别"
/>
</div>
<div>
<input
type=
"button"
id=
"flyTo"
value=
"设置相机"
/>
<input
type=
"button"
id=
"getCameraView"
value=
"获取相机参数"
/>
<input
type=
"button"
id=
"addCameraEvent"
value=
"监听相机参数"
/>
<input
type=
"button"
id=
"removeCameraEvent"
value=
"移除相机监听事件"
/>
<input
type=
"button"
id=
"flyTo"
value=
"设置相机"
/>
<input
type=
"button"
id=
"getCameraView"
value=
"获取相机参数"
/>
<input
type=
"button"
id=
"addCameraEvent"
value=
"监听相机参数"
/>
<input
type=
"button"
id=
"removeCameraEvent"
value=
"移除相机监听事件"
/>
</div>
<div>
<input
type=
"button"
id=
"startFly"
value=
"开始相机导览"
/>
<input
type=
"button"
id=
"pauseFly"
value=
"暂停相机导览"
/>
<input
type=
"button"
id=
"resuFly"
value=
"继续相机导览"
/>
<input
type=
"button"
id=
"stopFly"
value=
"结束相机导览"
/>
<input
type=
"button"
id=
"startFly"
value=
"开始相机导览"
/>
<input
type=
"button"
id=
"pauseFly"
value=
"暂停相机导览"
/>
<input
type=
"button"
id=
"resuFly"
value=
"继续相机导览"
/>
<input
type=
"button"
id=
"stopFly"
value=
"结束相机导览"
/>
</div>
<div>
<input
type=
"button"
id=
"addMapChangeEvent"
value=
"注册地图变化事件"
/>
<input
type=
"button"
id=
"removeMapChangeEvent"
value=
"注销地图变化事件"
/>
<input
type=
"button"
id=
"addMouseClickEvent"
value=
"注册鼠标点击事件"
/>
<input
type=
"button"
id=
"removeMouseClickEvent"
value=
"注销鼠标点击事件"
/>
<input
type=
"button"
id=
"addMapChangeEvent"
value=
"注册地图变化事件"
/>
<input
type=
"button"
id=
"removeMapChangeEvent"
value=
"注销地图变化事件"
/>
<input
type=
"button"
id=
"addMouseClickEvent"
value=
"注册鼠标点击事件"
/>
<input
type=
"button"
id=
"removeMouseClickEvent"
value=
"注销鼠标点击事件"
/>
</div>
<div>
<input
type=
"button"
id=
"addModelClickEvent"
value=
"注册模型点击事件"
/>
<input
type=
"button"
id=
"removeModelClickEvent"
value=
"注销模型点击事件"
/>
<input
type=
"button"
id=
"cancleHighLight"
value=
"取消模型高亮"
/>
<input
type=
"button"
id=
"removePopup"
value=
"取消弹窗"
/>
<input
type=
"button"
id=
"addModelClickEvent"
value=
"注册模型点击事件"
/>
<input
type=
"button"
id=
"removeModelClickEvent"
value=
"注销模型点击事件"
/>
<input
type=
"button"
id=
"cancleHighLight"
value=
"取消模型高亮"
/>
<input
type=
"button"
id=
"removePopup"
value=
"取消弹窗"
/>
</div>
<div>
<input
type=
"button"
id=
"addMarker"
value=
"添加路口标签"
/>
<input
type=
"button"
id=
"showMarker"
value=
"显示标签"
/>
<input
type=
"button"
id=
"hideMarker"
value=
"隐藏标签"
/>
<input
type=
"button"
id=
"removeMarker"
value=
"删除标签"
/>
<input
type=
"button"
id=
"addMarker"
value=
"添加路口标签"
/>
<input
type=
"button"
id=
"showMarker"
value=
"显示标签"
/>
<input
type=
"button"
id=
"hideMarker"
value=
"隐藏标签"
/>
<input
type=
"button"
id=
"removeMarker"
value=
"删除标签"
/>
</div>
<div>
<input
type=
"button"
id=
"startRsu"
value=
"开始Rsu特效"
/>
<input
type=
"button"
id=
"stopRsu"
value=
"停止Rsu特效"
/>
<input
type=
"button"
id=
"hideRsu"
value=
"隐藏Rsu特效"
/>
<input
type=
"button"
id=
"showRsu"
value=
"显示Rsu特效"
/>
<input
type=
"button"
id=
"startRsu"
value=
"开始Rsu特效"
/>
<input
type=
"button"
id=
"stopRsu"
value=
"停止Rsu特效"
/>
<input
type=
"button"
id=
"hideRsu"
value=
"隐藏Rsu特效"
/>
<input
type=
"button"
id=
"showRsu"
value=
"显示Rsu特效"
/>
</div>
<div>
<input
type=
"button"
id=
"rain"
value=
"开始下雨"
/>
<input
type=
"button"
id=
"stopRain"
value=
"停止下雨"
/>
<input
type=
"button"
id=
"snow"
value=
"开始下雪"
/>
<input
type=
"button"
id=
"stopSnow"
value=
"停止下雪"
/>
<input
type=
"button"
id=
"fog"
value=
"雾"
/>
<input
type=
"button"
id=
"stopFog"
value=
"清除雾"
/>
<input
type=
"button"
id=
"rain"
value=
"开始下雨"
/>
<input
type=
"button"
id=
"stopRain"
value=
"停止下雨"
/>
<input
type=
"button"
id=
"snow"
value=
"开始下雪"
/>
<input
type=
"button"
id=
"stopSnow"
value=
"停止下雪"
/>
<input
type=
"button"
id=
"fog"
value=
"雾"
/>
<input
type=
"button"
id=
"stopFog"
value=
"清除雾"
/>
</div>
<div>
<input
type=
"button"
id=
"point"
value=
"绘制点"
/>
<input
type=
"button"
id=
"polyline"
value=
"绘制线"
/>
<input
type=
"button"
id=
"polygon"
value=
"绘制面"
/>
<input
type=
"button"
id=
"remove"
value=
"清除绘制"
/>
<input
type=
"button"
id=
"point"
value=
"绘制点"
/>
<input
type=
"button"
id=
"polyline"
value=
"绘制线"
/>
<input
type=
"button"
id=
"polygon"
value=
"绘制面"
/>
<input
type=
"button"
id=
"remove"
value=
"清除绘制"
/>
</div>
<div>
<input
type=
"button"
id=
"start1"
value=
"坐标点"
/>
<input
type=
"button"
id=
"start2"
value=
"直线测量"
/>
<input
type=
"button"
id=
"start6"
value=
"地表面积"
/>
<input
type=
"button"
id=
"stopMeasurement"
value=
"停止量算"
/>
<input
type=
"button"
id=
"start1"
value=
"坐标点"
/>
<input
type=
"button"
id=
"start2"
value=
"直线测量"
/>
<input
type=
"button"
id=
"start6"
value=
"地表面积"
/>
<input
type=
"button"
id=
"stopMeasurement"
value=
"停止量算"
/>
</div>
<div>
<input
type=
"button"
id=
"toNorth"
value=
"显示指北针"
/>
<input
type=
"button"
id=
"hideNorth"
value=
"移除指北针"
/>
<input
type=
"button"
id=
"toNorth"
value=
"显示指北针"
/>
<input
type=
"button"
id=
"hideNorth"
value=
"移除指北针"
/>
</div>
<div>
<input
type=
"button"
id=
"setDark"
value=
"夜景"
/>
<input
type=
"button"
id=
"setday"
value=
"取消夜景"
/>
<input
type=
"button"
id=
"setDark"
value=
"夜景"
/>
<input
type=
"button"
id=
"setday"
value=
"取消夜景"
/>
</div>
<div>
<input
type=
"button"
id=
"addTrafficFlow"
value=
"全部车辆"
/>
<input
type=
"button"
id=
"addTrafficFlow6"
value=
"6号车"
/>
<input
type=
"button"
id=
"removeTrafficFlow"
value=
"清除联网车辆"
/>
<input
type=
"button"
id=
"focusCar1"
value=
"定位车辆(第一人称)"
/>
<input
type=
"button"
id=
"focusCar3"
value=
"定位车辆(第三人称)"
/>
<input
type=
"button"
id=
"focusNoneCar"
value=
"清除定位"
/>
<input
type=
"button"
id=
"addTrafficFlow"
value=
"全部车辆"
/>
<input
type=
"button"
id=
"addTrafficFlow6"
value=
"6号车"
/>
<input
type=
"button"
id=
"removeTrafficFlow"
value=
"清除联网车辆"
/>
<input
type=
"button"
id=
"focusCar1"
value=
"定位车辆(第一人称)"
/>
<input
type=
"button"
id=
"focusCar3"
value=
"定位车辆(第三人称)"
/>
<input
type=
"button"
id=
"focusNoneCar"
value=
"清除定位"
/>
</div>
<div>
<input
type=
"button"
id=
"loadarrowLineLaye"
value=
"加载车辆路径规划"
/>
<input
type=
"button"
id=
"hideRoute"
value=
"显示车辆路径规划"
/>
<input
type=
"button"
id=
"showRoute"
value=
"隐藏车辆路径规划"
/>
<input
type=
"button"
id=
"cleanarrowLineLaye"
value=
"清除车辆路径规划"
/>
<input
type=
"button"
id=
"loadarrowLineLaye"
value=
"加载车辆路径规划"
/>
<input
type=
"button"
id=
"hideRoute"
value=
"显示车辆路径规划"
/>
<input
type=
"button"
id=
"showRoute"
value=
"隐藏车辆路径规划"
/>
<input
type=
"button"
id=
"cleanarrowLineLaye"
value=
"清除车辆路径规划"
/>
</div>
<div>
<input
type=
"button"
id=
"loadPerceptual"
value=
"感知目标物渲染"
/>
<input
type=
"button"
id=
"showPerceptual"
value=
"显示感知目标物"
/>
<input
type=
"button"
id=
"hidePerceptual"
value=
"隐藏感知目标物"
/>
<input
type=
"button"
id=
"removePerceptual"
value=
"清除感知目标物"
/>
<input
type=
"button"
id=
"addPerceptualheat"
value=
"添加交通热力图"
/>
<input
type=
"button"
id=
"deletePerceptualheat"
value=
"删除交通热力图"
/>
<input
type=
"button"
id=
"loadPerceptual"
value=
"感知目标物渲染"
/>
<input
type=
"button"
id=
"showPerceptual"
value=
"显示感知目标物"
/>
<input
type=
"button"
id=
"hidePerceptual"
value=
"隐藏感知目标物"
/>
<input
type=
"button"
id=
"removePerceptual"
value=
"清除感知目标物"
/>
<input
type=
"button"
id=
"addPerceptualheat"
value=
"添加交通热力图"
/>
<input
type=
"button"
id=
"deletePerceptualheat"
value=
"删除交通热力图"
/>
</div>
<div>
<input
type=
"button"
id=
"addPerceptualheatEffect"
value=
"热力图宏观效果"
/>
<input
type=
"button"
id=
"removePerceptualheatEffect"
value=
"移除热力图宏观效果"
/>
<input
type=
"button"
id=
"addSignal"
value=
"信号灯"
/>
<input
type=
"button"
id=
"CreateTIMSignal"
value=
"创建停止线"
/>
<input
type=
"button"
id=
"DeleteTIMSignal"
value=
"删除停止线"
/>
<input
type=
"button"
id=
"addPerceptualheatEffect"
value=
"热力图宏观效果"
/>
<input
type=
"button"
id=
"removePerceptualheatEffect"
value=
"移除热力图宏观效果"
/>
<input
type=
"button"
id=
"addSignal"
value=
"信号灯"
/>
<input
type=
"button"
id=
"CreateTIMSignal"
value=
"创建停止线"
/>
<input
type=
"button"
id=
"DeleteTIMSignal"
value=
"删除停止线"
/>
</div>
<div>
<input
type=
"button"
id=
"addTrafficIncident"
value=
"交通流中的事件"
/>
<input
type=
"button"
id=
"addTrafficIncident2"
value=
"不在交通流中的事件"
/>
<input
type=
"button"
id=
"addTrafficIncident3"
value=
"区域坐标的交通事件"
/>
<input
type=
"button"
id=
"addTrafficIncident"
value=
"交通流中的事件"
/>
<input
type=
"button"
id=
"addTrafficIncident2"
value=
"不在交通流中的事件"
/>
<input
type=
"button"
id=
"addTrafficIncident3"
value=
"区域坐标的交通事件"
/>
</div>
<div>
<input
type=
"button"
id=
"bindHistoryVehicle"
value=
"开始历史轨迹"
/>
<input
type=
"button"
id=
"removeHistoryVehicle"
value=
"结束历史轨迹"
/>
<input
type=
"button"
id=
"pauseHistoryVehicle"
value=
"暂停历史轨迹"
/>
<input
type=
"button"
id=
"resumeHistoryVehicle"
value=
"重新开始历史轨迹"
/>
<input
type=
"button"
id=
"bindHistoryVehicle"
value=
"开始历史轨迹"
/>
<input
type=
"button"
id=
"removeHistoryVehicle"
value=
"结束历史轨迹"
/>
<input
type=
"button"
id=
"pauseHistoryVehicle"
value=
"暂停历史轨迹"
/>
<input
type=
"button"
id=
"resumeHistoryVehicle"
value=
"重新开始历史轨迹"
/>
</div>
<div>
<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=
"startV2X"
value=
"全部车辆V2X"
/>
<input
type=
"button"
id=
"startV2X6"
value=
"6号车V2X"
/>
<input
type=
"button"
id=
"removeV2X"
value=
"清除V2X"
/>
</div>
<div>
<input
type=
"button"
id=
"addPolygon"
value=
"绘制感知区域"
/>
<input
type=
"button"
id=
"showPolygon"
value=
"显示感知区域"
/>
<input
type=
"button"
id=
"hidePolygon"
value=
"隐藏感知区域"
/>
<input
type=
"button"
id=
"removePolygon"
value=
"删除感知区域"
/>
<input
type=
"button"
id=
"addPolygon"
value=
"绘制感知区域"
/>
<input
type=
"button"
id=
"showPolygon"
value=
"显示感知区域"
/>
<input
type=
"button"
id=
"hidePolygon"
value=
"隐藏感知区域"
/>
<input
type=
"button"
id=
"removePolygon"
value=
"删除感知区域"
/>
</div>
<div>
<input
type=
"button"
id=
"modelClickHighLight"
value=
"注册场景内模型点击高亮"
/>
<input
type=
"button"
id=
"cancelModelHighlight"
value=
"清除场景内模型高亮"
/>
<input
type=
"button"
id=
"modelClickRemove"
value=
"注销场景内模型点击事件"
/>
<input
type=
"button"
id=
"modelClickHighLight"
value=
"注册场景内模型点击高亮"
/>
<input
type=
"button"
id=
"cancelModelHighlight"
value=
"清除场景内模型高亮"
/>
<input
type=
"button"
id=
"modelClickRemove"
value=
"注销场景内模型点击事件"
/>
</div>
<div>
<input
type=
"button"
id=
"addMillimeterWave"
value=
"毫米波雷达"
/>
<input
type=
"button"
id=
"removeMillimeterWave"
value=
"移除毫米波雷达"
/>
<input
type=
"button"
id=
"addMillimeterWave"
value=
"毫米波雷达"
/>
<input
type=
"button"
id=
"removeMillimeterWave"
value=
"移除毫米波雷达"
/>
</div>
</div>
<div
id=
"main-container"
style=
"width: 100vw; height: 100vh; overflow: hidden"
></div>
</body>
<script
src=
"http://localhost:3000/gis_sdk/js/CMapLoader.map.js"
></script>
<script
src=
"./SignalLines.js"
></script>
</head>
<script>
</div>
<div
id=
"main-container"
style=
"width: 100vw; height: 100vh; overflow: hidden"
></div>
</body>
<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>
</head>
<script>
var
map
;
var
layer
;
var
road
;
...
...
@@ -198,879 +288,895 @@
var
compassItem
=
null
;
// 指北针
var
perceptualroad
=
null
;
var
perceptual
=
false
;
//是否加载了感知物
var
perceptualshow
=
false
;
//热力图否显示
var
trafficIncidentArr
=
[];
//热力图否显示
var
perceptualshow
=
false
;
//热力图否显示
var
trafficIncidentArr
=
[];
//热力图否显示
var
polygon
=
null
;
// 感知区域
var
v2xSocket
=
null
;
var
v2xArr
=
[];
// 记录所有v2x
var
trafficEventSocket
=
null
;
var
trafficEventArr
=
[];
// 记录所有的交通事件
//高亮模型Id
var
highlightModelId
=
null
;
var
handler
=
(
e
)
=>
{
alert
(
JSON
.
stringify
(
e
));
alert
(
JSON
.
stringify
(
e
));
};
initMap
(
"
51world
"
);
async
function
initMap
(
gis_sdk
)
{
var
url
=
"
http://localhost:3000/hdmap-platform/gateway/cmap2
"
;
var
secretKey
=
"
10b79c61bf1b42e2
"
;
var
url
=
"
http://localhost:3000/hdmap-platform/gateway/cmap2
"
;
var
secretKey
=
"
10b79c61bf1b42e2
"
;
var
config
=
{
gis_sdk
:
gis_sdk
,
};
var
config
=
{
gis_sdk
:
gis_sdk
,
};
config
.
gis_sdk
=
gis_sdk
;
config
.
gis_sdk
=
gis_sdk
;
map
=
await
CMapLoader
.
loadMap
(
"
main-container
"
,
config
,
url
,
secretKey
);
await
map
.
initMap
();
//地图加载
map
=
await
CMapLoader
.
loadMap
(
"
main-container
"
,
config
,
url
,
secretKey
);
await
map
.
initMap
();
//地图加载
drawControl
=
map
.
getControl
(
1
);
//类型 1 :绘制 2:量算
measureControl
=
map
.
getControl
(
2
);
//类型 1 :绘制 2:量算
drawControl
=
map
.
getControl
(
1
);
//类型 1 :绘制 2:量算
measureControl
=
map
.
getControl
(
2
);
//类型 1 :绘制 2:量算
camera
=
map
.
getCamera
();
road
=
map
.
initRoads
({
id
:
"
1600840132389756930
"
,
});
camera
=
map
.
getCamera
();
road
=
map
.
initRoads
({
id
:
"
1600840132389756930
"
,
});
}
// 获取地图中心点和级别
document
.
getElementById
(
"
getZoomAndCenter
"
).
onclick
=
getZoomAndCenter
;
async
function
getZoomAndCenter
()
{
var
points
=
await
map
.
getZoomAndCenter
();
alert
(
JSON
.
stringify
(
points
));
var
points
=
await
map
.
getZoomAndCenter
();
alert
(
JSON
.
stringify
(
points
));
}
// 设置地图中心点和级别
document
.
getElementById
(
"
setZoomAndCenter
"
).
onclick
=
setZoomAndCenter
;
function
setZoomAndCenter
()
{
var
options
=
{
"
longitude
"
:
117.346635
,
"
latitude
"
:
38.99408
,
"
height
"
:
51.43313
}
map
.
setZoomAndCenter
(
options
);
var
options
=
{
longitude
:
117.346635
,
latitude
:
38.99408
,
height
:
51.43313
,
};
map
.
setZoomAndCenter
(
options
);
}
// 限制地图显示范围和级别
document
.
getElementById
(
"
lockMap
"
).
onclick
=
lockMap
;
function
lockMap
()
{
var
options
=
{
xmin
:
117.31
,
ymin
:
38.842072
,
zmin
:
500
,
xmax
:
117.37358
,
ymax
:
39.109915
,
zmax
:
15000
,
};
var
options
=
{
xmin
:
117.31
,
ymin
:
38.842072
,
zmin
:
500
,
xmax
:
117.37358
,
ymax
:
39.109915
,
zmax
:
15000
,
};
var
points
=
map
.
lockMap
(
options
);
var
points
=
map
.
lockMap
(
options
);
}
// 解锁地图显示范围和级别
document
.
getElementById
(
"
unlockMap
"
).
onclick
=
unlockMap
;
function
unlockMap
()
{
map
.
unlockMap
();
map
.
unlockMap
();
}
// 获取相机参数
document
.
getElementById
(
"
getCameraView
"
).
onclick
=
getCameraView
;
async
function
getCameraView
()
{
var
points
=
await
camera
.
getCameraView
();
alert
(
JSON
.
stringify
(
points
));
var
points
=
await
camera
.
getCameraView
();
alert
(
JSON
.
stringify
(
points
));
}
// 监听相机参数变化
document
.
getElementById
(
"
addCameraEvent
"
).
onclick
=
addCameraEvent
;
function
addCameraEvent
()
{
camera
.
addCameraEvent
(
"
changed
"
,
(
e
)
=>
{
alert
(
JSON
.
stringify
(
e
));
});
camera
.
addCameraEvent
(
"
changed
"
,
(
e
)
=>
{
alert
(
JSON
.
stringify
(
e
));
});
}
// 移除相机参数监听事件
document
.
getElementById
(
"
removeCameraEvent
"
).
onclick
=
removeCameraEvent
;
function
removeCameraEvent
()
{
camera
.
removeCameraEvent
(
"
changed
"
);
camera
.
removeCameraEvent
(
"
changed
"
);
}
// 设置相机
document
.
getElementById
(
"
flyTo
"
).
onclick
=
flyTo
;
function
flyTo
()
{
var
options
=
{
position
:
[
117.34584096
,
38.99557144
,
276.84
],
orientation
:
[
0
,
-
90
],
};
camera
.
flyTo
(
options
);
var
options
=
{
position
:
[
117.34584096
,
38.99557144
,
276.84
],
orientation
:
[
0
,
-
90
],
};
camera
.
flyTo
(
options
);
}
// 开始相机导览
document
.
getElementById
(
"
startFly
"
).
onclick
=
startFly
;
function
startFly
()
{
const
options
=
{
id
:
"
startFly1
"
,
pathList
:
[
{
cameraState
:
{
longitude
:
117.31875105674682
,
latitude
:
38.98881187638633
,
height
:
16.151980453069932
,
pitch
:
-
3
,
heading
:
-
89.45378112792969
,
},
time
:
10
,
},
{
cameraState
:
{
longitude
:
117.31839940049078
,
latitude
:
38.99208154792654
,
height
:
100.212235805514
,
pitch
:
-
29.176807403564453
,
heading
:
37.64432144165039
,
},
time
:
10
,
},
{
cameraState
:
{
longitude
:
117.32332105679387
,
latitude
:
38.99363368117575
,
height
:
110.1469806258995
,
pitch
:
-
33.12812805175781
,
heading
:
130.16888427734375
,
},
time
:
10
,
},
],
};
camera
.
startFly
(
options
);
const
options
=
{
id
:
"
startFly1
"
,
pathList
:
[
{
cameraState
:
{
longitude
:
117.31875105674682
,
latitude
:
38.98881187638633
,
height
:
16.151980453069932
,
pitch
:
-
3
,
heading
:
-
89.45378112792969
,
},
time
:
10
,
},
{
cameraState
:
{
longitude
:
117.31839940049078
,
latitude
:
38.99208154792654
,
height
:
100.212235805514
,
pitch
:
-
29.176807403564453
,
heading
:
37.64432144165039
,
},
time
:
10
,
},
{
cameraState
:
{
longitude
:
117.32332105679387
,
latitude
:
38.99363368117575
,
height
:
110.1469806258995
,
pitch
:
-
33.12812805175781
,
heading
:
130.16888427734375
,
},
time
:
10
,
},
],
};
camera
.
startFly
(
options
);
}
// 暂停相机导览
document
.
getElementById
(
"
pauseFly
"
).
onclick
=
pauseFly
;
function
pauseFly
()
{
camera
.
pauseFly
();
camera
.
pauseFly
();
}
// 继续相机导览
document
.
getElementById
(
"
resuFly
"
).
onclick
=
resuFly
;
function
resuFly
()
{
camera
.
resuFly
();
camera
.
resuFly
();
}
// 结束相机导览
document
.
getElementById
(
"
stopFly
"
).
onclick
=
stopFly
;
function
stopFly
()
{
camera
.
stopFly
();
camera
.
stopFly
();
}
// 地图变化事件
document
.
getElementById
(
"
addMapChangeEvent
"
).
onclick
=
addMapChangeEvent
;
function
addMapChangeEvent
()
{
map
.
on
(
map
.
EventType
.
MAP_CHANGE
,
handler
);
map
.
on
(
map
.
EventType
.
MAP_CHANGE
,
handler
);
}
// 注销地图变化事件
document
.
getElementById
(
"
removeMapChangeEvent
"
).
onclick
=
removeMapChangeEvent
;
removeMapChangeEvent
;
function
removeMapChangeEvent
()
{
map
.
off
(
map
.
EventType
.
MAP_CHANGE
,
handler
);
map
.
off
(
map
.
EventType
.
MAP_CHANGE
,
handler
);
}
// 注册鼠标点击事件
document
.
getElementById
(
"
addMouseClickEvent
"
).
onclick
=
addMouseClickEvent
;
function
addMouseClickEvent
()
{
map
.
on
(
map
.
EventType
.
LEFT_CLICK
,
handler
);
map
.
on
(
map
.
EventType
.
LEFT_CLICK
,
handler
);
}
// 注销鼠标点击事件
document
.
getElementById
(
"
removeMouseClickEvent
"
).
onclick
=
removeMouseClickEvent
;
removeMouseClickEvent
;
function
removeMouseClickEvent
()
{
map
.
off
(
map
.
EventType
.
LEFT_CLICK
,
handler
);
map
.
off
(
map
.
EventType
.
LEFT_CLICK
,
handler
);
}
// 注册模型点击事件
let
clickModel
=
null
;
let
pick_model_handler
=
(
e
)
=>
{
console
.
log
(
"
模型点击事件
"
,
e
);
if
(
e
)
{
pickModel
=
map
.
getModel
(
e
);
if
(
pickModel
)
{
// 高亮
pickModel
.
highLight
();
var
content
=
(
content
=
{
popupSize
:
[
200
,
200
],
imagePath
:
`@path:images/radar_online.png`
,
popupURL
:
`http://172.29.128.30:65535/yizhuangDevicePopup.html?name=汽车&brand=厂商&code=型号&mode=通信模式`
,
});
pickModel
.
showPopup
(
content
);
}
console
.
log
(
"
模型点击事件
"
,
e
);
if
(
e
)
{
pickModel
=
map
.
getModel
(
e
);
if
(
pickModel
)
{
// 高亮
pickModel
.
highLight
();
var
content
=
(
content
=
{
popupSize
:
[
200
,
200
],
imagePath
:
`@path:images/radar_online.png`
,
popupURL
:
`http://172.29.128.30:65535/yizhuangDevicePopup.html?name=汽车&brand=厂商&code=型号&mode=通信模式`
,
});
pickModel
.
showPopup
(
content
);
}
}
};
document
.
getElementById
(
"
addModelClickEvent
"
).
onclick
=
addModelClickEvent
;
async
function
addModelClickEvent
()
{
if
(
!
clickModel
)
{
let
option
=
{
id
:
"
model1
"
,
//对象ID
url
:
"
SM_VEH_Bus_02_01
"
,
position
:
[
117.318863
,
38.989795
,
4
],
//坐标
rotation
:
[
0
,
0
,
190
],
};
clickModel
=
await
map
.
addModel
(
option
);
clickModel
.
focusModel
();
}
map
.
on
(
map
.
EventType
.
PICK_MODEL
,
pick_model_handler
);
if
(
!
clickModel
)
{
let
option
=
{
id
:
"
model1
"
,
//对象ID
url
:
"
SM_VEH_Bus_02_01
"
,
position
:
[
117.318863
,
38.989795
,
4
],
//坐标
rotation
:
[
0
,
0
,
190
],
};
clickModel
=
await
map
.
addModel
(
option
);
clickModel
.
focusModel
();
}
map
.
on
(
map
.
EventType
.
PICK_MODEL
,
pick_model_handler
);
}
// 注销模型点击事件
document
.
getElementById
(
"
removeModelClickEvent
"
).
onclick
=
removeModelClickEvent
;
removeModelClickEvent
;
async
function
removeModelClickEvent
()
{
map
.
off
(
map
.
EventType
.
PICK_MODEL
,
pick_model_handler
);
map
.
off
(
map
.
EventType
.
PICK_MODEL
,
pick_model_handler
);
}
// 取消模型高亮
document
.
getElementById
(
"
cancleHighLight
"
).
onclick
=
cancleHighLight
;
function
cancleHighLight
()
{
pickModel
.
cancleHighLight
();
pickModel
.
cancleHighLight
();
}
// 取消模型弹窗
document
.
getElementById
(
"
removePopup
"
).
onclick
=
removePopup
;
function
removePopup
()
{
pickModel
.
removePopup
();
pickModel
.
removePopup
();
}
// 添加路口标签
document
.
getElementById
(
"
addMarker
"
).
onclick
=
addMarker
;
async
function
addMarker
()
{
var
options
=
{
id
:
"
marker
"
,
name
:
"
一号路口
"
,
textColor
:
[
255
,
215
,
0
,
1
],
fontSize
:
"
16
"
,
position
:
[
117.318863
,
38.98979
],
//设置Marker位置
imageSize
:
[
184
,
126
],
//[1.5,1.6]
textOffset
:
[
50
,
50
],
//[0, -140]
image
:
"
http://wdpapi.51aes.com/doc-static/images/static/markerNormal.png
"
,
//mapbox图片
iconOffset
:
[
0
,
-
80
],
//mapbox图标的偏移
};
// 添加路口标签
marker
=
await
map
.
addMarkerOverlay
(
options
);
// 定位到路口标签
map
.
zoomToOverlay
(
marker
);
var
options
=
{
id
:
"
marker
"
,
name
:
"
一号路口
"
,
textColor
:
[
255
,
215
,
0
,
1
],
fontSize
:
"
16
"
,
position
:
[
117.318863
,
38.98979
],
//设置Marker位置
imageSize
:
[
184
,
126
],
//[1.5,1.6]
textOffset
:
[
50
,
50
],
//[0, -140]
image
:
"
http://wdpapi.51aes.com/doc-static/images/static/markerNormal.png
"
,
//mapbox图片
iconOffset
:
[
0
,
-
80
],
//mapbox图标的偏移
};
// 添加路口标签
marker
=
await
map
.
addMarkerOverlay
(
options
);
// 定位到路口标签
map
.
zoomToOverlay
(
marker
);
}
// 显示标签
document
.
getElementById
(
"
showMarker
"
).
onclick
=
showMarker
;
async
function
showMarker
()
{
map
.
showOverlay
(
marker
);
map
.
showOverlay
(
marker
);
}
// 隐藏标签
document
.
getElementById
(
"
hideMarker
"
).
onclick
=
hideMarker
;
function
hideMarker
()
{
map
.
hideOverlay
(
marker
);
map
.
hideOverlay
(
marker
);
}
// 删除标签
document
.
getElementById
(
"
removeMarker
"
).
onclick
=
removeMarker
;
async
function
removeMarker
()
{
map
.
removeOverlay
(
marker
);
map
.
removeOverlay
(
marker
);
}
// 开始Rsu特效
document
.
getElementById
(
"
startRsu
"
).
onclick
=
startRsu
;
function
startRsu
()
{
var
data
=
[
{
equipmentCode
:
"
S-LC-2503
"
,
//编号
longitude
:
117.318166
,
latitude
:
38.98827
,
height
:
5
,
radius
:
20
,
//辐射圈的大小,这个字段目前是晶众使用有效
},
{
equipmentCode
:
"
S-LC-2504
"
,
//编号
longitude
:
117.319236
,
latitude
:
38.98829
,
height
:
5
,
radius
:
20
,
//辐射圈的大小,这个字段目前是晶众使用有效
},
];
rsuArr
=
road
.
startRsu
(
data
);
var
data
=
[
{
equipmentCode
:
"
S-LC-2503
"
,
//编号
longitude
:
117.318166
,
latitude
:
38.98827
,
height
:
5
,
radius
:
20
,
//辐射圈的大小,这个字段目前是晶众使用有效
},
{
equipmentCode
:
"
S-LC-2504
"
,
//编号
longitude
:
117.319236
,
latitude
:
38.98829
,
height
:
5
,
radius
:
20
,
//辐射圈的大小,这个字段目前是晶众使用有效
},
];
rsuArr
=
road
.
startRsu
(
data
);
}
// 停止Rsu特效
document
.
getElementById
(
"
stopRsu
"
).
onclick
=
stopRsu
;
function
stopRsu
()
{
road
.
stopRsu
();
road
.
stopRsu
();
}
// 隐藏Rsu特效
document
.
getElementById
(
"
hideRsu
"
).
onclick
=
hideRsu
;
function
hideRsu
()
{
road
.
hideRsu
();
road
.
hideRsu
();
}
// 显示Rsu特效
document
.
getElementById
(
"
showRsu
"
).
onclick
=
showRsu
;
function
showRsu
()
{
road
.
showRsu
();
road
.
showRsu
();
}
// 开始下雨
document
.
getElementById
(
"
rain
"
).
onclick
=
rain
;
async
function
rain
()
{
map
.
addRainEffect
({
speed
:
0.5
,
// 速度,取值范围:[0~1],默认为0.5
size
:
0.5
,
// 大小,取值范围:[0~1],默认为0.5
density
:
0.5
,
// 密度,取值范围:[0~1],默认为0.5
});
map
.
addRainEffect
({
speed
:
0.5
,
// 速度,取值范围:[0~1],默认为0.5
size
:
0.5
,
// 大小,取值范围:[0~1],默认为0.5
density
:
0.5
,
// 密度,取值范围:[0~1],默认为0.5
});
}
// 停止下雨
document
.
getElementById
(
"
stopRain
"
).
onclick
=
stopRain
;
async
function
stopRain
()
{
map
.
stopRainEffect
();
map
.
stopRainEffect
();
}
// 开始下雪
document
.
getElementById
(
"
snow
"
).
onclick
=
snow
;
async
function
snow
()
{
map
.
addSnowEffect
({
speed
:
0.5
,
// 速度,取值范围:[0~1],默认为0.5
size
:
0.5
,
// 大小,取值范围:[0~1],默认为0.5
density
:
0.5
,
// 密度,取值范围:[0~1],默认为0.5
});
map
.
addSnowEffect
({
speed
:
0.5
,
// 速度,取值范围:[0~1],默认为0.5
size
:
0.5
,
// 大小,取值范围:[0~1],默认为0.5
density
:
0.5
,
// 密度,取值范围:[0~1],默认为0.5
});
}
// 停止下雪
document
.
getElementById
(
"
stopSnow
"
).
onclick
=
stopSnow
;
async
function
stopSnow
()
{
map
.
stopSnowEffect
();
map
.
stopSnowEffect
();
}
// 雾
document
.
getElementById
(
"
fog
"
).
onclick
=
fog
;
async
function
fog
()
{
map
.
addFogEffect
();
map
.
addFogEffect
();
}
// 清除雾
document
.
getElementById
(
"
stopFog
"
).
onclick
=
stopFog
;
async
function
stopFog
()
{
map
.
stopFogEffect
();
map
.
stopFogEffect
();
}
// 绘制点
document
.
getElementById
(
"
point
"
).
onclick
=
point
;
function
point
()
{
drawControl
.
startDraw
(
{
type
:
"
point
"
,
},
function
(
e
)
{
console
.
log
(
e
);
}
);
drawControl
.
startDraw
(
{
type
:
"
point
"
,
},
function
(
e
)
{
console
.
log
(
e
);
}
);
}
// 绘制线
document
.
getElementById
(
"
polyline
"
).
onclick
=
polyline
;
async
function
polyline
()
{
drawControl
.
startDraw
(
{
type
:
"
polyline
"
,
lineColor
:
[
255
,
246
,
45
,
0.5
],
width
:
1
,
},
function
(
e
)
{
console
.
log
(
e
);
}
);
drawControl
.
startDraw
(
{
type
:
"
polyline
"
,
lineColor
:
[
255
,
246
,
45
,
0.5
],
width
:
1
,
},
function
(
e
)
{
console
.
log
(
e
);
}
);
}
// 绘制面
document
.
getElementById
(
"
polygon
"
).
onclick
=
polygon
;
async
function
polygon
()
{
drawControl
.
startDraw
(
{
type
:
"
polygon
"
,
fill
:
[
255
,
246
,
45
,
0.5
],
lineColor
:
[
0
,
255
,
0
,
0.5
],
},
function
(
e
)
{
console
.
log
(
e
);
}
);
drawControl
.
startDraw
(
{
type
:
"
polygon
"
,
fill
:
[
255
,
246
,
45
,
0.5
],
lineColor
:
[
0
,
255
,
0
,
0.5
],
},
function
(
e
)
{
console
.
log
(
e
);
}
);
}
// 清除绘制
document
.
getElementById
(
"
remove
"
).
onclick
=
remove
;
async
function
remove
()
{
drawControl
.
stopDraw
();
drawControl
.
stopDraw
();
}
// 坐标点
document
.
getElementById
(
"
start1
"
).
onclick
=
start1
;
async
function
start1
()
{
measureControl
.
startMeasurement
(
1
);
//1:坐标点 2:直线测量 6 :地表面积
measureControl
.
startMeasurement
(
1
);
//1:坐标点 2:直线测量 6 :地表面积
}
// 直线测量
document
.
getElementById
(
"
start2
"
).
onclick
=
start2
;
async
function
start2
()
{
measureControl
.
startMeasurement
(
2
,
{
pointSize
:
4
,
// 点大小
pointColor
:
[
33
,
176
,
219
],
// 点颜色
textSize
:
16
,
// 文字大小
textColor
:
[
239
,
76
,
41
],
// 文字颜色
lineWidth
:
2
,
// 线宽度
lineColor
:
[
33
,
176
,
219
],
// 线颜色
});
//1:坐标点 2:直线测量 6 :地表面积
measureControl
.
startMeasurement
(
2
,
{
pointSize
:
4
,
// 点大小
pointColor
:
[
33
,
176
,
219
],
// 点颜色
textSize
:
16
,
// 文字大小
textColor
:
[
239
,
76
,
41
],
// 文字颜色
lineWidth
:
2
,
// 线宽度
lineColor
:
[
33
,
176
,
219
],
// 线颜色
});
//1:坐标点 2:直线测量 6 :地表面积
}
// 地表面积
document
.
getElementById
(
"
start6
"
).
onclick
=
start6
;
async
function
start6
()
{
measureControl
.
startMeasurement
(
6
,
{
pointSize
:
4
,
// 点大小
pointColor
:
[
33
,
176
,
219
],
// 点颜色
textSize
:
16
,
// 文字大小
textColor
:
[
239
,
76
,
41
],
// 文字颜色
lineColor
:
[
33
,
176
,
219
],
// 边框颜色
lineWidth
:
2
,
// 边框宽度
fillColor
:
[
33
,
176
,
219
],
// 线颜色
});
//1:坐标点 2:直线测量 6 :地表面积
measureControl
.
startMeasurement
(
6
,
{
pointSize
:
4
,
// 点大小
pointColor
:
[
33
,
176
,
219
],
// 点颜色
textSize
:
16
,
// 文字大小
textColor
:
[
239
,
76
,
41
],
// 文字颜色
lineColor
:
[
33
,
176
,
219
],
// 边框颜色
lineWidth
:
2
,
// 边框宽度
fillColor
:
[
33
,
176
,
219
],
// 线颜色
});
//1:坐标点 2:直线测量 6 :地表面积
}
// 停止量算
document
.
getElementById
(
"
stopMeasurement
"
).
onclick
=
stopMeasurement
;
async
function
stopMeasurement
()
{
measureControl
.
stopMeasurement
();
measureControl
.
stopMeasurement
();
}
// 创建指北针
document
.
getElementById
(
"
toNorth
"
).
onclick
=
toNorth
;
async
function
toNorth
()
{
if
(
compassItem
)
return
;
// 绑定指北针
compassItem
=
new
map
.
widgets
.
Compass
({
position
:
{
left
:
"
20px
"
,
top
:
"
60px
"
,
},
declaredClass
:
[
"
compass-class
"
],
iconClass
:
"
https://th.bing.com/th/id/R.9ac814eb0d80f60139dc27d8ef3193ad?rik=MLzrMDu9QdKAOQ&riu=http%3a%2f%2fpic.ntimg.cn%2ffile%2f20150530%2f2531170_201029314000_2.jpg&ehk=JODHCujwu7ut71vU4vVswA%2f3ljNn9MAdpziiOQMxFnE%3d&risl=&pid=ImgRaw&r=0
"
,
//替换指北针图片
});
if
(
compassItem
)
return
;
// 绑定指北针
compassItem
=
new
map
.
widgets
.
Compass
({
position
:
{
left
:
"
20px
"
,
top
:
"
60px
"
,
},
declaredClass
:
[
"
compass-class
"
],
iconClass
:
"
https://th.bing.com/th/id/R.9ac814eb0d80f60139dc27d8ef3193ad?rik=MLzrMDu9QdKAOQ&riu=http%3a%2f%2fpic.ntimg.cn%2ffile%2f20150530%2f2531170_201029314000_2.jpg&ehk=JODHCujwu7ut71vU4vVswA%2f3ljNn9MAdpziiOQMxFnE%3d&risl=&pid=ImgRaw&r=0
"
,
//替换指北针图片
});
}
// 销毁指南针
document
.
getElementById
(
"
hideNorth
"
).
onclick
=
hideNorth
;
async
function
hideNorth
()
{
if
(
!
compassItem
)
return
;
// 销毁
compassItem
.
destroy
();
compassItem
=
null
;
if
(
!
compassItem
)
return
;
// 销毁
compassItem
.
destroy
();
compassItem
=
null
;
}
// 设置夜景
document
.
getElementById
(
"
setDark
"
).
onclick
=
setDark
;
async
function
setDark
()
{
let
option
=
{
dark
:
true
,
time
:
1668009599000
,
};
map
.
setDark
(
option
);
let
option
=
{
dark
:
true
,
time
:
1668009599000
,
};
map
.
setDark
(
option
);
}
// 取消夜景
document
.
getElementById
(
"
setday
"
).
onclick
=
setday
;
async
function
setday
()
{
let
option
=
{
dark
:
false
,
time
:
1667966400000
,
};
map
.
setDark
(
option
);
let
option
=
{
dark
:
false
,
time
:
1667966400000
,
};
map
.
setDark
(
option
);
}
// 创建交通流
document
.
getElementById
(
"
addTrafficFlow
"
).
onclick
=
addTrafficFlow
;
async
function
addTrafficFlow
()
{
const
json
=
{
id
:
'
21e7a9e6d2884122804788dac1e002cc
'
,
url
:
'
ws://192.168.60.137:31000/ws/streamer/a9219e09346a44a28ee3d0aed79c27ea
'
// 全部车辆
}
map
.
bindVehicle
(
json
)
const
json
=
{
id
:
"
21e7a9e6d2884122804788dac1e002cc
"
,
url
:
"
ws://192.168.60.137:31000/ws/streamer/a9219e09346a44a28ee3d0aed79c27ea
"
,
// 全部车辆
}
;
map
.
bindVehicle
(
json
)
;
}
document
.
getElementById
(
"
addTrafficFlow6
"
).
onclick
=
addTrafficFlow6
;
async
function
addTrafficFlow6
()
{
const
json
=
{
id
:
'
21e7a9e6d2884122804788dac1e002cc
'
,
url
:
'
ws://192.168.60.137:31000/ws/streamer/e7c584dd5d294347bbc3ccec2f0aa8ea
'
// 6号车
}
map
.
bindVehicle
(
json
)
const
json
=
{
id
:
"
21e7a9e6d2884122804788dac1e002cc
"
,
url
:
"
ws://192.168.60.137:31000/ws/streamer/e7c584dd5d294347bbc3ccec2f0aa8ea
"
,
// 6号车
}
;
map
.
bindVehicle
(
json
)
;
}
// 删除交通流
document
.
getElementById
(
"
removeTrafficFlow
"
).
onclick
=
removeTrafficFlow
;
async
function
removeTrafficFlow
()
{
map
.
removeVehicles
();
map
.
removeVehicles
();
}
// 定位车辆(第一人称)
document
.
getElementById
(
"
focusCar1
"
).
onclick
=
focusCar1
;
async
function
focusCar1
()
{
let
options
=
{
vehicleId
:
"
仿AYZQS001
"
,
perspective
:
1
,
// 1第一人称视角、3第三人称视角
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
focusVehicle
(
options
);
let
options
=
{
vehicleId
:
"
仿AYZQS001
"
,
perspective
:
1
,
// 1第一人称视角、3第三人称视角
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
focusVehicle
(
options
);
}
// 定位车辆(第三人称)
document
.
getElementById
(
"
focusCar3
"
).
onclick
=
focusCar3
;
async
function
focusCar3
()
{
let
options
=
{
vehicleId
:
"
仿AYZQS001
"
,
perspective
:
3
,
// 1第一人称视角、3第三人称视角
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
focusVehicle
(
options
);
let
options
=
{
vehicleId
:
"
仿AYZQS001
"
,
perspective
:
3
,
// 1第一人称视角、3第三人称视角
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
focusVehicle
(
options
);
}
// 清除定位
document
.
getElementById
(
"
focusNoneCar
"
).
onclick
=
focusNoneCar
;
async
function
focusNoneCar
()
{
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
unfocusVehicle
();
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
unfocusVehicle
();
}
// 加载车辆路径规划
document
.
getElementById
(
"
loadarrowLineLaye
"
).
onclick
=
loadarrowLineLaye
;
function
loadarrowLineLaye
()
{
let
timestamp
=
1739419194500
;
var
pp
=
[];
for
(
var
key
in
roadPoints
)
{
timestamp
=
timestamp
+
2000
;
let
tt
=
{
vid
:
"
1
"
,
vmodel
:
"
1020001
"
,
vtype
:
"
0
"
,
coord
:
roadPoints
[
key
][
0
]
+
"
,
"
+
roadPoints
[
key
][
1
]
+
"
,
"
+
"
0.00
"
,
speed
:
46.92
,
timestamp
:
timestamp
,
};
pp
.
push
(
tt
);
}
console
.
log
(
pp
);
//行驶路线
// var option = {
// "id": '1604729991369719809',
// "vehicleId": '津A78F30',
// "coordinates": roadPoints,
// "height": 21,
// "width": 28,
// "color": "red" //red green yellow
// }
// map.getVehicle("21e7a9e6d2884122804788dac1e002cc").addRoute(option) //初始化行驶路线
let
timestamp
=
1739419194500
;
var
pp
=
[];
for
(
var
key
in
roadPoints
)
{
timestamp
=
timestamp
+
2000
;
let
tt
=
{
vid
:
"
1
"
,
vmodel
:
"
1020001
"
,
vtype
:
"
0
"
,
coord
:
roadPoints
[
key
][
0
]
+
"
,
"
+
roadPoints
[
key
][
1
]
+
"
,
"
+
"
0.00
"
,
speed
:
46.92
,
timestamp
:
timestamp
,
};
pp
.
push
(
tt
);
}
console
.
log
(
pp
);
//行驶路线
// var option = {
// "id": '1604729991369719809',
// "vehicleId": '津A78F30',
// "coordinates": roadPoints,
// "height": 21,
// "width": 28,
// "color": "red" //red green yellow
// }
// map.getVehicle("21e7a9e6d2884122804788dac1e002cc").addRoute(option) //初始化行驶路线
}
// 清除车辆路径规划
document
.
getElementById
(
"
cleanarrowLineLaye
"
).
onclick
=
cleanarrowLineLaye
;
function
cleanarrowLineLaye
()
{
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
removeRoute
();
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
removeRoute
();
}
// 显示车辆路径规划
document
.
getElementById
(
"
showRoute
"
).
onclick
=
showRoute
;
function
showRoute
()
{
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
showRoute
();
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
showRoute
();
}
// 隐藏车辆路径规划
document
.
getElementById
(
"
hideRoute
"
).
onclick
=
hideRoute
;
function
hideRoute
()
{
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
hideRoute
();
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
hideRoute
();
}
// 创建感知目标物
document
.
getElementById
(
"
loadPerceptual
"
).
onclick
=
loadPerceptual
;
async
function
loadPerceptual
()
{
if
(
perceptualroad
==
null
)
{
perceptualroad
=
map
.
initRoads
({
id
:
"
123456789
"
,
});
}
const
json
=
{
id
:
"
111
"
,
//ID
url
:
'
ws://192.168.60.137:31000/ws/streamer/86bf3faefe5f423483e4cd4d9782b046
'
,
// 全路口
// url: 'ws://192.168.60.137:31000/ws/streamer/eccd0f8b060d4bb088a1b9af1ad4070f', // 6号路口
};
perceptualroad
.
bindObjects
(
json
);
perceptual
=
true
;
//是否加载了感知物
// let options = {
// position: [117.34671, 38.9990358, 100.53],
// orientation: [-34.930073, -44.426579],
// };
// camera.flyTo(options);
if
(
perceptualroad
==
null
)
{
perceptualroad
=
map
.
initRoads
({
id
:
"
123456789
"
,
});
}
const
json
=
{
id
:
"
111
"
,
//ID
url
:
"
ws://192.168.60.137:31000/ws/streamer/86bf3faefe5f423483e4cd4d9782b046
"
,
// 全路口
// url: 'ws://192.168.60.137:31000/ws/streamer/eccd0f8b060d4bb088a1b9af1ad4070f', // 6号路口
};
perceptualroad
.
bindObjects
(
json
);
perceptual
=
true
;
//是否加载了感知物
// let options = {
// position: [117.34671, 38.9990358, 100.53],
// orientation: [-34.930073, -44.426579],
// };
// camera.flyTo(options);
}
// 显示感知目标物
document
.
getElementById
(
"
showPerceptual
"
).
onclick
=
showPerceptual
;
async
function
showPerceptual
()
{
perceptualroad
.
getObject
(
"
111
"
).
show
();
perceptualroad
.
getObject
(
"
111
"
).
show
();
}
// 隐藏感知目标物
document
.
getElementById
(
"
hidePerceptual
"
).
onclick
=
hidePerceptual
;
async
function
hidePerceptual
()
{
perceptualroad
.
getObject
(
"
111
"
).
hide
();
perceptualroad
.
getObject
(
"
111
"
).
hide
();
}
// 删除感知目标物
document
.
getElementById
(
"
removePerceptual
"
).
onclick
=
removePerceptual
;
async
function
removePerceptual
()
{
perceptualroad
.
getObject
(
"
111
"
).
remove
();
perceptual
=
false
;
//是否加载了感知物
perceptualroad
.
getObject
(
"
111
"
).
remove
();
perceptual
=
false
;
//是否加载了感知物
}
// 添加交通热力图
document
.
getElementById
(
"
addPerceptualheat
"
).
onclick
=
addPerceptualheat
;
async
function
addPerceptualheat
()
{
const
json
=
{
id
:
"
222
"
,
//ID
height
:
"
10
"
,
//高度
opacity
:
"
0.75
"
,
//透明度
dataUrl
:
"
D://51world//rlt//hdmap1.4(GCJ02_Ortho)_v2.xodr
"
,
//文件地址
url
:
"
ws://192.168.60.137:33021/AnalyzeResult
"
,
//ws地址
colorSymbols
:
[
{
minSpeed
:
0
,
maxSpeed
:
30
,
color
:
"
#FF0000
"
},
{
minSpeed
:
30
,
maxSpeed
:
60
,
color
:
"
#FFFF00
"
},
{
minSpeed
:
60
,
maxSpeed
:
90
,
color
:
"
#0000FF
"
},
{
minSpeed
:
90
,
maxSpeed
:
200
,
color
:
"
#00FF00
"
},
],
//颜色
};
perceptualroad
.
bindPerceptualheat
(
json
);
perceptualshow
=
true
;
const
json
=
{
id
:
"
222
"
,
//ID
height
:
"
10
"
,
//高度
opacity
:
"
0.75
"
,
//透明度
dataUrl
:
"
D://51world//rlt//hdmap1.4(GCJ02_Ortho)_v2.xodr
"
,
//文件地址
url
:
"
ws://192.168.60.137:33021/AnalyzeResult
"
,
//ws地址
colorSymbols
:
[
{
minSpeed
:
0
,
maxSpeed
:
30
,
color
:
"
#FF0000
"
},
{
minSpeed
:
30
,
maxSpeed
:
60
,
color
:
"
#FFFF00
"
},
{
minSpeed
:
60
,
maxSpeed
:
90
,
color
:
"
#0000FF
"
},
{
minSpeed
:
90
,
maxSpeed
:
200
,
color
:
"
#00FF00
"
},
],
//颜色
};
perceptualroad
.
bindPerceptualheat
(
json
);
perceptualshow
=
true
;
}
// 删除交通热力图
document
.
getElementById
(
"
deletePerceptualheat
"
).
onclick
=
deletePerceptualheat
;
deletePerceptualheat
;
async
function
deletePerceptualheat
()
{
perceptualroad
.
getPerceptualheat
(
"
222
"
).
remove
();
perceptualshow
=
false
;
perceptualroad
.
getPerceptualheat
(
"
222
"
).
remove
();
perceptualshow
=
false
;
}
// 交通热力图宏观效果
document
.
getElementById
(
"
addPerceptualheatEffect
"
).
onclick
=
addPerceptualheatEffect
;
addPerceptualheatEffect
;
async
function
addPerceptualheatEffect
()
{
if
(
!
perceptual
)
{
loadPerceptual
();
//加载感知物
}
map
.
on
(
map
.
EventType
.
MAP_CHANGE
,
PerceptualheatEffecthandler
);
if
(
!
perceptual
)
{
loadPerceptual
();
//加载感知物
}
map
.
on
(
map
.
EventType
.
MAP_CHANGE
,
PerceptualheatEffecthandler
);
}
PerceptualheatEffecthandler
=
(
e
)
=>
{
let
result
=
JSON
.
stringify
(
e
);
console
.
log
(
"
高度为====
"
+
e
.
height
);
if
(
e
.
height
>
500
)
{
hidePerceptual
();
if
(
!
perceptualshow
)
{
addPerceptualheat
();
}
}
else
{
showPerceptual
();
if
(
perceptualshow
)
{
deletePerceptualheat
();
}
let
result
=
JSON
.
stringify
(
e
);
console
.
log
(
"
高度为====
"
+
e
.
height
);
if
(
e
.
height
>
500
)
{
hidePerceptual
();
if
(
!
perceptualshow
)
{
addPerceptualheat
();
}
}
else
{
showPerceptual
();
if
(
perceptualshow
)
{
deletePerceptualheat
();
}
}
};
// 移除交通热力图宏观效果
document
.
getElementById
(
"
removePerceptualheatEffect
"
).
onclick
=
removePerceptualheatEffect
;
removePerceptualheatEffect
;
async
function
removePerceptualheatEffect
()
{
map
.
off
(
map
.
EventType
.
MAP_CHANGE
,
PerceptualheatEffecthandler
);
removePerceptual
();
deletePerceptualheat
();
map
.
off
(
map
.
EventType
.
MAP_CHANGE
,
PerceptualheatEffecthandler
);
removePerceptual
();
deletePerceptualheat
();
}
//添加信号灯
document
.
getElementById
(
"
addSignal
"
).
onclick
=
addSignal
;
function
addSignal
()
{
let
options
=
{
position
:
[
117.325673
,
38.996374
,
18.53
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
road
.
initSignals
({
id
:
"
51worldinitSignals
"
,
//ID
url
:
"
wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=3&reType=51world
"
,
});
let
options
=
{
position
:
[
117.325673
,
38.996374
,
18.53
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
road
.
initSignals
({
id
:
"
51worldinitSignals
"
,
//ID
url
:
"
wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=3&reType=51world
"
,
});
}
// 创建停止线
document
.
getElementById
(
"
CreateTIMSignal
"
).
onclick
=
CreateTIMSignal
;
async
function
CreateTIMSignal
()
{
road
.
addSignalStopLine
(
SignalLines
);
road
.
addSignalStopLine
(
SignalLines
);
}
// 删除停止线
document
.
getElementById
(
"
DeleteTIMSignal
"
).
onclick
=
DeleteTIMSignal
;
async
function
DeleteTIMSignal
()
{
road
.
removeSignalStopLine
();
road
.
removeSignalStopLine
();
}
var
arr
=
[]
//开始交通事件
document
.
getElementById
(
"
addTrafficIncident
"
).
onclick
=
addTrafficIncident
;
async
function
addTrafficIncident
()
{
let
options
=
{
position
:
[
117.325401
,
38.996133
,
28.12
],
// 订阅事件 websocket事件
const
url
=
"
wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=5&reType=51world
"
;
//&intersectionCode=51-D-JD0003
const
socket
=
new
WebSocket
(
url
);
socket
.
onopen
=
function
(
event
)
{
console
.
log
(
"
socket连接成功!
"
);
};
window
.
trafficIncidentArr
=
trafficIncidentArr
;
let
index
=
0
;
let
show
=
false
;
const
fun1
=
async
(
json
)
=>
{
const
{
endTime
,
id
,
name
,
location
}
=
json
;
console
.
log
(
"
idididididid
"
,
index
,
id
,
name
);
if
(
name
==
"
违规停车/停车占道
"
&&
!
show
)
{
show
=
true
;
console
.
log
(
"
违规停车/停车占道违规停车/停车占道
"
,
json
,
id
);
let
optionsTest
=
{
position
:
[
location
[
0
].
longitude
,
location
[
0
].
latitude
,
28.12
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
const
json
=
{
"
id
"
:
"
600286
"
,
"
type
"
:
"
ROADSIDE_TRAFFIC_EVENT
"
,
"
name
"
:
"
异常停车预警
"
,
"
ptcIds
"
:
[
'
1200002282
'
],
//字符串数组
"
location
"
:
[
{
longitude
:
117.32559766689558
,
latitude
:
38.99628656347781
,
elevation
:
null
,
}
],
"
level
"
:
1
,
"
description
"
:
null
,
"
imagesUrl
"
:
null
,
"
videosUrl
"
:
null
,
"
startTime
"
:
null
,
"
endTime
"
:
null
,
"
reportTime
"
:
null
,
"
mqttTime
"
:
null
,
"
accessTime
"
:
null
};
camera
.
flyTo
(
optionsTest
);
}
// 从 trafficIncidentArr 中的每一项中找出 trafficIncidentId== id 的数据
const
find
=
trafficIncidentArr
.
find
(
(
item
)
=>
item
.
trafficIncidentId
==
id
);
if
(
find
)
{
if
(
index
>
50
&&
name
==
"
违规停车/停车占道
"
)
{
map
.
stopTrafficIncident
(
id
,
json
);
}
return
;
}
index
++
;
// if (index > 50) {
// if (name == "违规停车/停车占道") {
// if (find) {
// debugger;
// map.stopTrafficIncident(id, json);
// }
// }
// return;
// } else {
// }
console
.
log
(
"
index
"
,
index
,
name
);
if
(
endTime
)
{
// trafficIncidentArr = map.stopTrafficIncident(id, json);
// debugger
// return;
}
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
console
.
log
(
"
tc.................
"
,
trafficIncidentArr
);
};
socket
.
onmessage
=
async
function
(
event
)
{
const
json
=
JSON
.
parse
(
event
.
data
);
fun1
(
json
);
let
index
=
0
;
const
timer
=
setInterval
(
async
()
=>
{
if
(
index
==
10
)
{
json
.
endTime
=
1741777564646
;
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
clearInterval
(
timer
);
}
if
(
arr
.
length
<
100
)
{
arr
.
push
(
json
)
}
index
++
;
},
200
);
};
}
// 不在交通流中的交通事件
document
.
getElementById
(
"
addTrafficIncident2
"
).
onclick
=
addTrafficIncident2
;
document
.
getElementById
(
"
addTrafficIncident2
"
).
onclick
=
addTrafficIncident2
;
async
function
addTrafficIncident2
()
{
let
options
=
{
position
:
[
117.325401
,
38.996133
,
28.12
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
const
json
=
{
"
id
"
:
"
600286
"
,
"
type
"
:
"
ROAD_ICE
"
,
"
name
"
:
"
道路结冰
"
,
"
ptcIds
"
:
null
,
"
location
"
:
[
{
longitude
:
117.32559766689558
,
latitude
:
38.99628656347781
,
elevation
:
null
,
}
],
"
level
"
:
1
,
"
description
"
:
null
,
"
imagesUrl
"
:
null
,
"
videosUrl
"
:
null
,
"
startTime
"
:
null
,
"
endTime
"
:
null
,
"
reportTime
"
:
null
,
"
mqttTime
"
:
null
,
"
accessTime
"
:
null
let
options
=
{
position
:
[
117.325401
,
38.996133
,
28.12
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
console
.
log
(
"
tc.................
"
,
trafficIncidentArr
);
let
index
=
0
;
const
timer
=
setInterval
(
async
()
=>
{
if
(
index
==
10
)
{
json
.
endTime
=
1741777564646
;
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
clearInterval
(
timer
);
}
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
console
.
log
(
"
tc.................
"
,
trafficIncidentArr
);
let
index
=
0
;
const
timer
=
setInterval
(
async
()
=>
{
if
(
index
==
10
)
{
json
.
endTime
=
1741777564646
;
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
clearInterval
(
timer
);
}
index
++
;
},
200
);
index
++
;
},
200
);
}
// 区域坐标的交通事件
document
.
getElementById
(
"
addTrafficIncident3
"
).
onclick
=
addTrafficIncident3
;
document
.
getElementById
(
"
addTrafficIncident3
"
).
onclick
=
addTrafficIncident3
;
async
function
addTrafficIncident3
()
{
let
options
=
{
position
:
[
117.325401
,
38.996133
,
28.12
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
const
json
=
{
"
id
"
:
"
600286
"
,
"
type
"
:
"
TRAFFIC_CONGESTION
"
,
"
name
"
:
"
交通拥堵
"
,
"
ptcIds
"
:
null
,
"
location
"
:
[
{
longitude
:
117.32564783
,
latitude
:
38.99632990
,
elevation
:
null
,
},
{
longitude
:
117.32611745
,
latitude
:
38.99734492
,
elevation
:
null
,
},
{
longitude
:
117.32596738
,
latitude
:
38.99737506
,
elevation
:
null
,
},
{
longitude
:
117.32552220
,
latitude
:
38.99636725
,
elevation
:
null
,
},
],
"
level
"
:
1
,
"
description
"
:
null
,
"
imagesUrl
"
:
null
,
"
videosUrl
"
:
null
,
"
startTime
"
:
null
,
"
endTime
"
:
null
,
"
reportTime
"
:
null
,
"
mqttTime
"
:
null
,
"
accessTime
"
:
null
let
options
=
{
position
:
[
117.325401
,
38.996133
,
28.12
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
const
json
=
{
id
:
"
600286
"
,
type
:
"
TRAFFIC_CONGESTION
"
,
name
:
"
交通拥堵
"
,
ptcIds
:
null
,
location
:
[
{
longitude
:
117.32564783
,
latitude
:
38.9963299
,
elevation
:
null
,
},
{
longitude
:
117.32611745
,
latitude
:
38.99734492
,
elevation
:
null
,
},
{
longitude
:
117.32596738
,
latitude
:
38.99737506
,
elevation
:
null
,
},
{
longitude
:
117.3255222
,
latitude
:
38.99636725
,
elevation
:
null
,
},
],
level
:
1
,
description
:
null
,
imagesUrl
:
null
,
videosUrl
:
null
,
startTime
:
null
,
endTime
:
null
,
reportTime
:
null
,
mqttTime
:
null
,
accessTime
:
null
,
};
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
console
.
log
(
"
tc.................
"
,
trafficIncidentArr
);
let
index
=
0
;
const
timer
=
setInterval
(
async
()
=>
{
if
(
index
==
10
)
{
json
.
endTime
=
1741777564646
;
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
clearInterval
(
timer
);
}
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
console
.
log
(
"
tc.................
"
,
trafficIncidentArr
);
let
index
=
0
;
const
timer
=
setInterval
(
async
()
=>
{
if
(
index
==
10
)
{
json
.
endTime
=
1741777564646
;
trafficIncidentArr
=
await
map
.
renderTrafficIncident
(
json
);
clearInterval
(
timer
);
}
index
++
;
},
200
);
index
++
;
},
200
);
}
// //结束交通事件
...
...
@@ -1117,293 +1223,302 @@
//开始历史轨迹
document
.
getElementById
(
"
bindHistoryVehicle
"
).
onclick
=
bindHistoryVehicle
;
async
function
bindHistoryVehicle
()
{
let
options
=
{
position
:
[
117.36914548090871335
,
39.01187038664559026
,
100.12
],
orientation
:
[
-
90
,
0
],
};
camera
.
flyTo
(
options
);
const
json
=
{
id
:
"
21002cc
"
,
url
:
"
ws://192.168.60.137:31000/ws/streamer/2a9e3045-8ff6-4da8-970c-8bb1e4ca1ed9
"
,
};
map
.
bindHistoryVehicle
(
json
);
let
options
=
{
position
:
[
117.36914548090871335
,
39.01187038664559026
,
100.12
],
orientation
:
[
-
90
,
0
],
};
camera
.
flyTo
(
options
);
const
json
=
{
id
:
"
21002cc
"
,
url
:
"
ws://192.168.60.137:31000/ws/streamer/2a9e3045-8ff6-4da8-970c-8bb1e4ca1ed9
"
,
};
map
.
bindHistoryVehicle
(
json
);
}
//结束历史轨迹
document
.
getElementById
(
"
removeHistoryVehicle
"
).
onclick
=
removeHistoryVehicle
;
removeHistoryVehicle
;
async
function
removeHistoryVehicle
()
{
map
.
removeHistoryVehicle
();
map
.
removeHistoryVehicle
();
}
// 暂停历史轨迹
document
.
getElementById
(
"
pauseHistoryVehicle
"
).
onclick
=
pauseHistoryVehicle
;
pauseHistoryVehicle
;
function
pauseHistoryVehicle
()
{
map
.
pauseHistoryVehicle
(
"
21002cc
"
);
map
.
pauseHistoryVehicle
(
"
21002cc
"
);
}
// 重新开始历史轨迹
document
.
getElementById
(
"
resumeHistoryVehicle
"
).
onclick
=
resumeHistoryVehicle
;
resumeHistoryVehicle
;
function
resumeHistoryVehicle
()
{
map
.
resumeHistoryVehicle
(
"
21002cc
"
);
map
.
resumeHistoryVehicle
(
"
21002cc
"
);
}
// 开始V2V
document
.
getElementById
(
"
startV2X
"
).
onclick
=
startV2X
;
function
startV2X
()
{
const
url
=
'
wss://itg-dev.cu-sc.com:13443/WSPLUS/socket?token=111&msgType=4&reType=51world
'
startVehicleV2X
(
url
)
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
)
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 = {
// color: [255, 255, 0, 1],
// vehicleId: "仿AYZQS001", //鄂A17U5N
// // vehicleId: "测试车辆001", //鄂A17U5N
// name: '注意行人'
// };
// 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
// 259 XM140002
// 261 XM140003
// 263 XM140004
// 265 XM140005
// 267 XM140006
// 269 XM140007
// 271 XM140008
// 219 仿AYZQS001
// 221 仿A-0234DA
v2xArr
=
[];
// 记录所有v2x
// 创建一个WebSocket实例
v2xSocket
=
new
WebSocket
(
url
);
// let options = {
// color: [255, 255, 0, 1],
// vehicleId: "仿AYZQS001", //鄂A17U5N
// // vehicleId: "测试车辆001", //鄂A17U5N
// name: '注意行人'
// };
// 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
// 259 XM140002
// 261 XM140003
// 263 XM140004
// 265 XM140005
// 267 XM140006
// 269 XM140007
// 271 XM140008
// 219 仿AYZQS001
// 221 仿A-0234DA
v2xArr
=
[];
// 记录所有v2x
// 创建一个WebSocket实例
v2xSocket
=
new
WebSocket
(
url
);
// 当WebSocket打开时执行
v2xSocket
.
onopen
=
function
(
event
)
{
console
.
log
(
"
socket连接成功!
"
);
};
// 当接收到消息时执行
v2xSocket
.
onmessage
=
function
(
event
)
{
let
data
=
JSON
.
parse
(
event
.
data
);
let
{
objects
,
endTime
,
typeName
,
id
}
=
data
;
// objects 如果只有一项,则是单车预警;如果有两项,则需要有两个车辆的通信效果
let
mainCar
=
objects
[
0
];
// 如果id不在v2xArr中,则添加
const
find
=
v2xArr
.
find
((
item
)
=>
item
.
id
===
id
);
if
(
!
find
)
{
v2xArr
.
push
(
data
);
}
// 当WebSocket打开时执行
v2xSocket
.
onopen
=
function
(
event
)
{
console
.
log
(
"
socket连接成功!
"
);
let
options
=
{
id
:
id
,
color
:
[
255
,
255
,
0
,
1
],
vehicleId
:
mainCar
.
id
,
name
:
typeName
,
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
startV2x
(
options
);
if
(
objects
.
length
>
1
)
{
const
options2
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
color
:
[
255
,
0
,
0
,
1
],
};
map
.
renderCommunication
(
options2
);
if
(
objects
.
length
>
1
)
{
console
.
log
(
"
开始
"
,
mainCar
.
id
,
objects
[
1
].
id
,
data
);
}
else
{
console
.
log
(
"
开始
"
,
mainCar
.
id
,
data
);
}
}
// 当接收到消息时执行
v2xSocket
.
onmessage
=
function
(
event
)
{
let
data
=
JSON
.
parse
(
event
.
data
)
let
{
objects
,
endTime
,
typeName
,
id
}
=
data
// objects 如果只有一项,则是单车预警;如果有两项,则需要有两个车辆的通信效果
let
mainCar
=
objects
[
0
]
// 如果id不在v2xArr中,则添加
const
find
=
v2xArr
.
find
(
item
=>
item
.
id
===
id
)
if
(
!
find
)
{
v2xArr
.
push
(
data
)
}
let
options
=
{
id
:
id
,
color
:
[
255
,
255
,
0
,
1
],
vehicleId
:
mainCar
.
id
,
name
:
typeName
};
map
.
getVehicle
(
"
21e7a9e6d2884122804788dac1e002cc
"
).
startV2x
(
options
);
if
(
objects
.
length
>
1
)
{
const
options2
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
color
:
[
255
,
0
,
0
,
1
],
}
map
.
renderCommunication
(
options2
)
if
(
objects
.
length
>
1
)
{
console
.
log
(
'
开始
'
,
mainCar
.
id
,
objects
[
1
].
id
,
data
)
}
else
{
console
.
log
(
'
开始
'
,
mainCar
.
id
,
data
)
}
}
if
(
endTime
)
{
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
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
}
console
.
log
(
'
前端结束通信
'
,
id
,
mainCar
.
id
,
objects
[
1
].
id
)
map
.
stopCommunication
(
options2
)
if
(
objects
.
length
>
1
)
{
// console.log('结束结束结束', mainCar.id, objects[1].id)
}
else
{
// console.log('结束结束结束', mainCar.id)
}
if
(
endTime
)
{
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
=
{
id
,
vehicleId
:
[
mainCar
.
id
,
objects
[
1
].
id
],
//车辆ID
};
console
.
log
(
"
前端结束通信
"
,
id
,
mainCar
.
id
,
objects
[
1
].
id
);
map
.
stopCommunication
(
options2
);
if
(
objects
.
length
>
1
)
{
// console.log('结束结束结束', mainCar.id, objects[1].id)
}
else
{
// console.log('结束结束结束', mainCar.id)
}
}
};
}
// 清除V2V
document
.
getElementById
(
"
removeV2X
"
).
onclick
=
removeV2X
;
function
removeV2X
()
{
v2xSocket
.
close
()
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
=
[]
v2xSocket
.
close
();
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
=
[];
}
// 绘制感知区域
document
.
getElementById
(
"
addPolygon
"
).
onclick
=
addPolygon
;
async
function
addPolygon
()
{
const
options
=
{
id
:
"
polygons
"
,
type
:
'
polygon3d
'
,
position
:
[
[
117.31930248
,
38.99171243
],
[
117.32246328
,
38.99176425
],
[
117.32174648
,
38.99001976
],
[
117.3192593
0
,
38.99073655
],
],
color
:
[
25
,
25
,
112
,
1
],
//设置填充颜色
maxHeight
:
20
,
extrudedHeight
:
60
,
}
// 添加感知区域
polygon
=
await
map
.
addPolygonOverlay
(
options
)
map
.
zoomToOverlay
(
polygon
)
const
options
=
{
id
:
"
polygons
"
,
type
:
"
polygon3d
"
,
position
:
[
[
117.31930248
,
38.99171243
],
[
117.32246328
,
38.99176425
],
[
117.32174648
,
38.99001976
],
[
117.3192593
,
38.99073655
],
],
color
:
[
25
,
25
,
112
,
1
],
//设置填充颜色
maxHeight
:
20
,
extrudedHeight
:
60
,
}
;
// 添加感知区域
polygon
=
await
map
.
addPolygonOverlay
(
options
)
;
map
.
zoomToOverlay
(
polygon
)
;
}
// 显示感知区域
document
.
getElementById
(
"
showPolygon
"
).
onclick
=
showPolygon
;
function
showPolygon
()
{
map
.
showOverlay
(
polygon
);
map
.
showOverlay
(
polygon
);
}
// 隐藏感知区域
document
.
getElementById
(
"
hidePolygon
"
).
onclick
=
hidePolygon
;
function
hidePolygon
()
{
map
.
hideOverlay
(
polygon
);
map
.
hideOverlay
(
polygon
);
}
// 删除感知区域
document
.
getElementById
(
"
removePolygon
"
).
onclick
=
removePolygon
;
function
removePolygon
()
{
map
.
removeOverlay
(
polygon
);
map
.
removeOverlay
(
polygon
);
}
// 注册模型点击高亮 modelClickHighLight
document
.
getElementById
(
"
modelClickHighLight
"
).
onclick
=
modelClickHighLight
;
document
.
getElementById
(
"
modelClickHighLight
"
).
onclick
=
modelClickHighLight
;
async
function
modelClickHighLight
()
{
map
.
on
(
map
.
EventType
.
ON_EQUIPMENT_CLICKED
,
pick_model_hightlight
);
map
.
on
(
map
.
EventType
.
ON_EQUIPMENT_CLICKED
,
pick_model_hightlight
);
}
function
pick_model_hightlight
(
e
)
{
// 取出id
const
modelId
=
e
?.
result
?.
Id
||
""
;
console
.
log
(
"
模型点击高亮
"
,
e
);
if
(
modelId
)
{
highlightModelId
=
modelId
;
map
.
setModelHighlight
(
modelId
);
map
.
addPopWindow
({
id
:
modelId
,
info
:
'
普通信号灯
'
})
return
;
}
console
.
warn
(
"
没有模型Id
"
,
e
);
// 取出id
const
modelId
=
e
?.
result
?.
Id
||
""
;
console
.
log
(
"
模型点击高亮
"
,
e
);
if
(
modelId
)
{
highlightModelId
=
modelId
;
map
.
setModelHighlight
(
modelId
);
map
.
addPopWindow
({
id
:
modelId
,
info
:
"
普通信号灯
"
,
})
;
return
;
}
console
.
warn
(
"
没有模型Id
"
,
e
);
}
// 清除模型高亮
document
.
getElementById
(
"
cancelModelHighlight
"
).
onclick
=
cancelModelHighlight
;
cancelModelHighlight
;
function
cancelModelHighlight
()
{
console
.
log
(
"
清除模型高亮
"
,
highlightModelId
);
if
(
highlightModelId
)
{
map
.
cancelModelHighlight
(
highlightModelId
);
map
.
removePopWindow
(
highlightModelId
);
// highlightModelId = null;
}
console
.
log
(
"
清除模型高亮
"
,
highlightModelId
);
if
(
highlightModelId
)
{
map
.
cancelModelHighlight
(
highlightModelId
);
map
.
removePopWindow
(
highlightModelId
);
// highlightModelId = null;
}
}
// 注销模型点击事件
document
.
getElementById
(
"
modelClickRemove
"
).
onclick
=
modelClickRemove
;
function
modelClickRemove
()
{
map
.
off
(
map
.
EventType
.
ON_EQUIPMENT_CLICKED
,
pick_model_hightlight
);
map
.
off
(
map
.
EventType
.
ON_EQUIPMENT_CLICKED
,
pick_model_hightlight
);
}
// 添加毫米波雷达
document
.
getElementById
(
"
addMillimeterWave
"
).
onclick
=
addMillimeterWave
;
function
addMillimeterWave
()
{
let
options
=
{
position
:
[
117.325673
,
38.996374
,
18.53
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
const
json
=
{
"
id
"
:
"
1200002282
"
,
"
color
"
:
"
0ffff0FF
"
,
"
opacity
"
:
0.4
,
"
xFov
"
:
90
,
//横向范围
"
yFov
"
:
30
,
//纵向范围
"
yawValue
"
:
90
,
//朝向,0为默认向东
"
pitchValue
"
:
0
,
//俯仰角
"
radius
"
:
1000
//辐射范围
}
map
.
addMillimeterWave
(
json
);
let
options
=
{
position
:
[
117.325673
,
38.996374
,
18.53
],
orientation
:
[
-
34.930073
,
-
44.426579
],
};
camera
.
flyTo
(
options
);
const
json
=
{
id
:
"
1200002282
"
,
color
:
"
0ffff0FF
"
,
opacity
:
0.4
,
xFov
:
90
,
//横向范围
yFov
:
30
,
//纵向范围
yawValue
:
90
,
//朝向,0为默认向东
pitchValue
:
0
,
//俯仰角
radius
:
1000
,
//辐射范围
};
map
.
addMillimeterWave
(
json
);
}
// 移除毫米波雷达
document
.
getElementById
(
"
removeMillimeterWave
"
).
onclick
=
removeMillimeterWave
;
document
.
getElementById
(
"
removeMillimeterWave
"
).
onclick
=
removeMillimeterWave
;
function
removeMillimeterWave
()
{
const
json
=
{
ids
:
[
"
1200002282
"
]
}
map
.
removeMillimeterWave
(
json
);
const
json
=
{
ids
:
[
"
1200002282
"
]
,
}
;
map
.
removeMillimeterWave
(
json
);
}
</script>
</html>
\ No newline at end of file
</script>
</html>
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