Skip to content

Instantly share code, notes, and snippets.

@abruzzi
Created May 6, 2014 05:57
Show Gist options
  • Save abruzzi/e422be92c3b330c14025 to your computer and use it in GitHub Desktop.
Save abruzzi/e422be92c3b330c14025 to your computer and use it in GitHub Desktop.
Example of how to use leaflet with geojson + osm
<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<div style="width:500px; height:500px" id="map"></div>
<script type='text/javascript'>
$(function() {
// create a map in the "map" div, set the view to a given place and zoom
var map = L.map('map').setView([34.192, 108.872], 10);
// add an OpenStreetMap tile layer
var tile = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
});
tile.addTo(map);
$.getJSON('/places-local.geojson', function(data) {
var geo = L.geoJson(data, {
onEachFeature: function (feature, layer) {
console.log(feature);
// layer.bindPopup(feature.properties.altitude);
}
});
geo.addTo(map);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment