Last active
August 29, 2015 14:00
-
-
Save zross/11184494 to your computer and use it in GitHub Desktop.
Put topojson on LeafletJS map
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>HTML5</title> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=650, user-scalable=yes"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | |
<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://d3js.org/topojson.v1.min.js"></script> | |
<style> | |
html, body { | |
height: 100%; | |
margin: 0; | |
} | |
#mapcanvas{ | |
height:100%; | |
} | |
</style> | |
<script> | |
var geoJsonObject; | |
$(document).ready(function(){ | |
map = new L.Map('mapcanvas'); | |
var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; | |
var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'; | |
var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib}); | |
// start the map in South-East England | |
map.setView(new L.LatLng(36.788283, -119.805891),6); | |
map.addLayer(osm); | |
//county.json is a topojson file | |
var myStyle = { | |
"color": "#003399", | |
"weight": 1, | |
"opacity": 0.65 | |
}; | |
$.getJSON("township.json", function(data){ | |
geoJsonObject = topojson.feature(data, data.objects.township) | |
L.geoJson(geoJsonObject,{ | |
style:myStyle | |
}).addTo(map); | |
}); | |
});//end document ready | |
</script> | |
</head> | |
<body> | |
<div id="mapcanvas"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment