-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
126 lines (112 loc) · 3.25 KB
/
main.js
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
$.ajaxSetup({async: false});
var map;
var week_index = 48
$.getJSON('DengueKH.json', function(data){
DengueKH = data
});
function initialize(){
/*map setting*/
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 10,
center: {lat: 22.75, lng: 120.50 }
});
$.getJSON('townKH.json', function( data ){
town = map.data.addGeoJson(data);
});
town.forEach(function(value){
var key = value.getProperty('TOWNNAME');
value.setProperty('num',DengueKH[key][week_index]);
});
map.data.setStyle(function(feature){
var num = feature.getProperty('num');
color = ColorBar(num);
return {
fillColor: color,
fillOpacity: 0.6,
strokeColor: 'gray',
strokeWeight: 1
}
});
map.data.addListener('mouseover', function(event){
var TownName = event.feature.getProperty('TOWNNAME');
map.data.revertStyle();
map.data.overrideStyle(event.feature, {fillColor: 'white'});
$('#detial > #content').empty();
$('#detial > #content').append('<div>'+TownName+':'+DengueKH[TownName][week_index]+'</div>');
});
map.data.addListener('mouseout', function(event){
map.data.revertStyle();
$('#detial > #content').empty();
});
map.data.addListener('click', function(event){
var TownName = event.feature.getProperty('TOWNNAME');
if($('#myTab a[name|="'+TownName+'"]').tab('show').length == 0){
$('#myTab').append('<li><a name="'+TownName+'" href="#'+TownName+'" data-toggle="tab">'+TownName+
'<button class="close" onclick="closeTab(this.parentNode)">×</button></a></li>');
$('#myTabContent').append('<div class="tab-pane fade" id="'+TownName+'"><div></div></div>');
$('#myTab a:last').tab('show');
createStockChart(TownName);
$('#myTab li a:last').click(function (e) {
$(window).trigger('resize');
});
}
});
createStockChart('合計');
}
function createStockChart(TownName){
start = new Date(2013,12-1,29);
var series = []
for(var i = 0 ; i < DengueKH[TownName].length ; i = i + 1){
start.setDate(start.getDate() + 7);
series.push([ start.getTime() , DengueKH[TownName][i] ]);
}
$('#'+TownName).highcharts('StockChart', {
chart: {
alignTicks: false,
width: $('#myTabContent').width(),
height: $('#myTabContent').height()
},
rangeSelector: {
enabled: false
},
tooltip: {
enabled: true,
positioner: function(){ return {x: 10, y: 30}}
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function(){
$('#detial > #title').text('第' + (this.index+1) + '週(' + new Date(this.x-1).toLocaleDateString() + ')');
week_index = this.index
town.forEach(function(value){
var key = value.getProperty('TOWNNAME');
value.setProperty('num', DengueKH[key][week_index]);
});
}
}
},
}
},
series: [{
type: 'column',
name: TownName,
data: series,
}]
});
}
$(window).resize(function() {
var len = $('#myTabContent > div').length;
for( var i = 1; i<=len; i = i + 1){
$('#myTabContent > div:nth-child('+i+')').highcharts().setSize($('#myTabContent').width(),$('#myTabContent').height());
}
});
function closeTab(node){
var nodename = node.name;
node.parentNode.remove();
$('#'+nodename).remove();
$('#myTab a:first').tab('show') ;
}
google.maps.event.addDomListener(window, 'load', initialize);