Created
January 10, 2017 17:04
-
-
Save jirik/a17f4aba8c7c8b29a170dca6111f765b to your computer and use it in GitHub Desktop.
Hillshade opacity slider for terrain style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>GL Style Package Preview</title> | |
<link rel="stylesheet" type="text/css" href="https://api.mapbox.com/mapbox-gl-js/v0.28.0/mapbox-gl.css" /> | |
<script src="https://api.mapbox.com/mapbox-gl-js/v0.28.0/mapbox-gl.js"></script> | |
<style> | |
html, body, #map {width:100%; height:100%; margin:0; padding:0;} | |
#slider-box { position: absolute; top:10px; right:70px; z-index:100; padding: 10px; background-color: rgba(255,255,255,0.8);} | |
#slider {outline: none;} | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<div id="slider-box"> | |
<input id="slider" type ="range" min ="0" max="1.0" step ="0.05" value ="0.2" /> | |
</div> | |
<script> | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'https://rawgit.com/openmaptiles/klokantech-terrain-gl-style/master/style.json', | |
attributionControl: true, | |
hash: true | |
}); | |
map.addControl(new mapboxgl.NavigationControl()); | |
var slider = document.getElementById('slider'); | |
map.on('load', function() { | |
slider.addEventListener('input', function(e) { | |
var opacity = parseFloat(e.target.value, 10); | |
map.setPaintProperty('hillshading', 'raster-opacity', opacity); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment