{"id":4155,"date":"2015-03-20T18:27:04","date_gmt":"2015-03-20T09:27:04","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4155"},"modified":"2015-03-21T13:54:00","modified_gmt":"2015-03-21T04:54:00","slug":"post-4155","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/leaflet-js\/4155","title":{"rendered":"Turf.js\u3092\u4f7f\u3063\u3066\u5730\u56f3\u4e0a\u306b\u52d5\u7684\u306b\u30d0\u30c3\u30d5\u30a1\u3092\u63cf\u304f"},"content":{"rendered":"<p>\u30d0\u30c3\u30d5\u30a1\u306f\u5bfe\u8c61\u3068\u3059\u308b\u70b9\u3084\u7dda\u30fb\u9762\u306b\u6cbf\u3063\u3066\u7279\u5b9a\u8ddd\u96e2\u306e\u7bc4\u56f2\u30a8\u30ea\u30a2\u3092\u751f\u6210\u3059\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/turf\/buffer\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turfbuffer150321.jpg\" alt=\"Turf buffer example\" width=\"690\" height=\"611\" class=\"aligncenter size-full wp-image-4156 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turfbuffer150321.jpg 690w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turfbuffer150321-169x150.jpg 169w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/turf\/buffer\/\">example<\/a><\/p>\n<p>\u4e0a\u8a18\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001\u5404\u30dd\u30a4\u30f3\u30c8\u30fb\u30e9\u30a4\u30f3\u30fb\u30dd\u30ea\u30b4\u30f3\u304b\u3089\u8ddd\u96e2100m\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u30b9\u30e9\u30a4\u30c0\u30fc\u3092\u5909\u5316\u3055\u305b\u308b\u3068\u751f\u6210\u3059\u308b\u30d0\u30c3\u30d5\u30a1\u306e\u8ddd\u96e2\u3092\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/gunmagisgeek.com\/blog\/map\/4152\">Turf.aggregate\u30e1\u30bd\u30c3\u30c9<\/a>\u3068\u5408\u308f\u305b\u3066\u4f7f\u3048\u3070\u3001\u3042\u308b\u5730\u70b9\u304b\u3089100m\u7bc4\u56f2\u5185\u306e\u30c7\u30fc\u30bf\u3092\u62bd\u51fa\u3057\u3066\u5206\u6790\u3059\u308b\u306a\u3069\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js decode:true \" >\r\n\/\/json\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u3002fetch\u3092\u4f7f\u3063\u3066\u3044\u308b\u304c jQuery.ajax\u3067\u3082\u3044\u3044\u3002\t\r\nfetch('..\/_dataset\/sample2.geojson')\r\n\t.then(function(response) {\r\n\t\treturn response.json()\r\n\t}).then(function(json) {\r\n\t\tdraw(json)\r\n\t});\r\n\t\r\nfunction draw(geodata){\r\n\r\n\tvar map = L.map('map').setView([36.322356, 139.013057], 15);\r\n\t\r\n\t\/\/\u5730\u7406\u9662\u5730\u56f3\u30ec\u30a4\u30e4\u30fc\u8ffd\u52a0\r\n\tL.tileLayer(\r\n\t\t'http:\/\/cyberjapandata.gsi.go.jp\/xyz\/std\/{z}\/{x}\/{y}.png',\r\n\t\t{\r\n\t\t\tattribution: \"&lt;a href='http:\/\/www.gsi.go.jp\/kikakuchousei\/kikakuchousei40182.html' target='_blank'&gt;\u56fd\u571f\u5730\u7406\u9662&lt;\/a&gt;\"\r\n\t\t}\r\n\t).addTo(map);\r\n\t\r\n\t\/\/\u5730\u7269\u8ffd\u52a0\r\n\tvar markerLayer = L.geoJson(geodata).addTo(map);\r\n\r\n\t\/\/\u30d0\u30c3\u30d5\u30a1\u30fc\u30ec\u30a4\u30e4\u30fc\u6e96\u5099\r\n\tvar bufferLayer = L.geoJson().addTo(map);\r\n\t\r\n\t\/\/\u30d0\u30c3\u30d5\u30a1\u30fc\u8ffd\u52a0\r\n\t var addbuffer = function(meter){\r\n\t\tbufferLayer.clearLayers(); \/\/\u524d\u56de\u306e\u30d0\u30c3\u30d5\u30a1\u3092\u30af\u30ea\u30a2\r\n\t\tvar buffered = geodata.features.map(function(feature){\r\n\t\t\treturn  turf.buffer(feature, meter, \"meters\");\r\n\t\t});\r\n\t\tbufferLayer.addData(buffered);\t\r\n\t\tbufferLayer.setStyle({color: \"#000000\"});\r\n\t};\r\n\t\r\n\t\/\/\u30b9\u30e9\u30a4\u30c0\u30fc\u306e\u5024\u304c\u5909\u66f4\u3055\u308c\u305f\u3089\u30d0\u30c3\u30d5\u30a1\u3092\u8ffd\u52a0\u3059\u308b\r\n\tdocument.querySelector(\"#range\").addEventListener(\"change\", function(){\r\n\t\tvar meter = this.value;\r\n\t\tdocument.querySelector(\"#meter\").innerText = meter;\t\r\n\t\taddbuffer(meter);\t\r\n\t})\r\n\r\n\t\/\/\u521d\u56de\u3060\u3051change\u30a4\u30d9\u30f3\u30c8\u3092JS\u3067\u767a\u706b\u3055\u305b\u308b\r\n\tdocument.querySelector(\"#range\").dispatchEvent(new Event('change'))\r\n\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30d0\u30c3\u30d5\u30a1\u306f\u5bfe\u8c61\u3068\u3059\u308b\u70b9\u3084\u7dda\u30fb\u9762\u306b\u6cbf\u3063\u3066\u7279\u5b9a\u8ddd\u96e2\u306e\u7bc4&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4156,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,62],"tags":[],"class_list":["post-4155","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-leaflet-js","category-turf-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4155","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=4155"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4155\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4156"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}