-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
72 lines (59 loc) · 2.67 KB
/
map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*global $*/
var map = (function () {
"use strict";
var pub = {};
var mapData, map, landmarks, restaurant, campsite;
/* Setup function is the main function of the script, it reads the data from the POI.geoJSON and draws a map */
pub.setup = function () {
$.ajax ({
type: "GET",
url: "./Resources/POI.geojson",
dataType: 'json',
cache: false,
success: function(data) {
mapData = data;
map = L.map('map').setView([-45.910, 170.495], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, '
}).addTo(map);
landmarks = L.geoJSON(mapData, {
filter: function(feature, layer) {
return (feature.properties.type === "landmark");
},
onEachFeature: function(feature, layer) {
layer.bindPopup('<strong>' + feature.properties.name + '</strong>' + '<br>' + feature.properties.type);
},
}).addTo(map);
restaurant = L.geoJSON(mapData, {
filter: function(feature, layer) {
return (feature.properties.type === "restaurant");
},
onEachFeature: function(feature, layer) {
layer.bindPopup('<strong>' + feature.properties.name + '</strong>' + '<br>' + feature.properties.type);
},
}).addTo(map);
campsite = L.geoJSON(mapData, {
filter: function(feature, layer) {
return (feature.properties.type === "campsite");
},
onEachFeature: function(feature, layer) {
layer.bindPopup('<strong>' + feature.properties.name + '</strong>' + '<br>' + feature.properties.type);
},
}).addTo(map);
var overlays = {
"Landmarks": landmarks,
"Restaurant": restaurant,
"Campsite": campsite
};
L.control.layers(null, overlays).addTo(map);
},
error: function() {
$("#map").html("Sorry, something has gone wrong on our end.");
}
});
}
return pub;
}());
$(document).ready(map.setup);