-
Notifications
You must be signed in to change notification settings - Fork 0
/
congestion_propagation_pattern_heapmap.jsp
322 lines (289 loc) · 11.9 KB
/
congestion_propagation_pattern_heapmap.jsp
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<%--
Created by IntelliJ IDEA.
User: GEORGE-pc
Date: 2020/2/29
Time: 15:07
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=SGZAQcGREz9ugRxt9eWnn7nHynec9lRb"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js"></script>
<script type="text/javascript" src="build/jquery-1.10.2.min.js"></script>
<title>拥堵传播模式热力图展示</title>
<style type="text/css">
ul,li{list-style: none;margin:0;padding:0;float:left;}
html{height:100%}
body{height:100%;margin:0px;padding:0px;font-family:"微软雅黑";}
#container{height:95%;width:100%;}
#r-result{width:100%;}
</style>
</head>
<body>
<div id="container" ></div>
<div id="r-result">
<div id="interval" style="float: left;margin-right: 10px;"></div>
<div id="progress" style="float: left;margin-right: 10px;"></div>
<input type="button" onclick="closeHeatmap();" value="关闭拥塞传播的热力图图示"/>
<input type="button" onclick="display_next_interval_heatmaps();" value="显示下一时间片的拥塞传播的热力图示集合"/>
<input type="button" onclick="display_next_heatmap();" value="显示下一拥塞传播的热力图示"/>
<input type="button" onclick="display_last_interval_heatmaps();" value="显示上一时间片的拥塞传播情热力图示集合"/>
<input type="button" onclick="display_last_heatmap();" value="显示上一拥塞传播情热力图示"/>
<input type="button" onclick="next_day();" value="转到下一天"/>
</div>
</body>
</html>
<script type="text/javascript">
// 这个文件需借助动态web应用来使用,因为使用了ajax获取本地服务器(本地)数据
cur_part_no = 4;
url_cpp = "data/sfba/part"+cur_part_no+"/grid32/visual_data/congestion_propagation_pattern_data/";
url_tg = "data/sfba/part"+cur_part_no+"/grid32/visual_data/transition_grid_data/";
time_interval_large = ["0600-1000", "1700-2100"];
function get_next_time_interval_congestion_propagation_data(interval_step) {
cpp_interval_index = (cpp_interval_index + interval_step);
if (cpp_interval_index <= -1) {
cpp_interval_index = time_interval_large.length - 1;
} else {
cpp_interval_index = cpp_interval_index % time_interval_large.length;
}
var interval_points = [];
var load_data = function () {
$.ajax({
url: "<%=basePath%>"+url_cpp+"cpp_"+time_interval_large[cpp_interval_index]+".json",
data: "",
async: false,
success: function (data) {
interval_points = data;
},
error: function(info) {
console.log("Fail to load congestion propagation data " + time_interval_large[cpp_interval_index])
},
dataType: "json"
});
};
load_data();
return interval_points;
}
function get_next_time_interval_transition_congestion_grid_data(interval_step) {
tg_interval_index = (tg_interval_index + interval_step);
if (tg_interval_index <= -1) {
tg_interval_index = time_interval_large.length - 1;
} else {
tg_interval_index = tg_interval_index % time_interval_large.length;
}
var interval_points = [];
var load_data = function () {
$.ajax({
url: "<%=basePath%>"+url_tg+"tg_"+time_interval_large[tg_interval_index]+".json",
data: "",
async: false,
success: function (data) {
interval_points = data;
},
error: function(info) {
console.log("Fail to load congestion propagation data " + time_interval_large[tg_interval_index])
},
dataType: "json"
});
};
load_data();
return interval_points;
}
var map = new BMap.Map("container");
// var point = new BMap.Point(-122.45, 37.755);
var point = new BMap.Point(-122.420586,37.78767);
map.centerAndZoom(point, 14);
map.enableScrollWheelZoom(true);
map.addControl(new BMap.ScaleControl());
if(!isSupportCanvas()){
alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~')
}
//详细的参数,可以查看heatmap.js的文档 https://github.com/pa7/heatmap.js/blob/master/README.md
//参数说明如下:
/* visible 热力图是否显示,默认为true
* opacity 热力的透明度,1-100
* radius 势力图的每个点的半径大小
* gradient {JSON} 热力图的渐变区间 . gradient如下所示
* {
.2:'rgb(0, 255, 255)',
.5:'rgb(0, 110, 255)',
.8:'rgb(100, 0, 255)'
}
其中 key 表示插值的位置, 0~1.
value 为颜色值.
*/
var cpp_interval_index = -1;
var tg_interval_index = -1;
var cpp_index = -1;
var tg_index = -1;
var interval_points;
var tg_interval_points;
var points;
var tg_points;
var options = {
"radius":25
};
heatmapOverlay = new BMapLib.HeatmapOverlay(options); // 14->25, 15->50, 16->90
map.addOverlay(heatmapOverlay);
zoom_icon_dict = {18:["image/position-2-1.png", 64], 17:["image/position-2-1.png", 64], 16:["image/position-2-2.png", 48],
15:["image/position-2.png", 32], 14:["image/position-2-3.png", 16], 13:["image/position-2-3.png", 16]};
// 放大到 14 级
var icon = new BMap.Icon(
'image/position-2-3.png',
new BMap.Size(16, 16)
);
// 放大到 15 级
// var icon = new BMap.Icon(
// 'image/position-2.png',
// new BMap.Size(32, 32)
// );
// 放大到 16 级
// var icon = new BMap.Icon(
// 'image/position-2-2.png',
// new BMap.Size(48, 48)
// );
// 保证网格大小与地图标尺大小一致
zoom_size_dict = {13:12, 14:25, 15:50, 16:90, 17:200};
map.addEventListener("zoomend", function(evt){
options.radius = zoom_size_dict[this.getZoom()];
console.log("current zoom is " + this.getZoom() + ", and current radius is " + options.radius);
if ((this.getZoom() < 13 || this.getZoom() > 17) || points == "undefined" || cpp_index == -1) {
return
}
if (typeof heatmapOverlay != "undefined") {
heatmapOverlay.toggle();
heatmapOverlay = new BMapLib.HeatmapOverlay({"radius":zoom_size_dict[this.getZoom()]}); // 14->25, 15->50, 16->90
map.addOverlay(heatmapOverlay);
openHeatmap();
}
icon_png = zoom_icon_dict[this.getZoom()][0];
icon_size = zoom_icon_dict[this.getZoom()][1];
icon = new BMap.Icon(
icon_png,
new BMap.Size(icon_size, icon_size)
);
showMarker();
});
zoom_offset_dict = {13:0.0014, 14:0.0014, 15:0.0012, 16:0.0010, 17:0.0008};
var marker_memo = new Array();
function showMarker() {
while (marker_memo.length > 0) {
marker = marker_memo.pop();
map.removeOverlay(marker)
}
for (var i = 0; i < tg_points.length; i++) {
mk = tg_points[i];
// markerPosOffset = 0.0012 // 放大到 15 级
// markerPosOffset = 0.0010; // 放大到 16 级
markerPosOffset = zoom_offset_dict[map.getZoom()];
var mostDensityPoint = new BMap.Point(mk['location'][0],mk['location'][1]+markerPosOffset);
var marker = new BMap.Marker(mostDensityPoint, {icon: icon});
map.addOverlay(marker);
marker_memo.push(marker)
}
}
function openHeatmap(){
heatmapOverlay.setDataSet({data:points,max:10});
heatmapOverlay.show();
showMarker()
}
function display_next_interval_heatmaps() {
interval_points = get_next_time_interval_congestion_propagation_data(1);
tg_interval_points = get_next_time_interval_transition_congestion_grid_data(1);
console.log(interval_points.length);
console.log(tg_interval_points.length);
$("#interval").text("当前时间片为:" + time_interval_large[tg_interval_index]);
tg_index =-1;
cpp_index = -1;
display_next_heatmap();
}
function display_last_interval_heatmaps() {
interval_points = get_next_time_interval_congestion_propagation_data(-1);
tg_interval_points = get_next_time_interval_transition_congestion_grid_data(-1);
console.log(interval_points.length);
console.log(tg_interval_points.length);
$("#interval").text("当前时间片为:" + time_interval_large[tg_interval_index]);
display_last_heatmap();
}
function patch() {
console.log("points length is " + points.length);
for (var i = 0; i < tg_points.length; i++) {
tg_p = tg_points[i];
exists = false;
for (var j = 0; j < points.length; j++) {
if (tg_p["location"][0] == points[j]["lng"] && tg_p["location"][1] == points[j]["lat"]) {
exists = true;
}
}
if (!exists) {
points.push({"count":20, "lat":tg_p["location"][1], "lng":tg_p["location"][0]});
}
}
console.log("points length is " + points.length);
}
function display_next_heatmap() {
tg_index = (tg_index + 1) % tg_interval_points.length;
tg_points = tg_interval_points[tg_index];
cpp_index = (cpp_index + 1) % interval_points.length;
points = interval_points[cpp_index];
patch();
console.log(tg_points.length);
console.log(points.length);
openHeatmap();
$("#progress").text("day" + (cur_part_no+24)+" "+ tg_index+"/"+(tg_interval_points.length-1));
}
function display_last_heatmap() {
tg_index = (tg_index -1);
if (tg_index <= -1) {
tg_index = tg_interval_points.length - 1;
}
tg_points = tg_interval_points[tg_index];
cpp_index = (cpp_index -1);
if (cpp_index <= -1) {
cpp_index = interval_points.length - 1;
}
points = interval_points[cpp_index];
patch();
console.log(tg_points.length);
console.log(points.length);
openHeatmap();
$("#progress").text("day" + (cur_part_no+24)+" "+ tg_index+"/"+(tg_interval_points.length-1));
}
function next_day() {
cur_part_no = (cur_part_no + 1) % 8;
url_cpp = "data/sfba/part"+cur_part_no+"/grid32/visual_data/congestion_propagation_pattern_data/";
url_tg = "data/sfba/part"+cur_part_no+"/grid32/visual_data/transition_grid_data/";
display_next_interval_heatmaps()
}
function closeHeatmap(){
heatmapOverlay.hide();
}
closeHeatmap();
function setGradient(){
/*:
{
0:'rgb(102, 255, 0)',
.5:'rgb(255, 170, 0)',
1:'rgb(255, 0, 0)'
}*/
var gradient = {};
var colors = document.querySelectorAll("input[type='color']");
colors = [].slice.call(colors,0);
colors.forEach(function(ele){
gradient[ele.getAttribute("data-key")] = ele.value;
});
heatmapOverlay.setOptions({"gradient":gradient});
}
function isSupportCanvas(){
var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d'));
}
</script>