Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
76 lines (74 loc) · 2.51 KB
/
Copy pathindex.html
File metadata and controls
76 lines (74 loc) · 2.51 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>simplifyjs</title>
<script src="resources/coordinates.js"></script>
<script src="src/clip.js"></script>
<script src="src/douglas_peucker.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css' rel='stylesheet' />
</head>
<body>
<div id="map"></div>
<div id="range">
<input id="range-control" type="range" max="1" step="0.0001", value="0">
<code id="range-result"></code>
</div>
</body>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top:0; bottom:0; width:100%; }
#range { pointer-events: all; display: flex; flex-direction: column; color: #ce2c69}
</style>
<script>
// clipeLines function unused
mapboxgl.accessToken = 'pk.eyJ1Ijoib2RkeSIsImEiOiJjanJld3R2ZnYwcGoyNGFyazJkdXA2OW5oIn0.ac5ztibRIaP3Laxf_wDHig';
const map = new mapboxgl.Map({
style: 'mapbox://styles/mapbox/dark-v9',
container: 'map',
center: [ 65.10836837339707, 50.63059929897108],
zoom: 6,
});
map.on('load', _ => {
map.addLayer({
'id': 'maine',
'type': 'fill',
'source': { 'type': 'geojson',
'data': {
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': coords,
}
}
},
'paint': {
'fill-color': '#ce2c69',
'fill-opacity': 0.5,
}
});
map.addControl({
onAdd: function(map) {
const range = document.getElementById('range-control');
range.addEventListener('input', function(e) {
const value = e.target && e.target.value || 0; // cause custom event dispatching
const simplified = [simplify(coords[0], value)];
document.getElementById('range-result').innerHTML = `vertx_count:${simplified[0].length}`;
map.getSource('maine').setData({
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': simplified,
},
});
})
range.dispatchEvent(new CustomEvent('input')); // inital event dispatching
return document.getElementById('range');
},
}, 'top-right')
});
</script>
</html>