Failed Conditions
Pull Request — master (#162)
by PoUpA
02:23
created

pokemon.maps.js ➔ ... ➔ $.done   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 19
rs 9.4285
1
var map, heatmap;
2
3
function initMap() {
4
	
5
	$.getJSON( "core/json/variables.json", function( jsondata ) {
6
7
		var variables = jsondata;
8
9
		var lattitude = Number(variables['system']['map_center_lat']);
10
		var longitude = Number(variables['system']['map_center_long']);
11
		var zoom_level = Number(variables['system']['zoom_level']);
12
13
14
		map = new google.maps.Map(document.getElementById('map'), {
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
15
			center: {lat: lattitude, lng: longitude},
16
			zoom: zoom_level,
17
			zoomControl: true,
18
			scaleControl: false,
19
			scrollwheel: true,
20
			disableDoubleClickZoom: false,
21
		});
22
		
23
		map.set('styles',[
24
			{
25
				"featureType":"all",
26
				"elementType":"labels.text.fill",
27
				"stylers":[{"saturation":36},{"color":"#333333"},{"lightness":40}]
28
			},
29
			{
30
				"featureType":"all",
31
				"elementType":"labels.text.stroke",
32
				"stylers":[{"visibility":"on"},{"color":"#ffffff"},{"lightness":16}]
33
			},
34
			{
35
				"featureType":"all",
36
				"elementType":"labels.icon",
37
				"stylers":[{"visibility":"off"}]
38
			},
39
			{
40
				"featureType":"administrative",
41
				"elementType":"geometry.fill",
42
				"stylers":[{"color":"#fefefe"},{"lightness":20}]
43
			},
44
			{
45
				"featureType":"administrative",
46
				"elementType":"geometry.stroke",
47
				"stylers":[{"color":"#fefefe"},{"lightness":17},{"weight":1.2}]
48
			},
49
			{
50
				"featureType":"landscape",
51
				"elementType":"geometry",
52
				"stylers":[{"color":"#f5f5f5"},{"lightness":20}]
53
			},
54
			{
55
				"featureType":"poi",
56
				"elementType":"geometry",
57
				"stylers":[{"color":"#f5f5f5"},{"lightness":21}]
58
			},
59
			{
60
				"featureType":"poi.park",
61
				"elementType":"geometry",
62
				"stylers":[{"color":"#dedede"},{"lightness":21}]
63
			},
64
			{
65
				"featureType":"poi.park",
66
				"elementType":"geometry.fill",
67
				"stylers":[{"color":"#c2ffd7"}]
68
			},
69
			{
70
				"featureType":"road.highway",
71
				"elementType":"geometry.fill",
72
				"stylers":[{"color":"#ffffff"},{"lightness":17}]},
73
			{
74
				"featureType":"road.highway",
75
				"elementType":"geometry.stroke",
76
				"stylers":[{"color":"#ffffff"},{"lightness":29},{"weight":0.2}]},
77
			{
78
				"featureType":"road.arterial",
79
				"elementType":"geometry",
80
				"stylers":[{"color":"#ffffff"},{"lightness":18}]},
81
			{
82
				"featureType":"road.local",
83
				"elementType":"geometry",
84
				"stylers":[{"color":"#ffffff"},{"lightness":16}]},
85
			{
86
				"featureType":"transit",
87
				"elementType":"geometry",
88
				"stylers":[{"color":"#f2f2f2"},{"lightness":19}]},
89
			{
90
				"featureType":"water",
91
				"elementType":"geometry",
92
				"stylers":[{"color":"#e9e9e9"},{"lightness":17}]},
93
			{
94
				"featureType":"water",
95
				"elementType":"geometry.fill",
96
				"stylers":[{"color":"#b3d8f9"}]
97
			}
98
		]);
99
		initSlider();
100
		});
101
102
}
103
function initSlider(){
104
	$.ajax({
105
		'async': true,
106
		'type': "GET",
107
		'global': false,
108
		'dataType': 'json',
109
		'url': "core/process/aru.php",
110
		'data': {
111
			'request': "",
112
			'target': 'arrange_url',
113
			'method': 'method_target',
114
			'type' : 'pokemon_slider_init'
115
		}
116
	}).done(function(bounds){
117
		var selectorMax = new Date(bounds.max);
118
		var selectorMin = new Date(bounds.min);
119
		var maxMinus2Weeks = new Date(selectorMax.getTime() - 2 * 7 * 24 * 60 * 60 * 1000);
120
		if(selectorMin < maxMinus2Weeks){
121
			selectorMin = maxMinus2Weeks;
122
		}
123
		$("#timeSelector").dateRangeSlider({
124
			bounds:{
125
				min: new Date(bounds.min),
126
				max: new Date(bounds.max)
127
			},
128
			defaultValues:{
129
				min: selectorMin,
130
				max: selectorMax
131
			}
132
		});
133
		createHeatmap();
134
	});
135
	
136
}
137
function createHeatmap() {
138
	
139
	heatmap = new google.maps.visualization.HeatmapLayer({
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
140
		data: [],
141
		map: map
142
	});
143
144
	var gradient = [
145
		'rgba(0, 255, 255, 0)',
146
		'rgba(0, 255, 255, 1)',
147
		'rgba(0, 191, 255, 1)',
148
		'rgba(0, 127, 255, 1)',
149
		'rgba(0, 63, 255, 1)',
150
		'rgba(0, 0, 255, 1)',
151
		'rgba(0, 0, 223, 1)',
152
		'rgba(0, 0, 191, 1)',
153
		'rgba(0, 0, 159, 1)',
154
		'rgba(0, 0, 127, 1)',
155
		'rgba(63, 0, 91, 1)',
156
		'rgba(127, 0, 63, 1)',
157
		'rgba(191, 0, 31, 1)',
158
		'rgba(255, 0, 0, 1)'
159
	];
160
	heatmap.set('gradient', gradient);
161
	heatmap.setMap(map);
162
	updateHeatmap();
163
	$("#timeSelector").bind("valuesChanged",function(){updateHeatmap()});
164
}
165
166
function updateHeatmap() {
167
	var dateMin = $("#timeSelector").dateRangeSlider("min");
168
	var dateMax = $("#timeSelector").dateRangeSlider("max");
169
	
170
	$.ajax({
171
		'async': true,
172
		'type': "GET",
173
		'global': false,
174
		'dataType': 'json',
175
		'url': "core/process/aru.php",
176
		'data': {
177
			'request': "",
178
			'target': 'arrange_url',
179
			'method': 'method_target',
180
			'type' : 'pokemon_heatmap_points',
181
			'pokemon_id' : pokemon_id,
0 ignored issues
show
Bug introduced by
The variable pokemon_id seems to be never declared. If this is a global, consider adding a /** global: pokemon_id */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
182
			'start' : Math.floor(dateMin.getTime()/1000),
183
			'end' : Math.floor(dateMax.getTime()/1000)
184
		}
185
	}).done(function(points){
186
		var googlePoints = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
187
		for (var i = 0; i < points.length; i++) {
188
			googlePoints.push(new google.maps.LatLng(points[i].latitude,points[i].longitude))
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
189
		}
190
		var newPoints = new google.maps.MVCArray(googlePoints);
191
		heatmap.set('data', newPoints);
192
	});
193
}