Skip to content

Instantly share code, notes, and snippets.

@chilijung
Last active August 29, 2015 13:59
Show Gist options
  • Save chilijung/10906524 to your computer and use it in GitHub Desktop.
Save chilijung/10906524 to your computer and use it in GitHub Desktop.
twTown1982 in map
*.old
twVote1982.topo.json

twTown1982 in map

<!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.category10();
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('twTown1982.topo.json', function(err, data) {
var topo = topojson.feature(data, data.objects["twTown1982.geo"]);
var topomesh = topojson.mesh(data, data.objects["twTown1982.geo"], function(a, b){
return a !== b;
});
topo.features.forEach(function(d, i) {
if(d.properties.TOWNID === "1605" || d.properties.TOWNID === "1603" || d.properties.TOWNID=== "1000128") {
topo.features.splice(i, 1);
}
})
svg.selectAll('path.county')
.data(topo.features)
.enter()
.append('path')
.attr('class', 'county')
.attr('class', function(d) {console.log(d); return d.properties.COUNTYNAME; })
.attr('id', function(d) { return d.properties.TOWNID; })
.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>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment