-
Notifications
You must be signed in to change notification settings - Fork 0
/
tanner.html
398 lines (371 loc) · 13.8 KB
/
tanner.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html>
<head>
<title>National Parks Gallery</title>
<!-- CSS Files -->
<link rel="stylesheet" type="text/css" href="https://mappingforyou.eu/parkgallery/node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://mappingforyou.eu/parkgallery/node_modules/leaflet/dist/leaflet.css">
<link rel="stylesheet" type="text/css" href="https://mappingforyou.eu/parkgallery/js/owl.carousel/assets/owl.carousel.css">
<link rel="stylesheet" type="text/css" href="https://mappingforyou.eu/parkgallery/js/lightbox/css/lightbox.css">
<style>
html, body {
height : 100%;
width : 100%;
margin : 0;
padding : 0;}
#map { height : 500px; /* make dynamic */
width : 100%;}
#sidebar { background-color : #132839;
color : #ffffff; text-align : center;}
#sidebar-content { padding : 8px;}
#slider { background : #000000;A}
#apptitle {
color : green; }
#sticky {
position : absolute;
bottom : 0;
left : 0;
width : 100%;
text-align : center;
background-color : black;
padding : 5px;}
.instructions {
color : #EDD8A2;
padding : 8px 15px;}
.thumbnail {
position: relative;
width: 200px;
height: 140px;
overflow: hidden;
margin : 0;
padding : 0;}
.thumbnail:hover {
cursor : pointer;}
.thumbnail img {
position: absolute;
left: 50%;
top: 50%;
height: 100%;
width: 100%;
-webkit-transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);}
.parkname-title {
z-index : 9999;
position : absolute;
width : 100%;
top : 0;
left : 0;
background-color : #000000;
opacity : 0.8;}
.parkname-title h2 {
font : 14px sans-serif;
font-weight : 250;
padding : 5px;
margin : 0;
color : #fff;}
.nopadding {
padding: 0 !important;
margin: 0 !important;}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-sm-6 nopadding">
<div id="map"> </div>
</div> <!-- end #map -->
<div id="sidebar" class="col-md-4 col-sm-6 nopadding">
<div id="sidebar-content">
<h2 id="apptitle">National Park Image Gallery</h2>
<p class="intro">The National Park Image Gallery showcases <a href="http://flickr.com" target="_blank">Flickr</a> images from every National Park in the United States. This application was created in honor of <a href="http://www.nps.gov/npweek/" target="_blank">National Park Week</a>.</p>
<h4>
©
<a class="brand" href="http://tannergeo.com" target="_blank">
<span class="tanner">Tanner</span><span class="dev">Geo</span>
</a>
</h4>
<p class="instructions">Zoom and pan around the map to discover National Parks. Use the bottom gallery slider to view user images.</p>
<hr>
<p id="parkslist"></p>
</div>
<div id="sticky">
<span>
<-<- Slide Gallery To View More Images ->->
</span>
</div>
</div>
</div> <!-- end row -->
<div class="row">
<div id="slider" class="col-md-12 nopadding">
</div> <!-- end slider -->
</div> <!-- end row -->
</div> <!-- end container-fluid -->
<!-- JavaScript Files -->
<script type="text/javascript" src="https://mappingforyou.eu/parkgallery/data/nps_boundary_simplified.js"></script>
<script type="text/javascript" src="https://mappingforyou.eu/parkgallery/node_modules/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="https://mappingforyou.eu/parkgallery/node_modules/leaflet/dist/leaflet.js"></script>
<script type="text/javascript" src="https://mappingforyou.eu/parkgallery/node_modules/turf/turf.min.js"></script>
<script type="text/javascript" src="https://mappingforyou.eu/parkgallery/js/owl.carousel/owl.carousel.min.js"></script>
<script type="text/javascript" src="https://mappingforyou.eu/parkgallery/js/lightbox/js/lightbox.min.js"></script>
<!-- End JS Files -->
<script>
// Author: TannerGeo
var map, // main appliation map
basemap; // leaflet basemap layer
var np_boundaries, // raw geojson
np_geo; // leaflet geojson layer
var queue = []; // placeholder if need for queue and digest management
var cached = {}; // cache park images to limit api calls
var current_gallery = {}; // images and details in current extent
var current_req_length = 0;
var queue_length = 0;
// Application Configuraton Object
var app_config = {
basemap : "http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png",
basemapAttribution : "© <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>"
};
// Flickr Configuration
var flickr_config = {
maxNumImages : 4, // max number of images to request for each park
url : "https://api.flickr.com/services/rest",
key : "5ca26e8c98a49ec95a0fa4dfaa7623d8"
};
// create map and add tiled basemap
map = L.map('map').setView([40.12, -98.57], 4);
basemap = L.tileLayer(app_config.basemap, {
attribution: app_config.basemapAttribution
});
basemap.addTo(map);
// setup map events
map.on('moveend', function (e) {
getImages();
});
// filter geojson to only parks
np_boundaries.features = $.map(np_boundaries.features, function (val, i) {
if(val.properties['UNIT_TYPE'] == 'National Park') {
return val;
}
});
/* GEOJSON FUNCTIONS */
function style(feature) {
return {
weight : 1,
color : 'green',
fillColor : 'green'
}
}
function highlightStyle() {
return {
weight : 4,
color : 'red',
fillColor : 'red'
}
}
/********************/
/* GEOJSON LAYER */
np_geo = L.geoJson(np_boundaries, {
style : style,
onEachFeature : function (f, l) {
var pn = f.properties['UNIT_NAME'] + " National Park";
l.bindPopup(
"<h3>" + pn + "</h3>" +
"<a href='http://en.wikipedia.org/wiki/" + pn.split(" ").join("_") +
"' target='_blank'>Learn more about this National Park</a>"
, {
autoPan : false
});
}
});
np_geo.addTo(map);
getImages(); // make inital call once
function highlightPark(park) {
var park = park;
$.each(np_geo.getLayers(), function (idx, layer) {
if (layer.feature.properties['UNIT_NAME'] == park) {
layer.setStyle(highlightStyle());
layer.openPopup();
/*
var centroid = turf.centroid(layer.feature);
var latlng = L.latLng([centroid.geometry.coordinates[1], centroid.geometry.coordinates[0]]);
map.panTo(latlng);
*/
} else {
layer.setStyle(style());
}
})
}
/****************/
/* APPLICATION FLICKR FUNCTIONS */
function getImages() {
// get current extent
var mapBounds = map.getBounds();
var centroid;
// clear current gallery
current_gallery = {};
current_req_length = 0;
queue_length = 0;
// calculate number of matches for queue
$.each(np_geo.getLayers(), function (i, l) {
// get centroid of layer
centroid = turf.centroid(l.feature);
var latlng = L.latLng([centroid.geometry.coordinates[1], centroid.geometry.coordinates[0]]);
if(mapBounds.contains(latlng)) {
current_req_length += 1;
}
});
// Make flickr calls
$.each(np_geo.getLayers(), function (i, l) {
// get centroid of layer
centroid = turf.centroid(l.feature);
var latlng = L.latLng([centroid.geometry.coordinates[1], centroid.geometry.coordinates[0]]);
if(mapBounds.contains(latlng)) {
if(l.feature.properties['UNIT_NAME'] in cached) {
// push existing parks with images
current_gallery[l.feature.properties['UNIT_NAME']] = cached[l.feature.properties['UNIT_NAME']];
queue_length += 1;
if(queue_length == current_req_length) {
buildHtml(l.feature.properties['UNIT_NAME']);
}
} else {
callFlickr(l.feature, l.feature.properties['UNIT_NAME']);
}
}
});
}
function callFlickr(f, parkName) {
var bbox = turf.extent(f.geometry).join(",");
var tags = parkName.split(" ");
tags.push("park");
tags.push("national");
tags = tags.join(",");
$.ajax({
url : flickr_config.url,
//jsonp : "jsonFlickrApi",
dataType : 'json',
data : {
api_key : flickr_config.key,
tags : tags,
bbox : bbox,
format : 'json',
method : 'flickr.photos.search',
per_page : flickr_config.maxNumImages,
nojsoncallback : 1
}
}).done(function (resp) {
queue_length += 1;
if(resp.stat !== "ok") {
if(queue_length == current_req_length) {
buildHtml(parkName)
}
return;
}
var photos = [];
$.each(resp.photos.photo, function (i, v) {
photos.push("https://farm" + v.farm + ".staticflickr.com/" + v.server + "/" + v.id + "_" + v.secret + "_n.jpg");
});
// add to cache
cached[parkName] = photos;
current_gallery[parkName] = photos;
if(queue_length == current_req_length) {
buildHtml(parkName);
}
});
}
// builds html for carousel
function buildHtml() {
var gallery_items;
var gallery_container = $("<div />", {
id : 'owl-slider',
class : 'own-carousel'
});
var list = [];
$.each(current_gallery, function (park, photos) {
list.push("<a class='park-item' href='' target='_blank'>" + park + "</a>");
$.each(photos, function (idx, photo) {
var div = $("<div />", {
class : 'thumbnail'
});
div.on('mouseover', function (e) {
highlightPark(park);
});
div.on('mouseout', function (e) {
$.each(np_geo.getLayers(), function (i, l) {
l.setStyle(style());
});
});
var title = $("<span />", {
html : "<h2><span class='glyphicon glyphicon-globe inverse'></span> " + park + " National Park</h2>",
class : 'parkname-title'
});
var fullPhoto = photo.replace("n.jpg", "b.jpg");
var link = $("<a />", {
"data-lightbox" : "image-" + idx,
"data-title" : park + " (courtesy of Flickr)",
href : fullPhoto
});
var img = $("<img />", {
src : photo
});
link.append(img);
div.append(link);
div.append(title);
gallery_container.append(div);
});
});
list = list.join(' | ');
$("#parkslist").html(list);
$(".park-item").on('click', function (e) {
e.preventDefault();
highlightPark(e.target.text);
})
$("#slider").empty();
$("#slider").append(gallery_container);
$("#owl-slider").owlCarousel({
margin : 10,
autoWidth : true,
stagePadding : 50
});
}
// adjust map height to change in page size
// run after DOM has loaded
$(function () {
var $map = $("#map");
var $sidebar = $("#sidebar")
var height;
$(window).on('resize', function () {
adjustMapHeight();
});
function adjustMapHeight() {
height = $(window).height() - 140;
$map.height(height);
$sidebar.height(height);
}
adjustMapHeight();
});
// adjust map height to change in page size
// run after DOM has loaded
$(function () {
var $map = $("#map");
var $sidebar = $("#sidebar")
var height;
$(window).on('resize', function () {
adjustMapHeight();
});
function adjustMapHeight() {
height = $(window).height() - 140;
$map.height(height);
$sidebar.height(height);
}
adjustMapHeight();
});
//// original
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-58675189-6', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>