Ajouter des données OSM en se connectant à la base de Mapbox
Last active
February 4, 2018 21:23
-
-
Save mastersigat/44318ffc47d5713d2941f6bc1de15c22 to your computer and use it in GitHub Desktop.
#MapboxGL / Ajouter des données 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>Display a map</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.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> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
// AccesToken | |
mapboxgl.accessToken = 'pk.eyJ1IjoibmluYW5vdW4iLCJhIjoiY2pjdHBoZGlzMnV4dDJxcGc5azJkbWRiYSJ9.o4dZRrdHcgVEKCveOXG1YQ'; | |
// Configuration de la carte | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'mapbox://styles/ninanoun/ciyo7h3mc001q2rpngdsa9zwh', // fond de carte | |
center: [-1.70, 48.119], // lat/long | |
zoom: 16, // zoom | |
pitch: 50, // Inclinaison | |
bearing: -10 // Rotation | |
}); | |
// Ajout de données OSM | |
map.on('load', function () { | |
// Ajout de la source | |
map.addSource('mapbox-streets-v7', { | |
type: 'vector', | |
url: 'mapbox://mapbox.mapbox-streets-v7'}); | |
// Ajout couche des routes | |
map.addLayer({ | |
"id": "Routes", | |
"type": "line", | |
"source": "mapbox-streets-v7", | |
"layout": {'visibility': 'visible'}, | |
"source-layer": "road", | |
"paint": {"line-color": "#ff8533", "line-width": 1} | |
}); | |
// Ajout couche hydrologie | |
map.addLayer({ | |
"id": "Batiments", | |
"type": "fill", | |
"source": "mapbox-streets-v7", | |
"source-layer": "building", | |
"layout": {'visibility': 'visible'}, | |
"paint": {"fill-color": "#d1e0e0"} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment