-
Notifications
You must be signed in to change notification settings - Fork 7
/
vector.html
207 lines (195 loc) · 10.3 KB
/
vector.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Tilegarden | Vector Tiles</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>
<!--Mapbox GL-->
<script src='https://api.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.css' rel='stylesheet' />
<link rel="stylesheet" href="style.css">
<script>
"use-strict"
document.addEventListener('DOMContentLoaded', function onload() {
mapboxgl.accessToken = "pk.eyJ1IjoibWRlbHNvcmRvLWF6YXZlYSIsImEiOiJjamp5Z3M5NTcwbHZpM3ZydzAxMXF3bWY5In0.GObbyRg_IX8mONaD98SIjQ"
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [ -75.15, 39.96,],
zoom: 15,
minZoom: 14,
});
// list of layers
var layers = {
'pwd_parcels': {
id: 'pwd_parcels',
type: 'fill',
source: 'pwd_parcels',
'source-layer': 'pwd_parcels',
paint: {
'fill-color': 'orange',
'fill-outline-color': 'red',
}
},
'street_centerline': {
id: 'street_centerline',
type: 'line',
source: 'street_centerline',
'source-layer': 'street_centerline',
paint: {
'line-color': 'red',
'line-width': 2,
}
},
'inlets': {
id: 'inlets',
type: 'circle',
source: 'inlets',
'source-layer': 'inlets',
paint: {
'circle-color': 'orange',
'circle-stroke-color': 'red',
'circle-stroke-width': 1
}
}
}
// 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;
map.on('load', function mapLoaded() {
map.addSource(
'inlets',
{
type: 'vector',
tiles: [TILESERVER_PATH+'vector/data-type-example/{z}/{x}/{y}?layers=["inlets"]']
},
)
map.addSource(
'street_centerline',
{
type: 'vector',
tiles: [TILESERVER_PATH+'vector/data-type-example/{z}/{x}/{y}?layers=["street_centerline"]']
},
)
map.addSource(
'pwd_parcels',
{
type: 'vector',
tiles: [TILESERVER_PATH+'vector/data-type-example/{z}/{x}/{y}?layers=["pwd_parcels"]']
},
)
map.addLayer(layers['inlets'])
document.getElementById('stylebox').value = JSON.stringify(layers['inlets'].paint)
document.getElementById('dataDesc').innerHTML = LAYER_DESCS['inlets'];
});
var LAYER_DESCS = {
'inlets': '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>',
'street_centerline': 'Street centerlines. Used citywide as base layer for many purposes/applications. The street centerline is available for reference purposes only and does not represent exact engineering specifiactions. | <a href="https://www.opendataphilly.org/dataset/street-centerlines">City of Philadelphia</a>',
'pwd_parcels': '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>',
}
var currentLayer = 'inlets';
document.getElementById("selector").addEventListener('change', function selectorChange (e) {
var selection = document.getElementById("selector").value;
console.log(JSON.stringify(selection));
map.removeLayer(currentLayer);
currentLayer = selection;
map.addLayer(layers[currentLayer]);
document.getElementById('stylebox').value = JSON.stringify(layers[selection].paint);
document.getElementById('dataDesc').innerHTML = LAYER_DESCS[selection];
});
// update styles by looping through properties of json object
document.getElementById('btnChangeStyle').addEventListener('click', function changeStyle() {
var newStyle = JSON.parse(document.getElementById('stylebox').value);
for (var p in newStyle) {
if (newStyle.hasOwnProperty(p)) {
map.setPaintProperty(currentLayer, p, newStyle[p]);
}
}
});
});
</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 Tiles</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>
<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">Vector Tiles</h2>
<p class="lead">Serve your geospatial data as <a href="https://www.mapbox.com/vector-tiles/">Mapbox Vector Tiles</a> for client-side styling and manipulation.</p>
<div class="row">
<div class="m-auto">
<code id="urlExample">https://yourtiles.cloudfront.net/vector/{z}/{x}/{y}.png</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">
<label for="selector">Data set</label>
<select id="selector" class="custom-select">
<option value="inlets">Points</option>
<option value="street_centerline">Lines</option>
<option value="pwd_parcels">Polygons</option>
</select>
</div>
<div class="form-group">
<layer for="stylebox">Style</layer>
<textarea id="stylebox" class="form-control"></textarea>
</div>
<div>
<button id="btnChangeStyle" class="btn btn-primary">Set style</button>
</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>