-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
193 lines (179 loc) · 5.62 KB
/
index.html
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<html>
<head>
<meta charset="utf-8">
<!-- 引入 ECharts 文件 -->
<link rel="stylesheet" href="./Openlayer/ol.css" type="text/css">
<link rel="stylesheet" href="./ol-infowindow/default.css" type="text/css">
<script src="./Openlayer/ol.js"></script>
<script src="./ol-infowindow/ol-infowindow.js"></script>
<style>
#map {
width: 100%;
height: 100%
}
.btn-overlay {
width: 40px;
height: 40px;
border-radius: 32px;
background: white;
color: #1E9FFF;
text-align: center;
line-height: 40px;
font-size: 0.5em;
position: absolute;
border: 3px solid #1E9FFF;
left: -20px
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var center = ol.proj.transform([117.4658331179, 31.6159870346], 'EPSG:4326', 'EPSG:3857');
var center1 = ol.proj.transform([117.3065185547, 31.2550741854], 'EPSG:4326', 'EPSG:3857');
var center2 = ol.proj.transform([116.5429687500, 31.6954557978], 'EPSG:4326', 'EPSG:3857');
var osm = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
view: new ol.View({
center: center,
zoom: 8,
maxZoom: 18
}),
target: 'map'
});
var attrs = {
title: {
show: true,
text: "标题",
textSize: "13px",
},
width: "250px",
hideBefore: true,
closeBtn: true,
content: [{
name: "设备编码",
value: "1234564789",
nameColor: "#666666",
valueColor: "#222222",
divider: false
}, {
name: "运行状态",
value: "运行",
nameColor: "#222222",
valueColor: "#00aa00",
divider: false
},
{
name: "时间",
value: 2019,
nameColor: "#222222",
divider: false
},
{
name: "管理单位",
value: "某某某公司",
nameColor: "#222222",
divider: false
},
{
name: "设备温度",
value: 34,
nameColor: "#222222",
divider: false
},
{
name: "设备厂商",
value: "某某某厂商",
nameColor: "#222222",
divider: false
}
],
button: {
show: true,
fullButton: {
text: "播放",
fullCallBack: function () {
alert(1);
}
}
}
};
map.addLayer(osm);
//无按钮
var noBtnElement = document.createElement('div');
noBtnElement.className = "btn-overlay";
noBtnElement.innerHTML = "无按钮"
var noBtnOverlay = new ol.Overlay({
element: noBtnElement,
positioning: 'bottom-center',
stopEvent: true,
autoPan: true,
position:center
});
noBtnElement.onmousedown = function (ev){
attrs.button.show = false;
attrs.position = center;
map.addInfoWindow(attrs)
}
map.addOverlay(noBtnOverlay);
//一个按钮
var oneBtnElement = document.createElement('div');
oneBtnElement.className = "btn-overlay";
oneBtnElement.innerHTML = "单按钮"
var oneBtnOverlay = new ol.Overlay({
element: oneBtnElement,
positioning: 'bottom-center',
stopEvent: true,
autoPan: true,
position:center1
});
oneBtnElement.onmousedown = function (ev){
attrs.position = center1;
attrs.button = {
show: true,
fullButton: {
text: "单按钮",
fullCallBack: function () {
alert(1);
}
}
}
map.addInfoWindow(attrs)
}
map.addOverlay(oneBtnOverlay);
//两个按钮
var twoBtnElement = document.createElement('div');
twoBtnElement.className = "btn-overlay";
twoBtnElement.innerHTML = "双按钮"
var twoBtnOverlay = new ol.Overlay({
element: twoBtnElement,
positioning: 'bottom-center',
stopEvent: true,
autoPan: true,
position:center2
});
twoBtnElement.onmousedown = function (ev){
attrs.position = center2;
attrs.button = {
show: true,
leftButton: {
text: "左侧按钮",
callBack: function () {
alert(1);
}
},
rightButton: {
text: "右侧按钮",
callBack: function () {
alert(1);
}
}
}
map.addInfoWindow(attrs)
}
map.addOverlay(twoBtnOverlay);
</script>
</body>
</html>