Failed Conditions
Pull Request — master (#275)
by Ramiro
03:09
created

SON(ꞌcore/json/darkstyle.jsonꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
/** global: google */
2
/** global: navigator */
3
/** global: MarkerClusterer */
4
5
function initMap()
6
{
7
	var pokestopOpts = {
8
		'type': "GET",
9
		'global': false,
10
		'dataType': 'json',
11
		'url': "core/process/aru.php",
12
		'data': { 'request': "", 'target': 'arrange_url', 'method': 'method_target', 'type' : 'pokestop' }
13
	};
14
	var geoOpts = {
15
		'type': "GET",
16
		'global': false,
17
		'dataType': 'json',
18
		'url': "core/process/aru.php",
19
		'data': {
20
			'request': "",
21
			'target': 'arrange_url',
22
			'method': 'method_target',
23
			'type': 'maps_localization_coordinates'
24
		}
25
	}
26
	$.when($.ajax(pokestopOpts), $.ajax(geoOpts)).then(function (response1, response2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
27
		var pokestops = response1[0];
28
		var coordinates = response2[0];
29
		$.getJSON("core/json/variables.json", function (variables) {
30
			var latitude = Number(variables['system']['map_center_lat']);
31
			var longitude = Number(variables['system']['map_center_long']);
32
			var zoom_level = Number(variables['system']['zoom_level']);
33
			var cluster = variables.system.cluster_stops;
34
35
			var map = new google.maps.Map(document.getElementById('map'), {
36
				center: {
37
					lat: latitude,
38
					lng: longitude
39
				},
40
				zoom: zoom_level,
41
				zoomControl: true,
42
				scaleControl: false,
43
				scrollwheel: true,
44
				disableDoubleClickZoom: false,
45
				streetViewControl: false,
46
				mapTypeControlOptions: {
47
					mapTypeIds: [
48
						google.maps.MapTypeId.ROADMAP,
49
						'pogo_style',
50
						'dark_style',
51
					]
52
				}
53
			});
54
		
55
			$.getJSON( 'core/json/pogostyle.json', function( data ) {
56
				var styledMap_pogo = new google.maps.StyledMapType(data, {name: 'PoGo'});
57
				map.mapTypes.set('pogo_style', styledMap_pogo);
58
			});
59
			$.getJSON( 'core/json/darkstyle.json', function( data ) {
60
				var styledMap_dark = new google.maps.StyledMapType(data, {name: 'Dark'});
61
				map.mapTypes.set('dark_style', styledMap_dark);
62
			});
63
			$.getJSON( 'core/json/defaultstyle.json', function( data ) {
64
				map.set('styles', data);
65
			});
66
67
			if (navigator.geolocation) {
68
				navigator.geolocation.getCurrentPosition(function(position) {
69
					var pos = {
70
						lat: position.coords.latitude,
71
						lng: position.coords.longitude
72
					};
73
74
					if (position.coords.latitude <= coordinates.max_latitude && position.coords.latitude >= coordinates.min_latitude) {
75
						if (position.coords.longitude <= coordinates.max_longitude && position.coords.longitude >= coordinates.min_longitude) {
76
							map.setCenter(pos);
77
						}
78
					}
79
				});
80
			}
81
82
			var infowindow = new google.maps.InfoWindow();
83
		
84
			var markers = [];
85
	
86
			for (var i = 0; i < pokestops.length; i++) {
87
				var marker = new google.maps.Marker({
88
					position: new google.maps.LatLng(pokestops[i][2], pokestops[i][3]),
89
					icon: 'core/img/'+pokestops[i][1]
90
				});
91
	
92
				google.maps.event.addListener(marker, 'click', (function (marker, i) {
93
						return function () {
94
							infowindow.setContent(pokestops[i][0]);
95
							infowindow.open(map, marker);
96
						}
97
				})(marker, i));
98
				if (pokestops[i][1].lastIndexOf('lured') !== -1) {
99
					marker.setMap(map);
100
					marker.setAnimation(google.maps.Animation.BOUNCE);
101
				} else if (!cluster) {
102
					marker.setMap(map);
103
				} else {					
104
					markers.push(marker);
105
				}
106
			}
107
			
108
			if (cluster) {
109
				var clusterOptions = {
110
					gridSize: cluster.grid || 80,
111
					minimumClusterSize: cluster.minCluster || 4,
112
					cssClass: 'pokeStopCluster'
113
				}
114
				var markerCluster = new MarkerClusterer(map, [], clusterOptions);			
115
				markerCluster.addMarkers(markers);
116
			}
117
		});
118
	});
119
}
120