Last active
August 29, 2015 13:56
-
-
Save skitazaki/8823193 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> | |
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | |
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | |
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | |
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>東京ポリゴン</title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width"> | |
<!-- Place favicon.ico and apple-touch-icon.png in the root directory --> | |
<!-- build:css styles/vendor.css --> | |
<!-- bower:css --> | |
<!-- endbower --> | |
<!-- endbuild --> | |
<!-- build:css(.tmp) styles/main.css --> | |
<link rel="stylesheet" href="styles/main.css"> | |
<!-- endbuild --> | |
<script src="bower_components/modernizr/modernizr.js"></script> | |
</head> | |
<body> | |
<!--[if lt IE 10]> | |
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | |
<![endif]--> | |
<div class="container"> | |
<div class="header"> | |
<ul class="nav nav-pills pull-right"> | |
<li class="active"><a href="#">東京都 23区</a></li> | |
<li><a href="#">東京都 島しょ部除く</a></li> | |
<li><a href="#">東京都 全域</a></li> | |
</ul> | |
<h3 class="text-muted">東京ポリゴン</h3> | |
</div> | |
<div class="row"> | |
<h3> | |
<span id="cityname">名称</span> | |
<span id="citycode" class="small">JISコード</span> | |
</h3> | |
</div> | |
<div class="row"> | |
<div id="main"></div> | |
</div> | |
<div class="footer"> | |
<p> | |
</p> | |
</div> | |
</div> | |
<!-- build:js scripts/vendor.js --> | |
<!-- bower:js --> | |
<script src="bower_components/jquery/jquery.js"></script> | |
<script src="bower_components/d3/d3.min.js"></script> | |
<!-- endbower --> | |
<!-- endbuild --> | |
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. --> | |
<script> | |
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]= | |
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date; | |
e=o.createElement(i);r=o.getElementsByTagName(i)[0]; | |
e.src='//www.google-analytics.com/analytics.js'; | |
r.parentNode.insertBefore(e,r)}(window,document,'script','ga')); | |
ga('create','UA-XXXXX-X');ga('send','pageview'); | |
</script> | |
<!-- build:js scripts/plugins.js --> | |
<script src="bower_components/sass-bootstrap/js/affix.js"></script> | |
<script src="bower_components/sass-bootstrap/js/alert.js"></script> | |
<script src="bower_components/sass-bootstrap/js/dropdown.js"></script> | |
<script src="bower_components/sass-bootstrap/js/tooltip.js"></script> | |
<script src="bower_components/sass-bootstrap/js/modal.js"></script> | |
<script src="bower_components/sass-bootstrap/js/transition.js"></script> | |
<script src="bower_components/sass-bootstrap/js/button.js"></script> | |
<script src="bower_components/sass-bootstrap/js/popover.js"></script> | |
<script src="bower_components/sass-bootstrap/js/carousel.js"></script> | |
<script src="bower_components/sass-bootstrap/js/scrollspy.js"></script> | |
<script src="bower_components/sass-bootstrap/js/collapse.js"></script> | |
<script src="bower_components/sass-bootstrap/js/tab.js"></script> | |
<!-- endbuild --> | |
<!-- build:js({app,.tmp}) scripts/main.js --> | |
<script src="scripts/main.js"></script> | |
<!-- endbuild --> | |
</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
/*global d3*/ | |
'use strict'; | |
var width = 960, | |
height = 520; | |
var files = [ | |
{name: 'tokyo23.geojson', scale: 50000}, | |
{name: 'tokyo-honsyu.geojson', scale: 64000}, | |
{name: 'tokyo.geojson', scale: 8000} | |
]; | |
var g = d3.select('#main').append('svg') | |
.attr('width', width) | |
.attr('height', height) | |
.append('g'); | |
function renderGeoJSON(f) { | |
// RESET | |
g.text(''); | |
d3.json(f.name, function(err, collection) { | |
if (err) { | |
return; | |
} | |
console.log(f.name); | |
console.dir(d3.geo.centroid(collection)); | |
var projection = d3.geo.mercator() | |
.scale(f.scale) | |
.center(d3.geo.centroid(collection)) | |
.translate([width / 2, height / 2]); | |
var path = d3.geo.path().projection(projection); | |
g.selectAll('path') | |
.data(collection.features) | |
.enter() | |
.append('path') | |
.attr('d', path) | |
.attr('class', function(d) { | |
return 'area area' + (d.properties.N03_004 ? 'City' : '23'); | |
}) | |
.attr('data-cityname', function(d) { | |
return d.properties.N03_003 ? d.properties.N03_003 : '' + | |
d.properties.N03_004 ? d.properties.N03_004 : ''; | |
}) | |
.attr('data-citycode', function(d) { | |
return d.properties.N03_007; | |
}) | |
.on('click', function() { | |
var self = d3.select(this); | |
d3.select('#cityname').text(self.attr('data-cityname')); | |
d3.select('#citycode').text(self.attr('data-citycode')); | |
}); | |
}); | |
} | |
renderGeoJSON(files[0]); | |
d3.select('ul.nav li:nth-child(1) a') | |
.on('click', function() { | |
$('ul.nav li').removeClass('active'); | |
renderGeoJSON(files[0]); | |
$(this).parent().addClass('active'); | |
}); | |
d3.select('ul.nav li:nth-child(2) a') | |
.on('click', function() { | |
$('ul.nav li').removeClass('active'); | |
renderGeoJSON(files[1]); | |
$(this).parent().addClass('active'); | |
}); | |
d3.select('ul.nav li:nth-child(3) a') | |
.on('click', function() { | |
$('ul.nav li').removeClass('active'); | |
renderGeoJSON(files[2]); | |
$(this).parent().addClass('active'); | |
}); |
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
$icon-font-path: "/bower_components/sass-bootstrap/fonts/"; | |
@import 'sass-bootstrap/lib/bootstrap'; | |
#main { | |
border: solid 2px gray; | |
} | |
.area23 { fill: #ddc; } | |
.areaCity { fill: #cdc; } | |
.areaIsle { fill: #cdd; } | |
.area { stroke: #000000; } | |
.area:hover { fill: #00ffff; } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment