Skip to content

Instantly share code, notes, and snippets.

@tkayne23
Last active February 17, 2017 03:07
Show Gist options
  • Save tkayne23/4d25adef813b1f20c0cecc692c79fdd5 to your computer and use it in GitHub Desktop.
Save tkayne23/4d25adef813b1f20c0cecc692c79fdd5 to your computer and use it in GitHub Desktop.
Mapbox style; addSource; addLayer
license: mit

Built with blockbuilder.org

Show and hide layers Create a custom layer switcher to display different datasets.

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.32.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.32.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoidGtheW5lMjMiLCJhIjoiN2ZuVll5MCJ9.INSHe8gm7HMfO8HZPUuAhg';
var map = new mapboxgl.Map({
container: 'map',
// use any style
style: 'mapbox://styles/tkayne23/ciyt1ibkz000r2rpdp6qsobt7',
center: [-100.789, 29.352],
zoom: 13.9
});
map.on('load', function () {
// source is a TMK tileset
map.addSource('laughlincombined4326', {
type: 'vector',
url: 'mapbox://tkayne23.5b9u73tj'
});
// add a layer name from the tileset
map.addLayer({
'id': 'homes-outline',
'type': 'line',
'source': 'laughlincombined4326',
'source-layer': 'LaughlinCombined4326-durrw3',
'layout': {
'visibility': 'visible',
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': '#877b59',
'line-width': 1
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment