Taiwan village map!
Last active
August 29, 2015 14:01
-
-
Save chilijung/0107065c0ce754c99c29 to your computer and use it in GitHub Desktop.
Taiwan village map!
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> | |
<meta charset="utf-8"> | |
<style> | |
/* CSS goes here. */ | |
#content { | |
fill: #FFF; | |
} | |
</style> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<div id="content"> | |
</div> | |
<script> | |
var w = 800, | |
h = 600; | |
var projection = d3.geo.mercator() | |
.center([120.979531, 23.978567]) | |
.scale(10000); | |
var color = d3.scale.category20(); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select('#content') | |
.append('svg') | |
.attr('width', w) | |
.attr('height', h) | |
.attr('viewBox', "0 0 800 600") | |
.attr('preserveAspectRatio', 'xMidYMid'); | |
/* JavaScript goes here. */ | |
d3.json('twVillage1982.topo.json', function(err, data) { | |
var topo = topojson.feature(data, data.objects["layer1"]); | |
var topomesh = topojson.mesh(data, data.objects["layer1"], function(a, b){ | |
return a !== b; | |
}); | |
svg.selectAll('path.village') | |
.data(topo.features) | |
.enter() | |
.append('path') | |
.attr('class', 'village') | |
.attr('class', function(d) { return d.properties.TOWNNAME; }) | |
.attr('id', function(d) { return d.properties.VILLAGEID; }) | |
.attr('d', path) | |
.style('fill', function(){ | |
return color(Math.random()); | |
}) | |
.style('stroke', 'none') | |
.style('opacity', 0.9); | |
svg.append('path') | |
.attr('class', 'boundary') | |
.datum(topomesh) | |
.attr('d', path) | |
.style('fill', 'none') | |
.style('stroke', "rgba(255,255,255,0.5)") | |
.style('stroke-width', '2px'); | |
}) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment