-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
231 lines (194 loc) · 6.86 KB
/
index.html
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Spooky Streets | Boston</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js"></script>
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css" rel="stylesheet"/>
<link rel="stylesheet" href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.4.2/mapbox-gl-geocoder.css" type="text/css">
<script src='https://npmcdn.com/csv2geojson@latest/csv2geojson.js'></script>
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.4.2/mapbox-gl-geocoder.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
.mapboxgl-popup {
padding-bottom: 5px;
}
.mapboxgl-popup-close-button {
display: none;
}
.mapboxgl-popup-content {
font: 400 15px/22px 'Source Sans Pro', 'Helvetica Neue', Sans-serif;
padding: 0;
width: 250px;
}
.mapboxgl-popup-content-wrapper {
padding: 1%;
}
.mapboxgl-popup-content h3 {
/*background: rgb(27, 160, 96);*/
background: #871ba0;
text-align: center;
color: #fff;
margin: 0;
display: block;
padding: 15px;
font-weight: 700;
margin-top: -5px;
}
.mapboxgl-popup-content h4 {
margin: 0;
display: block;
padding: 10px 3px 10px 10px;
font-weight: 400;
}
.mapboxgl-container {
cursor: pointer;
}
.mapboxgl-popup-anchor-top>.mapboxgl-popup-content {
margin-top: 3px;
}
.mapboxgl-popup-anchor-top>.mapboxgl-popup-tip {
border-bottom-color: #871ba0;
}
.mapboxgl-ctrl-geocoder {
width: 315px!important;
}
</style>
</head>
<body>
<div id='map'></div>
<script>
var locationData;
var transformRequest = (url, resourceType) => {
var isMapboxRequest =
url.slice(8, 22) === "api.mapbox.com" ||
url.slice(10, 26) === "tiles.mapbox.com";
return {
url: isMapboxRequest
? url.replace("?", "?pluginName=sheetMapper&")
: url
};
};
function forwardGeocoder(query) {
var matchingFeatures = [];
for (var i = 0; i < locationData.features.length; i++) {
var feature = locationData.features[i];
if (feature.properties.Neighborhood.toLowerCase().search(query.toLowerCase()) !== -1) {
feature['place_name'] = `🎃 ${feature.properties.Name} in ${feature.properties.Neighborhood}`
feature['center'] = feature.geometry.coordinates;
feature['place_type'] = ['Community-Garden'];
matchingFeatures.push(feature);
}
}
return matchingFeatures;
};
mapboxgl.accessToken = 'pk.eyJ1IjoibmV3dXJiYW5tZWNocyIsImEiOiJjbG54a2I1anYwaDNpMmltazBhNjFmMTZlIn0.LMwTo9mgHziYKD6oLeOhdA';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/newurbanmechs/clnvxuth2002g01pbfkai0whb',
center: [-71.0661, 42.3395],
zoom: 11,
hash: true,
attributionControl: false,
transformRequest: transformRequest
});
//map.showCollisionBoxes = true;
map.addControl(new mapboxgl.AttributionControl({
customAttribution: ""
}));
map.scrollZoom.disable();
map.addControl(new mapboxgl.NavigationControl(), 'bottom-right');
map.loadImage('ghost.png', function(error, image) {
map.addImage('ghost-marker', image);
});
map.loadImage('icons8-pumpkin-48.png', function(error, image) {
map.addImage('custom-marker', image);
});
$(document).ready(function () {
$.ajax({
type: "GET",
url: 'https://docs.google.com/spreadsheets/d/1FsCUcfhK0xHtekDlSRMQKrvWWTTP8u81lpJdViLwXPY/gviz/tq?tqx=out:csv&sheet=Sheet2',
dataType: "text",
success: function (csvData) {
makeGeoJSON(csvData);
}
});
function makeGeoJSON(csvData) {
csv2geojson.csv2geojson(csvData, {
latfield: 'Latitude',
lonfield: 'Longitude',
delimiter: ','
}, function (err, data) {
locationData = data;
map.on('load', function () {
map.loadImage('icons8-pumpkin-48.png', function(error, image) {
//map.addImage('custom-marker', image);
map.addLayer({
'id': 'csvData',
'type': 'symbol',
'source': {
'type': 'geojson',
'data': data
},
'layout': {
'icon-image': [
'match',
['get', 'type'],
'weekend', 'ghost-marker',
'custom-marker'
]
}
});
})
map.on('click', 'csvData', function (e) {
var coordinates = e.features[0].geometry.coordinates.slice();
var description = '<h3>' + e.features[0].properties.Name + '</h3>' + '<h4>' + '<strong>' + 'Address: ' + '</strong>' + '<a target="_blank" rel="noopener noreferrer" href="' + e.features[0].properties.Link + '">' + e.features[0].properties.Address + '</a></h4>'
+ '<h4>' + '<strong>' + 'Time: ' + '</strong>' + e.features[0].properties.Time + '</h4>';
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
map.on('mouseenter', 'csvData', function () {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'places', function () {
map.getCanvas().style.cursor = '';
});
map.addControl(
new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl,
bbox: [-71.190336,42.240688,-70.985076,42.393463],
proximity: {
longitude: -71.080463,
latitude: 42.330631
},
localGeocoder: forwardGeocoder,
placeholder: 'Search by neighborhood or address'
}),'top-left'
);
});
});
};
});
</script>
</body>
</html>