-
Notifications
You must be signed in to change notification settings - Fork 7
/
client-filter.html
156 lines (144 loc) · 7.59 KB
/
client-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
147
148
149
150
151
152
153
154
155
156
<!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/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/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.97, -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/data-type-example/{z}/{x}/{y}.png?layers=' + encodeURIComponent(JSON.stringify(filters)))
}
var EXAMPLE_PATH = 'https://yourtiles.cloudfront.net/tile/CONFIG/{z}/{x}/{y}.png?layers='
var INITIAL_QUERY = [
{
name: 'pwd_parcels',
mode: 'AND',
filters: [
{
col: 'owner2',
val: 'OF PHILADELPHIA',
},
{
col: 'gross_area',
op: '>',
val: '3000'
}
]
}
]
// keep track of active layers so
var currentSelection;
document.getElementById("btnUpdateQuery").addEventListener('click', function selectorMouseUp() {
// remove old layer
map.removeLayer(currentSelection);
// get new layer schema
var layerObj;
try {
layerObj = JSON.parse(document.getElementById('querybox').value);
currentSelection = newLayer(layerObj);
currentSelection.addTo(map);
document.getElementById('urlExample').innerText = EXAMPLE_PATH + JSON.stringify(layerObj);
} catch (e) {
console.error(e);
}
});
currentSelection = newLayer(INITIAL_QUERY);
document.getElementById('urlExample').innerText = EXAMPLE_PATH + JSON.stringify(INITIAL_QUERY);
document.getElementById('querybox').value = JSON.stringify(INITIAL_QUERY, null, 2);
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="layer-filter.html">Queryable Layers</a>
<a class="dropdown-item" href="#">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 Query</h2>
<p class="lead">Allow users to modify pre-defined layers by specifying filter conditions.</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">
PWD stormwater billing parcels. The primary purpose of PWD_PARCEL layer is to calculate parcel-based stormwater charges for PWD customers under the new parcel-based stormwater billing program. | <a href="https://www.opendataphilly.org/dataset/pwd-stormwater-billing-parcels">City of Philadelphia</a>
</figcaption>
</figure>
</div>
<div class="col">
<div class="form-group">
<label for="querybox">Query schema</label>
<textarea rows="14" id=querybox class="form-control"></textarea>
<div class="w-100 text-right"><button id="btnUpdateQuery" class="btn btn-primary mt-1">Set query</button></div>
</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>