-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdemo.html
352 lines (300 loc) · 9.74 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tile Filters Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Leaflet Tile Filter Demo">
<meta name="author" content="Scott Fairgrieve, HumanGeo">
<link rel="stylesheet" href="bower_components/leaflet/dist/leaflet.css" type="text/css" media="screen" />
<style>
body {
padding: 0px;
margin: 0px;
font-family: Verdana, Tahoma, Arial, Sans Serif;
font-size: 14px;
}
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
h5 {
padding: 10px 0px 10px 10px;
margin: 0px;
border-bottom: solid 1px #c0c0c0;
background-color: #e0e0e0;
}
#options {
position: absolute;
bottom: 0px;
right: 0px;
background-color: rgba(255, 255, 255, 0.7);
border: solid 1px #c0c0c0;
}
#layers {
width: 158px;
height: 276px;
overflow: auto;
}
#filters div {
display: block;
margin: 10px;
padding: 10px 10px 10px 10px;
border-radius: 10px;
background-color: #e0e0e0;
}
div.wrapper {
display: inline-block;
margin: 10px 0px 0px 10px;
}
div.wrapper.selected {
}
div.layer {
width: 128px;
height: 128px;
background-size: cover;
position: relative;
}
div.layer .details {
background-color: rgba(255, 255, 255, 0.7);
position: absolute;
bottom: 0px;
width: 100%;
padding: 10px;
}
div.wrapper.selected div.layer .details {
background-color: rgba(40, 40, 240, 0.9);
color: #fff;
}
#map {
background: url(http://subtlepatterns.com/patterns/swirl_pattern.png);
}
</style>
</head>
<body>
<div id="map"></div>
<div id="options">
<h5>Layers</h5>
<div id="layers"></div>
<h5>Filters</h5>
<div id="filters">
<div>
<h5>Canvas Filter</h5>
<select id="canvas-filters"></select>
</div>
<div>
<h5>CSS Filter</h5>
<select id="css-filters"></select>
</div>
</div>
</div>
<script type="text/template" id="layer-template">
<div class="layer" style="background-image: url(<%= thumbnail %>);">
<div class="details">
<span class="provider"><%= provider %></span>
<span class="style"><%= style %></span>
</div>
</div>
</script>
<script>
(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-51577600-1', 'humangeo.github.io');
ga('send', 'pageview');
</script>
<script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="bower_components/underscore/underscore-min.js"></script>
<script type="text/javascript" src="bower_components/leaflet/dist/leaflet.js"></script>
<script type="text/javascript" src="src/leaflet-tilefilter.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var map;
var legendControl;
var classFunc = L.TileLayer.CanvasTMS;
// Function for resizing the map to fill the available space on the screen
var resize = function () {
var $map = $('#map');
$map.height($(window).height());
if (map) {
map.invalidateSize();
}
};
// Resize the map element on window resize
$(window).on('resize', function () {
resize();
});
// Resize the map element
resize();
// Initialize the map
map = L.map('map').setView([38.895843, -77.043085], 15);
var apiKey = 'pk.eyJ1Ijoic2ZhaXJncmlldmUiLCJhIjoiY2FmNGI2OGEwZDI1YTcyMjJkNzQyY2MyMmI0NTRhMzAifQ.b03Wm6qBoeErDTg77XuvzQ';
// Build menu choices
// Stamen, MapQuest, OSM
var layerChoices = {
Stamen: {
Toner: {
thumbnail: 'http://a.tile.stamen.com/toner/12/655/1583.png',
getLayer: function (classFunction) {
return new classFunction('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', {
detectRetina: true
});
}
},
Terrain: {
thumbnail: 'http://tile.stamen.com/terrain/12/655/1583.jpg',
getLayer: function (classFunction) {
return new classFunction('http://{s}.tile.stamen.com/terrain/{z}/{x}/{y}.jpg', {
detectRetina: true
});
}
},
Watercolor: {
thumbnail: 'http://tile.stamen.com/watercolor/12/655/1583.jpg',
getLayer: function (classFunction) {
return new classFunction('http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg', {
detectRetina: true
});
}
}
},
MapQuest: {
OSM: {
thumbnail: 'http://otile1.mqcdn.com/tiles/1.0.0/map/12/655/1583.jpg',
getLayer: function (classFunction) {
return new classFunction('http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', {
detectRetina: true
});
},
selected: true
},
Aerial: {
thumbnail: 'http://otile1.mqcdn.com/tiles/1.0.0/sat/12/655/1583.jpg',
getLayer: function (classFunction) {
return new classFunction('http://otile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg', {
detectRetina: true
});
}
}
},
OSM: {
Default: {
thumbnail: 'http://a.tile.openstreetmap.org/12/655/1583.png',
getLayer: function (classFunction) {
return new classFunction('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
detectRetina: true
});
}
}
},
CartoDB: {
Positron: {
thumbnail: 'http://a.basemaps.cartocdn.com/light_all/12/655/1583.png',
getLayer: function (classFunction) {
return new classFunction('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',{
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>',
detectRetina: true
});
}
},
'Dark Matter': {
thumbnail: 'http://a.basemaps.cartocdn.com/dark_all/12/655/1583.png',
getLayer: function (classFunction) {
return new classFunction('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',{
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>',
detectRetina: true
});
}
}
}
};
var styles = ['streets', 'light', 'dark', 'satellite', 'streets-satellite', 'wheatpaste', 'streets-basic', 'comic', 'outdoors', 'run-bike-hike', 'pencil', 'pirates', 'emerald', 'high-contrast'];
var createFunc = function (styleName) {
return function (classFunction) {
return new classFunction('https://{s}.tiles.mapbox.com/v4/mapbox.' + styleName + '/{z}/{x}/{y}.png?access_token=' + apiKey, {
attribution: '<a href="http://www.mapbox.com/about/maps/" target="_blank">Terms & Feedback</a>',
detectRetina: true
});
}
};
// Store the currently selected filters
var selectedCSSFilter = L.ImageFilters.Presets.CSS.None;
var selectedChannelFilter = L.ImageFilters.Presets.CanvasChannel.None;
var selectedFilter = function () {
return new L.CombinedFilter(this, {
cssFilter: selectedCSSFilter,
canvasFilter: selectedChannelFilter
}).render();
};
var $layers = $('#layers');
var $template = $('#layer-template');
var template = _.template($template.html());
var baseLayer = layerChoices.MapQuest.OSM.getLayer(classFunc);
var getFilter = function () {
selectedFilter = function (image, ctx) {
return new L.CombinedFilter({
cssFilter: selectedCSSFilter,
canvasFilter: selectedChannelFilter
}).render(this, image, ctx);
};
baseLayer.setFilter(selectedFilter);
};
getFilter();
// Iterate through the layer choices and create a way for users to select a tile provider
for (var provider in layerChoices) {
var layerChoice = layerChoices[provider];
for (var style in layerChoice) {
var option = layerChoice[style];
var $layer = $('<div class="wrapper"></div>');
$layer.html(template({
thumbnail: option.thumbnail,
provider: provider,
style: style
}));
if (option.selected) {
$layer.addClass('selected');
}
$layers.append($layer);
var clickFunction = function (option) {
return function () {
var tempLayer = baseLayer;
baseLayer = option.getLayer(classFunc);
/*
if (selectedFilter) {
baseLayer.setFilter(selectedFilter);
}
*/
getFilter();
map.addLayer(baseLayer);
map.removeLayer(tempLayer);
$layers.find('.selected').removeClass('selected');
$(this).addClass('selected');
}
};
$layer.on('click', clickFunction(option));
}
}
// Setup filter options
var $canvasFilters = $('#canvas-filters');
var $cssFilters = $('#css-filters');
for (var filterChoice in L.ImageFilters.Presets.CanvasChannel) {
$canvasFilters.append('<option value="' + filterChoice + '">' + filterChoice + '</option>');
}
for (var filterChoice in L.ImageFilters.Presets.CSS) {
$cssFilters.append('<option value="' + filterChoice + '">' + filterChoice + '</option>');
}
$canvasFilters.on('change', function (e) {
selectedChannelFilter = L.ImageFilters.Presets.CanvasChannel[$canvasFilters.val()];
getFilter();
});
$cssFilters.on('change', function (e) {
selectedCSSFilter = L.ImageFilters.Presets.CSS[$cssFilters.val()];
getFilter();
});
baseLayer.addTo(map);
});
</script>
</body>
</html>