Skip to content

Commit

Permalink
Create new client-side filtering demo and update other demos
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdelsordo committed Aug 23, 2018
1 parent d5e8161 commit 664f807
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 14 deletions.
155 changes: 155 additions & 0 deletions demo/client-filter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!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://korona.geog.uni-heidelberg.de/tiles/roadsg/x={x}&y={y}&z={z}', {
maxZoom: 19,
attribution: 'Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
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/{z}/{x}/{y}.png?config=data-type-example&layers=' + encodeURIComponent(JSON.stringify(filters)))
}

var EXAMPLE_PATH = 'https://yourtiles.cloudfront.net/tile/{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/{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">&copy; 2018 Azavea. Built for the <a href="https://fellowship.azavea.com/">2018 Azavea Open Source Fellowship.</a></span>
</div>
</footer>

</body>
</html>
14 changes: 8 additions & 6 deletions demo/filter.html → demo/layer-filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@

// get new layer names from selector
var layerNames = Object.values(this.selectedOptions).map(function(v) {
return v.value;
return '"' + v.value + '"';
}).join(',');
layerNames = "[" + layerNames + "]"

currentSelection = newLayer(layerNames);
currentSelection.addTo(map);
document.getElementById('urlExample').innerText = EXAMPLE_PATH + layerNames;
});

currentSelection = newLayer('PRIV,PARK');
currentSelection = newLayer('["PRIV","PARK"]');
map.addLayer(currentSelection);
});
</script>
Expand All @@ -82,7 +83,8 @@
<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="#">Filtering</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>
Expand All @@ -97,11 +99,11 @@
</div>
</nav>
<div class="mt-3">
<h2 class="display-4">Filtering</h2>
<p class="lead">Perform server-side filtering on raster data that can be queried by your users.</p>
<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/{z}/{x}/{y}.png?layers=PARK,PRIV</code>
<code id="urlExample">https://yourtiles.cloudfront.net/tile/{z}/{x}/{y}.png?layers=["PARK","PRIV"]</code>
</div>
<div class="col-8">
<figure class="figure">
Expand Down
5 changes: 3 additions & 2 deletions demo/raster.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
else TILESERVER_PATH = PROD_PATH;

function makeLayer (layer) {
return L.tileLayer(TILESERVER_PATH + 'tile/{z}/{x}/{y}.png?config=data-type-example&layers=' + layer);
return L.tileLayer(TILESERVER_PATH + 'tile/{z}/{x}/{y}.png?config=data-type-example&layers=["' + layer + '"]');
}

var currentLayer;
Expand Down Expand Up @@ -81,7 +81,8 @@
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Raster Tiles</a>
<a class="dropdown-item" href="vector.html">Vector Tiles</a>
<a class="dropdown-item" href="filter.html">Filtering</a>
<a class="dropdown-item" href="layer-filter.html">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>
Expand Down
7 changes: 4 additions & 3 deletions demo/utf-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
if (!host || host === 'localhost') TILESERVER_PATH = DEV_PATH;
else TILESERVER_PATH = PROD_PATH;

L.tileLayer(TILESERVER_PATH + 'tile/{z}/{x}/{y}.png?config=data-type-example&layers=inlets').addTo(map);
var grid = L.utfGrid(TILESERVER_PATH + 'grid/{z}/{x}/{y}?config=data-type-example&layers=inlets&utfFields=owner,operator', { useJsonP: false })
L.tileLayer(TILESERVER_PATH + 'tile/{z}/{x}/{y}.png?config=data-type-example&layers=["inlets"]').addTo(map);
var grid = L.utfGrid(TILESERVER_PATH + 'grid/{z}/{x}/{y}?config=data-type-example&layers=["inlets"]&utfFields=owner,operator', { useJsonP: false })

// keep track of currently active marker
//var marker
Expand Down Expand Up @@ -79,7 +79,8 @@
<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="filter.html">Filtering</a>
<a class="dropdown-item" href="layer-filter.html">Queryable Layers</a>
<a class="dropdown-item" href="client-filter.html">Client-side Filtering</a>
<a class="dropdown-item" href="#">UTF Grids</a>
</div>
</li>
Expand Down
3 changes: 2 additions & 1 deletion demo/vector.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
<div class="dropdown-menu">
<a class="dropdown-item" href="raster.html">Raster Tiles</a>
<a class="dropdown-item" href="#">Vector Tiles</a>
<a class="dropdown-item" href="filter.html">Filtering</a>
<a class="dropdown-item" href="layer-filter.html">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>
Expand Down
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<div class="dropdown-menu">
<a class="dropdown-item" href="demo/raster.html">Raster Tiles</a>
<a class="dropdown-item" href="demo/vector.html">Vector Tiles</a>
<a class="dropdown-item" href="demo/filter.html">Filtering</a>
<a class="dropdown-item" href="demo/layer-filter.html">Queryable Layers</a>
<a class="dropdown-item" href="demo/client-filter.html">Client-side Filtering</a>
<a class="dropdown-item" href="demo/utf-grid.html">UTF Grids</a>
</div>
</li>
Expand Down Expand Up @@ -62,7 +63,8 @@ <h4>Demos:</h4>
<div class="text-center">
<a href="demo/raster.html" type="button" class="btn btn-primary">Serve Raster Tiles</a>
<a href="demo/vector.html" type="button" class="btn btn-primary" disabled>Serve Vector Tiles</a>
<a href="demo/filter.html" type="button" class="btn btn-primary">Filter Layers</a>
<a href="demo/layer-filter.html" type="button" class="btn btn-primary">Queryable Layers</a>
<a href="demo/client-filter.html" type="button" class="btn btn-primary">Client-side Filtering</a>
<a href="demo/utf-grid.html" type="button" class="btn btn-primary">UTF Grid Support</a>
</div>
</div>
Expand Down

0 comments on commit 664f807

Please sign in to comment.