Created
November 8, 2017 14:22
-
-
Save nlehuby/9b20d1a881f14f0925c43276033449d6 to your computer and use it in GitHub Desktop.
Mixing vector tiles sources
This file contains 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' /> | |
<title>Switch to vector tiles</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.41.0/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.41.0/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> | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'glstyle.json', | |
center: [ | |
2.6553, 48.8336 | |
], | |
zoom: 15, | |
hash: true | |
}); | |
map.addControl(new mapboxgl.NavigationControl()); | |
map.addControl(new mapboxgl.GeolocateControl({ | |
positionOptions: { | |
enableHighAccuracy: true | |
}, | |
trackUserLocation: true | |
})); | |
map.on('load', function() { | |
map.addLayer({ | |
"id": "transit-line", | |
"source": { | |
"type": 'vector', | |
"tiles": ["https://tile.mapzen.com/mapzen/vector/v1/roads/{z}/{x}/{y}.mvt?api_key=<myapikey>"], | |
"attribution": "Mapzen" | |
}, | |
"source-layer": "roads", | |
"type": "line", | |
"filter": ["any", ["==", "is_bus_route", "yes"], | |
["==", "is_bus_route", true] | |
], | |
"paint": { | |
"line-color": "#000", | |
"line-width": { | |
"base": 1.2, | |
"stops": [ | |
[8, 0.5], | |
[20, 15] | |
] | |
} | |
} | |
}) | |
//debug | |
map.on('click', 'transit-line', function(e) { | |
console.log(e.features[0]) | |
}); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment