Greasy Fork is available in English.

WME Aerial Shifter (beta fixed)

This script helps you adjust the position and opacity of underlying satellite imagery

  1. // ==UserScript==
  2. // @name WME Aerial Shifter (beta fixed)
  3. // @version 1.6.7
  4. // @description This script helps you adjust the position and opacity of underlying satellite imagery
  5. // @match https://beta.waze.com/*editor*
  6. // @match https://www.waze.com/*editor*
  7. // @grant none
  8. // @icon http://s3.amazonaws.com/uso_ss/icon/176646/large.png?1391605696
  9. // @namespace https://www.waze.com/forum/viewtopic.php?t=53022
  10. // @author byo
  11. // @contributor berestovskyy
  12. // @contributor iainhouse
  13. // @contributor ragacs
  14. // ==/UserScript==
  15. /*
  16.  
  17. This program is free software: you can redistribute it and/or modify
  18. it under the terms of the GNU General Public License as published by
  19. the Free Software Foundation, either version 3 of the License, or
  20. (at your option) any later version.
  21.  
  22. This program is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. GNU General Public License for more details.
  26.  
  27. You should have received a copy of the GNU General Public License
  28. along with this program. If not, see <http://www.gnu.org/licenses/>.
  29.  
  30. */
  31.  
  32. (function()
  33. {
  34. var version = "1.6";
  35. var WM;
  36.  
  37. var prefix = 'WAS_';
  38. var settings = prefix + 'settings';
  39.  
  40. var sx, sy, so;
  41.  
  42. function init()
  43. {
  44. // init shortcuts
  45. if(!(WM = window.Waze.map) || !$('#search').length)
  46. {
  47. window.console.log("WME Aerial Shifter v" + version
  48. + ": waiting for WME...");
  49. setTimeout(init, 500);
  50. return;
  51. }
  52.  
  53. var suffix = ' of satellite imagery';
  54. var psx = prefix + 'sx', psy = prefix + 'sy', pso = prefix + 'so',
  55. psr = prefix + 'reset';
  56.  
  57. var nav = $(
  58. '<div style="direction:ltr;text-align:right;color:white;width:420px;'
  59. + 'line-height:20px;position:absolute;right:10px;top:52px">'
  60. + '<label title="Horizontal shift' + suffix + ' (meters)"'
  61. + 'style="font-weight:normal" for="' + psx + '">'
  62. + '<i class="fa fa-arrow-right"></i> '
  63. + '<input type="number" max="100" min="-100" step="10"'
  64. + 'style="text-align:right;width:60px;height:25px;padding:0 5px"'
  65. + 'id="' + psx + '" value="0"/>'
  66. + ' m'
  67. + '</label>'
  68. + ' &nbsp; '
  69. + '<label title="Vertical shift' + suffix + ' (meters)"'
  70. + 'style="font-weight:normal" for="' + psy + '">'
  71. + '<i class="fa fa-arrow-down"></i> '
  72. + '<input type="number" max="100" min="-100" step="10"'
  73. + 'style="text-align:right;width:60px;height:25px;padding:0 5px"'
  74. + 'id="' + psy + '" value="0"/>'
  75. + ' m'
  76. + '</label>'
  77. + ' &nbsp; '
  78. + '<label title="Opacity' + suffix + ' (pecent)"'
  79. + 'style="font-weight:normal" for="' + pso + '">'
  80. + '<i class="fa fa-adjust"></i> '
  81. + '<input type="number" max="100" min="0" step="25"'
  82. + 'style="text-align:right;width:55px;height:25px;padding:0 5px"'
  83. + 'id="' + pso + '" value="100"/>'
  84. + ' %'
  85. + '</label>'
  86. + ' &nbsp; '
  87. + '<a id="' + psr + '" style="color:white;text-decoration:none"'
  88. + 'href="#" title="Reset defaults">'
  89. + '<i class="fa fa-undo"></i>'
  90. + '</a>'
  91. + ' | '
  92. + '<a target="_blank" style="color:white;text-decoration:none"'
  93. + 'href="https://www.waze.com/forum/viewtopic.php?t=53022"'
  94. + 'title="WME Aerial Shifter v' + version + '">'
  95. + '<i class="fa fa-question"></i>'
  96. + '</a>'
  97. + '</div>'
  98. );
  99. sx = nav.find('#' + psx);
  100. sy = nav.find('#' + psy);
  101. so = nav.find('#' + pso);
  102. if($('#header-actions').length)
  103. $('#header-actions').append(nav);
  104. else
  105. {
  106. nav.css('right', '');
  107. nav.css('top', '');
  108. nav.css('left', 0);
  109. nav.css('padding-top', 6);
  110. nav.css('position', 'relative');
  111. $('#search').after(nav);
  112. }
  113.  
  114. loadFromStorage();
  115. update();
  116.  
  117. WM.events.on({
  118. zoomend : update,
  119. moveend : update
  120. });
  121. WM.baseLayer.events.on({
  122. loadend : update,
  123. });
  124. sx.change(update);
  125. sy.change(update);
  126. so.change(update);
  127. nav.find('#' + psr).click(resetDefaults);
  128. }
  129.  
  130. function resetDefaults()
  131. {
  132. sx.val(0);
  133. sy.val(0);
  134. so.val(100);
  135.  
  136. update();
  137. }
  138.  
  139. function loadFromStorage()
  140. {
  141. var obj = JSON.parse(localStorage.getItem(settings));
  142. if(obj)
  143. {
  144. sx.val(obj.sx);
  145. sy.val(obj.sy);
  146. so.val(obj.so);
  147. }
  148. }
  149.  
  150. function saveToStorage()
  151. {
  152. localStorage.setItem(settings, JSON.stringify({
  153. sx: sx.val(),
  154. sy: sy.val(),
  155. so: so.val(),
  156. }));
  157. }
  158.  
  159. function update()
  160. {
  161. // calculate meters per pixel factor of current map
  162. var ipu = OpenLayers.INCHES_PER_UNIT;
  163. var metersPerPixel = WM.getResolution() * ipu['m']
  164. / ipu[WM.getUnits()];
  165. var shiftX = parseInt(sx.val(), 10);
  166. var shiftY = parseInt(sy.val(), 10);
  167. var opacity = parseInt(so.val(), 10);
  168.  
  169. // Apply the shift and opacity
  170. WM.baseLayer.div.style.left =
  171. Math.round(shiftX / metersPerPixel) + 'px';
  172. WM.baseLayer.div.style.top =
  173. Math.round(shiftY / metersPerPixel) + 'px';
  174. WM.baseLayer.div.style.opacity = opacity/100;
  175.  
  176. saveToStorage();
  177. }
  178.  
  179. init();
  180. })();