Passed
Pull Request — master (#250)
by
unknown
14:11 queued 05:31
created

pokestops.maps.js ➔ ... ➔ $.done   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 16
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
B pokestops.maps.js ➔ ... ➔ navigator.geolocation.getCurrentPosition 0 12 5
1
/** global: google */
2
/** global: navigator */
3
4
function initMap()
5
{
6
7
	var locations;
8
9
	$.ajax({
10
		'async': true,
11
		'type': "GET",
12
		'global': false,
13
		'dataType': 'text',
14
		'url': "core/process/aru.php",
15
		'data': { 'request': "", 'target': 'arrange_url', 'method': 'method_target', 'type' : 'pokestop' },
16
		'success': function (data) {
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
		 
25
				// Convert return to JSON Array
26
			
27
				locations = JSON.parse(data);
28
				var arr = [];
29
			
30
				for (i = 0; i < locations.length; i++) {
31
					arr.push(JSON.parse(locations[i]));
32
				}
33
				
34
				var map = new google.maps.Map(document.getElementById('map'), {
35
					center: {
36
						lat: latitude,
37
						lng: longitude
38
					},
39
					zoom: zoom_level,
40
					zoomControl: true,
41
					scaleControl: false,
42
					scrollwheel: true,
43
					disableDoubleClickZoom: false,
44
					streetViewControl: false,
45
					mapTypeControlOptions: {
46
						mapTypeIds: [
47
							google.maps.MapTypeId.ROADMAP,
48
							'pogo_style',
49
							'dark_style',
50
						]
51
					}
52
				});
53
			
54
				$.getJSON( 'core/json/pogostyle.json', function( data ) {
55
					var styledMap_pogo = new google.maps.StyledMapType(data, {name: 'PoGo'});
56
					map.mapTypes.set('pogo_style', styledMap_pogo);
57
				});
58
				$.getJSON( 'core/json/darkstyle.json', function( data ) {
59
					var styledMap_dark = new google.maps.StyledMapType(data, {name: 'Dark'});
60
					map.mapTypes.set('dark_style', styledMap_dark);
61
				});
62
				$.getJSON( 'core/json/defaultstyle.json', function( data ) {
63
					map.set('styles', data);
64
				});
65
66
				$.ajax({
67
					'async': true,
68
					'type': "GET",
69
					'global': false,
70
					'dataType': 'json',
71
					'url': "core/process/aru.php",
72
					'data': {
73
						'request': "",
74
						'target': 'arrange_url',
75
						'method': 'method_target',
76
						'type': 'maps_localization_coordinates'
77
					}
78
				}).done(function(coordinates) {
79
					if (navigator.geolocation) {
80
						navigator.geolocation.getCurrentPosition(function(position) {
81
							var pos = {
82
								lat: position.coords.latitude,
83
								lng: position.coords.longitude
84
							};
85
86
							if (position.coords.latitude <= coordinates.max_latitude && position.coords.latitude >= coordinates.min_latitude) {
87
								if (position.coords.longitude <= coordinates.max_longitude && position.coords.longitude >= coordinates.min_longitude) {
88
									map.setCenter(pos);
89
								}
90
							}
91
						});
92
					}
93
				});
94
95
				var infowindow = new google.maps.InfoWindow();
96
			
97
				var marker, i;
98
		
99
				for (i = 0; i < arr.length; i++) {
100
					marker = new google.maps.Marker({
101
						position: new google.maps.LatLng(arr[i][2], arr[i][3]),
102
						map: map,
103
						icon: 'core/img/'+arr[i][1]
104
					});
105
		
106
					google.maps.event.addListener(marker, 'click', (function (marker, i) {
107
							return function () {
108
								infowindow.setContent(arr[i][0]);
109
								infowindow.open(map, marker);
110
							}
111
					})(marker, i));
112
				}
113
			
114
					
115
			});
116
		}
117
	});
118
}
119