Skip to content

Instantly share code, notes, and snippets.

@mastersigat
Created February 2, 2021 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mastersigat/961dbbd80d9be998ff6ad3a3426a9384 to your computer and use it in GitHub Desktop.
Save mastersigat/961dbbd80d9be998ff6ad3a3426a9384 to your computer and use it in GitHub Desktop.
#MapboxGL / Animation 2
license: mit
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<meta name="robots" content="noindex, nofollow" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"></script>
<link
href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css"
rel="stylesheet"
/>
<style>
#map {
position: absolute;
height: 900px;
width: 100%;
}
.marker {
background-image: url('mapbox-icon.png');
background-size: cover;
width: 50px;
height: 50px;
border-radius: 50%;
cursor: pointer;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibmluYW5vdW4iLCJhIjoiY2pjdHBoZGlzMnV4dDJxcGc5azJkbWRiYSJ9.o4dZRrdHcgVEKCveOXG1YQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
minZoom: 6,
maxZoom: 18,
center: [-1.702, 48.119] });
function rotate() {
map.easeTo({ bearing: 100, duration: 8000, pitch: 80, zoom: 17 });
window.setTimeout(function () {
map.easeTo({ bearing: 180, duration: 5000, pitch: 0, zoom: 14 });
window.setTimeout(function () {
map.easeTo({ bearing: 270, duration: 5000, pitch: 50, zoom: 18 });
window.setTimeout(function () {
rotator();
}, 8000);
}, 5000);
}, 5000);
}
map.on('load', function () {
rotate();
map.addLayer({
'id': '3d-buildings',
'source': 'composite',
'source-layer': 'building',
'filter': ['==', 'extrude', 'true'],
'type': 'fill-extrusion',
'minzoom': 15,
'paint': {
'fill-extrusion-color': '#aaa',
// use an 'interpolate' expression to add a smooth transition effect to the
// buildings as the user zooms in
'fill-extrusion-height': [
"interpolate", ["linear"], ["zoom"],
15, 0,
15.05, ["get", "height"]
],
'fill-extrusion-base': [
"interpolate", ["linear"], ["zoom"],
15, 0,
15.05, ["get", "min_height"]
],
'fill-extrusion-opacity': .6
}
});
var marker = new mapboxgl.Marker()
.setLngLat([-1.702, 48.119])
.addTo(map);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment