WME True Segment Length

Displays geodesic segment length in feet & meters

Mint 2018.02.22.. Lásd a legutóbbi verzió

  1. // ==UserScript==
  2. // @name WME True Segment Length
  3. // @namespace https://greasyfork.org/users/30701-justins83-waze
  4. // @version 2018.02.22.01
  5. // @description Displays geodesic segment length in feet & meters
  6. // @author JustinS83
  7. // @include https://www.waze.com/editor*
  8. // @include https://www.waze.com/*/editor*
  9. // @include https://beta.waze.com/*
  10. // @exclude https://www.waze.com/user/editor*
  11. // @grant none
  12. // @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
  13. // @license GPLv3
  14. // ==/UserScript==
  15.  
  16. (function() {
  17.  
  18. function bootstrap(tries) {
  19. tries = tries || 1;
  20.  
  21. if (W &&
  22. W.map &&
  23. W.model &&
  24. $ && WazeWrap.Ready) {
  25. init();
  26. } else if (tries < 1000) {
  27. setTimeout(function () {bootstrap(tries++);}, 200);
  28. }
  29. }
  30.  
  31. bootstrap();
  32.  
  33. function init(){
  34. W.selectionManager.events.register("selectionchanged", null, updateDisplay);
  35. W.model.actionManager.events.register("afteraction",null, updateDisplay);
  36. W.model.actionManager.events.register("afterundoaction",null, updateDisplay);
  37. W.model.actionManager.events.register("afterclearactions",null, updateDisplay);
  38. W.model.actionManager.events.register("noActions",null, noActions);
  39. console.log("WME True Segment Length" + GM_info.script.version);
  40. }
  41.  
  42. function noActions(){
  43. setTimeout( updateDisplay, 100 ); //have to put in a delay for when the user uses undo to clear all actions - WME updates on top of my changes otherwise.
  44. }
  45.  
  46. function updateDisplay(){
  47. var count = W.selectionManager.selectedItems.length;
  48. var metersLength = 0;
  49. var bold = false;
  50. if(count > 0){
  51. for(i=0;i<count;i++){
  52. if(W.selectionManager.selectedItems[i].model.type === "segment"){
  53. metersLength += WazeWrap.Geometry.calculateDistance(W.selectionManager.selectedItems[i].geometry.components);
  54. if(!W.selectionManager.selectedItems[0].model.isUnchanged())
  55. bold = true;
  56. }
  57. }
  58. if(metersLength >0){
  59. var isUSA = (W.location.code === "usa");
  60. var ftLength = Math.round(metersLength * 3.28084 *100)/100;
  61. var milesLength = Math.round(ftLength/5280 *100)/100;
  62.  
  63. if(W.selectionManager.selectedItems[0].model.attributes.id < 0){ //segment has not yet been saved
  64. var list = $('#segment-edit-general > ul')[0];
  65. var newItem = document.createElement("LI");
  66. var textnode = document.createTextNode("Length: " + metersLength +" m");
  67. newItem.appendChild(textnode);
  68. list.insertBefore(newItem, list.childNodes[0]);
  69.  
  70. if(isUSA){
  71. newItem = document.createElement("LI");
  72. textnode = document.createTextNode(`Length: ${ftLength} ft (${milesLength} miles)`);
  73. newItem.appendChild(textnode);
  74. list.insertBefore(newItem, list.childNodes[0]);
  75. }
  76. }
  77. else{
  78. try
  79. {
  80. $('#segment-edit-general > ul > li:nth-child(1) > span')[1].innerHTML = (Math.round(metersLength*100)/100) + " m";
  81. if($('#segment-edit-general > ul > li:nth-child(1) > span').length === 2 && isUSA)
  82. $('#segment-edit-general > ul > li:nth-child(1)').append(`<br/><span class="name">Length: </span><span class="value">${ftLength} ft</span><span class="value"> (${milesLength} miles)</span>`);
  83. if(bold){
  84. $('#segment-edit-general > ul > li:nth-child(1) > span').css('font-weight', "bold");
  85. if(isUSA)
  86. $('#segment-edit-general > ul > li:nth-child(2) > span').css('font-weight', "bold");
  87. }
  88. }
  89. catch(ex)
  90. {
  91.  
  92. }
  93. }
  94. }
  95. }
  96. }
  97.  
  98. })();