Built with blockbuilder.org
Last active
December 5, 2019 14:01
-
-
Save mastersigat/deff3908c0f5a4ab86b1167069e03a0d to your computer and use it in GitHub Desktop.
#MapboxGL / Afficher et filtrer des données d'OSM
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
license: mit |
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>MapboxGL</title> | |
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.0/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.0/mapbox-gl.css' rel='stylesheet' /> | |
<style> | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
// AccesToken | |
mapboxgl.accessToken = 'pk.eyJ1IjoibWFzdGVyc2lnYXQiLCJhIjoiY2loNG9mamxwMHp2dHgxbTBjY2hlb2RteiJ9.dDYKXX9907pbT6sTAJ4fvA'; | |
// Configuration de la carte | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'mapbox://styles/mapbox/dark-v9', | |
center: [-1.68, 48.12], // lat/long | |
zoom: 15, // zoom | |
pitch: 50, // Inclinaison | |
bearing: -10 // Rotation | |
}); | |
// Ajout de données OSM | |
map.on('load', function () { | |
// Config source | |
map.addSource('mapbox-streets-v7', { | |
type: 'vector', | |
url: 'mapbox://mapbox.mapbox-streets-v7'}); | |
// Ajout routes | |
map.addLayer({ | |
"id": "routes", | |
"type": "line", | |
"source": "mapbox-streets-v7", | |
"layout": {'visibility': 'visible'}, | |
"source-layer": "road", | |
"filter": ["all", ["in", "class", "motorway", "trunk", "primary"]], | |
"paint": {"line-color": "#FF7F50", "line-width": 3} | |
}); | |
// Ajout hydrologie | |
map.addLayer({ | |
"id": "hydrologie", | |
"type": "line", | |
"source": "mapbox-streets-v7", | |
"source-layer": "waterway", | |
"layout": {'visibility': 'visible'}, | |
"paint": {"line-color": "#4dd2ff", | |
"line-width": 10} | |
}); | |
// Batiments | |
map.addLayer({ | |
"id": "batiments", | |
"type": "fill", | |
"source": "mapbox-streets-v7", | |
"source-layer": "building", | |
"paint": {"fill-color": "#FFFFFF", | |
"fill-opacity": 0.8} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment