{"id":2631,"date":"2013-03-13T11:35:03","date_gmt":"2013-03-13T02:35:03","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2631"},"modified":"2018-03-06T11:34:05","modified_gmt":"2018-03-06T02:34:05","slug":"post-2631","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3v4\/2631","title":{"rendered":"\u3010D3.js\u3011 SVG\u3067\u5730\u7403\u5100\u3092\u63cf\u304f"},"content":{"rendered":"<p>\u56de\u8ee2\u3055\u305b\u308b\u306e\u3082\u7c21\u5358\u3001\u305d\u3046D3\u306a\u3089\u306d\u3002<br \/>\n<a href=\"https:\/\/bl.ocks.org\/shimizu\/b9b7187b75366ab46be12137b05f277b\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/d3glob.jpg\" alt=\"d3glob\" width=\"564\" height=\"503\" class=\"alignnone size-full wp-image-2634\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/d3glob.jpg 564w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/d3glob-168x150.jpg 168w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/b9b7187b75366ab46be12137b05f277b\">example<\/a><\/p>\n<p>\u30c7\u30fc\u30bf\u306fNaturalEarth\u306e\u300c<a href=\"http:\/\/www.naturalearthdata.com\/downloads\/110m-cultural-vectors\/\">Admin 0 \u2013 Countries<\/a>\u300d\u304b\u3089\u3002<br \/>\n\u898b\u3065\u3089\u304f\u306a\u308b\u306e\u3067\u5357\u6975\u5927\u9678\u306b\u306f\u6d88\u3048\u3066\u3044\u305f\u3060\u3044\u305f\u3002<br \/>\n\u6d88\u3057\u65b9\u306f\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fsahpe\u30c7\u30fc\u30bf\u3092 <a href=\"http:\/\/www.qgis.org\/\">Quantum GIS<\/a>\u306b\u53d6\u308a\u8fbc\u3093\u3067\u3001\u30e1\u30cb\u30e5\u30fc\u306e\u300c\u30ec\u30a4\u30e4\u30fc\u300d\u304b\u3089\u300c\u5c5e\u6027\u30c6\u30fc\u30d6\u30eb\u306e\u30aa\u30fc\u30d7\u30f3\u300d\u3092\u9078\u629e\u3002<br \/>\n\u5c5e\u6027\u30c6\u30fc\u30d6\u30eb\u306e\u4e2d\u304b\u3089\u300csovereignt\u300d\u306e\u5024\u304c\u300cAntractica\u300d\u306b\u306a\u3063\u3066\u3044\u308b\u884c\u3092\u9078\u629e\u3057\u3001\u4e0b\u306e\u307b\u3046\u306b\u3042\u308b\u30a2\u30a4\u30b3\u30f3\u304b\u3089\u300c\u9078\u629e\u90e8\u5206\u3092\u53cd\u8ee2\u3059\u308b\u300d\u3092\u30af\u30ea\u30c3\u30af\u3002<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/qgisdelete.jpg\" alt=\"qgisdelete\" width=\"1211\" height=\"608\" class=\"size-full wp-image-2633\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/qgisdelete.jpg 1211w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/qgisdelete-300x150.jpg 300w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/qgisdelete-768x386.jpg 768w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/qgisdelete-1024x514.jpg 1024w\" sizes=\"auto, (max-width: 1211px) 100vw, 1211px\" \/><br \/>\n\u5357\u6975\u5927\u9678\u4ee5\u5916\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u308b\u306e\u3092\u78ba\u8a8d\u3057\u3066\u300c\u30ec\u30a4\u30e4\u30fc\u300d\u304b\u3089\u300c\u9078\u629e\u90e8\u5206\u3092\u30d9\u30af\u30bf\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u4fdd\u5b58\u3059\u308b\u300d\u3092\u30af\u30ea\u30c3\u30af\u2192\u300cGeo JSON\u300d\u5f62\u5f0f\u3067\u4fdd\u5b58\u3002<br \/>\n\u4e00\u5fdctopojson\u306b\u5909\u63db\u3057\u3066\u8efd\u91cf\u5316\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >$ topojson -o conuntries.topojson conuntries.geojson<\/pre>\n<p>\u4ee5\u4e0a\u3067\u3001\u5730\u56f3\u30c7\u30fc\u30bf\u4f5c\u6210\u7d42\u4e86\u3002<br \/>\n\u3042\u3068\u306f\u3001D3\u306e\u300c<a href=\"https:\/\/github.com\/mbostock\/d3\/wiki\/Geo-Projections\">Geo Projections<\/a>\u300d\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u8868\u793a\u3059\u308b\u3060\u3051\u3002<br \/>\n\u3053\u306e\u8fba\u306e\u30c7\u30fc\u30bf\u4f5c\u6210\u306b\u3064\u3044\u3066\u306f\u3001\u904e\u53bb\u306e\u8a18\u4e8b\u306b\u8a73\u7d30\u3092\u8f09\u305b\u3066\u3044\u308b\u306e\u3067\u8208\u5473\u3042\u308b\u65b9\u306f<a href=\"https:\/\/gunmagisgeek.com\/blog\/category\/map\">\u3053\u3061\u3089<\/a>\u3092\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"lang:js decode:true \" >const stage = d3.select(\"svg\");\nconst seaLayer = stage.append(\"g\");\nconst landLayer = stage.append(\"g\");\n\nconst projection = d3.geoOrthographic() \/\/\u6295\u5f71\u6cd5\u3092\u6307\u5b9a\nconst path = d3.geoPath()\/\/geometry\u3092svg\u306e\u30d1\u30b9\u306b\u5909\u63db\u3059\u308b\u95a2\u6570\n        \nd3.json(\"conuntries.topojson\", function(json){ \/\/\u5730\u56f3\u60c5\u5831\u306e\u8aad\u307f\u8fbc\u307f\n  \n  const  data = topojson.feature(json, json.objects.conuntries).features; \/\/topojson-&gt;geojson\u5909\u63db\n\n  \/*\u30d7\u30ed\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u8a2d\u5b9a*\/\n  projection\n    .rotate([0,0,0]) \/\/x,y,z\u56de\u8ee2\n    .clipAngle(90); \/\/\u8868\u793a\u3059\u308b\u89d2\u5ea6 180\u5ea6\u3092\u6307\u5b9a\u3059\u308b\u3068\u88cf\u5074\u306e\u5927\u9678\u307e\u3067\u8868\u793a\u3055\u308c\u308b\n  \n  \/*\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\u306b\u30d7\u30ed\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u3092\u8a2d\u5b9a*\/\n  path.projection(projection);\n\n  \/*\u6d77\u9762\u3092\u63cf\u753b\u3059\u308b\u305f\u3081\u306e\u30d1\u30b9\u3092DOM\u306b\u8ffd\u52a0*\/\n  seaLayer.append(\"path\")\n    .datum({type: \"Sphere\"})\n    .attr(\"fill\", \"blue\")\n   \n   \/*\u5730\u56f3\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u306e\u30d1\u30b9\u3092DOM\u306b\u8ffd\u52a0*\/\n  landLayer\n    .selectAll(\"path\")\n    .data(data) \n    .enter()\n    .append(\"path\")\n    .style(\"background-color\", \"blue\")\n    .attr(\"fill\", \"green\")\n    .attr(\"stroke\", \"#222\")\n    .on(\"mouseover\", function(){\n        d3.select(this).attr(\"fill\", \"red\");\n    })\n    .on(\"mouseout\", function(){\n        d3.select(this).transition().duration(500).attr(\"fill\", \"green\");\n    })\n       \n});\n    \n\/*\u5730\u5f62\u3092\u56de\u8ee2\u3055\u305b\u308b*\/ \nconst draw = () =&gt; {\n  let  i = 0;\n  return () =&gt; {\n    const w = stage.node().clientWidth;\n    const h = stage.node().clientHeight;\n    i = i+0.5;\n    projection\n      .rotate([i,0,0])  \/\/rotate\u306ex\u5024\u3092\u5897\u3084\u3057\u3066\u6a2a\u306b\u56de\u8ee2\u3055\u305b\u308b\n      .scale(d3.min([w, h]) \/ 2) \/\/\u753b\u9762\u30b5\u30a4\u30ba\u3092\u5143\u306b\u5730\u7403\u5100\u306e\u5927\u304d\u3055\u3092\u6c7a\u5b9a\n      .translate([w\/2, h\/2]) \/\/\u753b\u9762\u4e2d\u592e\u306b\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u79fb\u52d5\u3059\u308b\n    path.projection(projection);    \/\/path\u95a2\u6570\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\n    \n    seaLayer.select(\"path\").attr(\"d\", path); \/\/\u6d77\u9762\u7528\u30d1\u30b9\u3092\u63cf\u753b\n    landLayer.selectAll(\"path\").attr(\"d\", path); \/\/\u5730\u56f3\u7528\u30d1\u30b9\u3092\u63cf\u753b\n    \n  }\n}\n    \nsetInterval(draw(), 100); \/\/\u5b9a\u671f\u7684\u306b\u56de\u8ee2\u3055\u305b\u308b<\/pre>\n<h3>\u95a2\u9023<\/h3>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4052\">\u5730\u8ef8\u3092\u50be\u3051\u306a\u304c\u3089SVG\u3067\u5730\u7403\u5100\u3092\u8868\u793a\u3059\u308b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u56de\u8ee2\u3055\u305b\u308b\u306e\u3082\u7c21\u5358\u3001\u305d\u3046D3\u306a\u3089\u306d\u3002 exampl&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2634,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-2631","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3v4","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2631","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=2631"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2631\/revisions"}],"predecessor-version":[{"id":2795,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2631\/revisions\/2795"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2634"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}