forked from vincentsarago/lambda-tiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
86 lines (71 loc) · 2.54 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>example</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
<script src='https://npmcdn.com/@turf/turf@3.5.1/turf.min.js'></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.43.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.43.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
var endpoint = '{YOUR-API-GATEWAY-ENDPOINT}'; //e.g https://xxxxxxxxxx.execute-api.xxxxxxx.amazonaws.com/production
var map = new mapboxgl.Map({
container: 'map',
style: { version: 8, sources: {}, layers: [] },
center: [-119.5591, 37.715],
zoom: 9
});
var url = 'https://oin-hotosm.s3.amazonaws.com/5ac626e091b5310010e0d482/0/5ac626e091b5310010e0d483.tif';
map.on('load', () => {
const bounds_query = `${endpoint}/bounds?url=${url}`;
$.getJSON(bounds_query).done()
.then(data => {
console.log(data);
map.addSource('tiles', {
"type": "raster",
"tiles": [`${endpoint}/tiles/{z}/{x}/{y}.png?url=${url}&nodata=0&tile=256`],
"tileSize": 256,
"bounds": data.bounds
});
map.addLayer({
"id": "tiles",
"source": "tiles",
"type": "raster"
});
const geojson = {
'type': 'FeatureCollection',
'features': [turf.bboxPolygon(data.bounds)]
};
map.addSource('tile', {
'type': 'geojson',
'data': geojson
});
map.addLayer({
'id': 'tile',
'type': 'line',
'source': 'tile',
'layout': {
'line-cap': 'round',
'line-join': 'round'
},
'paint': {
'line-color': '#1b34db',
'line-width': 2
}
});
const extent = data.bounds;
const llb = mapboxgl.LngLatBounds.convert([[extent[0],extent[1]], [extent[2],extent[3]]]);
map.fitBounds(llb, {padding: 50});
});
});
</script>
</body>
</html>