-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
180 lines (158 loc) · 4.44 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Brooklyn Height Walking Tour - NYC Space/Time Directory</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" ></script>
<link rel="stylesheet" href="css/L.Control.Locate.min.css" />
<script src="js/L.Control.Locate.min.js" charset="utf-8"></script>
<script src="js/d3.v4.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
position: absolute;
font-family: monospace;
}
article {
width: 100%;
height: 100%;
}
#map {
width: 100%;
height: 100%;
}
#slider-container {
border-width: 2px;
border-color: rgba(0, 0, 0, 0.5);
border-style: solid;
width: 30%;
box-sizing: border-box;
left: calc(50% - 15%);
z-index: 9999;
position: absolute;
bottom: 20px;
margin: 0 auto;
background-color: white;
padding: .5em 1em;
border-radius: 20px;
display: flex;
}
#slider {
margin: 0 1em;
padding: 0;
width: 100%;
}
#opacity {
text-align: right;
width: 4.5em;
}
@media (max-width: 1000px) {
#slider-container {
width: 95%;
left: 2.5%;
}
}
</style>
</head>
<body>
<header>
</header>
<article>
<div id="map">
</div>
<div id="slider-container">
<label for="slider">Opacity:</label>
<input id="slider" type="range" min="1" max="100" step="1" value="100">
</div>
</article>
<script>
var routeStyle = {
color: '#ff7800',
weight: 8,
opacity: 0.65
}
var map = L.map('map', {
center: [
40.69937,
-73.99153
],
zoom: 18,
maxZoom: 20
})
var baseMapTileUrl = 'https://api.mapbox.com/styles/v1/nypllabs/cj2gmix25005o2rpapartqm07/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibnlwbGxhYnMiLCJhIjoiSFVmbFM0YyJ9.sl0CRaO71he1XMf_362FZQ'
var baseLayer = L.tileLayer(baseMapTileUrl, {
attribution: '© Mapbox, © OpenStreetMap',
maxZoom: 20,
maxNativeZoom: 19
}).addTo(map)
L.control.locate().addTo(map)
function getTileUrl (mapId) {
return 'http://maps.nypl.org/warper/maps/tile/' + mapId + '/{z}/{x}/{y}.png'
}
var mapwarperMaps = [
{
title: 'Plate C - Farm Line Atlas, Vol. 5 (1880)',
mapId: 11859
},
{
title: 'Plate 6 - Maps of the City of Brooklyn (1855)',
mapId: 7238
},
{
title: 'Plate 15 - Maps of the City of Brooklyn (1855)',
mapId: 7247
},
{
title: 'Plate 7 - Maps of the City of Brooklyn (1855)',
mapId: 7239
},
{
title: 'Plate E - Farm Line Atlas, Vol. 5 (1880)',
mapId: 11861
},
{
title: 'Plate 31 - Brooklyn Atlas 66, Vol. 2 (1887)',
mapId: 19213
}
]
var mapwarperLayersByTitle = {}
var mapwarperLayers = mapwarperMaps.map(function (mapwarperMap, index) {
var layer = L.tileLayer(getTileUrl(mapwarperMap.mapId), {
maxZoom: 20,
maxNativeZoom: 19
})
if (index === 0) {
layer.addTo(map)
}
mapwarperLayersByTitle[mapwarperMap.title] = layer
return layer
})
d3.json('route.json', function (route) {
var routeLayer = L.geoJSON(route, {
style: routeStyle
}).addTo(map)
var overlayMaps = {
'Walking tour route': routeLayer
}
L.control.layers(mapwarperLayersByTitle, overlayMaps).addTo(map)
})
var slider = document.getElementById('slider')
function updateOpacity() {
var opacity = slider.value / 100
mapwarperLayers.forEach(function (layer) {
layer.setOpacity(opacity)
})
}
slider.addEventListener('input', updateOpacity)
// In IE<=11, input event does not work
slider.addEventListener('change', updateOpacity)
updateOpacity()
</script>
</body>
</html>