{"id":4152,"date":"2015-03-20T08:36:56","date_gmt":"2015-03-19T23:36:56","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4152"},"modified":"2015-03-23T12:19:29","modified_gmt":"2015-03-23T03:19:29","slug":"post-4152","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/leaflet-js\/4152","title":{"rendered":"\u30d6\u30e9\u30a6\u30b6\u304a\u3088\u3073node.js\u306e\u305f\u3081\u306e\u9ad8\u5ea6\u306a\u5730\u7406\u7a7a\u9593\u30c7\u30fc\u30bf\u5206\u6790\u30e9\u30a4\u30d6\u30e9\u30ea\u300cturf.js\u300d"},"content":{"rendered":"<p>\u9078\u629e\u3057\u305f\u7bc4\u56f2\u5185\u306e\u5bb6\u8cc3\u76f8\u5834\u3092\u6c42\u3081\u308b\u3068\u304b\u3044\u308d\u3093\u306a\u3053\u3068\u306b\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/turf\/Aggregation\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turf_Aggregation150309.jpg\" alt=\"turf Aggregation example\" width=\"690\" height=\"643\" class=\"aligncenter size-full wp-image-4153 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turf_Aggregation150309.jpg 690w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/turf_Aggregation150309-161x150.jpg 161w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/turf\/Aggregation\/\">example<\/a><\/p>\n<p><a href=\"http:\/\/turfjs.org\/\">Turf.js<\/a>\u306f<a href=\"https:\/\/www.mapbox.com\/\">Mapbox<\/a>\u793e\u8b39\u88fd\u306e\u5730\u7406\u7a7a\u9593\u30c7\u30fc\u30bf\u5206\u6790\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u30d4\u30e5\u30a2JavaScript\u3067\u4f5c\u6210\u3055\u308c\u3066\u3044\u3066\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u3082\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u3082\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<p>Turf\u306e\u7279\u5fb4\u3068\u3057\u3066\u306f\u3001\u5bfe\u5fdc\u3059\u308b\u30c7\u30fc\u30bf\u5f62\u5f0f\u3092GeoJSON\u3092\u7d5e\u3063\u3066\u304a\u308a\u3001\u57fa\u672cGeoJSON\u3067\u53d7\u3051\u53d6\u3063\u305f\u30c7\u30fc\u30bf\u3092\u5206\u6790\u3057\u3066\u5206\u6790\u7d50\u679c\u3092GeoJSON\u3067\u8fd4\u3059\u3068\u3044\u3063\u305f\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u306e\u305f\u3081\u3001GeoJSON\u306b\u5bfe\u5fdc\u3057\u305f\u5730\u56f3\u30e9\u30a4\u30d6\u30e9\u30ea\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u5206\u6790\u7d50\u679c\u3092\u7c21\u5358\u306b\u8996\u899a\u5316\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3082\u3061\u308d\u3093D3.js\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u3046\u306e\u3082\u7c21\u5358\uff01\u3000\u3044\u308d\u3044\u308d\u306a\u53ef\u80fd\u6027\u3092\u79d8\u3081\u305f\u4eca\u5f8c\u304c\u697d\u3057\u307f\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u5165\u9580\u7de8\u3068\u3057\u3066\u3001Leaflet\u4e0a\u3067\u9078\u629e\u3057\u305f\u7bc4\u56f2\u5185\u306e\u30c7\u30fc\u30bf\u306e\u57fa\u672c\u7d71\u8a08\u91cf\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002<br \/>\n\u30de\u30fc\u30ab\u30fc\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u306f\u3001\u305d\u308c\u305e\u308c\u300cvalue\u300d\u5024\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u3066\u3001\u9078\u629e\u7bc4\u56f2\u306b\u542b\u307e\u308c\u308b\u30de\u30fc\u30ab\u30fc\u306evalue\u5024\u306e\u5408\u8a08\u3084\u5e73\u5747\u5024\u3001\u6a19\u6e96\u504f\u5dee\u306a\u3069\u3092\u52d5\u7684\u306b\u6c42\u3081\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u56db\u89d2\u3044\u30dd\u30ea\u30b4\u30f3\u306e\u4e2d\u306b\u542b\u307e\u308c\u308b\u30c7\u30fc\u30bf\u3092\u5206\u6790\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u4f8b\u3048\u3070\u753a\u5883\u30c7\u30fc\u30bf\u306e\u3088\u3046\u306a\u3082\u3063\u3068\u8907\u96d1\u306a\u30dd\u30ea\u30b4\u30f3\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u5206\u6790\u3092\u884c\u3046\u306a\u3069\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u30de\u30fc\u30ab\u30fc\u306e\u4e0b\u90e8\u3001\u4e00\u756a\u5c16\u304c\u3063\u3066\u3044\u308b\u90e8\u5206\u304c\u9078\u629e\u7bc4\u56f2\u5185\u306b\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u3068\u8a08\u7b97\u5bfe\u8c61\u306b\u306a\u3089\u306a\u3044\u306e\u3067\u6ce8\u610f\u3002<\/p>\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\/sample.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(points){\r\n\t\/\/\u51fa\u529b\u8a2d\u5b9a\r\n\tvar aggregations = [\r\n\t\t{\r\n\t\t\taggregation: 'sum',\r\n\t\t\tinField: 'value',\r\n\t\t\toutField: '\u5408\u8a08'\r\n\t\t},\r\n\t\t{\r\n\t\t\taggregation: 'average',\r\n\t\t\tinField: 'value',\r\n\t\t\toutField: '\u5e73\u5747\u5024'\r\n\t\t},\r\n\t\t{\r\n\t\t\taggregation: 'median',\r\n\t\t\tinField: 'value',\r\n\t\t\toutField: '\u4e2d\u592e\u5024'\r\n\t\t},\r\n\t\t{\r\n\t\t\taggregation: 'min',\r\n\t\t\tinField: 'value',\r\n\t\t\toutField: '\u6700\u5c11\u5024'\r\n\t\t},\r\n\t\t{\r\n\t\t\taggregation: 'max',\r\n\t\t\tinField: 'value',\r\n\t\t\toutField: '\u6700\u5927\u5024'\r\n\t\t},\r\n\t\t{\r\n\t\t\taggregation: 'deviation',\r\n\t\t\tinField: 'value',\r\n\t\t\toutField: '\u6a19\u6e96\u504f\u5dee\u5024'\r\n\t\t},\r\n\t\t{\r\n\t\t\taggregation: 'variance',\r\n\t\t\tinField: 'value',\r\n\t\t\toutField: '\u5206\u6563\u5024'\r\n\t\t},\r\n\t\t{\r\n\t\t\taggregation: 'count',\r\n\t\t\tinField: '',\r\n\t\t\toutField: '\u500b\u6570'\r\n\t\t}\r\n\t];\t\r\n\r\n\tvar map = L.map('map').setView([36.3219088\u3000, 139.0032936], 14);\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\/\/\u30de\u30fc\u30ab\u30fc\u8ffd\u52a0\r\n\tvar onEachFeature = function(feature, layer) {\r\n\t\tvar popupContent = \"value:\";\r\n\t\tif (feature.properties &amp;&amp; feature.properties.value) {\r\n\t\t\tpopupContent += feature.properties.value;\r\n\t\t}\r\n\t\tlayer.bindPopup(popupContent);\r\n\t}\t\r\n\tvar markerLayer = L.geoJson(points, { onEachFeature: onEachFeature }).addTo(map);\r\n\t\r\n\t\/\/area\u30bb\u30ec\u30af\u30bf\u30fc\u8ffd\u52a0\r\n\tvar areaSelect = L.areaSelect({width:200, height:250});\r\n\t\/\/\u30bb\u30ec\u30af\u30bf\u30fc\u30c1\u30a7\u30f3\u30b8\u30a4\u30d9\u30f3\u30c8\r\n\tareaSelect.on(\"change\", function() {\r\n\t\t\/\/\u56db\u9685\u53d6\u308b\r\n\t\tvar b = this.getBounds();\t\t\r\n\t\tvar extend = [\r\n\t\t\t[b.getSouthWest().lng , b.getSouthWest().lat],\r\n\t\t\t[b.getSouthEast().lng, b.getSouthEast().lat],\r\n\t\t\t[b.getNorthEast().lng, b.getNorthEast().lat],\r\n\t\t\t[b.getNorthWest().lng, b.getNorthWest().lat]\r\n\t\t]\r\n\t\t\r\n\t\t\/\/\u30dd\u30ea\u30b4\u30f3\u306b\u3059\u308b\r\n\t\tvar polygons = turf.featurecollection([\r\n\t\t\t{\r\n\t\t\t  \"type\": \"Feature\",\r\n\t\t\t  \"properties\": {},\r\n\t\t\t  \"geometry\": {\r\n\t\t\t\t\"type\": \"Polygon\",\r\n\t\t\t\t\"coordinates\": [ extend ]\r\n\t\t\t  }\r\n\t\t\t}\r\n\t\t  ]);\r\n\t\t\r\n\t\t\/\/\u30dd\u30ea\u30b4\u30f3\u5185\u306b\u542b\u307e\u308c\u308b\u30dd\u30a4\u30f3\u30c8\u306e\u7d71\u8a08\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\r\n\t\tvar aggregated = turf.aggregate(polygons, points, aggregations);\r\n\t\t\r\n\t\t\/\/\u7d71\u8a08\u30c7\u30fc\u30bf\u3092\u51fa\u529b\r\n\t\tdocument.querySelector(\".info\").value = JSON.stringify(aggregated.features[0].properties, null, \"t\");\r\n\t\t\t\t\r\n\t});\r\n\t\r\n\tareaSelect.addTo(map);\r\n\t\t\r\n}<\/pre>\n<p>Turf\u306b\u306f\u4ed6\u306b\u3082\u7d20\u6674\u3089\u3057\u3044\u6a5f\u80fd\u304c\u6ca2\u5c71\u3042\u308b\u306e\u3067\u3001\u968f\u6642\u7d39\u4ecb\u3057\u3066\u3044\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/category\/turf-js\">\u305d\u306e\u4ed6\u3001Turf\u306e\u8a18\u4e8b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9078\u629e\u3057\u305f\u7bc4\u56f2\u5185\u306e\u5bb6\u8cc3\u76f8\u5834\u3092\u6c42\u3081\u308b\u3068\u304b\u3044\u308d\u3093\u306a\u3053\u3068\u306b&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4153,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,62],"tags":[],"class_list":["post-4152","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\/4152","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=4152"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4152\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4153"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}