forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markers-custom.html
141 lines (121 loc) · 3.99 KB
/
markers-custom.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
<!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; }
.marker {
background-image: url('/debug/pin.png');
background-size: cover;
width: 50px;
height: 50px;
border-radius: 50%;
cursor: pointer;
}
</style>
</head>
<body>
<div id='map'></div>
<div id='controls'>
<button id="animate">Animate</button><br />
<label><input id='terrain-checkbox' type='checkbox'> terrain</label><br />
<div>
<label>Projection:</label>
<select id="projName">
<option value="mercator" selected>Mercator</option>
<option value="globe">Globe</option>
<option value="albers">Albers USA</option>
<option value="equalEarth">Equal Earth</option>
<option value="equirectangular">Equirectangular</option>
<option value="lambertConformalConic">Lambert Conformal Conic</option>
<option value="naturalEarth">Natural Earth</option>
<option value="winkelTripel">Winkel Tripel</option>
</select>
</div>
</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',
devtools: true,
zoom: 3,
style: 'mapbox://styles/mapbox/streets-v9',
hash: true,
});
const rots = ['horizon', 'horizon', 'horizon', 'horizon'];
const pits = ['auto', 'auto', 'auto'];
const spinningMarkers = [];
rots.forEach((rotationAlignment, i) => {
pits.forEach((pitchAlignment, j) => {
var bounds = map.getBounds();
var s = bounds.getSouth();
var n = bounds.getNorth();
var w = bounds.getWest();
var e = bounds.getEast();
var lng = w + (e - w) * ((i + .5) / 4);
var lat = s + (n - s) * ((j + .5) / 3);
var popup = new mapboxgl.Popup().setHTML(`Pitch Alignment: ${pitchAlignment}<br>Rotation Alignment: ${rotationAlignment}`);
var r = Math.round(Math.random() * 255);
var g = Math.round(Math.random() * 255);
var b = Math.round(Math.random() * 255);
var sc = Math.random() * 2.5 + 0.5;
const el = document.createElement('div');
el.className = 'marker';
var marker = new mapboxgl.Marker({
element: el,
offset: [0, -25],
draggable: true,
rotationAlignment,
pitchAlignment
})
.setLngLat([lng, lat])
.setPopup(popup)
.addTo(map);
marker.togglePopup();
spinningMarkers.push(marker);
});
});
let animate = false;
document.getElementById('animate').addEventListener('click', () => {
animate = !animate;
if (animate) {
spinMarkers();
}
});
let rotation = 0;
function spinMarkers() {
rotation++;
spinningMarkers.forEach((marker) => {
marker.setRotation(rotation);
});
if (animate) {
window.requestAnimationFrame(spinMarkers);
}
}
window.requestAnimationFrame(spinMarkers);
map.addControl(new mapboxgl.NavigationControl());
map.on('load', function() {
map.addSource('mapbox-dem', {
"type": "raster-dem",
"url": "mapbox://mapbox.mapbox-terrain-dem-v1",
"tileSize": 512,
"maxzoom": 14
});
map.setFog({});
});
document.getElementById('terrain-checkbox').onclick = function() {
map.setTerrain(this.checked ? {"source": "mapbox-dem", "exaggeration": 10} : null);
};
document.getElementById('projName').addEventListener('change', (e) => {
const el = document.getElementById('projName');
map.setProjection(el.options[el.selectedIndex].value);
});
</script>
</body>
</html>