{"id":7654,"date":"2021-12-09T08:21:06","date_gmt":"2021-12-08T23:21:06","guid":{"rendered":"https:\/\/gunmagisgeek.com\/blog\/?p=7654"},"modified":"2021-12-09T08:32:09","modified_gmt":"2021-12-08T23:32:09","slug":"deck-gl%e3%81%a7geojson%e3%82%92%e5%8f%af%e8%a6%96%e5%8c%96%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/deck-gl\/7654","title":{"rendered":"deck.gl\u3067GeoJSON\u3092\u53ef\u8996\u5316\u3059\u308b"},"content":{"rendered":"\n<p> \u3053\u306e\u8a18\u4e8b\u306f<a href=\"https:\/\/qiita.com\/advent-calendar\/2021\/deckgl\">deck.gl Advent Calendar 2021&nbsp;<\/a>\u53c2\u52a0\u8a18\u4e8b\u3067\u3059\u3002 <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6982\u8981<\/h2>\n\n\n\n<p>deck.gl\u306b\u306f\u69d8\u3005\u306a\u30ec\u30a4\u30e4\u30fc\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u305d\u306e\u4e2d\u3067\u3082\u6700\u3082\u6c4e\u7528\u6027\u304c\u9ad8\u3044\u306e\u304c<a href=\"https:\/\/deck.gl\/docs\/api-reference\/layers\/geojson-layer\" data-type=\"URL\" data-id=\"https:\/\/deck.gl\/docs\/api-reference\/layers\/geojson-layer\">GeoJsonLayer<\/a>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>GeoJsonLayer\u3067\u306f\u3001\u30dd\u30a4\u30f3\u30c8\u30fb\u30e9\u30a4\u30f3\u30fb\u30dd\u30ea\u30b4\u30f3\u3068\u3044\u3063\u305f\u57fa\u672c\u7684\u306a\u5730\u7269\u306e\u8868\u793a\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u307b\u304b\u3001\u30a2\u30a4\u30b3\u30f3\u306e\u8868\u793a\u3001\u30c6\u30ad\u30b9\u30c8\u30e9\u30d9\u30eb\u306e\u8868\u793a\u30013D\u8868\u73fe\u307e\u3067\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p> GeoJsonLayer\u306e\u4f7f\u3044\u65b9\u3092\u899a\u3048\u308b\u3060\u3051\u3067\u683c\u6bb5\u306bdeck.gl\u304c\u4f7f\u3044\u3084\u3059\u304f\u306a\u308b\u306e\u3067\u3001\u305c\u3072\u4f7f\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h2>\n\n\n\n<iframe src=\"https:\/\/codesandbox.io\/embed\/deck-gl-geojsonreiyanoshi-ifang-m2wk3?fontsize=14&amp;hidenavigation=1&amp;module=%2Fsrc%2FRenderLayers.js&amp;theme=dark&amp;view=split\" style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\" title=\"deck.gl - GeoJSON\u30ec\u30a4\u30e4\u30fc\u306e\u4f7f\u3044\u65b9\" 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>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u8aac<\/h2>\n\n\n\n<p>GeoJsonLayer\u306edata\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u306f<a href=\"https:\/\/ja.wikipedia.org\/wiki\/GeoJSON\" data-type=\"URL\" data-id=\"https:\/\/ja.wikipedia.org\/wiki\/GeoJSON\">GeoJSON\u5f62\u5f0f<\/a>\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6e21\u3059\u4ee5\u5916\u306b\u3001GeoJSON\u30d5\u30a1\u30a4\u30eb\u3078\u306eURL\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u76f4\u63a5\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u306b\u95a2\u3057\u3066\u306fpointType\u30d7\u30ed\u30d1\u30c6\u30a3\u3067\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30b5\u30fc\u30af\u30eb\u3001\u30a2\u30a4\u30b3\u30f3\u3001\u30c6\u30ad\u30b9\u30c8\u30e9\u30d9\u30eb\u306e\u51fa\u529b\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:js decode:true \" >import { GeoJsonLayer } from \"deck.gl\";\n\nexport function renderLayers(props) {\n  const { pointData } = props;\n\n  \/\/point\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u304c\u7d42\u308f\u308b\u307e\u3067\u51e6\u7406\u3092\u30b9\u30eb\u30fc\n  if (!pointData) return;\n\n  \/\/\u5c5e\u6027\u5024\u306e\u30e9\u30d9\u30eb\u304b\u3089\u5fc5\u8981\u306a\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u30bb\u30c3\u30c8\u3092\u53d6\u5f97\u3059\u308b\n  const tmp = pointData.features\n    .map((d) =&gt; Array.from(d.properties.label)) \/\/\u30e9\u30d9\u30eb\u6587\u5b57\u5217\u3092\u53ce\u96c6\n    .flat();\n\n  \/\/\u91cd\u8907\u3092\u524a\u9664\n  const charaSet = Array.from(new Set(tmp)) \n\n  \/\/\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u3092\u30b5\u30fc\u30af\u30eb+\u30c6\u30ad\u30b9\u30c8\u3068\u3057\u3066\u51fa\u529b\n  const point = new GeoJsonLayer({\n    id: \"point\",\n    data: pointData,\n    stroked: true,\n    filled: true,\n    pointType: \"circle+text\", \/\/circle, text, icon\u3092\u8a2d\u5b9a\u53ef\u80fd\u3001+\u63a5\u7d9a\u8a5e\u3067\u8907\u6570\u306e\u30bf\u30a4\u30d7\u3082\u540c\u6642\u9078\u629e\u3067\u304d\u308b\n    \/\/circle\u306e\u8a2d\u5b9a\n    getPointRadius: 30, \/\/circle\u306e\u534a\u5f84\n    getFillColor: [255, 0, 0, 180],\n    getLineColor: [0, 255, 0, 255],\n    lineWidthMinPixels: 2,    \n    \/\/\u30c6\u30ad\u30b9\u30c8\u30e9\u30d9\u30eb\u8a2d\u5b9a\n    getText: (d) =&gt; d.properties.label,\u3000\/\/\u5c5e\u6027\u5024\u306elabel\u306e\u5024\u3092\u30c6\u30ad\u30b9\u30c8\u30e9\u30d9\u30eb\u3068\u3057\u3066\u8868\u793a\u3059\u308b\n    getTextPixelOffset: [0, -20], \/\/\u30c6\u30ad\u30b9\u30c8\u30e9\u30d9\u30eb\u306e\u76f8\u5bfe\u7684\u306a\u4f4d\u7f6e\n    getTextColor: [180, 0, 0],\n    textFontWeight: \"bold\",\n    textSizeScale: 0.6,\n    textCharacterSet: charaSet \/\/\u751f\u6210\u3057\u305f\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u30bb\u30c3\u30c8\u3092deck.gl\u306b\u6e21\u3059\n  });\n\n  \/\/\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u3092icon\u3068\u3057\u3066\u51fa\u529b\n  const icon = new GeoJsonLayer({\n    id: \"icon\",\n    data: \".\/data\/icon.geojson\",\n    stroked: true,\n    filled: true,\n    pointType: \"icon\",\n    \/\/icon\u306e\u8a2d\u5b9a\n    getIcon: () =&gt; { return {\n      url: \".\/img\/marker.png\",\n      x: 0, \/\/\u753b\u50cf\u8aad\u307f\u8fbc\u307f\u306eX\u8ef8\u30aa\u30d5\u30bb\u30c3\u30c8\n      y: 0, \/\/\u753b\u50cf\u8aad\u307f\u8fbc\u307f\u306eY\u8ef8\u30aa\u30d5\u30bb\u30c3\u30c8\n      anchorY: 512, \/\/Y\u8ef8\u306e\u8868\u793a\u4f4d\u7f6e\uff08\u901a\u5e38\u753b\u50cf\u306e\u7e26\u5e45\u306b\u5408\u308f\u305b\u308b\uff09\n      width: 512, \/\/\u30a2\u30a4\u30b3\u30f3\u753b\u50cf\u306e\u6a2a\u5e45\n      height: 512, \/\/\u30a2\u30a4\u30b3\u30f3\u753b\u50cf\u306e\u7e26\u5e45\n      mask: true \/\/ture\u306b\u3059\u308b\u3068\u30a2\u30a4\u30b3\u30f3\u753b\u50cf\u306e\u8272\u306e\u4e0a\u5857\u308a\u306a\u3069\u304c\u53ef\u80fd\u306b\u306a\u308b\n    }},\n    iconSizeScale: 60,\n    getIconColor: [255, 124, 0] \/\/\u30aa\u30ec\u30f3\u30b8\u8272\n  });\n\n  \/\/\u30e9\u30a4\u30f3\u30c7\u30fc\u30bf\u3092\u51fa\u529b\n  const line = new GeoJsonLayer({\n    id: \"line\",\n    data: \".\/data\/line.geojson\",\n    stroked: true,\n    filled: true,\n    getLineColor: [0, 0, 255, 255],\n    lineWidthMinPixels: 4\n  });\n\n  \/\/\u30dd\u30ea\u30b4\u30f3\u30c7\u30fc\u30bf\u3092\u51fa\u529b\n  const polygon = new GeoJsonLayer({\n    id: \"polygon\",\n    data: \".\/data\/polygon.geojson\",\n    stroked: true,\n    filled: true,\n    getFillColor: [0, 160, 0, 180],\n    getLineColor: [0, 0, 255, 255],\n    lineWidthMinPixels: 2\n  });\n\n  \/\/\u30dd\u30ea\u30b4\u30f3\u30c7\u30fc\u30bf\u3092\u51fa\u529b\n  const polygon3D = new GeoJsonLayer({\n    id: \"polygon3D\",\n    data: \".\/data\/3d-polygon.geojson\",\n    stroked: true,\n    filled: true,\n    extruded: true, \/\/ 3d\u8868\u793a\u3092\u6709\u52b9\u306b\u3059\u308b\n    wireframe: true, \/\/\u30a2\u30a6\u30c8\u30e9\u30a4\u30f3\u3092\u8868\u793a\u3059\u308b\n    getFillColor: [0, 160, 255, 180],\n    getLineColor: [255, 0, 0, 255],\n    getElevation: (d, { index }) =&gt; { \/\/\u30dd\u30ea\u30b4\u30f3\u306e\u9ad8\u3055\u3092\u6307\u5b9a\u3059\u308b\n      const i = index + 1; \n      return 500 * i; \/\/500m * index\u3092\u9ad8\u3055\u306b\u6307\u5b9a\n    }\n  });\n\n\n  \/\/\u914d\u5217\u306e\u9806\u3067\u30ec\u30a4\u30e4\u30fc\u306e\u91cd\u306a\u308a\u9806\u304c\u5909\u308f\u308a\u307e\u3059\u3002\n  return [line, point, icon, polygon, polygon3D];\n}\n<\/pre><\/div>\n\n\n\n<p>GeoJsonLayer\u306f\u69d8\u3005\u306a\u8868\u793a\u5f62\u5f0f\u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u3001\u8a2d\u5b9a\u9805\u76ee\u304c\u591a\u5c90\u306b\u308f\u305f\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u8a73\u3057\u304f\u306f\u516c\u5f0f\u30b5\u30a4\u30c8\u3092\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/deck.gl\/docs\/api-reference\/layers\/geojson-layer\">deck.gl | GeoJsonLayer<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u306fdeck.gl Advent Calen&hellip;<\/p>\n","protected":false},"author":1,"featured_media":7655,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"class_list":["post-7654","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-deck-gl","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/7654","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=7654"}],"version-history":[{"count":12,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/7654\/revisions"}],"predecessor-version":[{"id":7792,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/7654\/revisions\/7792"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/7655"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=7654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=7654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=7654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}