Incorporer à la carte un GeoJSON en ligne (ici sur un portail Open data)
Last active
January 22, 2023 15:09
-
-
Save mastersigat/d16b8c83616e94f9062bc99e2fb55bf7 to your computer and use it in GitHub Desktop.
#leaflet / Ajouter un GeoJSON
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
<html> | |
<head> | |
<title>A Leaflet map!</title> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" /> | |
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script> | |
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> | |
<style> | |
#map {width: 90%; height:600px; margin: auto; } | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
// Initialiser la carte | |
var map = L.map('map', { | |
center: [48.11, -1.66], | |
zoom: 13 }); | |
// Fond de carte | |
L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png').addTo(map); | |
// Ajout des Stations de vélos | |
var url = 'https://raw.githubusercontent.com/mastersigat/data/main/velostar.geojson'; | |
$.getJSON(url, function (geojson) { | |
var velos = L.geoJson(geojson,{ | |
// Transformer les marqueurs en point | |
pointToLayer: function (geoJsonPoint, latlng) { | |
return L.circleMarker(latlng); | |
}, | |
// Modifier la symbologie des points | |
style: function (geoJsonFeature) { | |
return { | |
fillColor: '#001f3f', | |
radius: 6, | |
fillOpacity: 0.7, | |
stroke: false}; | |
}, | |
} | |
).addTo(map); | |
velos.bindPopup(function(velos) {console.log(velos.feature.properties); | |
return "<h1> Station : "+velos.feature.properties.nom+"</h1>"+"<hr><h2>" +velos.feature.properties.nombreemplacementstheorique+ " vélos</h2>" ; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment