Greasy Fork is available in English.

WME KYTC Lookup

Look up KY road info from KYTC. Mouse over a road and hit 'ALT+k'.

  1. // ==UserScript==
  2. // @name WME KYTC Lookup
  3. // @namespace
  4. // @version 2020.07.21.002
  5. // @description Look up KY road info from KYTC. Mouse over a road and hit 'ALT+k'.
  6. // @author MapOMatic
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @grant none
  9. // eslint-disable-next-line max-len
  10. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AUeAB0qhmG7NAAABedJREFUWMO9lntwVFcdxz/n3Ht3yYO8yO7dNAGb8LBgO8IUmNpCjDJiZUbGOi1Yx2kF41RMHTODI6WjwdE+rIPWwakWUf7QsWWEGVpLlQRJx2lSR5M1aFugpGQ37yYNZEOWzT7uPcc/Nlk3UNJUQn8zd+455977+3zv93fOPVcwx7Fv376q9evXVxqGYZ05c6Z369atb850v5gLaH19va+uru6JeV7vA/F4zDM6OobSiuLCQnLy8nAc96Xm5uZHa2tr35hzAU1NTTuXLlm8NzR4gVGVi8j34S+eT54lSMWjREaGSEUjfKzqJnp6+35dXV390JwJaGxsPFhZWbktHDWxSsrJNaGiwMCUYEmBZQi8psDVEDzdRanXYXhoqLW6unrdVA75/8Kfe/75Ryqrqra9o4so8KfhC3IlSVeTciGpNClXk3A0oLnrtiomrCLKKyruOnr06G+u7cA6rTPtFjH9+p3ubqR8Yqr7lbuj9I7k8Ld2A4Bbbla8+LSLxxRYUmAaYAKfrpP853w6Vc2qCX61I8wfDx9etWfPnlOzd2Cdcy9SPD7VvWfdZXZ93cPu7S7zPAqAs2HJoUaBoyClNI4Lv28iA8/P0Ty7y4PMK2LFihVPzb4Ed6TWgPwdpB25Y9kFHvtmEsuQLAwIvrFFZW79+R8kkXGFo2Aspnjy4P9M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5T3jr8aalEXDm2gFzyvbTEStUvMBXbNs2fr8fv9+PaZo3FA4gH1mDdTri6SkqKS0OBAIEAgFs20ZKecPhmRKU2wvaAhU3r7Ztm9LS0sk37w2fPH5iafwGwjOroH/owpqSgtygbQcwTZPhwb5w84cAv2oV3H/fF9suRiJLTpxo/oxKw9XkoSfP7hVnJ6vvvsf4lcesPkQ3CbB0GkrWg9lCptruNcaz2zqrfVX8F7qhodkBJUFcAAAAAElFTkSuQmCC
  11. // @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
  12. // @namespace
  13. // ==/UserScript==
  14.  
  15. /* global W */
  16. /* global $ */
  17. /* global WazeWrap */
  18.  
  19. function log(message) {
  20. console.log('KYTC Lookup:', message);
  21. }
  22. function logDebug(message) {
  23. console.debug('KYTC Lookup:', message);
  24. }
  25.  
  26. function processKYTCRouteInfo(routeInfos) {
  27. $('#kytc-button').text('KYTC').css('color', 'blue');
  28. if (routeInfos.RouteInfos.length > 0) {
  29. const routeInfo = routeInfos.RouteInfos[0];
  30. const match = routeInfo.RTUnique.match(/\d+-(.*-\d+)\s+/);
  31. const number = (match && match.length) > 1 ? match[1] : routeInfo.RTUnique;
  32. WazeWrap.Alerts.info(null,
  33. $('<table>').append(
  34. [
  35. ['NUMBER:', number],
  36. ['NAME:', routeInfo.Routename],
  37. ['COUNTY:', routeInfo.CountyName],
  38. ['DISTRICT:', routeInfo.District],
  39. ['MILE POINT:', routeInfo.MilePoint],
  40. ['GOV LEVEL:', routeInfo.GovLevelValue],
  41. ['FC:', routeInfo.FunctionalClass],
  42. ['POSTED SL:', routeInfo.PostedSpeedLimit]
  43. ].map(itm => $('<tr>').append(
  44. $('<td class="kytc-lookup-row-header">').text(itm[0]),
  45. $('<td>').text(itm[1])
  46. ))
  47. ).prop('outerHTML'), true);
  48. } else {
  49. WazeWrap.Alerts.error(null, 'No road found at this location. Try again, or click the KYTC button in the footer to open the KYTC map.');
  50. }
  51. }
  52.  
  53. async function processKYTCCoords(coordsIn) {
  54. const jsonCoords = coordsIn;
  55. const searchRadius = W.map.zoom <= 6 ? 640 / (W.map.zoom ** 2) : 10;
  56. const url = `https://maps.kytc.ky.gov/arcgis/rest/services/MeasuredRoute/MapServer/exts/KYTCGISREST/GetRouteInfo?X=${
  57. jsonCoords.geometries[0].x}&Y=${jsonCoords.geometries[0].y}&SearchRadius=${searchRadius}&f=json`;
  58. const routes = await $.getJSON(url);
  59. processKYTCRouteInfo(routes);
  60. }
  61.  
  62. async function checkKeyDown(e) {
  63. if (e.keyCode === 75 && e.altKey) {
  64. $('#kytc-button').text('KYTC...').css('color', 'gray');
  65. const mousePosition = $('.mouse-position').text().split(' ');
  66. logDebug(`looking up road at coordinate ${mousePosition}`);
  67. const url = `https://kygisserver.ky.gov/arcgis/rest/services/Utilities/Geometry/GeometryServer/project?inSR=4326&outSR=102763&geometries=${
  68. mousePosition[0]}%2C${mousePosition[1]}&transformation=&transformForward=true&f=json`;
  69. logDebug(url);
  70. const coords = await $.getJSON(url);
  71. processKYTCCoords(coords);
  72. }
  73. }
  74.  
  75. async function kytcButtonClick() {
  76. const wazeExt = W.map.getExtent();
  77. // let url = `https://maps.kytc.ky.gov/arcgis/rest/services/Utilities/Geometry/GeometryServer/project?inSR=3857&outSR=102763&geometries=${
  78. // wazeExt.left}%2C${wazeExt.bottom}%2C${wazeExt.right}%2C${wazeExt.top}&transformation=&transformForward=true&f=json`;
  79. // logDebug(url);
  80. // const result = await $.getJSON(url);
  81. // const pts = result.geometries;
  82. const url = `https://maps.kytc.ky.gov/functionalclass/?xmin=${wazeExt.left}&ymin=${wazeExt.bottom}&xmax=${wazeExt.right}&ymax=${wazeExt.top}`;
  83. logDebug(url);
  84. window.open(url, '_blank');
  85. }
  86.  
  87. function init() {
  88. $('.WazeControlPermalink').prepend(
  89. $('<div>').css({ float: 'left', dispaly: 'inline-block', padding: '0px 5px 0px 3px' }).append(
  90. $('<a>', { id: 'kytc-button', title: 'Open the KYTC map in a new window' })
  91. // eslint-disable-next-line no-script-url
  92. .text('KYTC').attr('href', 'javascript:void(0)')
  93. .css({
  94. float: 'left', textDecoration: 'none', color: 'blue', fontWeight: 'bold'
  95. })
  96. .click(kytcButtonClick)
  97. )
  98. );
  99.  
  100. $('head').append([
  101. '<style type="text/css">',
  102. '.kytc-lookup-row-header { padding-right: 5px; }',
  103. '</style>'
  104. ].join(' '));
  105.  
  106.  
  107. /* Event listeners */
  108. W.loginManager.events.register('afterloginchanged', this, init);
  109. document.addEventListener('keydown', checkKeyDown, false);
  110.  
  111. log('Initialized.');
  112. }
  113.  
  114. function bootstrap() {
  115. if (W && W.loginManager
  116. && W.loginManager.events.register
  117. && W.map) {
  118. log('Initializing...');
  119. init();
  120. } else {
  121. log('Bootstrap failed. Trying again...');
  122. window.setTimeout(bootstrap, 1000);
  123. }
  124. }
  125.  
  126. log('Bootstrap...');
  127. bootstrap();