Skip to content

Instantly share code, notes, and snippets.

@lukecampbell
Created March 9, 2016 21:43
Show Gist options
  • Save lukecampbell/84c21f503c9551e842d7 to your computer and use it in GitHub Desktop.
Save lukecampbell/84c21f503c9551e842d7 to your computer and use it in GitHub Desktop.
Simple leaflet map that loads geojson
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
</head>
<style>
#mapid { height: 800px; }
.circle {
border-radius: 50%;
width: 20px;
height: 20px;
background: black;
}
.leaflet-container {
background-color: #ffffff;
}
</style>
<body>
<h1>The Map</h1>
<div id="mapid"></div>
<script>
$(document).ready(function() {
var map = L.map('mapid').setView([51.505, -0.09], 13);
var icon = L.divIcon({className: 'icon'});
var markerOptions = {
radius: 5,
fillColor: '#561D92',
color: '#000',
weight: 1,
opacity: 1,
fillOpacity: .4
};
$.getJSON('TB_Fence.geojson', function(data) {
var features = L.geoJson(data, {
style: function(feature) {
return {
icon: icon
};
},
onEachFeature: function(feature, layer) {
layer.bindPopup(feature.properties.name);
},
pointToLayer: function(feature, latlng) {
return L.circleMarker(latlng, markerOptions);
}
});
features.addTo(map);
var bounds = features.getBounds();
console.log(bounds);
map.fitBounds(bounds);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment