{"id":2993,"date":"2013-08-13T09:50:14","date_gmt":"2013-08-13T00:50:14","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2993"},"modified":"2014-04-16T12:03:38","modified_gmt":"2014-04-16T03:03:38","slug":"post-2993","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2993","title":{"rendered":"\u3010D3.js\u3011 \u5730\u56f3\u4e0a\u306e\u30eb\u30fc\u30c8\u306b\u6cbf\u3063\u3066\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example2\/geo3\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/08\/maplineanimation.jpg\" alt=\"maplineanimation\" width=\"590\" height=\"469\" class=\"aligncenter size-full wp-image-2994\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/08\/maplineanimation.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/08\/maplineanimation-189x150.jpg 189w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example2\/geo3\/index.html\">example<\/a><\/p>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2913\">\u4ee5\u524d\u306e\u8a18\u4e8b<\/a>\u3067\u3001\u5730\u56f3\u4e0a\u306e\uff12\u70b9\u3092\u7d50\u3076\u7dda\u3092\u5f15\u304f\u65b9\u6cd5\u3092\u63b2\u8f09\u3057\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306f\u305d\u306e\u5f15\u3044\u305f\u7dda\u4e0a\u306b\u6cbf\u3063\u3066circle\u3092\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u308b\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js decode:true \" >\r\nd3.json(\"gunma.topojson\", function(json) {\r\n\td3main(json);\r\n});\r\n \r\n \r\nfunction d3main(json){\r\n\tvar width = 960;\r\n\tvar height = 960;\r\n    \r\n\tvar svg = d3.select(\"svg\")\r\n\t\t.attr(\"width\", width)\r\n\t\t.attr(\"height\", height);\r\n \r\n\t\/\/\u6295\u5f71\u6cd5\u8a2d\u5b9a\r\n\tvar projection = d3.geo\r\n\t\t.mercator()        \/\/\u6295\u5f71\u6cd5\u306e\u6307\u5b9a\r\n\t\t.scale(40000)    \/\/\u30b9\u30b1\u30fc\u30eb\uff08\u30ba\u30fc\u30e0\uff09\u306e\u6307\u5b9a\r\n\t\t.translate([width\/2,height\/2])\r\n\t\t.center([139.0032936, 36.3219088]); \/\/\u4e2d\u5fc3\u306e\u5ea7\u6a19\u3092\u6307\u5b9a\r\n\r\n\t\/\/\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\r\n\tvar path = d3.geo.path().projection(projection);\r\n\r\n\r\n\t\/\/\u5730\u56f3\u8ffd\u52a0  \r\n\tvar land = svg.insert(\"path\", \".graticule\")\r\n\t\t.datum(topojson.object(json, json.objects.gunma))\r\n\t\t.attr({\r\n\t\t\t\"class\": \"land\",\r\n\t\t\t\"d\": path,\r\n\t\t\t\"fill\": \"green\",\r\n\t\t\t\"opacity\": 0.5\r\n\t\t});\r\n\r\n\t\/\/\u5883\u7dda\u8ffd\u52a0\r\n\tvar boundary = svg.insert(\"path\", \".graticule\")\r\n\t\t.datum(topojson.object(json, json.objects.gunma, function(a, b) { return a !== b; }))\r\n\t\t.attr({\r\n\t\t\t\"class\": \"boundary\",\r\n\t\t\t\"d\": path,\r\n\t\t\t\"fill\": \"none\",\r\n\t\t\t\"stroke\": \"white\",\r\n\t\t\t\"stroke-width\": .5\r\n\t\t});\r\n \r\n\t\/\/\u30dd\u30a4\u30f3\u30c8\u4f4d\u7f6e\u60c5\u5831\r\n\tvar pointdata = {\"type\": \"LineString\", \"coordinates\": [\r\n\t\t[139.013057, 36.322356], \/\/\u9ad8\u5d0e\r\n\t\t[139.073177, 36.383191], \/\/\u524d\u6a4b\r\n\t\t[139.19382500000006, 36.32668100000001], \/\/\u592a\u7530\r\n\t\t[139.0441608,36.6460769], \/\/\u6cbc\u7530\r\n\t\t[138.6388879,36.5314431], \/\/\u543e\u59bb\r\n\t\t[138.59605290000002,36.6207784], \/\/\u8349\u6d25\r\n\t\t[139.13282479999998,36.8052796], \/\/\u6b66\u5c0a\u5c71\r\n\t\t[139.33068750000007,36.4054907] \/\/\u6850\u751f\u5e02\r\n\t]}\r\n\r\n\t\/\/\u30dd\u30a4\u30f3\u30c8\u9593\u30e9\u30a4\u30f3\u8ffd\u52a0\r\n\tvar line = svg.selectAll(\".line\")\r\n\t\t.data([pointdata])\r\n\t\t.enter()\r\n\t\t.append(\"path\")\r\n\t\t.attr({\r\n\t\t\t\"class\":\"line\",\r\n\t\t\t\"d\": path,\r\n\t\t\t\"fill\": \"none\",\r\n\t\t\t\"stroke\": \"black\",\r\n\t\t\t\"stroke-width\": 1.5\r\n\t\t});\r\n\r\n\t\/\/\u30dd\u30a4\u30f3\u30c8\u8ffd\u52a0        \r\n\tvar point = svg.selectAll(\".point\")\r\n\t\t.data(pointdata.coordinates)\r\n\t\t.enter()\r\n\t\t.append(\"circle\")\r\n\t\t.attr({\r\n\t\t\t\"cx\":function(d) { return projection(d)[0]; },\r\n\t\t\t\"cy\":function(d) { return projection(d)[1]; },\r\n\t\t\t\"r\":4,\r\n\t\t\t\"fill\":\"black\",\r\n\t\t\t\"fill-opacity\":1\r\n\t\t});\r\n\r\n\r\n\t\/\/path\u60c5\u5831\u53d6\u5f97\r\n\tvar pathNode = d3.selectAll('.line').node();\u3000\/\/\u30bf\u30fc\u30b2\u30c3\u30c8\u30d1\u30b9\u6307\u5b9a\r\n\tvar pathLength = pathNode.getTotalLength(); \r\n\r\n\t\/\/\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3circle\u8ffd\u52a0    \r\n\tvar circle = svg.append(\"circle\")\r\n\t\t.attr({\r\n\t\t\tr: 10,\r\n\t\t\tfill: 'red',\r\n\t\t\ttransform: function () {\r\n\t\t\tvar p = pathNode.getPointAtLength(0)\r\n\t\t\t\treturn \"translate(\" + [p.x, p.y] + \")\";\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\/\/\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\r\n\tcircle.transition()\r\n\t\t.duration(5000)\r\n\t\t.ease(\"linear\")\r\n\t\t.attrTween(\"transform\", function (d, i) {\r\n\t\t\treturn function (t) {\r\n\t\t\t\tvar p = pathNode.getPointAtLength(pathLength*t);\r\n\t\t\t\treturn \"translate(\" + [p.x, p.y] + \")\";\r\n\t\t\t}\r\n\t\t});\r\n\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example \u4ee5\u524d\u306e\u8a18\u4e8b\u3067\u3001\u5730\u56f3\u4e0a\u306e\uff12\u70b9\u3092\u7d50\u3076\u7dda&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2994,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2993","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=2993"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2993\/revisions"}],"predecessor-version":[{"id":3484,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2993\/revisions\/3484"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2994"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}