Skip to content

Commit c293d83

Browse files
authoredJan 30, 2018
Merge pull request github#631 from denmch/patch-1
Don't try to fetch map data unless #map is present
2 parents cfbc69f + 2759535 commit c293d83

File tree

1 file changed

+68
-68
lines changed

1 file changed

+68
-68
lines changed
 

‎assets/js/mapsAPI.js

+68-68
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
---
2-
---
31
function initialize() {
4-
$.getJSON(
5-
'https://githubschool.github.io/open-enrollment-classes-introduction-to-github/createMap.topojson',
6-
function (data) {
7-
var mapSize = new google.maps.Size(256, 256), // original size, fallback for space invador images
8-
scaledSize = new google.maps.Size(20, 20), // size on map, fallback for space invador images
9-
anchor = new google.maps.Point(0, 32), // start point
10-
map = new google.maps.Map(document.getElementById('map'), {
11-
zoom: 2,
12-
minZoom: 2,
13-
center: new google.maps.LatLng(10, 15),
14-
mapTypeId: 'terrain',
15-
//disableDefaultUI: true,
16-
mapTypeControl: false,
17-
panControl: false,
18-
//scaleControl: false,
19-
scrollwheel: false,
20-
streetViewControl: false,
21-
//zoomControl: false,
22-
//draggable: false,
23-
styles: [
24-
{
25-
featureType: 'administrative',
26-
elementType: 'geometry',
27-
stylers: [{visibility: 'off'}]
28-
},
29-
{
30-
featureType: 'administrative.country',
31-
stylers: [{visibility: 'off'}]
32-
},
33-
{
34-
featureType: 'water',
35-
elementType: 'labels',
36-
stylers: [{visibility: 'off'}]
37-
},
38-
{
39-
featureType: 'administrative',
40-
elementType: 'labels',
41-
stylers: [{visibility: 'off'}]
42-
}
43-
]
44-
}),
45-
markers = data.features.map(function (coords) {
46-
var coordinates = coords.geometry.coordinates,
47-
username = coords.properties.username;
2+
if ($("#map").length) {
3+
$.getJSON(
4+
'https://githubschool.github.io/open-enrollment-classes-introduction-to-github/createMap.topojson',
5+
function (data) {
6+
var mapSize = new google.maps.Size(256, 256), // original size, fallback for space invador images
7+
scaledSize = new google.maps.Size(20, 20), // size on map, fallback for space invador images
8+
anchor = new google.maps.Point(0, 32), // start point
9+
map = new google.maps.Map(document.getElementById('map'), {
10+
zoom: 2,
11+
minZoom: 2,
12+
center: new google.maps.LatLng(10, 15),
13+
mapTypeId: 'terrain',
14+
//disableDefaultUI: true,
15+
mapTypeControl: false,
16+
panControl: false,
17+
//scaleControl: false,
18+
scrollwheel: false,
19+
streetViewControl: false,
20+
//zoomControl: false,
21+
//draggable: false,
22+
styles: [
23+
{
24+
featureType: 'administrative',
25+
elementType: 'geometry',
26+
stylers: [{visibility: 'off'}]
27+
},
28+
{
29+
featureType: 'administrative.country',
30+
stylers: [{visibility: 'off'}]
31+
},
32+
{
33+
featureType: 'water',
34+
elementType: 'labels',
35+
stylers: [{visibility: 'off'}]
36+
},
37+
{
38+
featureType: 'administrative',
39+
elementType: 'labels',
40+
stylers: [{visibility: 'off'}]
41+
}
42+
]
43+
}),
44+
markers = data.features.map(function (coords) {
45+
var coordinates = coords.geometry.coordinates,
46+
username = coords.properties.username;
4847

49-
return new google.maps.Marker({
50-
position: new google.maps.LatLng(
51-
coordinates[1],
52-
coordinates[0]
53-
),
54-
map: map,
55-
title: username,
56-
icon: {
57-
url: 'https://github.com/' + username + '.png?size=20',
58-
size: mapSize,
59-
scaledSize: scaledSize,
60-
anchor: anchor
61-
}
62-
});
63-
});
48+
return new google.maps.Marker({
49+
position: new google.maps.LatLng(
50+
coordinates[1],
51+
coordinates[0]
52+
),
53+
map: map,
54+
title: username,
55+
icon: {
56+
url: 'https://github.com/' + username + '.png?size=20',
57+
size: mapSize,
58+
scaledSize: scaledSize,
59+
anchor: anchor
60+
}
61+
});
62+
});
6463

65-
new MarkerClusterer(map, markers, {
66-
imagePath: '{{site.baseurl}}/images/cluster/m',
67-
averageCenter: true,
68-
minimumClusterSize: 42
69-
});
70-
}
71-
);
64+
new MarkerClusterer(map, markers, {
65+
imagePath: '{{site.baseurl}}/images/cluster/m',
66+
averageCenter: true,
67+
minimumClusterSize: 42
68+
});
69+
}
70+
);
71+
}
7272
}

0 commit comments

Comments
 (0)
Please sign in to comment.