Created
January 17, 2013 06:26
-
-
Save JasonSanford/4554134 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Leaflet TopoJSON Example</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.4.5/leaflet.css" /> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script src="//cdn.leafletjs.com/leaflet-0.4.5/leaflet.js"></script> | |
<script src="https://raw.github.com/mbostock/topojson/master/topojson.js"></script> | |
<style> | |
body { | |
padding: 0; | |
margin: 0; | |
} | |
html, body, #map { | |
height: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="some-javascripts.js"></script> | |
</body> | |
</html> |
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
var county_layer = L.geoJson(null, { | |
style: { | |
color: '#666', | |
weight: 1, | |
opacity: 1, | |
fillOpacity: 0.3 | |
} | |
}), | |
state_layer = L.geoJson(null, { | |
style: { | |
color: '#333', | |
weight: 3, | |
opacity: 1, | |
fillOpacity: 0 | |
} | |
}), | |
map = L.map('map'); | |
L.tileLayer('http://{s}.tiles.mapbox.com/v3/jcsanford.map-xu5k4lii/{z}/{x}/{y}.png', { | |
maxZoom: 17, | |
attribution: 'Map data © Someone, Somewhere.', | |
}).addTo(map); | |
map | |
.addLayer(county_layer) | |
.addLayer(state_layer) | |
.setView([40, -100], 5); | |
$.getJSON('us_counties.json', function (data) { | |
var county_geojson = topojson.object(data, data.objects.counties), | |
state_geojson = topojson.object(data, data.objects.states); | |
county_layer.addData(county_geojson); | |
state_layer.addData(state_geojson); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment