not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
7.1 KiB

  1. //* comment *//
  2. Copyright (C) 2015 Yash Khandelwal
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. NOTE: Default local is downtown Boston.
  14. //* globals *//
  15. var gmapMashapeKey = 'JidA8phgY8mshJ8MiEUeHTdwFjjtp1wq209jsncYthfRDMQNW6';
  16. var cityName = '';
  17. var cityLatitude = 0;
  18. var cityLongitude = 0;
  19. //* block:cityToLat *//
  20. var cityToLatBlk = new ProtoBlock('cityToLat');
  21. cityToLatBlk.palette = palettes.dict['GMAP'];
  22. blocks.protoBlockDict['cityToLat'] = cityToLatBlk;
  23. cityToLatBlk.staticLabels.push(_('city latitude'));
  24. cityToLatBlk.adjustWidthToLabel();
  25. cityToLatBlk.oneArgMathBlock();
  26. cityToLatBlk.dockTypes[1] = 'anyin';
  27. cityToLatBlk.defaults.push("Boston");
  28. //* block:cityToLong *//
  29. var cityToLongBlk = new ProtoBlock('cityToLong');
  30. cityToLongBlk.palette = palettes.dict['GMAP'];
  31. blocks.protoBlockDict['cityToLong'] = cityToLongBlk;
  32. cityToLongBlk.staticLabels.push(_('city longitude'));
  33. cityToLongBlk.adjustWidthToLabel();
  34. cityToLongBlk.oneArgMathBlock();
  35. cityToLongBlk.dockTypes[1] = 'anyin';
  36. cityToLongBlk.defaults.push("Boston");
  37. //* arg:cityToLong *//
  38. var block = logo.blocks.blockList[blk];
  39. var conns = block.connections;
  40. var city = logo.parseArg(logo, turtle, conns[1]);
  41. if (city == cityName) {
  42. block.value = cityLongitude;
  43. } else {
  44. var apiURL = 'https://devru-latitude-longitude-find-v1.p.mashape.com/latlon.php?location=' + city;
  45. var request = new XMLHttpRequest();
  46. request.open('GET', apiURL, false);
  47. request.setRequestHeader('X-Mashape-Authorization', gmapMashapeKey);
  48. request.send(null);
  49. var response = request.responseText;
  50. var data = JSON.parse(response);
  51. var longitude = 0;
  52. if (data['Results'].length > 0) {
  53. data = data['Results'][0]['ll'];
  54. var parts = data.split(' ');
  55. try {
  56. cityLatitude = Number(parts[0]);
  57. cityLongitude = Number(parts[1]);
  58. var longitude = cityLongitude;
  59. cityName = city;
  60. } catch (e) {
  61. logo.errorMsg(_('Coordinate data not available.'), blk);
  62. }
  63. } else {
  64. logo.errorMsg(_('Coordinate data not available.'), blk);
  65. }
  66. block.value = longitude;
  67. }
  68. //* arg:cityToLat *//
  69. var block = logo.blocks.blockList[blk];
  70. var conns = block.connections;
  71. var city = logo.parseArg(logo, turtle, conns[1]);
  72. if (city == cityName) {
  73. block.value = cityLatitude;
  74. } else {
  75. var apiURL = 'https://devru-latitude-longitude-find-v1.p.mashape.com/latlon.php?location=' + city;
  76. var request = new XMLHttpRequest();
  77. request.open('GET', apiURL, false);
  78. request.setRequestHeader('X-Mashape-Authorization', gmapMashapeKey);
  79. request.send(null);
  80. var response = request.responseText;
  81. var data = JSON.parse(response);
  82. var latitude = 0;
  83. if(data['Results'].length > 0) {
  84. data = data['Results'][0]['ll'];
  85. var parts = data.split(' ');
  86. try {
  87. cityLatitude = Number(parts[0]);
  88. cityLongitude = Number(parts[1]);
  89. var latitude = cityLatitude;
  90. cityName = city;
  91. } catch (e) {
  92. logo.errorMsg(_('Coordinate data not available.'), blk);
  93. }
  94. } else {
  95. logo.errorMsg(_('Coordinate data not available.'), blk);
  96. }
  97. block.value = latitude;
  98. }
  99. //* block:gmap *//
  100. var gmapBlk = new ProtoBlock('gmap');
  101. gmapBlk.palette = palettes.dict['GMAP'];
  102. blocks.protoBlockDict['gmap'] = gmapBlk;
  103. gmapBlk.staticLabels.push(_('Google map'),_('coordinates'),_('zoom factor'));
  104. gmapBlk.adjustWidthToLabel();
  105. gmapBlk.twoArgMathBlock();
  106. //* arg:gmap *//
  107. var block = logo.blocks.blockList[blk];
  108. var conns = block.connections;
  109. var url = logo.parseArg(logo, turtle, conns[1]);
  110. var zoom_factor = logo.parseArg(logo, turtle, conns[2]);
  111. if(!url) {
  112. url = 'http://maps.googleapis.com/maps/api/staticmap?center=42.357279,-71.065740';
  113. }
  114. if(!zoom_factor) {
  115. zoom_factor = 10;
  116. }
  117. if(zoom_factor == 0) {
  118. zoom_factor = 0;
  119. }
  120. gmapURL = url + '&size=800x800&zoom=' + zoom_factor +'&sensor=false';
  121. block.value = gmapURL;
  122. //* block:zoom *//
  123. var zoomBlk = new ProtoBlock('zoom');
  124. zoomBlk.palette = palettes.dict['GMAP'];
  125. blocks.protoBlockDict['zoom'] = zoomBlk;
  126. zoomBlk.staticLabels.push(_('zoom'));
  127. zoomBlk.adjustWidthToLabel();
  128. zoomBlk.oneArgMathBlock();
  129. zoomBlk.dockTypes[1] = 'anyin';
  130. zoomBlk.defaults.push(10);
  131. //* arg:zoom *//
  132. var block = logo.blocks.blockList[blk];
  133. var conns = block.connections;
  134. var zoomFactor = logo.parseArg(logo, turtle, conns[1]);
  135. block.value = zoomFactor;
  136. //* block:coord *//
  137. var coordBlk = new ProtoBlock('coord');
  138. coordBlk.palette = palettes.dict['GMAP'];
  139. blocks.protoBlockDict['coord'] = coordBlk;
  140. coordBlk.staticLabels.push(_('coordinates'),_('latitude'),_('longitude'));
  141. coordBlk.adjustWidthToLabel();
  142. coordBlk.twoArgMathBlock();
  143. coordBlk.dockTypes[1] = 'anyin';
  144. coordBlk.dockTypes[2] = 'anyin';
  145. coordBlk.defaults.push(42.357279,-71.065740);
  146. //* arg:coord *//
  147. var block = logo.blocks.blockList[blk];
  148. var conns = block.connections;
  149. var latitude = logo.parseArg(logo, turtle, conns[1]);
  150. var longitude = logo.parseArg(logo, turtle, conns[2]);
  151. latitude = eval(latitude);
  152. longitude = eval(longitude);
  153. if(!latitude || !longitude) {
  154. latitude = 42.357279;
  155. longitude = -71.065740;
  156. }
  157. gmapURL = 'http://maps.googleapis.com/maps/api/staticmap?center=' + latitude + ',' + longitude;
  158. block.value = gmapURL;
  159. //* palette-icon:GMAP *//
  160. <svg
  161. xmlns="http://www.w3.org/2000/svg"
  162. version="1.1"
  163. width="55"
  164. height="55">
  165. <g
  166. transform="translate(0,-997.36218)">
  167. <path
  168. d="m 26.666222,1048.911 c -0.09596,-0.1879 -0.280246,-1.1767 -0.409529,-2.1972 -0.565075,-4.4605 -1.668106,-8.4319 -3.417528,-12.3047 -1.042617,-2.3081 -1.991286,-4.0116 -4.785815,-8.5938 -2.157572,-3.5377 -3.416439,-6.1924 -3.906374,-8.2377 -1.94515,-8.1203 3.386556,-15.8819 11.66714,-16.9844 6.55392,-0.87256 12.754344,3.0441 14.884012,9.4018 0.303361,0.9057 0.454986,1.948 0.528971,3.6362 0.12683,2.8942 -0.172817,4.4431 -1.375035,7.1077 -0.81051,1.7964 -1.193239,2.47 -3.882801,6.8343 -4.222383,6.8514 -6.42126,12.8338 -7.162043,19.4855 -0.09889,0.8879 -0.288049,1.7449 -0.420357,1.9043 -0.340934,0.4108 -1.502333,0.3757 -1.720641,-0.052 z m 3.610049,-29.2554 c 2.087523,-1.02 3.263533,-2.9613 3.249324,-5.3637 -0.01655,-2.7984 -1.484926,-4.8055 -4.176295,-5.7086 -1.149887,-0.3858 -3.454027,-0.19 -4.573135,0.3887 -0.987414,0.5106 -2.073445,1.6471 -2.65731,2.7808 -0.65002,1.2622 -0.65002,3.816 0,5.0782 1.595933,3.0989 5.107552,4.3148 8.157416,2.8246 z"
  169. style="fill:#ffffff" />
  170. </g>
  171. </svg>
  172. //* palette-fill:GMAP *// #00abff
  173. //* palette-stroke:GMAP *// #005aaa
  174. //* palette-highlight:GMAP *// #00c5ff
  175. //* palette-stroke-highlight:GMAP *// #002659