{"id":2877,"date":"2013-06-07T15:35:05","date_gmt":"2013-06-07T06:35:05","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2877"},"modified":"2018-03-06T15:09:40","modified_gmt":"2018-03-06T06:09:40","slug":"post-2877","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/google-map-api\/2877","title":{"rendered":"\u3010D3.js\u3011\u5730\u56f3\u4e0a\u306b\u56db\u5206\u6728\u3092\u63cf\u304f"},"content":{"rendered":"<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/449ee7297fa93276bec916cbb8a8c213\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/06\/test000009.jpg\" alt=\"test000009\" width=\"590\" height=\"393\" class=\"aligncenter size-full wp-image-2878\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/06\/test000009.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/06\/test000009-225x150.jpg 225w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/449ee7297fa93276bec916cbb8a8c213\">example<\/a><\/p>\n<p>\u4ee5\u524d\u3001<a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2819\">\u5730\u56f3\u4e0a\u306b\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u3044\u3066\u307f\u307e\u3057\u305f<\/a>\u304c\u3001\u4eca\u56de\u306f\u56db\u5206\u6728\u3092\u63cf\u3044\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u30c7\u30fc\u30bf\u306f\u524d\u56de\u540c\u69d8\u3001\u9ad8\u5d0e\u5e02\u306e\u30ac\u30bd\u30ea\u30f3\u30b9\u30bf\u30f3\u30c9\u4f4d\u7f6e\u60c5\u5831\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/ja.wikipedia.org\/wiki\/%E5%9B%9B%E5%88%86%E6%9C%A8\">Wikipedia:\u56db\u5206\u6728<\/a><\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"lang:js decode:true \" >const width = 980;\nconst height = 500;\n\nconst svg = d3.select(\"svg\");\nconst mapLayer = svg.append(\"g\");\nconst treeLayer = svg.append(\"g\");\n\nconst projection = d3.geoMercator();\nconst path = d3.geoPath();\u3000\n\nconst q = d3.queue();\n\nq\n .defer(d3.json, \"takasaki.topojson\")\n .defer(d3.json, \"gasStation.geojson\")\n .await((error, maps2topo, point2geo) =&gt; {\n    const maps2geo = topojson.feature(maps2topo, maps2topo.objects.takasaki);\n\n    \/\/\u8aad\u307f\u8fbc\u3093\u3060\u5730\u56f3\u30c7\u30fc\u30bf\u304c\u63cf\u753b\u9818\u57df\u306b\u53ce\u307e\u308b\u3088\u3046\u306b\u81ea\u52d5\u7684\u306b\u30d7\u30ed\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u3092\u8abf\u6574\u3059\u308b\u3002\n    projection.fitExtent([[0,0],[width, height]], maps2geo);\n    path.projection(projection);\n\n    drawMaps(maps2geo);\n    drawVoronoi(point2geo);\n});\n\n\nfunction drawMaps(geojson){\n    \/\/\u5730\u56f3\u8868\u793a\n    const map =  mapLayer.attr(\"id\", \"map\")\n        .selectAll(\"path\")\n        .data(geojson.features)\n        .enter()\n        .append(\"svg:path\")\n        .attr(\"d\", path)\n        .attr(\"fill\", \"#99ff99\")\n        .attr(\"fill-opacity\", 1)\n        .attr(\"stroke\", \"black\");\n    \n}\n\nfunction drawVoronoi(geojson){\n    const pointdata = geojson.features;\n    const positions = [];\n    \n    pointdata.forEach(d =&gt; {\n        positions.push(projection(d.geometry.coordinates)); \/\/\u4f4d\u7f6e\u60c5\u5831\u3092\u30d4\u30af\u30bb\u30eb\u5ea7\u6a19\u306b\u5909\u63db\u3059\u308b\n    });\n    \n    \/\/\u6bcd\u70b9\u8868\u793a\n    treeLayer.selectAll(\".point\")\n        .data(positions)\n        .enter()\n        .append(\"circle\")\n        .attr(\"class\", \"point\")\n        .attr(\"transform\", d =&gt;  `translate(${d[0]}, ${d[1]})` )\n        .attr(\"r\", 2);\n                    \n        \/\/ \u56db\u5206\u6728\u751f\u6210\n        var quadtree = d3.quadtree()\n            .extent([[-1, -1], [width + 1, height + 1]])\n            .addAll(positions)\n        \n        \n    treeLayer.selectAll(\".node\")\n        .data(nodes(quadtree))\n        .enter()\n        .append(\"rect\")\n        .attr(\"class\", \"node\")\n        .attr(\"fill\", \"none\")\n        .attr(\"stroke\", \"black\")\n        .attr(\"x\", function(d) { return d.x0; })\n        .attr(\"y\", function(d) { return d.y0; })\n        .attr(\"width\", function(d) { return d.y1 - d.y0; })\n        .attr(\"height\", function(d) { return d.x1 - d.x0; });\n        \n    \n}\n\n\/\/rect\u8981\u7d20\u3067\u51e6\u7406\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u3001\u56db\u5206\u6728\u306e\u5ea7\u6a19\u30c7\u30fc\u30bf\u3092\u914d\u5217\u306b\u5909\u63db\u3059\u308b\nfunction nodes(quadtree) {\n  var nodes = [];\n  quadtree.visit(function(node, x0, y0, x1, y1) {\n    node.x0 = x0, node.y0 = y0;\n    node.x1 = x1, node.y1 = y1;\n    nodes.push(node);\n  });\n  return nodes;\n}\n<\/pre>\n<h2>Google Map\u4e0a\u3067\u3082\u63cf\u3044\u3066\u307f\u305f<\/h2>\n<p>\u4e00\u5fdc\u3001\u8868\u793a\u306f\u3067\u304d\u307e\u3057\u305f\u304c\u62e1\u5927\u3057\u3066\u3044\u304f\u3068\u56db\u5206\u6728\u306e\u8868\u793a\u304c\u304a\u304b\u3057\u304f\u306a\u308a\u307e\u3059\u3002<br \/>\n\u539f\u56e0\u4e0d\u660e orz<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example\/geo14\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/06\/test000010.jpg\" alt=\"test000010\" width=\"590\" height=\"389\" class=\"aligncenter size-full wp-image-2879\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/06\/test000010.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/06\/test000010-228x150.jpg 228w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example\/geo14\/\">example<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>example \u4ee5\u524d\u3001\u5730\u56f3\u4e0a\u306b\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u3044\u3066\u307f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2878,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,37],"tags":[],"class_list":["post-2877","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3v4","category-google-map-api","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2877","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=2877"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2877\/revisions"}],"predecessor-version":[{"id":5644,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2877\/revisions\/5644"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2878"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}