forked from chef-cft/national-parks-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
red-index.html
96 lines (78 loc) · 3.38 KB
/
red-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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Map of National Parks</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
<script src="https://code.jquery.com/jquery-2.0.0.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<style type="text/css">
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
font-family: 'oswald';
}
.leaflet-container .leaflet-control-zoom {
margin-left: 13px;
margin-top: 70px;
}
#map {
z-index: 1;
}
#title {
z-index: 2;
position: absolute;
left: 10px;
}
</style>
</head>
<body>
<h1 id="title">U.S. National Parks</h1>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
<script type="text/coffeescript" src="scripts/sprite.coffee"></script>
<script type="text/coffeescript" src "script.coffee"></script>
<script>
center = new L.LatLng(39.82, -98.57);
zoom = 5;
var map = L.map('map').setView(center, zoom);
var markerLayerGroup = L.layerGroup().addTo(map);
L.tileLayer('https://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey=816f897a456b4595a09bf8e1d42cfa0b', {
maxZoom: 18,
attribution: 'Maps © <a href="http://www.thunderforest.com">Thunderforest</a>, Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
function getPins(e) {
bounds = map.getBounds();
url = "ws/parks/within?lat1=" +
bounds.getNorthEast().lat + "&lon1=" + bounds.getNorthEast().lng +
"&lat2=" + bounds.getSouthWest().lat + "&lon2=" + bounds.getSouthWest().lng;
$.get(url, pinTheMap, "json")
}
Number.prototype.toCurrencyString = function () {
return "$" + Math.floor(this).toLocaleString() + (this % 1).toFixed(2).toLocaleString().replace(/^0/, '');
}
function pinTheMap(data) {
//clear the current pins
map.removeLayer(markerLayerGroup);
//add the new pins
var markerArray = new Array(data.length)
for (var i = 0; i < data.length; i++) {
nationalPark = data[i];
var popupInformation = "<b>" + nationalPark.locationName + "</b></br>" +
nationalPark.address + "</br>" +
nationalPark.city + ", " + nationalPark.state + "</br>" +
nationalPark.zipCode + "</br>";
markerArray[i] = L.marker(
[nationalPark.location.coordinates[1], nationalPark.location.coordinates[0]], { icon: L.icon({ iconUrl: 'images/redicon.png', iconAnchor: [12.5,40]}) }).bindPopup(popupInformation);
}
markerLayerGroup = L.layerGroup(markerArray).addTo(map);
}
map.on('dragend', getPins);
map.on('zoomend', getPins);
map.whenReady(getPins)
</script>
</body>
</html>