{"id":7556,"date":"2021-12-14T08:34:06","date_gmt":"2021-12-13T23:34:06","guid":{"rendered":"https:\/\/gunmagisgeek.com\/blog\/?p=7556"},"modified":"2021-12-15T10:41:46","modified_gmt":"2021-12-15T01:41:46","slug":"deck-gl%e3%81%a7%e7%89%b9%e5%ae%9a%e3%81%ae%e5%9c%b0%e7%89%a9%e3%82%92%e7%94%bb%e9%9d%a2%e5%86%85%e3%81%ab%e8%87%aa%e5%8b%95%e7%9a%84%e3%81%ab%e5%8f%8e%e3%82%81%e3%82%8b%e3%80%82","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/deck-gl\/7556","title":{"rendered":"deck.gl\u3067\u7279\u5b9a\u306e\u5730\u7269\u3092\u753b\u9762\u5185\u306b\u81ea\u52d5\u7684\u306b\u53ce\u3081\u308b\u3002"},"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>\u7279\u5b9a\u306e\u5730\u7269\u3084\u30de\u30fc\u30ab\u7fa4\u306a\u3069\u304c\u753b\u9762\u5185\u306b\u3061\u3087\u3046\u3069\u53ce\u307e\u308b\u3088\u3046\u306b\u30ab\u30e1\u30e9(viewState)\u3092\u81ea\u52d5\u7684\u306b\u8a2d\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h2>\n\n\n\n<p>\u90fd\u9053\u5e9c\u770c\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u305d\u306e\u770c\u304c\u753b\u9762\u5185\u306b\u53ce\u307e\u308b\u4f4d\u7f6e\u3078\u30ab\u30e1\u30e9\u304c\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<iframe src=\"https:\/\/codesandbox.io\/embed\/deck-gl-di-wu-wohua-mian-nei-nizi-dong-de-nishou-meru-90fm1?fontsize=14&#038;hidenavigation=1&#038;theme=dark&#038;view=split\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"deck.gl - \u5730\u7269\u3092\u753b\u9762\u5185\u306b\u81ea\u52d5\u7684\u306b\u53ce\u3081\u308b\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   ><\/iframe>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u8aac<\/h2>\n\n\n\n<p><a href=\"https:\/\/deck.gl\/docs\/api-reference\/core\/web-mercator-viewport\" data-type=\"URL\" data-id=\"https:\/\/deck.gl\/docs\/api-reference\/core\/web-mercator-viewport\">WebMercatorViewport<\/a>\u3092\u4f7f\u3046\u3068\u3001\u7279\u5b9a\u306e\u7bc4\u56f2(bounding box)\u304c\u753b\u9762\u306b\u3061\u3087\u3046\u3069\u53ce\u307e\u308b\u7def\u5ea6\u7d4c\u5ea6\u3068\u30ba\u30fc\u30e0\u30ec\u30d9\u30eb\u3092\u7b97\u51fa\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u3053\u3067\u306f\u3001<a href=\"https:\/\/turfjs.org\/\" data-type=\"URL\" data-id=\"https:\/\/turfjs.org\/\">turf.js<\/a>\u3092\u4f7f\u3063\u3066\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u90fd\u9053\u5e9c\u770c\u306ebounding box\u3092\u53d6\u5f97\u3057\u3001\u305d\u306e\u5024\u3092 WebMercatorViewport \u306b\u308f\u305f\u3059\u3053\u3068\u3067\u3001\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u90fd\u9053\u5e9c\u770c\u304c\u3061\u3087\u3046\u3068\u753b\u9762\u5185\u306b\u53ce\u307e\u308b\u3088\u3046\u306bviewState\u3092\u66f4\u65b0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30dd\u30a4\u30f3\u30c8\u3068\u3057\u3066\u306f WebMercatorViewport  \u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308b\u969b\u306b\u3001deck.gl\u306e\u63cf\u753b\u9818\u57df\u306e\u30b5\u30a4\u30ba(width.height)\u3092\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u63cf\u753b\u9818\u57df\u306e\u30b5\u30a4\u30ba\u304c\u6b63\u3057\u304f\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3001\u6b63\u3057\u3044\u5024\u3092\u8a08\u7b97\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:js decode:true \">\/\/ WebMercatorViewport\u3092\u8aad\u307f\u8fbc\u307f\nimport DeckGL, { WebMercatorViewport } from \"deck.gl\";\n\/\/turf.js\u306ebbox\u95a2\u6570\u3092\u8aad\u307f\u8fbc\u307f\nimport bbox from \"@turf\/bbox\";\n\n\n\/\/\u5730\u7269\u30af\u30ea\u30c3\u30af\u6642\u306bviewState\u3092\u66f4\u65b0\u3059\u308b\nconst clickHandler = (e) =&gt; {\n    \/\/\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u5730\u7269(\u90fd\u9053\u5e9c\u770c)\u306egeometory\u3092\u53d6\u5f97\u3059\u308b\n    const geo = e.object.geometry;\n    \/\/turf.js\u3092\u4f7f\u3063\u3066geometry\u304b\u3089\u30d0\u30a6\u30f3\u30c7\u30a3\u30dc\u30c3\u30af\u30b9\u3092\u7b97\u51fa\u3059\u308b\n    const [minLng, minLat, maxLng, maxLat] = bbox(geo);\n    \/\/\u5ea7\u6a19\u5909\u63db\u3092\u884c\u3046\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3059\u308b\n    const viewportWebMercator = new WebMercatorViewport({\n        width: document.querySelector(\"#deckgl-wrapper\").clientWidth,\n        height: document.querySelector(\"#deckgl-wrapper\").clientHeight\n    });\n\n    \/\/\u6307\u5b9a\u3055\u308c\u305f\u30d0\u30a6\u30f3\u30c7\u30a3\u30dc\u30c3\u30af\u30b9\u304c\u753b\u9762\u5185\u306b\u4e01\u5ea6\u53ce\u307e\u308b\u7def\u5ea6\u7d4c\u5ea6\u3068\u30ba\u30fc\u30e0\u30ec\u30d9\u30eb\u3092\u7b97\u51fa\u3059\u308b\n    const { longitude, latitude, zoom } = viewportWebMercator.fitBounds(\n        [\n            [minLng, minLat],\n            [maxLng, maxLat]\n        ],\n        {\n            padding: 0 \/\/\u5730\u7269\u3092\u753b\u9762\u5185\u306b\u53ce\u3081\u308b\u969b\u306b\u4f59\u767d\u3092\u8a2d\u5b9a\u3059\u308b\n        }\n    );\n\n    \/\/viewState\u3092\u66f4\u65b0\u3057\u30ab\u30e1\u30e9\u3092\u5730\u7269\u304c\u53ce\u307e\u308b\u4f4d\u7f6e\u3078\u79fb\u52d5\u3059\u308b\n    setViewState((v) =&gt; {\n        return {\n            ...v, \/\/current viewState\n            latitude: latitude,\n            longitude: longitude,\n            zoom: zoom,\n            transitionDuration: 1000,\n            transitionInterpolator: new FlyToInterpolator()\n        };\n    });\n};\n\nreturn (\n    &lt;DeckGL\n        layers={renderLayers({\n            onClick: clickHandler  \/\/geojson layer\u306eonClick\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u6e21\u3059\n        })}\n    \/&gt;\n);<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u306fdeck.gl Advent Calen&hellip;<\/p>\n","protected":false},"author":1,"featured_media":7818,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"class_list":["post-7556","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\/7556","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=7556"}],"version-history":[{"count":8,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/7556\/revisions"}],"predecessor-version":[{"id":7826,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/7556\/revisions\/7826"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/7818"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=7556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=7556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=7556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}