Skip to content

Instantly share code, notes, and snippets.

@mapsmania
Created November 13, 2019 13:37
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 mapsmania/08bb6cc21c180f9afa1e2842c723b5c7 to your computer and use it in GitHub Desktop.
Save mapsmania/08bb6cc21c180f9afa1e2842c723b5c7 to your computer and use it in GitHub Desktop.
typhoon tracking
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Fengshen</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
<style>
.map-overlay {
font:bold 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
position: absolute;
width: 25%;
top: 0;
left: 0;
padding: 10px;
}
.map-overlay .map-overlay-inner {
background-color: #fff;
box-shadow:0 1px 2px rgba(0, 0, 0, 0.20);
border-radius: 3px;
padding: 10px;
margin-bottom: 10px;
}
.map-overlay label {
display: block;
margin: 0 0 10px;
}
.map-overlay input {
background-color: transparent;
display: inline-block;
width: 100%;
position: relative;
margin: 0;
cursor: ew-resize;
}
</style>
</head>
<body>
<div id='map'></div>
<div class='map-overlay top'>
<div class='map-overlay-inner'>
<label>video opacity: <span id='slider-value'>100%</span></label>
<input id='slider' type='range' min='0' max='100' step='0' value='100' />
</div>
</div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZ21hcHNtYW5pYSIsImEiOiJOYnlnSFpvIn0.5f62d0cnrWCA1KioxzXtqg';
var videoStyle = {
"version": 8,
"sources": {
"satellite": {
"type": "raster",
"tiles": ["https://api.mapbox.com/styles/v1/gmapsmania/ck2x5phhc28c81co62dr8xiuy/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoiZ21hcHNtYW5pYSIsImEiOiJOYnlnSFpvIn0.5f62d0cnrWCA1KioxzXtqg"],
"tileSize": 256
},
"video": {
"type": "video",
"urls": ["https://i.imgur.com/stpNe4T.mp4"],
"coordinates": [
[144.404296875, 23.187404991398775],
[160.048828125, 23.187404991398775],
[160.048828125, 11.746969318460001],
[144.404296875, 11.746969318460001]
]
}
},
"layers": [{
"id": "background",
"type": "background",
"paint": {
"background-color": "rgb(4,7,14)"
}
}, {
"id": "satellite",
"type": "raster",
"source": "satellite"
}, {
"id": "video",
"type": "raster",
"source": "video"
}]
};
var slider = document.getElementById('slider');
var sliderValue = document.getElementById('slider-value');
var map = new mapboxgl.Map({
container: 'map',
zoom: 3,
center: [154.84130859375, 17.24574420800713],
style: videoStyle
});
map.addControl(new mapboxgl.NavigationControl());
var playingVideo = true;
map.on("click", function() {
playingVideo = !playingVideo;
if (playingVideo) map.getSource("video").play();
else map.getSource("video").pause();
});
slider.addEventListener('input', function(e) {
// Adjust the layers opacity. layer here is arbitrary - this could
// be another layer name found in your style or a custom layer
// added on the fly using `addSource`.
map.setPaintProperty('video', 'raster-opacity', parseInt(e.target.value, 10) / 100);
// Value indicator
sliderValue.textContent = e.target.value + '%';
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment