-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
109 lines (92 loc) · 3.33 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var tiyIcon = L.icon({
iconUrl: 'iron-yard-logo.svg',
iconSize: [50, 50],
iconAnchor: [25, 50],
popupAnchor: [0, -50]
});
var trainIcon = L.AwesomeMarkers.icon({
icon: 'fa-bus',
prefix: 'fa',
markerColor: 'darkpurple',
iconColor: 'white'
});
function createIcon(image, count) {
var height = Math.round(81 / 3) * count;
var width = Math.round(59 / 3) * count;
var icon = L.icon({
iconUrl: image,
iconSize: [width, height],
iconAnchor: [width / 2, height],
popupAnchor: [0, -1 * height]
});
return icon;
}
var map = L.map('map', {
center: new L.LatLng(33.7518732,-84.3914068),
zoom: 15
});
new L.TileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '<a href="http://proximityviz.com/">Proximity Viz</a> | © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
}).addTo(map);
var MARTALayer = new L.geoJson(martaStations, {
onEachFeature: function(feature, layer) {layer.bindPopup(feature.properties.Description)},
pointToLayer: function(feature, latlng) {
return L.marker(latlng, {icon: trainIcon});
}
}).addTo(map);
window.onload = function() { init() };
var eatingLayer = L.geoJson(null);
var drinkingLayer = L.geoJson(null);
var spreadsheet = 'https://docs.google.com/spreadsheet/pub?key=1BE4-odCRrcTA1WOFFWsWLscihNzvS5HVYoYjMr7uIS0&output=html';
function init() {
Tabletop.init( { key: spreadsheet,
callback: createMarkers,
simpleSheet: true } )
}
function createMarkers(data, tabletop) {
var pattLat = /,.*/;
var pattLon = /.*,+/;
for (var i = 0; i < data.length; i++) {
var point = data[i];
var coordinates = point.coordinates;
var latitude = coordinates.replace(pattLat, "");
var longitude = coordinates.replace(pattLon, "");
var popupContent = point.place + "<br>" + point.address + "<br>Votes: " + point.count;
// this code will need to go in the if statement
if (point.type == "Eating") {
var icon = createIcon('food.png', point.count);
var marker = L.marker(new L.LatLng(latitude, longitude), {icon: icon});
marker.bindPopup(popupContent);
marker.addTo(eatingLayer);
} else if (point.type == "Drinking") {
var icon = createIcon('beer.png', point.count);
var marker = L.marker(new L.LatLng(latitude, longitude), {icon: icon});
marker.bindPopup(popupContent);
marker.addTo(drinkingLayer);
};
};
eatingLayer.addTo(map);
drinkingLayer.addTo(map);
var overlayMaps = {
"<i class='fa fa-cutlery' style='color:#0069A1'></i> Eating": eatingLayer,
"<i class='fa fa-beer' style='color:#8E9134'></i> Drinking": drinkingLayer,
"<i class='fa fa-bus' style='color:#593869'></i> Train Stations": MARTALayer
};
L.control.layers(null, overlayMaps, {
collapsed: false
}).addTo(map);
// TIY marker
L.marker(new L.LatLng(33.7518732,-84.3914068), {icon: tiyIcon})
.bindPopup("The Iron Yard")
.addTo(map);
// GitHub link
var info = L.control({
position: 'bottomleft'
});
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this._div.innerHTML = '<a href="https://github.com/mollietaylor/tiy-lunch" target="_blank">Fork me on GitHub!</a>';
return this._div;
};
info.addTo(map);
}