Passed
Pull Request — master (#312)
by
unknown
02:10
created

pokestops.maps.js ➔ ... ➔ $(ꞌ#lureSelectorꞌ).click   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
/** global: google */
2
/** global: navigator */
3
4
var markersWithoutLure = [];
5
var map;
6
7
function initMap()
8
{
9
	$.ajax({
10
		'async': true,
11
		'type': "GET",
12
		'global': false,
13
		'dataType': 'json',
14
		'url': "core/process/aru.php",
15
		'data': { 'request': "", 'target': 'arrange_url', 'method': 'method_target', 'type' : 'pokestop' },
16
		'success': function (pokestops) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
17
			
18
		
19
			$.getJSON("core/json/variables.json", function (variables) {
20
				var latitude = Number(variables['system']['map_center_lat']);
21
				var longitude = Number(variables['system']['map_center_long']);
22
				var zoom_level = Number(variables['system']['zoom_level']);
23
24
				map = new google.maps.Map(document.getElementById('map'), {
25
					center: {
26
						lat: latitude,
27
						lng: longitude
28
					},
29
					zoom: zoom_level,
30
					zoomControl: true,
31
					scaleControl: false,
32
					scrollwheel: true,
33
					disableDoubleClickZoom: false,
34
					streetViewControl: false,
35
					mapTypeControlOptions: {
36
						mapTypeIds: [
37
							google.maps.MapTypeId.ROADMAP,
38
							'pogo_style',
39
							'dark_style',
40
						]
41
					}
42
				});
43
			
44
				$.getJSON( 'core/json/pogostyle.json', function( data ) {
45
					var styledMap_pogo = new google.maps.StyledMapType(data, {name: 'PoGo'});
46
					map.mapTypes.set('pogo_style', styledMap_pogo);
47
				});
48
				$.getJSON( 'core/json/darkstyle.json', function( data ) {
49
					var styledMap_dark = new google.maps.StyledMapType(data, {name: 'Dark'});
50
					map.mapTypes.set('dark_style', styledMap_dark);
51
				});
52
				$.getJSON( 'core/json/defaultstyle.json', function( data ) {
53
					map.set('styles', data);
54
				});
55
56
				$.ajax({
57
					'async': true,
58
					'type': "GET",
59
					'global': false,
60
					'dataType': 'json',
61
					'url': "core/process/aru.php",
62
					'data': {
63
						'request': "",
64
						'target': 'arrange_url',
65
						'method': 'method_target',
66
						'type': 'maps_localization_coordinates'
67
					}
68
				}).done(function(coordinates) {
69
					if (navigator.geolocation) {
70
						navigator.geolocation.getCurrentPosition(function(position) {
71
							var pos = {
72
								lat: position.coords.latitude,
73
								lng: position.coords.longitude
74
							};
75
76
							if (position.coords.latitude <= coordinates.max_latitude && position.coords.latitude >= coordinates.min_latitude) {
77
								if (position.coords.longitude <= coordinates.max_longitude && position.coords.longitude >= coordinates.min_longitude) {
78
									map.setCenter(pos);
79
								}
80
							}
81
						});
82
					}
83
				});
84
85
				var infowindow = new google.maps.InfoWindow();
86
			
87
				var marker, i;
88
		
89
				for (i = 0; i < pokestops.length; i++) {
90
					marker = new google.maps.Marker({
91
						position: new google.maps.LatLng(pokestops[i][2], pokestops[i][3]),
92
						map: map,
93
						icon: 'core/img/'+pokestops[i][1],
94
						zIndex: 0 + pokestops[i][4]
95
					});
96
		
97
					google.maps.event.addListener(marker, 'click', (function (marker, i) {
98
							return function () {
99
								infowindow.setContent(pokestops[i][0]);
100
								infowindow.open(map, marker);
101
							}
102
					})(marker, i));
103
					
104
					if (!pokestops[i][4]) {
105
							markersWithoutLure.push(marker);
106
					}			
107
				}	
108
			});
109
			initSelector();
110
		}	
111
	});
112
 }
113
								
114
function initSelector(){
115
 	$('#pokestopSelector').click(function(){
116
		$('#pokestopSelector').addClass('active');
117
		$('#lureSelector').removeClass('active');
118
		updateMap(false);
119
 	});
120
 	$('#lureSelector').click(function(){
121
		$('#lureSelector').addClass('active');
122
		$('#pokestopSelector').removeClass('active');
123
		updateMap(true);
124
 	});
125
}
126
127
function updateMap(onlyLured) {
128
 	if (onlyLured) {
129
		for (var i = 0; i < markersWithoutLure.length; i++) {
130
			markersWithoutLure[i].setMap(null);
131
		}
132
 	}
133
 	else {
134
		for (var i = 0; i < markersWithoutLure.length; i++) {
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 129. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
135
			markersWithoutLure[i].setMap(map);
136
		}
137
 	}
138
}
139