forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpadding.html
More file actions
93 lines (87 loc) · 2.4 KB
/
Copy pathpadding.html
File metadata and controls
93 lines (87 loc) · 2.4 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>Mapbox GL JS debug page</title>
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel='stylesheet' href='../dist/mapbox-gl.css' />
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
#controls { position: absolute; top: 0; left: 0; }
</style>
</head>
<body>
<div id='map'></div>
<div id="controls">
<button id="getBounds">getBounds</button>
<button id="setBounds">setBounds</button>
<button id="maintainBearing">Maintain Bearing: false</button>
</div>
<script src='../dist/mapbox-gl-dev.js'></script>
<script src='../debug/access_token_generated.js'></script>
<script>
var map = window.map = new mapboxgl.Map({
container: 'map',
zoom: 12.5,
center: [-122.4194, 37.7749],
style: 'mapbox://styles/mapbox/streets-v10',
hash: true
});
map.setPadding({
left: 400,
top: 50,
right: 50,
bottom: 50
});
map.showPadding = true;
map.on('load', function () {
map.addSource('bounds', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: []
}
});
map.addLayer({
type: 'line',
id: 'bounds',
source: 'bounds',
paint: {
'line-width': 10
}
});
});
var bounds;
var maintainBearing = false;
document.getElementById('getBounds').addEventListener('click', function () {
bounds = map.getBounds();
map.getSource('bounds').setData({
type: 'Feature',
properties: {},
geometry: {
type: 'Polygon',
coordinates: [[
bounds.getNorthEast().toArray(),
bounds.getSouthEast().toArray(),
bounds.getSouthWest().toArray(),
bounds.getNorthWest().toArray(),
bounds.getNorthEast().toArray()
]]
}
});
});
document.getElementById('setBounds').addEventListener('click', function () {
map.fitBounds(bounds, {
duration: 0,
bearing: maintainBearing ? map.getBearing() : 0,
});
});
const maintainBearingElement = document.getElementById('maintainBearing');
maintainBearingElement.addEventListener('click', function() {
maintainBearing = !maintainBearing;
maintainBearingElement.innerHTML = `Maintain Bearing: ${maintainBearing}`;
});
</script>
</body>
</html>