{"id":4163,"date":"2015-03-23T10:08:31","date_gmt":"2015-03-23T01:08:31","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4163"},"modified":"2015-03-23T10:08:31","modified_gmt":"2015-03-23T01:08:31","slug":"post-4163","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/leaflet-js\/4163","title":{"rendered":"[Turf.js]\u30e9\u30a4\u30f3\u306b\u6cbf\u3063\u3066\u4efb\u610f\u306e\u8ddd\u96e2\u3092\u79fb\u52d5\u3059\u308b"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/turf\/along\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turfalong.jpg\" alt=\"turf.js along\" width=\"690\" height=\"586\" class=\"aligncenter size-full wp-image-4162 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turfalong.jpg 690w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turfalong-177x150.jpg 177w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/turf\/along\/\">example<\/a><\/p>\n<p>\u30b9\u30e9\u30a4\u30c0\u30fc\u3067\u9078\u629e\u3057\u305f\u8ddd\u96e2\u3060\u3051\u5404\u30e9\u30a4\u30f3\u4e0a\u306b\u6cbf\u3063\u3066\u30de\u30fc\u30ab\u30fc\u304c\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js decode:true \" >\r\nfetch('..\/_dataset\/line.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\tvar map = L.map('map').setView([36.3221588, 139.00579059999], 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\/\/\u30e9\u30a4\u30f3\u30ec\u30a4\u30e4\u30fc\u8ffd\u52a0\r\n\tvar lineLayer = L.geoJson(geodata, {\r\n\t\t\tstyle: function(feature) {\r\n\t\t\t\tswitch (feature.properties.id) {\r\n\t\t\t\t\tcase 1: return {color: \"#ff0000\",opacity:1};\r\n\t\t\t\t\tcase 2:   return {color: \"#0000ff\",opacity:1};\r\n\t\t\t\t\tcase 3:   return {color: \"#00ff00\",opacity:1};\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t}).addTo(map);\r\n\r\n\t\/\/\u30de\u30fc\u30ab\u30fc\u306e\u30b9\u30bf\u30a4\u30eb\u3092\u6307\u5b9a\u3059\u308b\r\n\tvar geojsonMarkerOptions = {\r\n\t\tradius: 8,\r\n\t\tfillColor: \"#ff7800\",\r\n\t\tcolor: \"#000\",\r\n\t\tweight: 1,\r\n\t\topacity: 1,\r\n\t\tfillOpacity: 0.8\r\n\t};\t\r\n\t\r\n\t\/\/\u30de\u30fc\u30ab\u30fc\u30ec\u30a4\u30e4\u30fc\u3092\u6e96\u5099\r\n\tvar markerLayer = L.geoJson(null,  {\r\n\t\tpointToLayer: function (feature, latlng) {\r\n\t\t\treturn L.circleMarker(latlng, geojsonMarkerOptions);\r\n\t\t}\r\n\t}).addTo(map);\r\n\t\r\n\t\/\/\u30de\u30fc\u30ab\u30fc\u3092\u30e9\u30a4\u30f3\u4e0a\u306e\u4efb\u610f\u306e\u4f4d\u7f6e\u3078\u8ffd\u52a0\u3059\u308b\r\n\t var addMarker = function(meter){\r\n\t\tmarkerLayer.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.along(feature, meter\/1000, \"kilometers\");\r\n\t\t});\r\n\t\tmarkerLayer.addData(buffered);\r\n\t};\r\n\t\r\n\t\/\/\u30b9\u30e9\u30a4\u30c0\u30fc\u306e\u5024\u304c\u5909\u66f4\u3055\u308c\u305f\u969b\u306e\u51e6\u7406\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\tdocument.querySelector(\"#meter\").textContent = meter; \/\/firefox\u7528\r\n\t\taddMarker(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}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example \u30b9\u30e9\u30a4\u30c0\u30fc\u3067\u9078\u629e\u3057\u305f\u8ddd\u96e2\u3060\u3051\u5404\u30e9\u30a4&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4162,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,62],"tags":[],"class_list":["post-4163","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\/4163","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=4163"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4163\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4162"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}