-
Notifications
You must be signed in to change notification settings - Fork 7
/
layer-filter.html
146 lines (133 loc) · 7.12 KB
/
layer-filter.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Tilegarden</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.2/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.2/dist/leaflet.js"></script>
<link rel="stylesheet" href="style.css">
<script>
"use-strict"
document.addEventListener('DOMContentLoaded', function pageLoaded() {
var map = L.map('map', {
center: [39.99, -75.15], zoom: 11
});
// add basemap
var basemap = L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',
subdomains: 'abcd',
maxZoom: 19
});
map.addLayer(basemap)
// dynamically set path based on host
var PROD_PATH = 'https://d3hvvzen5hf4hb.cloudfront.net/';
var DEV_PATH = 'http://localhost:3000/';
var TILESERVER_PATH;
var host = window.location.hostname;
if (!host || host === 'localhost') TILESERVER_PATH = DEV_PATH;
else TILESERVER_PATH = PROD_PATH;
// add filtered layers
function newLayer (filters) {
return L.tileLayer(TILESERVER_PATH + 'tile/point-example/{z}/{x}/{y}.png?layers=' + filters)
}
var EXAMPLE_PATH = 'https://yourtiles.cloudfront.net/tile/config/{z}/{x}/{y}.png?layers='
// keep track of active layers so
var currentSelection;
document.getElementById("selector").addEventListener('mouseup', function selectorMouseUp() {
// remove old layer
map.removeLayer(currentSelection);
// get new layer names from selector
var layerNames = Object.values(this.selectedOptions).map(function(v) {
return '"' + v.value + '"';
}).join(',');
layerNames = "[" + layerNames + "]"
currentSelection = newLayer(layerNames);
currentSelection.addTo(map);
document.getElementById('urlExample').innerText = EXAMPLE_PATH + layerNames;
});
currentSelection = newLayer('["PRIV","PARK"]');
map.addLayer(currentSelection);
});
</script>
</head>
<body>
<div class="container content">
<nav class="navbar navbar-expand-sm navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="../index.html">Home</a>
</li>
<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="demoDropdown" role="button" data-toggle="dropdown">
Demo
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="raster.html">Raster Tiles</a>
<a class="dropdown-item" href="vector.html">Vector Tiles</a>
<a class="dropdown-item" href="#">Queryable Layers</a>
<a class="dropdown-item" href="client-filter.html">Client-side Filtering</a>
<a class="dropdown-item" href="utf-grid.html">UTF Grids</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/azavea/tilegarden/blob/develop/README.md">Documentation</a>
</li>
</ul>
<a class="navbar-brand" href="https://github.com/azavea/tilegarden/">
View on GitHub
</a>
<a class="github-button" href="https://github.com/azavea/tilegarden/archive/master.zip" data-icon="octicon-cloud-download" data-size="large" aria-label="Download azavea/tilegarden on GitHub">Download</a>
</div>
</nav>
<div class="mt-3">
<h2 class="display-4">Filter by Layer</h2>
<p class="lead">Define customizable map layers that can be queried by your users.</p>
<div class="row">
<div class="m-auto">
<code id="urlExample">https://yourtiles.cloudfront.net/tile/{config}/{z}/{x}/{y}.png?layers=["PARK","PRIV"]</code>
</div>
<div class="col-8">
<figure class="figure">
<div id="map" class="figure-img"></div>
<figcaption class="figure-caption" id="dataDesc">
This point layer contains all the wastewater and stormwater inlets in Philadelphia with latitude and longitude coordinates. | <a href="https://www.opendataphilly.org/dataset/water-inlets">City of Philadelphia</a>
</figcaption>
</figure>
</div>
<div class="col">
<div class="form-group h-75">
<label for="selector">Filter (by inlet owner)</label>
<select id="selector" class="custom-select h-75" multiple>
<option>AIRPRT</option>
<option>CHEL</option>
<option>FEDERAL</option>
<option>LM</option>
<option selected>PARK</option>
<option selected>PRIV</option>
<option>PRIVPWDMAINT</option>
<option>PWD</option>
<option>STATE</option>
<option>USNAVY</option>
</select>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="container text-center">
<span class="text-muted">© 2018 Azavea. Built for the <a href="https://fellowship.azavea.com/">2018 Azavea Open Source Fellowship.</a></span>
</div>
</footer>
</body>
</html>