{"id":1347,"date":"2015-07-28T13:19:49","date_gmt":"2015-07-28T04:19:49","guid":{"rendered":"http:\/\/www.digifie.jp\/blog\/?p=1347"},"modified":"2015-07-29T23:39:52","modified_gmt":"2015-07-29T14:39:52","slug":"three-js-geoglobe-openweathermap","status":"publish","type":"post","link":"https:\/\/www.digifie.jp\/blog\/archives\/1347","title":{"rendered":"three.js GeoGlobe + OpenWeatherMap"},"content":{"rendered":"<div class='wp_social_bookmarking_light'>        <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=https%3A%2F%2Fwww.digifie.jp%2Fblog%2Farchives%2F1347&t=three.js%20GeoGlobe%20%2B%20OpenWeatherMap' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/www.digifie.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.digifie.jp\/blog\/archives\/1347\" data-text=\"three.js GeoGlobe + OpenWeatherMap\" data-via=\"LLC DigiFie\" data-lang=\"ja\">Tweet<\/a><\/div><\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n<div id=\"attachment_1350\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.digifie.jp\/labo\/threejs_ex\/geo_globe\/\" target=\"_blank\"><img aria-describedby=\"caption-attachment-1350\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.digifie.jp\/blog\/wp-content\/uploads\/2015\/07\/150728.jpg\" alt=\"\u753b\u50cf\u30af\u30ea\u30c3\u30af\u3067\u30b5\u30f3\u30d7\u30eb\u30da\u30fc\u30b8\u3092\u8868\u793a\" width=\"600\" height=\"208\" class=\"size-full wp-image-1350\" srcset=\"https:\/\/www.digifie.jp\/blog\/wp-content\/uploads\/2015\/07\/150728.jpg 600w, https:\/\/www.digifie.jp\/blog\/wp-content\/uploads\/2015\/07\/150728-300x104.jpg 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-1350\" class=\"wp-caption-text\">\u753b\u50cf\u30af\u30ea\u30c3\u30af\u3067\u30b5\u30f3\u30d7\u30eb\u30da\u30fc\u30b8\u3092\u8868\u793a<\/p><\/div>\n<p>Flash \u304b js \u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u30013D \u306e\u5730\u7403\u5100\u4e0a\u306b\u8a72\u5f53\u5730\u70b9\u3092\u793a\u3059\u30de\u30fc\u30ab\u30fc\u3092\u7acb\u3066\u3066\u3001\u305d\u306e\u5730\u70b9\u306e\u5929\u6c17\u3092\u5225\u67a0\u3067\u8868\u793a\u3068\u3044\u3046\u3088\u3046\u306a\u3053\u3068\u3092\u3084\u308b\u5fc5\u8981\u304c\u3067\u3066\u304d\u305f\u307f\u305f\u3044\u306a\u306e\u3067\u3001\u8abf\u67fb\u3092\u304b\u306d\u3066 three.js \u3067\u30b5\u30f3\u30d7\u30eb\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>3\u6b21\u5143\u4e0a\u3078\u306e\u30de\u30fc\u30ab\u30fc\u8868\u793a\u306f\u3061\u3087\u3063\u3068\u60c5\u5831\u304c\u53e4\u3044\u3067\u3059\u304c <a href=\"http:\/\/demo.2mobile.jp\/adobe\/newsletters\/edge\/june2008\/articles\/article4\/\" target=\"_blank\">\u3053\u3061\u3089<\/a> \u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u3001\u3053\u306e Flash \u3092\u5143\u306b three.js \u3067\u5b9f\u88c5\u3057\u307e\u3057\u305f\u3002<br \/>\n\u305d\u308c\u306b\u52a0\u3048\u3066\u3001\u5ea7\u6a19\u3092\u30d7\u30ed\u30c3\u30c8\u3059\u308b\u969b\u306b <a href=\"http:\/\/openweathermap.org\" target=\"_blank\">OpenWeatherMap<\/a> \u304b\u3089\u305d\u306e\u5730\u70b9\u306e\u5929\u6c17\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u304d\u3066\u3001\u753b\u9762\u4e0a\u90e8\u306e\u30d5\u30a9\u30fc\u30e0\u306b\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3063\u3066\u3044\u3046\u304b js \u3084\u308b\u3093\u3060\u3063\u305f\u3089\u3044\u3064\u307e\u3067\u3082\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067\u66f8\u3044\u3066\u306a\u3044\u3067\u3001\u305d\u308d\u305d\u308d\u3061\u3083\u3093\u3068 IDE \u3092\u5c0e\u5165\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u304b\u306a\u2026<\/p>\n<p>\u4eca\u56de\u306e\u30bd\u30fc\u30b9\u306f\u4e0b\u8a18\u3067\u3059\u3002<\/p>\n<p>\u30fbearth.js<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">var container;\r\nvar camera;\r\nvar scene;\r\nvar geometry;\r\nvar material;\r\nvar spherMesh;\r\nvar renderer;\r\nvar controls;\r\nvar radius = 200;\r\nvar latitudeDegreeOffset = 90;\r\nvar longitudeDegreeOffset = 0;\r\nvar markers = [];\r\nvar tempOfset = 273.15;\r\n\r\nsetup();\r\n\r\nfunction setup()\r\n{\r\n    container = document.getElementById('container');\r\n    camera = new THREE.PerspectiveCamera(45, window.innerWidth \/ window.innerHeight, 1, 1000);\r\n    camera.position.z = 700;\r\n\r\n    scene = new THREE.Scene();\r\n    geometry = new THREE.SphereGeometry(radius, 30, 30);\r\n    material = new THREE.MeshBasicMaterial({\r\n        map: THREE.ImageUtils.loadTexture(&quot;earth.jpg&quot;)\r\n    });\r\n    spherMesh = new THREE.Mesh(geometry, material);\r\n    spherMesh.overdraw = true;\r\n    spherMesh.rotation.y = 60;\r\n    scene.add(spherMesh);\r\n\r\n    renderer = new THREE.WebGLRenderer();\r\n    renderer.setSize(window.innerWidth, window.innerHeight);\r\n    container.appendChild(renderer.domElement);\r\n\r\n    controls = new THREE.OrbitControls(camera, renderer.domElement);\r\n\r\n    renderer.setSize( window.innerWidth, window.innerHeight );\r\n\r\n    render();\r\n}\r\n\r\nfunction render()\r\n{\r\n    requestAnimationFrame(render);\r\n    spherMesh.rotation.y -= 0.001;\r\n    controls.update();\r\n    renderer.render(scene, camera);\r\n}\r\n\r\n\/\/\r\nfunction translateGeoCoords( latitude, longitude, radius )\r\n{\r\n  \tlatitude = Math.PI * latitude \/ 180;\r\n\tlongitude = Math.PI * longitude \/ 180;\r\n\r\n\tlatitude -= ( latitudeDegreeOffset * ( Math.PI \/ 180 )); \/\/ offset latitude by n degrees (in radians).\r\n\tlongitude -= ( longitudeDegreeOffset * ( Math.PI \/ 180 )); \/\/ offset longitude by n degrees (in radians).\r\n\r\n\tvar x = radius * Math.sin( latitude ) * Math.cos( longitude );\r\n\tvar y = radius * Math.sin( latitude ) * Math.sin( longitude );\r\n\tvar z = radius * Math.cos( latitude );\r\n\r\n\treturn new THREE.Vector3( -x, z, y ); \/\/ threejs \u306e\u53f3\u624b\u5ea7\u6a19\u7cfb\u306b\u5408\u308f\u305b\u3066\u5024\u3092\u5165\u308c\u308b\uff08\u4e0a\u8a18\u5909\u63db\u5f0f\u306f\u5de6\u624b\u5ea7\u6a19\u7cfb\uff09\r\n}\r\n\r\n\/\/\r\nfunction onClick()\r\n{\r\n  var lat = form1.field1.value;\r\n  var lon = form1.field2.value;\r\n\r\n  \/\/ test\r\n  apiRequest(lat, lon);\r\n}\r\n\r\nfunction onClear()\r\n{\r\n  for (var i = 0; i &lt; markers.length; i++) {\r\n    spherMesh.remove(markers[i]);\r\n    markers[i].geometry.dispose();\r\n    markers[i].material.dispose();\r\n    markers[i] = null;\r\n  }\r\n\r\n  markers = [];\r\n  form1.field3.value = &quot;&quot;;\r\n}\r\n\r\n\/\/\r\nfunction addMarker(lat, lon, col)\r\n{\r\n  if(isNaN(lat) || isNaN(lon))\r\n  {\r\n    alert(&quot;NaN&quot;)\r\n    return;\r\n  }\r\n\r\n  var vec3 = translateGeoCoords(lat, lon, radius);\r\n  var geo = new THREE.BoxGeometry(2,2,20);\r\n  var mat = new THREE.MeshBasicMaterial({color:col});\r\n  markers.push(new THREE.Mesh(geo, mat));\r\n  markers[markers.length-1].position.set(vec3.x, vec3.y, vec3.z);\r\n  spherMesh.add(markers[markers.length-1]);\r\n\r\n  markers[markers.length-1].lookAt(spherMesh.position);\r\n}\r\n\r\n\r\n\/**\r\n* OpenWeatheMap API\r\n**\/\r\nfunction getOpenWeatheMapQueri(lat, lon)\r\n{\r\n  var api = &quot;http:\/\/api.openweathermap.org\/data\/2.5\/weather&quot;;\r\n  var queri = api + &quot;?lat=&quot; + lat + &quot;&amp;lon=&quot; + lon;\r\n  return queri;\r\n}\r\n\r\n\/\/ OpenWeatheMap API \u306e\u547c\u3073\u51fa\u3057\r\nfunction apiRequest(lat, lon)\r\n{\r\n  var httpObj = new XMLHttpRequest();\r\n  httpObj.open(&quot;get&quot;, getOpenWeatheMapQueri(lat, lon), true);\r\n\r\n  \/\/ onload \u30cf\u30f3\u30c9\u30e9\r\n  httpObj.onload = function(){\r\n  \tvar json = JSON.parse(this.responseText);\r\n    console.log(json);\r\n\r\n    var weather = json.weather[0].main;\r\n    var temp = new Number(json.main.temp);\r\n    temp -= tempOfset;\r\n\r\n    form1.field3.value = json.name + &quot;  |  weather : &quot; + weather + &quot;  |  temp : &quot; + temp.toFixed(1) + &quot;\u00b0C  humidity : &quot; + json.main.humidity + &quot;%&quot;;\r\n\r\n    \/\/\r\n    var col;\r\n    switch (weather)\r\n    {\r\n      case &quot;Clear&quot;:\r\n        col = 0xFF9900;\r\n        break;\r\n      case &quot;Clouds&quot;:\r\n        col = 0xCCAAFF;\r\n        break;\r\n      case &quot;Rain&quot;:\r\n        col = 0x0099FF;\r\n        break;\r\n      case &quot;Snow&quot;:\r\n        col = 0xFFFFFF;\r\n        break;\r\n      default:\r\n        col = 0xFF0000;\r\n    }\r\n    addMarker(lat, lon, col);\r\n  }\r\n  httpObj.send(null);\r\n}\r\n\r\n\/\/\r\nwindow.addEventListener('resize', function()\r\n{\r\n\trenderer.setSize(window.innerWidth, window.innerHeight);\r\n\tcamera.aspect = window.innerWidth \/ window.innerHeight;\r\n\tcamera.updateProjectionMatrix();\r\n}, false );\r\n<\/pre>\n<p>\u30fbindex.html<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;!DOCTYPE html&gt;\r\n\t&lt;html&gt;\r\n\t&lt;head&gt;\r\n\t\t&lt;meta charset=&quot;UTF-8&quot; \/&gt;\r\n\t\t&lt;title&gt;Three.js Geo Globe&lt;\/title&gt;\r\n\t\t&lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;style.css&quot; \/&gt;\r\n\t\t&lt;script type=&quot;text\/javascript&quot; src=&quot;..\/three.min.js&quot;&gt;&lt;\/script&gt;\r\n\t\t&lt;script src=&quot;..\/OrbitControls.js&quot;&gt;&lt;\/script&gt;\r\n\t&lt;\/head&gt;\r\n\t&lt;body&gt;\r\n\t\t&lt;form name=&quot;form1&quot;&gt;\r\n\t\t\t&lt;p&gt;\u3000\u3000latitude : &lt;input type=&quot;text&quot; name=&quot;field1&quot; size=&quot;10&quot; value=&quot;33.6&quot;&gt;\r\n\t\t\t\t\u3000longitude : &lt;input type=&quot;text&quot; name=&quot;field2&quot; size=&quot;10&quot;  value=&quot;130.4&quot;&gt;\r\n\t\t\t\t\u3000&lt;input class=&quot;button1&quot; type=&quot;button&quot; value=&quot;ADD GeoLocation Marker&quot; onClick=onClick()&gt;\r\n\t\t\t\t&lt;input class=&quot;button2&quot; type=&quot;button&quot; value=&quot;CLEAR GeoLocation Marker&quot; onClick=onClear()&gt;\r\n\t\t\t\t&lt;output type=&quot;text&quot; name=&quot;field3&quot; size=&quot;14&quot;&gt;\r\n\t\t\t&lt;\/p&gt;\r\n\t\t&lt;\/form&gt;\r\n\t\t&lt;div id=&quot;container&quot;&gt;&lt;\/div&gt;\r\n\t\t&lt;script type=&quot;text\/javascript&quot; src=&quot;earth.js&quot;&gt;&lt;\/script&gt;\r\n\t&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>\u30fbstyle.css<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">* {\r\n  margin: 0;\r\n  padding: 0;\r\n  border: 0;\r\n  overflow: hidden;\r\n  font-family: &quot;Arial&quot;, sans-serif;\r\n  font-size: 11px;\r\n}\r\n\r\np {\r\n  background: #CCCCCC;\r\n  line-height: 32px;\r\n}\r\n\r\ninput.button1 {\r\n  background: #990000;\r\n  color: #ffffff;\r\n  width: 180px;\r\n  margin: 2px;\r\n  line-height: 20px;\r\n}\r\n\r\ninput.button1:hover {\r\n  background: #ffffff;\r\n  color: #990000;\r\n}\r\n\r\ninput.button2 {\r\n  background: #ff6600;\r\n  color: #ffffff;\r\n  width: 200px;\r\n  margin: 2px;\r\n  line-height: 20px;\r\n}\r\n\r\ninput.button2:hover {\r\n  background: #ffffff;\r\n  color: #ff6600;\r\n}\r\n\r\nbody {\r\n  background: #000000;\r\n}\r\n<\/pre>\n<div class='wp_social_bookmarking_light'>        <div class=\"wsbl_facebook\"><a href='http:\/\/www.facebook.com\/share.php?u=https%3A%2F%2Fwww.digifie.jp%2Fblog%2Farchives%2F1347&t=three.js%20GeoGlobe%20%2B%20OpenWeatherMap' title='Facebook \u306b\u30b7\u30a7\u30a2' rel=nofollow class='wp_social_bookmarking_light_a' target=_blank><img src='https:\/\/www.digifie.jp\/blog\/wp-content\/plugins\/wp-social-bookmarking-light\/public\/images\/facebook.png' alt='Facebook \u306b\u30b7\u30a7\u30a2' title='Facebook \u306b\u30b7\u30a7\u30a2' width='16' height='16' class='wp_social_bookmarking_light_img' \/><\/a><\/div>        <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.digifie.jp\/blog\/archives\/1347\" data-text=\"three.js GeoGlobe + OpenWeatherMap\" data-via=\"LLC DigiFie\" data-lang=\"ja\">Tweet<\/a><\/div><\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Flash \u304b js \u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3067\u30013D \u306e\u5730\u7403\u5100\u4e0a\u306b\u8a72\u5f53\u5730\u70b9\u3092\u793a\u3059\u30de\u30fc\u30ab\u30fc\u3092\u7acb\u3066\u3066\u3001\u305d\u306e\u5730\u70b9\u306e\u5929\u6c17\u3092\u5225\u67a0\u3067\u8868\u793a\u3068\u3044\u3046\u3088\u3046\u306a\u3053\u3068\u3092\u3084\u308b\u5fc5\u8981\u304c\u3067\u3066\u304d\u305f\u307f\u305f\u3044\u306a\u306e\u3067\u3001\u8abf\u67fb\u3092\u304b\u306d\u3066 three.js \u3067\u30b5\u30f3\u30d7\u30eb\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[45],"tags":[],"_links":{"self":[{"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/posts\/1347"}],"collection":[{"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/comments?post=1347"}],"version-history":[{"count":10,"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/posts\/1347\/revisions"}],"predecessor-version":[{"id":1359,"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/posts\/1347\/revisions\/1359"}],"wp:attachment":[{"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/media?parent=1347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/categories?post=1347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.digifie.jp\/blog\/wp-json\/wp\/v2\/tags?post=1347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}