{"id":6424,"date":"2019-06-26T11:15:32","date_gmt":"2019-06-26T02:15:32","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=6424"},"modified":"2021-12-30T10:59:48","modified_gmt":"2021-12-30T01:59:48","slug":"deck-gl%e3%81%a8d3-js%e3%82%92%e7%b5%84%e3%81%bf%e5%90%88%e3%82%8f%e3%81%9b%e3%81%a6%e3%80%81%e5%9c%b0%e5%9b%b3%e4%b8%8a%e3%81%ab%e3%83%9c%e3%83%ad%e3%83%8e%e3%82%a4%e5%9b%b3%e3%82%92%e6%8f%8f","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3v4\/6424","title":{"rendered":"deck.gl\u3068D3.js\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u3001\u5730\u56f3\u4e0a\u306b\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u753b\u3059\u308b"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u6982\u8981<\/h2>\n\n\n\n<p>deck.gl\u3092\u4f7f\u3063\u3066WebGL\u3067\u63cf\u753b\u3057\u305f\u5730\u56f3\u306e\u4e0a\u306b\u3001D3.js\u3092\u4f7f\u3063\u3066svg\u3092\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3057\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u753b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n\n\n\n<p><iframe style=\"width: 100%; height: 500px; border: 0; border-radius: 4px; overflow: hidden;\" src=\"https:\/\/codesandbox.io\/embed\/d3-volonoi-overlay-6kx6e?fontsize=14&amp;hidenavigation=1&amp;theme=dark&amp;view=split\" title=\"d3-volonoi-overlay\" allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\" sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"><\/iframe><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u8aac<\/h2>\n\n\n\n<p>deck.gl\u3067\u306f\u3001\u7def\u5ea6\u7d4c\u5ea6\u3068\u753b\u9762\u4e0a\u306e\u5ea7\u6a19\u306e\u6295\u5f71\u5909\u63db\u3092Viewport\u30af\u30e9\u30b9\u304c\u62c5\u3063\u3066\u3044\u307e\u3059\u3002<br>Viewport\u30af\u30e9\u30b9\u306f\u901a\u5e38\u5916\u90e8\u304b\u3089\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306a\u5f62\u3067\u30a4\u30f3\u30bf\u30f3\u30b9\u5316\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u30b5\u30d6\u30af\u30e9\u30b9\u3067\u3042\u308bWebMercatorViewport\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u6295\u5f71\u5909\u63db\u3092\u884c\u3046\u305f\u3081\u306eproject\u30e1\u30bd\u30c3\u30c9\u3092\u5916\u90e8\u304b\u3089\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/deck.gl\/#\/documentation\/deckgl-api-reference\/viewports\/web-mercator-viewport\">WebMercatorViewport Class<\/a><\/p>\n\n\n\n<p>project\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u6bcd\u70b9\u306e\u753b\u9762\u4e0a\u306e\u5ea7\u6a19\u3092\u53d6\u5f97\u3057\u3001\u305d\u308c\u3089\u3092\u57fa\u306bd3-voronoi\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u7528\u3044\u3066\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u753b\u3059\u308b\u305f\u3081\u306e\u5ea7\u6a19\u3092\u7b97\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3042\u3068\u306f\u3001webGL\u4e0a\u306b\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3057\u305fSVG\u8981\u7d20\u306bPath\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u8a2d\u7f6e\u3057\u3066\u30dc\u30ed\u30ce\u30a4\u3092\u63cf\u753b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:js decode:true\">import React, { useRef, useEffect } from \"react\";\nimport { voronoi } from \"d3-voronoi\";\nimport { select } from \"d3-selection\";\n\nexport default props =&gt; {\n  const { viewport, data } = props;\n\n  if (!data.map) return null;\n  const width = viewport.width;\n  const height = viewport.height;\n  \/\/WebMercatorViewport\u306eproject\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u7def\u5ea6\u7d4c\u5ea6\u3092\u753b\u9762\u4e0a\u306e\u5ea7\u6a19\u306b\u5909\u63db\u3059\u308b\n  const point = data.map(d =&gt; viewport.project(d.position));\n  \/\/\u53d6\u5f97\u3057\u305f\u753b\u9762\u4e0a\u306e\u5ea7\u6a19\u3092\u7528\u3044\u3066\u30dc\u30ed\u30ce\u30a4\u56f3\u306e\u63cf\u753b\u306b\u5fc5\u8981\u306a\u5ea7\u6a19\u3092\u8a08\u7b97\u3059\u308b\n  const vor = voronoi().extent([[0, 0], [width, height]]);\n  const polygons = vor(point).polygons();\n\n  \/\/path\u3092\u63cf\u753b\u3059\u308b\u89aa\u8981\u7d20\u3092\u53d6\u5f97\n  const pathGroupEl = useRef(null);\n  const update = React.useRef();\n\n  \/\/\u30dc\u30ed\u30ce\u30a4\u3092path\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u4f7f\u3063\u3066\u63cf\u753b\n  update.current =  () =&gt; {\n    const selected = select(pathGroupEl.current)\n      .selectAll(\".cell\")\n      .data(polygons);\n\n    const enter = selected\n      .enter()\n      .append(\"path\")\n      .attr(\"class\", \"cell\")\n      .attr(\"fill\", \"none\")\n      .attr(\"stroke\", \"black\");\n\n    selected.merge(enter).attr(\"d\", d =&gt; {\n      if (!d || d.length &lt; 1) return null;\n      return `M${d.join(\"L\")}Z`;\n    });\n  };\n\n  \/\/polygons\u306e\u30c7\u30fc\u30bf\u306b\u5909\u5316\u304c\u3042\u3063\u305f\u3089\u30dc\u30ed\u30ce\u30a4\u3092\u518d\u63cf\u753b\u3059\u308b\n  useEffect(() =&gt; {\n    update.current();enderVoronoi();\n  }, [polygons]);\n\n  return (\n    &lt;svg viewBox={`0 0 ${viewport.width} ${viewport.height}`}&gt;\n      &lt;g ref={pathGroupEl} \/&gt;\n    &lt;\/svg&gt;\n  );\n};\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u304a\u307e\u3051<\/h2>\n\n\n\n<p>\u4eca\u56de\u306fsvg\u3092\u4f7f\u3063\u3066\u30dc\u30ed\u30ce\u30a4\u3092\u63cf\u753b\u3057\u307e\u3057\u305f\u304c\u3001d3-voronoi\u306e\u8a08\u7b97\u7d50\u679c\u3092deck.gl\u306ePathLayer\u306b\u6e21\u3057\u3066webGL\u4e0a\u306b\u63cf\u753b\u3059\u308b\u65b9\u304c\u30b9\u30de\u30fc\u30c8\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 deck.gl\u3092\u4f7f\u3063\u3066WebGL\u3067\u63cf\u753b\u3057\u305f\u5730&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6830,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,73],"tags":[],"class_list":["post-6424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3v4","category-deck-gl","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/6424","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=6424"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/6424\/revisions"}],"predecessor-version":[{"id":7877,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/6424\/revisions\/7877"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/6830"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=6424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=6424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=6424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}