Created
March 9, 2016 21:43
-
-
Save lukecampbell/84c21f503c9551e842d7 to your computer and use it in GitHub Desktop.
Simple leaflet map that loads geojson
This file contains hidden or 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> | |
<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