{"id":4331,"date":"2015-06-22T19:26:20","date_gmt":"2015-06-22T10:26:20","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4331"},"modified":"2015-06-23T11:15:02","modified_gmt":"2015-06-23T02:15:02","slug":"post-4331","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4331","title":{"rendered":"Github\u304b\u3089GeoJSON\u3092\u691c\u7d22\u3057\u3066\u5730\u56f3\u4e0a\u306b\u8868\u793a\u3059\u308b\u30da\u30fc\u30b8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/googleCustom_Search_API\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/06\/github_geojson_search.jpg\" alt=\"github_geojson_search\" width=\"590\" height=\"417\" class=\"aligncenter size-full wp-image-4332 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/06\/github_geojson_search.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/06\/github_geojson_search-212x150.jpg 212w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/googleCustom_Search_API\/\">example<\/a><\/p>\n<p>Google Custom Search API\u3092\u4f7f\u3063\u3066\u3001Github\u304b\u3089Geojson\u3092\u691c\u7d22\u3057\u5730\u56f3\u306b\u8868\u793a\u3059\u308b\u30da\u30fc\u30b8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\nGithub\u3067\u306fGeojson\u3092\u30a2\u30c3\u30d7\u3059\u308b\u3068\u30d8\u30c3\u30c0\u306b\u300cAccess-Control-Allow-Origin: *\u300d\u3092\u4ed8\u52a0\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3001\u5916\u90e8\u304b\u3089\u8aad\u307f\u3060\u3057\u3066\u5730\u56f3\u4e0a\u306b\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u5730\u7406\u60c5\u5831\u3092\u516c\u958b\u3059\u308b\u65b9\u6cd5\u3068\u3057\u3066\u9762\u767d\u3044\u306a\u3068\u601d\u3063\u305f\u306e\u3067\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u305f\u3060\u3001API\u306e\u5236\u9650\u304c\u304b\u306a\u308a\u304d\u3064\u304f\u3001\u7121\u6599\u30b5\u30fc\u30d3\u30b9\u306e\u7bc4\u56f2\u5185\u3067\u306f<strong>\uff11\u56de\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3067\u53d6\u308c\u308b\u306e\u304c10\u4ef6\u307e\u3067\u306a\u3046\u3048\u65e5\u306b100\u56de\u691c\u7d22\u30ea\u30af\u30a8\u30b9\u30c8\u304c\u304b\u304b\u308b\u3068\u5236\u9650\u304c\u304b\u304b\u308b<\/strong>\u3089\u3057\u3044\u306e\u3067\u5b9f\u7528\u7684\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u691c\u7d22\u3057\u3066\u3082\u7d50\u679c\u304c\u8fd4\u3063\u3066\u3053\u306a\u304f\u306a\u3063\u305f\u3089\u3001\u5225\u306e\u65e5\u306b\u3067\u3082\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\uff08\u3042\u3068\u305f\u307e\u306b\u3001\u3082\u306e\u3059\u3054\u30fc\u304f\u5de8\u5927\u306aGeoJSON\u3092\u8aad\u307f\u8fbc\u3082\u3046\u3068\u3057\u3066\u56fa\u307e\u308b\u6642\u304c\u3042\u308a\u307e\u3059\uff09<\/p>\n<p><a href=\"http:\/\/qiita.com\/megu_ma\/items\/8cad39f61e35588e5476\">GoogleCustomSearchAPI &#8211; Google Custom Search API \u3092\u4f7f\u3063\u3066\u307f\u308b &#8211; Qiita<\/a><\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>API key\u3068\u30ab\u30b9\u30bf\u30e0\u30b5\u30fc\u30c1ID(cx)\u306f\u81ea\u5206\u3067\u53d6\u5f97\u3057\u305f\u3082\u306e\u3092\u3064\u304b\u3063\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u3042\u3068\u3001<a href=\"https:\/\/github.com\/d3\/d3-plugins\/tree\/master\/jsonp\">d3.jsonp.js<\/a>\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002 <\/p>\n<pre class=\"lang:js decode:true \" >(function(){\r\n\t\"use strict\";\r\n\r\n\r\n\t\/****************************************************\r\n\t * Google Custom search Ajax\r\n\t ***************************************************\/\t\t\r\n\tvar getGeoJson = function(keyword){\r\n\t\tvar url = \"https:\/\/www.googleapis.com\/customsearch\/v1?key=\uff1cAPI key\uff1e=\uff1c\u30ab\u30b9\u30bf\u30e0\u30b5\u30fc\u30c1ID\uff1e&amp;q=\"+keyword+\" FeatureCollection filetype:geojson&amp;callback=d3.jsonp.foo\";\r\n\t\t\/\/var url = \".\/mock.js?&amp;callback=d3.jsonp.foo\"\r\n\t\td3.jsonp(url, function() {\r\n\t\t\tif (arguments.lenght &lt;= 0){ webix.message('not found data'); return }\r\n\t\t\tArray.prototype.slice.call(arguments).forEach(function(row){\r\n\t\t\t\trow.items.forEach(function(item){\r\n\t\t\t\t\t$$('geojsonList').add(item);\r\n\t\t\t\t});\r\n\t\t\t});\t\t\r\n\t\t});\r\n\t}\t\r\n\t\r\n\t\r\n\t\/****************************************************\r\n\t * webix Layout\t\r\n\t ***************************************************\/\t\r\n\tvar resultList = {\r\n\t\tid:'geojsonList',\r\n\t\tview:\"list\",\r\n\t\tselect:true,\r\n\t\ttemplate:'&lt;a target=\"_blank\" href=\"#link#\"&gt;link&lt;\/a&gt;:#link#',\r\n\t\tdata:[]\r\n\t}\r\n\t\r\n\tvar search_input = {id:'search_input', view:'text'};\r\n\t\r\n\tvar search_btn = { id:'search_btn', view:'button', width:120,label:'search'}\r\n\t\r\n\tvar resultClear_btn = {id:'resultClear_btn', view:'button',height:30, label:'Clear'}\r\n\t\t\t\r\n\twebix.ui({\r\n\t\trows:[\r\n\t\t\t{template:'&lt;h1&gt;Github GeoJSON Search\u3000\u03b2&lt;\/h1&gt;', height:40, css:'header'},\r\n\t\t\t{view:\"form\", elements:[\r\n\t\t\t\t{cols:[\r\n\t\t\t\t\tsearch_input,\r\n\t\t\t\t\tsearch_btn\r\n\t\t\t\t\t]\r\n\t\t\t\t}\r\n\t\t\t\t]\r\n\t\t\t},\r\n\t\t\t{\r\n\t\t\t\tcols:[\r\n\t\t\t\t\t{rows:[\r\n\t\t\t\t\t\tresultList,\r\n\t\t\t\t\t\tresultClear_btn\r\n\t\t\t\t\t]},\r\n\t\t\t\t\t{view:'resizer'},\r\n\t\t\t\t\t{template:'&lt;div id=\"map\"&gt;&lt;\/div&gt;'}\r\n\t\t\t\t]\r\n\t\t\t}\r\n\t\t]\r\n\t});\r\n\r\n\t\/****************************************************\r\n\t * webix Event Handling \t\r\n\t ***************************************************\/\t\r\n\t$$('search_btn').attachEvent('onItemClick', function(){\r\n\t\tvar keyword = $$('search_input').getValue();\r\n\t\tgetGeoJson(keyword.trim());\r\n\t});\r\n\t$$('resultClear_btn').attachEvent('onItemClick', function(){\r\n\t\t$$('geojsonList').clearAll();\r\n\t\twebix.message(\"\u691c\u7d22\u7d50\u679c\u3092\u30af\u30ea\u30a2\u3057\u307e\u3057\u305f\");\t\t\r\n\t});\r\n\t\r\n\t$$('geojsonList').attachEvent('onAfterSelect', function(id){\r\n\t\t\tvar item = this.getItem(id);\r\n\t\t\tgeojsonLayer.clearLayers();\r\n\t\t\td3.json(item.link, function(geodata){\r\n\t\t\t\tgeojsonLayer.addData(geodata);\r\n\t\t\t\tmap.fitBounds(geojsonLayer.getBounds())\r\n\t\t\t});\r\n\t});\r\n\t\r\n\t\r\n\t\/****************************************************\r\n\t * leaflet Init \t\r\n\t ***************************************************\/\t\r\n\tvar map = L.map('map').setView([-41.2858, 174.78682], 14);\r\n\tvar mapLink = '&lt;a href=\"http:\/\/openstreetmap.org\"&gt;OpenStreetMap&lt;\/a&gt;';\r\n\tL.tileLayer(\r\n\t\t'http:\/\/{s}.tile.openstreetmap.org\/{z}\/{x}\/{y}.png',\r\n\t\t{\r\n\t\t\tattribution: 'Map data &amp;copy; ' + mapLink,\r\n\t\t\tmaxZoom: 18\r\n\t\t}\r\n\t).addTo(map);\r\n\t\t\r\n\tvar onEachFeature = function(feature, layer) {\r\n\t\t\tif (!feature.properties) return ;\r\n\t\t\tvar properties = '&lt;table width=\"300\"&gt;';\r\n\t\t\tObject.keys(feature.properties).forEach(function(key){\r\n\t\t\t\tvar status = typeof feature.properties[key];\r\n\t\t\t\tvar text = \"\";\r\n\t\t\t\tswitch (status) {\r\n\t\t\t\t\tcase 'string': text = feature.properties[key].slice(0, 10) + \"...\";break;\r\n\t\t\t\t\tcase 'object': text = \"[object]\";break;\r\n\t\t\t\t\tcase 'function': text = '[function]'; break;\r\n\t\t\t\t}\t\t\t\t\r\n\t\t\t\tproperties += '&lt;tr&gt;&lt;td&gt;'+key+'&lt;\/td&gt;&lt;td&gt;'+text+'&lt;\/td&gt;&lt;\/tr&gt;'\r\n\t\t\t});\r\n\t\t\tproperties += '&lt;\/table&gt;';\r\n\t\t\tlayer.bindPopup(properties);\r\n\t}\r\n\t\r\n\tvar geojsonLayer = L.geoJson(null, {onEachFeature:onEachFeature}).addTo(map);\r\n\t\r\n\r\n})();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example Google Custom Sea&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4332,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,55,58],"tags":[],"class_list":["post-4331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","category-leaflet-js","category-webix","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4331","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=4331"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4331\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4332"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}