Skip to content

Instantly share code, notes, and snippets.

@zross
Last active May 3, 2023 19:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zross/10654766 to your computer and use it in GitHub Desktop.
Save zross/10654766 to your computer and use it in GitHub Desktop.
Putting TopoJSON on a Google Map
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<head>
<title>HTML5</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=650, user-scalable=yes">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.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;
var thejson;
$(document).ready(function(){
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(38.284335, -120.833818),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map=new google.maps.Map($('#mapcanvas')[0], mapOptions);
//county.json is a topojson file
$.getJSON("county.json", function(data){
geoJsonObject = topojson.feature(data, data.objects.county)
map.data.addGeoJson(geoJsonObject);
});
});//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