Skip to content

Instantly share code, notes, and snippets.

@mastersigat
Last active March 14, 2020 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mastersigat/c753f27dc1703d024050f1bc0d015cd0 to your computer and use it in GitHub Desktop.
Save mastersigat/c753f27dc1703d024050f1bc0d015cd0 to your computer and use it in GitHub Desktop.
#MapboxGL / Afficher des Geojson hébérgés sur une Dropbox
license: mit
<!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.eyJ1IjoibmluYW5vdW4iLCJhIjoiY2pjdHBoZGlzMnV4dDJxcGc5azJkbWRiYSJ9.o4dZRrdHcgVEKCveOXG1YQ';
// Configuration de la carte
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/ninanoun/ciytbjeef002u2sppd5xvl0q2',
center: [2.34, 46], // lat/long
zoom: 5, // zoom
pitch: 30, // Inclinaison
bearing: 0 // Rotation
});
// Ajout de données d'un GeoJSON (sur une dropbox)
map.on('load', function () {
// Region de France
map.addSource('regions', {
type: 'geojson',
data: 'https://dl.dropboxusercontent.com/s/0awomd6rjyiom4h/regions.geojson?dl=0'
});
map.addLayer({
'id': 'region',
'type': 'fill',
'source': 'regions',
'paint': {
'fill-color': 'blue', 'fill-opacity': 0.3, 'fill-outline-color': 'red'}});
// Gare SNCF
map.addSource('gares', {
type: 'geojson',
data: 'https://www.dl.dropboxusercontent.com/s/m8d4dykzekkmvxa/garessncf.geojson?dl=0'
});
map.addLayer({
'id': 'gare',
'type': 'circle',
'source': 'gares',
'paint': {
'circle-color': 'black' , 'circle-radius' : 2}});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment