-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
120 lines (114 loc) · 3.46 KB
/
Copy pathindex.html
File metadata and controls
120 lines (114 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>LineLayer图层</title>
<style type="text/css">
body,
html {
width: 100%;
height: 100%;
margin: 0;
}
#allmap {
height: 100%;
width: 100%;
}
ul li {
list-style: none;
}
.btn-wrap {
z-index: 999;
position: fixed;
bottom: 3.5rem;
margin-left: 3rem;
padding: 1rem 1rem;
border-radius: .25rem;
background-color: #fff;
box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
}
.btn {
width: 75px;
height: 30px;
float: left;
background-color: #fff;
color: rgba(27, 142, 236, 1);
font-size: 14px;
border: 1px solid rgba(27, 142, 236, 1);
border-radius: 5px;
margin: 0 5px;
text-align: center;
line-height: 30px;
}
.btn:hover {
background-color: rgba(27, 142, 236, 0.8);
color: #fff;
}
</style>
<script type="text/javascript"
src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=zLhopYPPERGtpGOgimcdKcCimGRyyIsh"></script>
<script src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script> <script></script>
<script>
// 开启移动端控制台
var vConsole = new VConsole();
</script>
</head>
<body>
<div id="allmap"></div>
<ul class="btn-wrap" style="z-index: 99;">
<li class="light btn" onclick="addLineLayer()">添加图层</li>
<li class="night btn" onclick="removeLineLayer()">清除图层</li>
</ul>
</body>
</html>
<script type="text/javascript">
if (!window.location.href.includes('wv=lg')) {
window.location.href = `${window.location.href}?fix_font=true&is_nav_show=false&wv=lg`
}
setTimeout(() => {
var map = new BMapGL.Map('allmap', {
});
var point = new BMapGL.Point(116.51397, 39.73517);
map.centerAndZoom(point, 11);
map.enableScrollWheelZoom(true);
var lineLayer = null;
// 添加图层
function addLineLayer() {
fetch("https://mapopen-pub-jsapigl.bj.bcebos.com/svgmodel/lineLayerData.json").then(res => {
return res.json();
}).then(testLineData => {
if (!lineLayer) {
lineLayer = new BMapGL.LineLayer({
selectedIndex: -1,
enablePicked: true,
autoSelect: false,
// selectedColor: 'black', // 选中项颜色
style: {
// borderMask: false,
width: 10,
borderColor: 'rgba(27, 142, 236, .6)',
borderWeight: 0,
strokeWeight: 10,
strokeStyle: 'solid',
strokeColor: 'red',
}
});
}
lineLayer.addEventListener('click', function (e) {
if (e.value.dataIndex !== -1 && e.value.dataItem) {
// 使用样式配置,实现单选效果
this.updateState(e.value.dataIndex, { picked: true })
}
})
lineLayer.setData(testLineData);
map.addNormalLayer(lineLayer);
})
}
// 移除图层
function removeLineLayer() {
map.removeNormalLayer(lineLayer);
}
addLineLayer();
}, 3000);
</script>