WME RA Util

Providing basic utility for RA adjustment without the need to delete & recreate

目前为 2023-12-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME RA Util
  3. // @namespace https://greasyfork.org/users/30701-justins83-waze
  4. // @version 2023.12.01.01
  5. // @description Providing basic utility for RA adjustment without the need to delete & recreate
  6. // @include https://www.waze.com/editor*
  7. // @include https://www.waze.com/*/editor*
  8. // @include https://beta.waze.com/*
  9. // @exclude https://www.waze.com/user/editor*
  10. // @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
  11. // @connect greasyfork.org
  12. // @author JustinS83
  13. // @grant GM_xmlhttpRequest
  14. // @license GPLv3
  15. // @contributionURL https://github.com/WazeDev/Thank-The-Authors
  16. // ==/UserScript==
  17.  
  18. /* global W */
  19. /* global WazeWrap */
  20. /* global OpenLayers */
  21. /* global require */
  22. /* global $ */
  23. /* global _ */
  24. /* global I18n */
  25. /* eslint curly: ["warn", "multi-or-nest"] */
  26.  
  27. /*
  28. non-normal RA color:#FF8000
  29. normal RA color:#4cc600
  30. */
  31. (function() {
  32.  
  33. var RAUtilWindow = null;
  34. var UpdateSegmentGeometry;
  35. var MoveNode, MultiAction;
  36. var drc_layer;
  37. let wEvents;
  38. const SCRIPT_VERSION = GM_info.script.version.toString();
  39. const SCRIPT_NAME = GM_info.script.name;
  40. const DOWNLOAD_URL = GM_info.scriptUpdateURL;
  41.  
  42. //var totalActions = 0;
  43. var _settings;
  44. const updateMessage = "Updating for .geometry changes";
  45.  
  46. function bootstrap(tries = 1) {
  47.  
  48. if (W && W.map && W.model && require && WazeWrap.Ready){
  49. loadScriptUpdateMonitor();
  50. init();
  51. }
  52. else if (tries < 1000)
  53. setTimeout(function () {bootstrap(++tries);}, 200);
  54. }
  55.  
  56. bootstrap();
  57.  
  58. function loadScriptUpdateMonitor() {
  59. let updateMonitor;
  60. try {
  61. updateMonitor = new WazeWrap.Alerts.ScriptUpdateMonitor(SCRIPT_NAME, SCRIPT_VERSION, DOWNLOAD_URL, GM_xmlhttpRequest);
  62. updateMonitor.start();
  63. } catch (ex) {
  64. // Report, but don't stop if ScriptUpdateMonitor fails.
  65. console.error(`${SCRIPT_NAME}:`, ex);
  66. }
  67. }
  68.  
  69. function init(){
  70. injectCss();
  71. UpdateSegmentGeometry = require('Waze/Action/UpdateSegmentGeometry');
  72. MoveNode = require("Waze/Action/MoveNode");
  73. MultiAction = require("Waze/Action/MultiAction");
  74.  
  75. console.log("RA UTIL");
  76. console.log(GM_info.script);
  77. if(W.map.events)
  78. wEvents = W.map.events;
  79. else
  80. wEvents = W.map.getMapEventsListener();
  81.  
  82. RAUtilWindow = document.createElement('div');
  83. RAUtilWindow.id = "RAUtilWindow";
  84. RAUtilWindow.style.position = 'fixed';
  85. RAUtilWindow.style.visibility = 'hidden';
  86. RAUtilWindow.style.top = '15%';
  87. RAUtilWindow.style.left = '25%';
  88. RAUtilWindow.style.width = '510px';
  89. RAUtilWindow.style.zIndex = 100;
  90. RAUtilWindow.style.backgroundColor = '#FFFFFE';
  91. RAUtilWindow.style.borderWidth = '0px';
  92. RAUtilWindow.style.borderStyle = 'solid';
  93. RAUtilWindow.style.borderRadius = '10px';
  94. RAUtilWindow.style.boxShadow = '5px 5px 10px Silver';
  95. RAUtilWindow.style.padding = '4px';
  96.  
  97. var alertsHTML = '<div id="header" style="padding: 4px; background-color:#92C3D3; border-radius: 5px;-moz-border-radius: 5px;-webkit-border-radius: 5px; color: white; font-weight: bold; text-align:center; letter-spacing: 1px;text-shadow: black 0.1em 0.1em 0.2em;"><img src="https://storage.googleapis.com/wazeopedia-files/1/1e/RA_Util.png" style="float:left"></img> Roundabout Utility <a data-toggle="collapse" href="#divWrappers" id="collapserLink" style="float:right"><span id="collapser" style="cursor:pointer;padding:2px;color:white;" class="fa fa-caret-square-o-up"></a></span></div>';
  98. // start collapse // I put it al the beginning
  99. alertsHTML += '<div id="divWrappers" class="collapse in">';
  100. //***************** Round About Angles **************************
  101. alertsHTML += '<p style="margin: 10px 0px 0px 20px;"><input type="checkbox" id="chkRARoundaboutAngles">&nbsp;Enable Roundabout Angles</p>';
  102. //***************** Shift Amount **************************
  103. // Define BOX
  104. alertsHTML += '<div id="contentShift" style="text-align:center;float:left; width: 120px;max-width: 24%;height: 170px;margin: 1em 5px 0px 0px;opacity:1;border-radius: 2px;-moz-border-radius: 2px;-webkit-border-radius: 4px;border-width:1px;border-style:solid;border-color:#92C3D3;padding:2px;}">';
  105. alertsHTML += '<b>Shift amount</b></br><input type="text" name="shiftAmount" id="shiftAmount" size="1" style="float: left; text-align: center;font: inherit; line-height: normal; width: 30px; height: 20px; margin: 5px 4px; box-sizing: border-box; display: block; padding-left: 0; border-bottom-color: rgba(black,.3); background: transparent; outline: none; color: black;" value="1"/> <div style="margin: 5px 4px;">Meter(s)';
  106. // Shift amount controls
  107. alertsHTML += '<div id="controls" style="text-align:center; padding:06px 4px;width=100px; height=100px;margin: 5px 0px;border-style:solid; border-width: 2px;border-radius: 50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;box-shadow: inset 0px 0px 50px -14px rgba(0,0,0,1);-moz-box-shadow: inset 0px 0px 50px -14px rgba(0,0,0,1);-webkit-box-shadow: inset 0px 0px 50px -14px rgba(0,0,0,1); background:#92C3D3;align:center;">';
  108. //Single Shift Up Button
  109. alertsHTML += '<span id="RAShiftUpBtn" style="cursor:pointer;font-size:14px;">';
  110. alertsHTML += '<i class="fa fa-angle-double-up fa-2x" style="color: white; text-shadow: black 0.1em 0.1em 0.2em; vertical-align: top;"> </i>';
  111. alertsHTML += '<span id="UpBtnCaption" style="font-weight: bold;"></span>';
  112. alertsHTML += '</span><br>';
  113. //Single Shift Left Button
  114. alertsHTML += '<span id="RAShiftLeftBtn" style="cursor:pointer;font-size:14px;margin-left:-40px;">';
  115. alertsHTML += '<i class="fa fa-angle-double-left fa-2x" style="color: white; text-shadow: black 0.1em 0.1em 0.2em; vertical-align: middle"> </i>';
  116. alertsHTML += '<span id="LeftBtnCaption" style="font-weight: bold;"></span>';
  117. alertsHTML += '</span>';
  118. //Single Shift Right Button
  119. alertsHTML += '<span id="RAShiftRightBtn" style="float: right;cursor:pointer;font-size:14px;margin-right:5px;">';
  120. alertsHTML += '<i class="fa fa-angle-double-right fa-2x" style="color: white;text-shadow: black 0.1em 0.1em 0.2em; vertical-align: middle"> </i>';
  121. alertsHTML += '<span id="RightBtnCaption" style="font-weight: bold;"></span>';
  122. alertsHTML += '</span><br>';
  123. //Single Shift Down Button
  124. alertsHTML += '<span id="RAShiftDownBtn" style="cursor:pointer;font-size:14px;margin-top:0px;">';
  125. alertsHTML += '<i class="fa fa-angle-double-down fa-2x" style="color: white;text-shadow: black 0.1em 0.1em 0.2em; vertical-align: middle"> </i>';
  126. alertsHTML += '<span id="DownBtnCaption" style="font-weight: bold;"></span>';
  127. alertsHTML += '</span>';
  128. alertsHTML += '</div></div></div>';
  129. //***************** Rotation **************************
  130. // Define BOX
  131. alertsHTML += '<div id="contentRotate" style="float:left; text-align: center;width: 120px;max-width: 24%;max-height:145px;margin: 1em auto;opacity:1;border-radius: 2px;-moz-border-radius: 2px;-webkit-border-radius: 4px;border-width:1px;border-style:solid;border-color:#92C3D3;padding:2px; display:inline-block; border-style:solid; border-width:1px; height:152px; margin-right:5px;">';
  132. alertsHTML += '<b>Rotation amount</b></br><input type="text" name="rotationAmount" id="rotationAmount" size="1" style="float: left; text-align: center;font: inherit; line-height: normal; width: 30px; height: 20px; margin: 5px 4px; box-sizing: border-box; display: block; padding-left: 0; border-bottom-color: rgba(black,.3); background: transparent; outline: none; color: black;" value="1"/> <div style="margin: 5px 4px;">Degree(s)';
  133. // Rotation controls
  134. alertsHTML += '<div id="rotationControls" style="padding: 6px 4px;width=100px; margin: 20px 0px 50px 0px;align:center;">';
  135. // Rotate Button on the Left
  136. alertsHTML += '<span id="RARotateLeftBtn" class="btnRotate" style="float: left;">';
  137. alertsHTML += '<i class="fa fa-undo fa-2x" style="color: white; text-shadow: black 0.1em 0.1em 0.2em; padding:2px;"> </i>';
  138. alertsHTML += '<span id="RotateLeftBtnCaption" style="font-weight: bold;"></span>';
  139. alertsHTML += '</span>';
  140. // Rotate button on the Right
  141. alertsHTML += '<span id="RARotateRightBtn" class="btnRotate" style="float: right;">';
  142. alertsHTML += '<i class="fa fa-repeat fa-2x" style="color: white; text-shadow: black 0.1em 0.1em 0.2em; padding:2px;"> </i>';
  143. alertsHTML += '<span id="RotateRightBtnCaption" style="font-weight: bold;"></span>';
  144. alertsHTML += '</div></div></div>';
  145. //********************* Diameter change ******************
  146. // Define BOX
  147. alertsHTML += '<div id="diameterChange" style="float:left; text-align: center;width: 120px;max-width: 24%;max-height:145px;margin: 1em auto;opacity:1;border-radius: 2px;-moz-border-radius: 2px;-webkit-border-radius: 4px;border-width:1px;border-style:solid;border-color:#92C3D3;padding:2px; display:inline-block; border-style:solid; border-width:1px; height:152px; margin-right:5px;">';
  148. alertsHTML += '<b>Change diameter</b></br></br>';
  149. // Diameter Change controls
  150. alertsHTML += '<div id="DiameterChangeControls" style="padding: 6px 4px;width=100px; margin: 5px 7px 50px 7px;align:center;">';
  151. // Decrease Button
  152. alertsHTML += '<span id="diameterChangeDecreaseBtn" style="float: left; width=45px; height=45px; background-color:#92C3D3; cursor:pointer; padding: 5px; font-size:14px; border:thin outset black; border-style:solid; border-width: 1px;border-radius: 50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);-moz-box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);-webkit-box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);">';
  153. alertsHTML += '<i class="fa fa-compress fa-2x" style="color: white; text-shadow: black 0.1em 0.1em 0.2em; padding:2px;;"> </i>';
  154. alertsHTML += '<span id="diameterChangeDecreaseCaption" style="font-weight: bold;"></span>';
  155. alertsHTML += '</span>';
  156. // Increase Button
  157. alertsHTML += '<span id="diameterChangeIncreaseBtn" style="float: right; width=45px; height=45px; background-color:#92C3D3; cursor:pointer; padding: 5px; font-size:14px; border:thin outset black; border-style:solid; border-width: 1px;border-radius: 50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);-moz-box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);-webkit-box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);">';
  158. alertsHTML += '<i class="fa fa-arrows-alt fa-2x" style="color: white; text-shadow: black 0.1em 0.1em 0.2em; padding:2px;"> </i>';
  159. alertsHTML += '<span id="diameterChangeIncreaseCaption" style="font-weight: bold;"></span>';
  160. alertsHTML += '</span>';
  161. alertsHTML += '</div></div>';
  162. //***************** Bump nodes **********************
  163. // Define BOX
  164. alertsHTML += '<div id="bumpNodes" style="float:left; text-align: center;width: 120px;max-width: 24%;max-height:145px;margin: 1em auto 0px auto;opacity:1;border-radius: 2px;-moz-border-radius: 2px;-webkit-border-radius: 4px;border-width:1px;border-style:solid;border-color:#92C3D3;padding:2px; display:inline-block; border-style:solid; border-width:1px; height:152px; margin-right:5px;">';
  165. alertsHTML += '<b>Move nodes</b></br>';
  166. // Move Nodes controls
  167. alertsHTML += '<div id="MoveNodesControls" style="padding: 2px;">';
  168. // Button A
  169. alertsHTML += '<div style="text-align:center; font-size:18px;">A Node';
  170. // Move node IN
  171. alertsHTML += '<p><span id="btnMoveANodeIn" class="btnMoveNode" style="color: white; font-size: 0.875em; text-shadow: black 0.1em 0.1em 0.2em; padding:3px 15px 3px 15px; margin:3px;">in</span>';
  172. // Move node OUT
  173. alertsHTML += '<span id="btnMoveANodeOut" class="btnMoveNode" class="btnMoveNode" style="color: white; font-size: 0.875em; text-shadow: black 0.1em 0.1em 0.2em; padding:3px 10px 3px 10px; margin:3px;">out</span>';
  174. alertsHTML += '</div>';
  175. // Button B
  176. alertsHTML += '<div style="text-align:center; font-size:18px;">B Node';
  177. // Move node IN
  178. alertsHTML += '<p><span id="btnMoveBNodeIn" class="btnMoveNode" style="color: white; font-size: 0.875em; text-shadow: black 0.1em 0.1em 0.2em; padding:3px 15px 3px 15px; margin:3px;">in</span>';
  179. // Move node OUT
  180. alertsHTML += '<span id="btnMoveBNodeOut" class="btnMoveNode" class="btnMoveNode" style="color: white; font-size: 0.875em; text-shadow: black 0.1em 0.1em 0.2em; padding:3px 10px 3px 10px; margin:3px;">out</span>';
  181. alertsHTML += '</div>';
  182. alertsHTML += '</div></div></div>';
  183.  
  184.  
  185. RAUtilWindow.innerHTML = alertsHTML;
  186. document.body.appendChild(RAUtilWindow);
  187.  
  188. $('#RAShiftLeftBtn').click(RAShiftLeftBtnClick);
  189. $('#RAShiftRightBtn').click(RAShiftRightBtnClick);
  190. $('#RAShiftUpBtn').click(RAShiftUpBtnClick);
  191. $('#RAShiftDownBtn').click(RAShiftDownBtnClick);
  192.  
  193. $('#RARotateLeftBtn').click(RARotateLeftBtnClick);
  194. $('#RARotateRightBtn').click(RARotateRightBtnClick);
  195.  
  196. $('#diameterChangeDecreaseBtn').click(diameterChangeDecreaseBtnClick);
  197. $('#diameterChangeIncreaseBtn').click(diameterChangeIncreaseBtnClick);
  198.  
  199. $('#btnMoveANodeIn').click(function(){moveNodeIn(WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.id, WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.fromNodeID);});
  200. $('#btnMoveANodeOut').click(function(){moveNodeOut(WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.id, WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.fromNodeID);});
  201. $('#btnMoveBNodeIn').click(function(){moveNodeIn(WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.id, WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.toNodeID);});
  202. $('#btnMoveBNodeOut').click(function(){moveNodeOut(WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.id, WazeWrap.getSelectedFeatures()[0].WW.getObjectModel().attributes.toNodeID);});
  203.  
  204. $('#shiftAmount').keypress(function(event) {
  205. if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57))
  206. event.preventDefault();
  207. });
  208.  
  209. $('#rotationAmount').keypress(function(event) {
  210. if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57))
  211. event.preventDefault();
  212. });
  213.  
  214. $('#collapserLink').click(function(){
  215. if($('#collapser').attr('class') == "fa fa-caret-square-o-down"){
  216. $("#collapser").removeClass("fa-caret-square-o-down");
  217. $("#collapser").addClass("fa-caret-square-o-up");
  218. }
  219. else{
  220. $("#collapser").removeClass("fa-caret-square-o-up");
  221. $("#collapser").addClass("fa-caret-square-o-down");
  222. }
  223. saveSettingsToStorage();
  224. });
  225.  
  226. W.selectionManager.events.register("selectionchanged", null, checkDisplayTool);
  227. //W.model.actionManager.events.register("afterundoaction",null, undotriggered);
  228. //W.model.actionManager.events.register("afterclearactions",null,actionsCleared);
  229.  
  230. var loadedSettings = $.parseJSON(localStorage.getItem("WME_RAUtil"));
  231. var defaultSettings = {
  232. divTop: "15%",
  233. divLeft: "25%",
  234. Expanded: true,
  235. RoundaboutAngles: true
  236. };
  237. _settings = loadedSettings ? loadedSettings : defaultSettings;
  238.  
  239. $('#RAUtilWindow').css('left', _settings.divLeft);
  240. $('#RAUtilWindow').css('top', _settings.divTop);
  241. $("#chkRARoundaboutAngles").prop('checked', _settings.RoundaboutAngles);
  242. $("#chkRARoundaboutAngles").prop('checked', _settings.RoundaboutAngles);
  243.  
  244. if(!_settings.Expanded){
  245. $("#divWrappers").removeClass("in");
  246. $("#divWrappers").addClass("collapse");
  247. $("#collapser").removeClass("fa-caret-square-o-up");
  248. $("#collapser").addClass("fa-caret-square-o-down");
  249. }
  250.  
  251. $("#chkRARoundaboutAngles").click(function(){
  252. saveSettingsToStorage();
  253.  
  254. if($("#chkRARoundaboutAngles").is(":checked")){
  255. wEvents.register("zoomend", null, DrawRoundaboutAngles);
  256. wEvents.register("moveend", null, DrawRoundaboutAngles);
  257. DrawRoundaboutAngles();
  258. drc_layer.setVisibility(true);
  259. }
  260. else{
  261. wEvents.unregister("zoomend", null, DrawRoundaboutAngles);
  262. wEvents.unregister("moveend", null, DrawRoundaboutAngles);
  263. drc_layer.setVisibility(false);
  264. }
  265. });
  266.  
  267. if(_settings.RoundaboutAngles){
  268. wEvents.register("zoomend", null, DrawRoundaboutAngles);
  269. wEvents.register("moveend", null, DrawRoundaboutAngles);
  270. DrawRoundaboutAngles();
  271. }
  272.  
  273. WazeWrap.Interface.ShowScriptUpdate("WME RA Util", GM_info.script.version, updateMessage, "https://greasyfork.org/en/scripts/23616-wme-ra-util", "https://www.waze.com/forum/viewtopic.php?f=819&t=211079");
  274. }
  275.  
  276. function saveSettingsToStorage() {
  277. if (localStorage) {
  278. var settings = {
  279. divTop: "15%",
  280. divLeft: "25%",
  281. Expanded: true,
  282. RoundaboutAngles: true
  283. };
  284.  
  285. settings.divLeft = $('#RAUtilWindow').css('left');
  286. settings.divTop = $('#RAUtilWindow').css('top');
  287. settings.Expanded = $("#collapser").attr('class').indexOf("fa-caret-square-o-up") > -1;
  288. settings.RoundaboutAngles = $("#chkRARoundaboutAngles").is(":checked");
  289. localStorage.setItem("WME_RAUtil", JSON.stringify(settings));
  290. }
  291. }
  292.  
  293. function checkDisplayTool(){
  294. if(WazeWrap.hasSelectedFeatures() && WazeWrap.getSelectedFeatures()[0].WW.getType() === 'segment'){
  295. if(!AllSelectedSegmentsRA() || WazeWrap.getSelectedFeatures().length === 0)
  296. $('#RAUtilWindow').css({'visibility': 'hidden'});
  297. else{
  298. $('#RAUtilWindow').css({'visibility': 'visible'});
  299. if(typeof jQuery.ui !== 'undefined')
  300. $('#RAUtilWindow' ).draggable({ //Gotta nuke the height setting the dragging inserts otherwise the panel cannot collapse
  301. stop: function(event, ui) {
  302. $('#RAUtilWindow').css("height", "");
  303. saveSettingsToStorage();
  304. }
  305. });
  306. //checkSaveChanges();
  307. checkAllEditable(WazeWrap.Model.getAllRoundaboutSegmentsFromObj(WazeWrap.getSelectedFeatures()[0]));
  308. }
  309. }
  310. else{
  311. $('#RAUtilWindow').css({'visibility': 'hidden'});
  312. if(typeof jQuery.ui !== 'undefined')
  313. $('#RAUtilWindow' ).draggable({
  314. stop: function(event, ui) {
  315. $('#RAUtilWindow').css("height", "");
  316. saveSettingsToStorage();
  317. }
  318. });
  319. }
  320. }
  321.  
  322. function checkAllEditable(RASegs){
  323. var $RAEditable = $('#RAEditable');
  324. var allEditable = true;
  325. var segObj, fromNode, toNode;
  326.  
  327. for(let i=0; i<RASegs.length;i++){
  328. segObj = W.model.segments.getObjectById(RASegs[i]);
  329. fromNode = segObj.getFromNode();
  330. toNode = segObj.getToNode();
  331.  
  332. if(segObj !== "undefined"){
  333. if(fromNode && fromNode !== "undefined" && !fromNode.areConnectionsEditable())
  334. allEditable = false;
  335. else if(toNode && toNode !== "undefined" && !toNode.areConnectionsEditable())
  336. allEditable = false;
  337. var toConnected, fromConnected;
  338.  
  339. if(toNode){
  340. toConnected = toNode.attributes.segIDs;
  341. for(let j=0;j<toConnected.length;j++){
  342. if(W.model.segments.getObjectById(toConnected[j]) !== "undefined")
  343. if(W.model.segments.getObjectById(toConnected[j]).hasClosures())
  344. allEditable = false;
  345. }
  346. }
  347.  
  348. if(fromNode){
  349. fromConnected = fromNode.attributes.segIDs;
  350. for(let j=0;j<fromConnected.length;j++){
  351. if(W.model.segments.getObjectById(fromConnected[j]) !== "undefined")
  352. if(W.model.segments.getObjectById(fromConnected[j]).hasClosures())
  353. allEditable = false;
  354. }
  355. }
  356. }
  357. }
  358. if(allEditable)
  359. $RAEditable.remove();
  360. else{
  361. if($RAEditable.length === 0){
  362. $RAEditable = $('<div>', {id:'RAEditable', style:'color:red'});
  363. $RAEditable.text('One or more segments are locked above your rank or have a closure.');
  364. $('#RAUtilWindow').append($RAEditable);
  365. }
  366. }
  367. return allEditable;
  368. }
  369.  
  370. function AllSelectedSegmentsRA(){
  371. for (let i = 0; i < WazeWrap.getSelectedFeatures().length; i++){
  372. if(WazeWrap.getSelectedFeatures()[i].WW.getObjectModel().attributes.id < 0 || !WazeWrap.Model.isRoundaboutSegmentID(WazeWrap.getSelectedFeatures()[i].WW.getObjectModel().attributes.id))
  373. return false;
  374. }
  375. return true;
  376. }
  377.  
  378. function ShiftSegmentNodesLat(segObj, latOffset){
  379. var RASegs = WazeWrap.Model.getAllRoundaboutSegmentsFromObj(segObj);
  380. if(checkAllEditable(RASegs)){
  381. var newGeometry, originalLength;
  382. var multiaction = new MultiAction();
  383. multiaction.setModel(W.model);
  384.  
  385. for(let i=0; i<RASegs.length; i++){
  386. segObj = W.model.segments.getObjectById(RASegs[i]);
  387. newGeometry = structuredClone(segObj.attributes.geoJSONGeometry);
  388. originalLength = segObj.attributes.geoJSONGeometry.coordinates.length;
  389. for(j=1; j < originalLength-1; j++){
  390. newGeometry.coordinates[j][1] += latOffset;
  391. }
  392. //W.model.actionManager.add(new UpdateSegmentGeometry(segObj, segObj.geometry, newGeometry));
  393. multiaction.doSubAction(new UpdateSegmentGeometry(segObj, segObj.attributes.geoJSONGeometry, newGeometry));
  394.  
  395. var node = W.model.nodes.objects[segObj.attributes.toNodeID];
  396. if(segObj.attributes.revDirection)
  397. node = W.model.nodes.objects[segObj.attributes.fromNodeID];
  398. var newNodeGeometry = structuredClone(node.attributes.geoJSONGeometry);
  399. newNodeGeometry.coordinates[1] += latOffset;
  400.  
  401. var connectedSegObjs = {};
  402. var emptyObj = {};
  403. for(var j=0;j<node.attributes.segIDs.length;j++){
  404. var segid = node.attributes.segIDs[j];
  405. connectedSegObjs[segid] = structuredClone(W.model.segments.getObjectById(segid).attributes.geoJSONGeometry);
  406. }
  407. //W.model.actionManager.add(new MoveNode(segObj, segObj.geometry, newNodeGeometry, connectedSegObjs, i));
  408. multiaction.doSubAction(new MoveNode(node, node.attributes.geoJSONGeometry, newNodeGeometry, connectedSegObjs, emptyObj));
  409. //W.model.actionManager.add(new MoveNode(node, node.geometry, newNodeGeometry));
  410. //totalActions +=2;
  411. }
  412. W.model.actionManager.add(multiaction);
  413. }
  414. }
  415.  
  416. function ShiftSegmentsNodesLong(segObj, longOffset){
  417. var RASegs = WazeWrap.Model.getAllRoundaboutSegmentsFromObj(segObj);
  418. if(checkAllEditable(RASegs)){
  419. var newGeometry, originalLength;
  420. var multiaction = new MultiAction();
  421. multiaction.setModel(W.model);
  422.  
  423. //Loop through all RA segments & adjust
  424. for(let i=0; i<RASegs.length; i++){
  425. segObj = W.model.segments.getObjectById(RASegs[i]);
  426. newGeometry = structuredClone(segObj.attributes.geoJSONGeometry);
  427. originalLength = segObj.attributes.geoJSONGeometry.coordinates.length;
  428. for(let j=1; j < originalLength-1; j++){
  429. newGeometry.coordinates[j][0] += longOffset;
  430. }
  431. //W.model.actionManager.add(new UpdateSegmentGeometry(segObj, segObj.geometry, newGeometry));
  432. multiaction.doSubAction(new UpdateSegmentGeometry(segObj, segObj.attributes.geoJSONGeometry, newGeometry));
  433.  
  434. var node = W.model.nodes.objects[segObj.attributes.toNodeID];
  435. if(segObj.attributes.revDirection)
  436. node = W.model.nodes.objects[segObj.attributes.fromNodeID];
  437.  
  438. var newNodeGeometry = structuredClone(node.attributes.geoJSONGeometry);
  439. newNodeGeometry.coordinates[0] += longOffset;
  440.  
  441. var connectedSegObjs = {};
  442. var emptyObj = {};
  443. for(let j=0;j<node.attributes.segIDs.length;j++){
  444. var segid = node.attributes.segIDs[j];
  445. connectedSegObjs[segid] = structuredClone(W.model.segments.getObjectById(segid).attributes.geoJSONGeometry);
  446. }
  447. //W.model.actionManager.add(new MoveNode(node, node.geometry, newNodeGeometry));
  448. multiaction.doSubAction(new MoveNode(node, node.attributes.geoJSONGeometry, newNodeGeometry, connectedSegObjs, emptyObj));
  449. //totalActions +=2;
  450. }
  451. W.model.actionManager.add(multiaction);
  452. }
  453. }
  454.  
  455. function rotatePoints(origin, points, angle){
  456. var lineFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points),null,null);
  457. lineFeature.geometry.rotate(angle, new OpenLayers.Geometry.Point(origin[0], origin[1]));
  458. return [].concat(lineFeature.geometry.components);
  459. }
  460.  
  461. function RotateRA(segObj, angle){
  462. var RASegs = WazeWrap.Model.getAllRoundaboutSegmentsFromObj(segObj);
  463. var raCenter = W.model.junctions.objects[WazeWrap.Model.getObjectModel(segObj).attributes.junctionID].attributes.geoJSONGeometry.coordinates;
  464.  
  465. if(checkAllEditable(RASegs)){
  466. var gps, newGeometry, originalLength;
  467. var multiaction = new MultiAction();
  468. multiaction.setModel(W.model);
  469.  
  470. //Loop through all RA segments & adjust
  471. for(let i=0; i<RASegs.length; i++){
  472. segObj = W.model.segments.getObjectById(RASegs[i]);
  473. newGeometry = structuredClone(segObj.attributes.geoJSONGeometry);
  474. originalLength = segObj.attributes.geoJSONGeometry.coordinates.length;
  475.  
  476. var center = raCenter; //WazeWrap.Geometry.ConvertTo900913(raCenter.x, raCenter.y);
  477. var segPoints = [];
  478. //Have to copy the points manually (can't use .clone()) otherwise the geometry rotation modifies the geometry of the segment itself and that hoses WME.
  479. for(let j=0; j<originalLength;j++)
  480. segPoints.push(new OpenLayers.Geometry.Point(segObj.attributes.geoJSONGeometry.coordinates[j][0], segObj.attributes.geoJSONGeometry.coordinates[j][1]));
  481.  
  482. var newPoints = rotatePoints(center, segPoints, angle);
  483.  
  484. for(let j=1; j<originalLength-1;j++){
  485. newGeometry.coordinates[j] = [newPoints[j].x, newPoints[j].y];
  486. }
  487.  
  488. //W.model.actionManager.add(new UpdateSegmentGeometry(segObj, segObj.geometry, newGeometry));
  489. multiaction.doSubAction(new UpdateSegmentGeometry(segObj, segObj.attributes.geoJSONGeometry, newGeometry));
  490.  
  491. //**************Rotate Nodes******************
  492. var node = W.model.nodes.objects[segObj.attributes.toNodeID];
  493. if(segObj.attributes.revDirection)
  494. node = W.model.nodes.objects[segObj.attributes.fromNodeID];
  495.  
  496. var nodePoints = [];
  497. var newNodeGeometry = structuredClone(node.attributes.geoJSONGeometry);
  498.  
  499. nodePoints.push(new OpenLayers.Geometry.Point(node.attributes.geoJSONGeometry.coordinates[0], node.attributes.geoJSONGeometry.coordinates[1]));
  500. nodePoints.push(new OpenLayers.Geometry.Point(node.attributes.geoJSONGeometry.coordinates[0], node.attributes.geoJSONGeometry.coordinates[1])); //add it twice because lines need 2 points
  501.  
  502. gps = rotatePoints(center, nodePoints, angle);
  503.  
  504. newNodeGeometry.coordinates = [gps[0].x, gps[0].y];
  505.  
  506. var connectedSegObjs = {};
  507. var emptyObj = {};
  508. for(let j=0;j<node.attributes.segIDs.length;j++){
  509. var segid = node.attributes.segIDs[j];
  510. connectedSegObjs[segid] = structuredClone(W.model.segments.getObjectById(segid).attributes.geoJSONGeometry);
  511. }
  512. multiaction.doSubAction(new MoveNode(node, node.attributes.geoJSONGeometry, newNodeGeometry, connectedSegObjs, emptyObj));
  513. //totalActions +=2;
  514. }
  515. W.model.actionManager.add(multiaction);
  516. }
  517. }
  518.  
  519. function RARotateLeftBtnClick(e){
  520. e.stopPropagation();
  521. var segObj = WazeWrap.getSelectedFeatures()[0];
  522. RotateRA(segObj, $('#rotationAmount').val());
  523. }
  524.  
  525. function RARotateRightBtnClick(e){
  526. e.stopPropagation();
  527.  
  528. var segObj = WazeWrap.getSelectedFeatures()[0];
  529. RotateRA(segObj, -$('#rotationAmount').val());
  530. }
  531.  
  532. function ChangeDiameter(segObj, amount){
  533. var RASegs = WazeWrap.Model.getAllRoundaboutSegmentsFromObj(segObj);
  534. var raCenter = W.model.junctions.objects[WazeWrap.Model.getObjectModel(segObj).attributes.junctionID].attributes.geoJSONGeometry.coordinates;
  535. let { lon: centerX, lat: centerY } = WazeWrap.Geometry.ConvertTo900913(raCenter);
  536.  
  537. if(checkAllEditable(RASegs)){
  538. var newGeometry, originalLength;
  539.  
  540. //Loop through all RA segments & adjust
  541. for(let i=0; i<RASegs.length; i++){
  542. segObj = W.model.segments.getObjectById(RASegs[i]);
  543. newGeometry = structuredClone(segObj.attributes.geoJSONGeometry);
  544. originalLength = segObj.attributes.geoJSONGeometry.coordinates.length;
  545.  
  546. for(let j=1; j < originalLength-1; j++){
  547. let pt = segObj.attributes.geoJSONGeometry.coordinates[j];
  548. let { lon: pointX, lat: pointY } = WazeWrap.Geometry.ConvertTo900913(pt);
  549. let h = Math.sqrt(Math.abs(Math.pow(pointX - centerX, 2) + Math.pow(pointY - centerY, 2)));
  550. let ratio = (h + amount)/h;
  551. let x = centerX + (pointX - centerX) * ratio;
  552. let y = centerY + (pointY - centerY) * ratio;
  553.  
  554. let { lon: newX, lat: newY } = WazeWrap.Geometry.ConvertTo4326([x, y]);
  555. newGeometry.coordinates[j] = [newX, newY];
  556. }
  557. W.model.actionManager.add(new UpdateSegmentGeometry(segObj, segObj.attributes.geoJSONGeometry, newGeometry));
  558.  
  559. var node = W.model.nodes.objects[segObj.attributes.toNodeID];
  560. if(segObj.attributes.revDirection)
  561. node = W.model.nodes.objects[segObj.attributes.fromNodeID];
  562.  
  563. var newNodeGeometry = structuredClone(node.attributes.geoJSONGeometry);
  564. let { lon: pointX, lat: pointY } = WazeWrap.Geometry.ConvertTo900913(newNodeGeometry.coordinates);
  565. let h = Math.sqrt(Math.abs(Math.pow(pointX - centerX, 2) + Math.pow(pointY - centerY, 2)));
  566. let ratio = (h + amount)/h;
  567. let x = centerX + (pointX - centerX) * ratio;
  568. let y = centerY + (pointY - centerY) * ratio;
  569.  
  570. let { lon: newX, lat: newY } = WazeWrap.Geometry.ConvertTo4326([x, y]);
  571. newNodeGeometry.coordinates = [newX, newY];
  572.  
  573. var connectedSegObjs = {};
  574. var emptyObj = {};
  575. for(let j=0;j<node.attributes.segIDs.length;j++){
  576. var segid = node.attributes.segIDs[j];
  577. connectedSegObjs[segid] = structuredClone(W.model.segments.getObjectById(segid).attributes.geoJSONGeometry);
  578. }
  579. W.model.actionManager.add(new MoveNode(node, node.attributes.geoJSONGeometry, newNodeGeometry, connectedSegObjs, emptyObj));
  580. }
  581. if(_settings.RoundaboutAngles)
  582. DrawRoundaboutAngles();
  583. }
  584. }
  585.  
  586. function diameterChangeDecreaseBtnClick(e){
  587. e.stopPropagation();
  588. var segObj = WazeWrap.getSelectedFeatures()[0];
  589. ChangeDiameter(segObj, -1);
  590. }
  591.  
  592. function diameterChangeIncreaseBtnClick(e){
  593. e.stopPropagation();
  594. var segObj = WazeWrap.getSelectedFeatures()[0];
  595. ChangeDiameter(segObj, 1);
  596. }
  597.  
  598. function moveNodeIn(sourceSegID, nodeID){
  599. let isANode = true;
  600. let curSeg = W.model.segments.getObjectById(sourceSegID);
  601. if (curSeg.attributes.geoJSONGeometry.coordinates.length > 2) {
  602. if(nodeID === curSeg.attributes.toNodeID)
  603. isANode = false;
  604. //Add geo point on the other segment
  605. let node = W.model.nodes.getObjectById(nodeID);
  606. let currNodePOS = structuredClone(node.attributes.geoJSONGeometry.coordinates);
  607. let otherSeg; //other RA segment that we are adding a geo point to
  608. let nodeSegs = [...W.model.nodes.getObjectById(nodeID).attributes.segIDs];
  609. nodeSegs = _.without(nodeSegs, sourceSegID); //remove the source segment from the node Segs - we need to find the segment that is a part of the RA that is prior to our source seg
  610. for(let i=0; i<nodeSegs.length; i++){
  611. let s = W.model.segments.getObjectById(nodeSegs[i]);
  612. if(s.attributes.junctionID){
  613. otherSeg = s;
  614. break;
  615. }
  616. }
  617.  
  618. var multiaction = new MultiAction();
  619. multiaction.setModel(W.model);
  620. //note and remove first geo point, move junction node to this point
  621. var newNodeGeometry = { type: 'Point', coordinates: structuredClone(curSeg.attributes.geoJSONGeometry.coordinates[isANode ? 1 : curSeg.attributes.geoJSONGeometry.coordinates.length - 2]) };
  622.  
  623. let newSegGeo = structuredClone(curSeg.attributes.geoJSONGeometry);
  624. newSegGeo.coordinates.splice(isANode ? 1 : newSegGeo.coordinates.length - 2, 1);
  625. multiaction.doSubAction(new UpdateSegmentGeometry(curSeg, curSeg.attributes.geoJSONGeometry, newSegGeo));
  626.  
  627. //move the node
  628. var connectedSegObjs = {};
  629. var emptyObj = {};
  630. for(var j=0;j<node.attributes.segIDs.length;j++){
  631. var segid = node.attributes.segIDs[j];
  632. connectedSegObjs[segid] = structuredClone(W.model.segments.getObjectById(segid).attributes.geoJSONGeometry);
  633. }
  634. multiaction.doSubAction(new MoveNode(node, node.attributes.geoJSONGeometry, newNodeGeometry, connectedSegObjs, emptyObj));
  635.  
  636. if((otherSeg.attributes.revDirection && !curSeg.attributes.revDirection) || (!otherSeg.attributes.revDirection && curSeg.attributes.revDirection))
  637. isANode = !isANode;
  638.  
  639. let newGeo = structuredClone(otherSeg.attributes.geoJSONGeometry);
  640. newGeo.coordinates.splice(isANode ? -1 : 1, 0, [currNodePOS[0], currNodePOS[1]]);
  641. multiaction.doSubAction(new UpdateSegmentGeometry(otherSeg, otherSeg.attributes.geoJSONGeometry, newGeo));
  642. W.model.actionManager.add(multiaction);
  643.  
  644. if(_settings.RoundaboutAngles)
  645. DrawRoundaboutAngles();
  646. }
  647. }
  648.  
  649. function moveNodeOut(sourceSegID, nodeID){
  650. let isANode = true;
  651. let curSeg = W.model.segments.getObjectById(sourceSegID);
  652. if(nodeID === curSeg.attributes.toNodeID)
  653. isANode = false;
  654. //Add geo point on the other segment
  655. let node = W.model.nodes.getObjectById(nodeID);
  656. let currNodePOS = structuredClone(node.attributes.geoJSONGeometry.coordinates);
  657. let otherSeg; //other RA segment that we are adding a geo point to
  658. let nodeSegs = [...W.model.nodes.getObjectById(nodeID).attributes.segIDs];
  659. nodeSegs = _.without(nodeSegs, sourceSegID); //remove the source segment from the node Segs - we need to find the segment that is a part of the RA that is after our source seg
  660. for(let i=0; i<nodeSegs.length; i++){
  661. let s = W.model.segments.getObjectById(nodeSegs[i]);
  662. if(s.attributes.junctionID){
  663. otherSeg = s;
  664. break;
  665. }
  666. }
  667.  
  668. if(otherSeg.attributes.geoJSONGeometry.coordinates.length > 2){
  669. let newSegGeo = structuredClone(curSeg.attributes.geoJSONGeometry);
  670. newSegGeo.coordinates.splice(isANode ? 1 : newSegGeo.coordinates.length - 1, 0, [currNodePOS[0], currNodePOS[1]]);
  671. var multiaction = new MultiAction();
  672. multiaction.setModel(W.model);
  673. multiaction.doSubAction(new UpdateSegmentGeometry(curSeg, curSeg.attributes.geoJSONGeometry, newSegGeo));
  674. if((otherSeg.attributes.revDirection && !curSeg.attributes.revDirection) || (!otherSeg.attributes.revDirection && curSeg.attributes.revDirection))
  675. isANode = !isANode;
  676.  
  677. //note and remove first geo point, move junction node to this point
  678. var newNodeGeometry = { type: 'Point', coordinates: structuredClone(otherSeg.attributes.geoJSONGeometry.coordinates[isANode ? otherSeg.attributes.geoJSONGeometry.coordinates.length - 2 : 1]) };
  679. let newGeo = structuredClone(otherSeg.attributes.geoJSONGeometry);
  680. newGeo.coordinates.splice(isANode ? -2 : 1, 1);
  681. multiaction.doSubAction(new UpdateSegmentGeometry(otherSeg, otherSeg.attributes.geoJSONGeometry, newGeo));
  682.  
  683. //move the node
  684. var connectedSegObjs = {};
  685. var emptyObj = {};
  686. for(var j=0; j < node.attributes.segIDs.length;j++){
  687. var segid = node.attributes.segIDs[j];
  688. connectedSegObjs[segid] = structuredClone(W.model.segments.getObjectById(segid).attributes.geoJSONGeometry);
  689. }
  690. multiaction.doSubAction(new MoveNode(node, node.attributes.geoJSONGeometry, newNodeGeometry, connectedSegObjs, emptyObj));
  691. W.model.actionManager.add(multiaction);
  692.  
  693. if(_settings.RoundaboutAngles)
  694. DrawRoundaboutAngles();
  695. }
  696. }
  697.  
  698. //Left
  699. function RAShiftLeftBtnClick(e){
  700. // this traps the click to prevent it falling through to the underlying area name element and potentially causing the map view to be relocated to that area...
  701. e.stopPropagation();
  702.  
  703. //if(!pendingChanges){
  704. var segObj = WazeWrap.getSelectedFeatures()[0];
  705. var convertedCoords = WazeWrap.Geometry.ConvertTo4326(segObj.geometry.components[0].x, segObj.geometry.components[0].y);
  706. var gpsOffsetAmount = WazeWrap.Geometry.CalculateLongOffsetGPS(-$('#shiftAmount').val(), convertedCoords.lon, convertedCoords.lat);
  707. ShiftSegmentsNodesLong(segObj, gpsOffsetAmount);
  708. //}
  709. }
  710. //Right
  711. function RAShiftRightBtnClick(e){
  712. // this traps the click to prevent it falling through to the underlying area name element and potentially causing the map view to be relocated to that area...
  713. e.stopPropagation();
  714.  
  715. //if(!pendingChanges){
  716. var segObj = WazeWrap.getSelectedFeatures()[0];
  717. var convertedCoords = WazeWrap.Geometry.ConvertTo4326(segObj.geometry.components[0].x, segObj.geometry.components[0].y);
  718. var gpsOffsetAmount = WazeWrap.Geometry.CalculateLongOffsetGPS($('#shiftAmount').val(), convertedCoords.lon, convertedCoords.lat);
  719. ShiftSegmentsNodesLong(segObj, gpsOffsetAmount);
  720. //}
  721. }
  722. //Up
  723. function RAShiftUpBtnClick(e){
  724. // this traps the click to prevent it falling through to the underlying area name element and potentially causing the map view to be relocated to that area...
  725. e.stopPropagation();
  726.  
  727. //if(!pendingChanges){
  728. var segObj = WazeWrap.getSelectedFeatures()[0];
  729. var gpsOffsetAmount = WazeWrap.Geometry.CalculateLatOffsetGPS($('#shiftAmount').val(), WazeWrap.Geometry.ConvertTo4326(segObj.geometry.components[0].x, segObj.geometry.components[0].y));
  730. ShiftSegmentNodesLat(segObj, gpsOffsetAmount);
  731. //}
  732. }
  733. //Down
  734. function RAShiftDownBtnClick(e){
  735. // this traps the click to prevent it falling through to the underlying area name element and potentially causing the map view to be relocated to that area...
  736. e.stopPropagation();
  737.  
  738. //if(!pendingChanges){
  739. var segObj = WazeWrap.getSelectedFeatures()[0];
  740. var gpsOffsetAmount = WazeWrap.Geometry.CalculateLatOffsetGPS(-$('#shiftAmount').val(), WazeWrap.Geometry.ConvertTo4326(segObj.geometry.components[0].x, segObj.geometry.components[0].y));
  741. ShiftSegmentNodesLat(segObj, gpsOffsetAmount);
  742. //}
  743. }
  744.  
  745. //*************** Roundabout Angles **********************
  746. function DrawRoundaboutAngles(){
  747. //---------get or create layer
  748. var layers = W.map.getLayersBy("uniqueName","__DrawRoundaboutAngles");
  749.  
  750. if(layers.length > 0)
  751. drc_layer = layers[0];
  752. else {
  753. var drc_style = new OpenLayers.Style({
  754. fillOpacity: 0.0,
  755. strokeOpacity: 1.0,
  756. fillColor: "#FF40C0",
  757. strokeColor: "${strokeColor}",
  758. strokeWidth: 10,
  759. fontWeight: "bold",
  760. pointRadius: 0,
  761. label : "${labelText}",
  762. fontFamily: "Tahoma, Courier New",
  763. labelOutlineColor: "#FFFFFF",
  764. labelOutlineWidth: 3,
  765. fontColor: "${labelColor}",
  766. fontSize: "10px"
  767. });
  768.  
  769. drc_layer = new OpenLayers.Layer.Vector("Roundabout Angles", {
  770. displayInLayerSwitcher: true,
  771. uniqueName: "__DrawRoundaboutAngles",
  772. styleMap: new OpenLayers.StyleMap(drc_style)
  773. });
  774.  
  775. I18n.translations[I18n.currentLocale()].layers.name["__DrawRoundaboutAngles"] = "Roundabout Angles";
  776. W.map.addLayer(drc_layer);
  777.  
  778. drc_layer.setVisibility(true);
  779. }
  780.  
  781. localStorage.WMERAEnabled = drc_layer.visibility;
  782.  
  783. if (drc_layer.visibility == false) {
  784. drc_layer.removeAllFeatures();
  785. return;
  786. }
  787.  
  788. if (W.map.getZoom() < 1) {
  789. drc_layer.removeAllFeatures();
  790. return;
  791. }
  792.  
  793. //---------collect all roundabouts first
  794. var rsegments = {};
  795.  
  796. for (var iseg in W.model.segments.objects) {
  797. let isegment = W.model.segments.getObjectById(iseg);
  798. var iattributes = isegment.attributes;
  799. var iline = isegment.getOLGeometry().id;
  800.  
  801. let irid = iattributes.junctionID;
  802.  
  803. if (iline !== null && irid != undefined) {
  804. var rsegs = rsegments[irid];
  805. if (rsegs == undefined)
  806. rsegments[irid] = rsegs = new Array();
  807. rsegs.push(isegment);
  808. }
  809. }
  810.  
  811. var drc_features = [];
  812.  
  813. //-------for each roundabout do...
  814. for (let irid in rsegments) {
  815. let rsegs = rsegments[irid];
  816.  
  817. let isegment = rsegs[0];
  818.  
  819. var nodes = [];
  820. var nodes_x = [];
  821. var nodes_y = [];
  822.  
  823. nodes = rsegs.map(seg => seg.attributes.fromNodeID); //get from nodes
  824. nodes = [...nodes, ...rsegs.map(seg => seg.attributes.toNodeID)]; //get to nodes add to from nodes
  825. nodes = _.uniq(nodes); //remove duplicates
  826.  
  827. var node_objects = W.model.nodes.getByIds(nodes);
  828. nodes_x = node_objects.map(n => n.getOLGeometry().x); //get all x locations
  829. nodes_y = node_objects.map(n => n.getOLGeometry().y); //get all y locations
  830.  
  831. var sr_x = 0;
  832. var sr_y = 0;
  833. var radius = 0;
  834. var numNodes = nodes_x.length;
  835.  
  836. if (numNodes >= 1) {
  837. var ax = nodes_x[0];
  838. var ay = nodes_y[0];
  839.  
  840. var junction = W.model.junctions.getObjectById(irid);
  841. var junction_coords = junction && junction.getOLGeometry() && junction.getOLGeometry().coordinates;
  842.  
  843. if (junction_coords && junction_coords.length == 2) {
  844. //---------- get center point from junction model
  845. let lonlat = new OpenLayers.LonLat(junction_coords[0], junction_coords[1]);
  846. lonlat.transform(W.Config.map.projection.remote, W.Config.map.projection.local);
  847. let pt = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
  848. sr_x = pt.x;
  849. sr_y = pt.y;
  850. }
  851. else if (numNodes >= 3) {
  852. //-----------simple approximation of centre point calculated from three first points
  853. let bx = nodes_x[1];
  854. let by = nodes_y[1];
  855. let cx = nodes_x[2];
  856. let cy = nodes_y[2];
  857.  
  858. let x1 = (bx + ax) * 0.5;
  859. let y11 = (by + ay) * 0.5;
  860. let dy1 = bx - ax;
  861. let dx1 = -(by - ay);
  862. let x2 = (cx + bx) * 0.5;
  863. let y2 = (cy + by) * 0.5;
  864. let dy2 = cx - bx;
  865. let dx2 = -(cy - by);
  866. sr_x = (y11 * dx1 * dx2 + x2 * dx1 * dy2 - x1 * dy1 * dx2 - y2 * dx1 * dx2)/ (dx1 * dy2 - dy1 * dx2);
  867. sr_y = (sr_x - x1) * dy1 / dx1 + y11;
  868. }
  869. else {
  870. //---------- simple bounds-based calculation of center point
  871. var rbounds = new OpenLayers.Bounds();
  872. rbounds.extend(isegment.getOLGeometry().bounds);
  873.  
  874. var center = rbounds.getCenterPixel();
  875. sr_x = center.x;
  876. sr_y = center.y;
  877. }
  878.  
  879. var angles = [];
  880. var rr = -1;
  881. var r_ix;
  882.  
  883. for(let i=0; i<nodes_x.length; i++) {
  884.  
  885. var dx = nodes_x[i] - sr_x;
  886. var dy = nodes_y[i] - sr_y;
  887.  
  888. var rr2 = dx*dx + dy*dy;
  889. if (rr < rr2) {
  890. rr = rr2;
  891. r_ix = i;
  892. }
  893.  
  894. var angle = Math.atan2(dy, dx);
  895. angle = (360.0 + (angle * 180.0 / Math.PI));
  896. if (angle < 0.0) angle += 360.0;
  897. if (angle > 360.0) angle -= 360.0;
  898. angles.push(angle);
  899. }
  900.  
  901. radius = Math.sqrt(rr);
  902.  
  903. //---------sorting angles for calulating angle difference between two segments
  904. angles = angles.sort(function(a,b) { return a - b; });
  905. angles.push( angles[0] + 360.0);
  906. angles = angles.sort(function(a,b) { return a - b; });
  907.  
  908. var drc_color = (numNodes <= 4) ? "#0040FF" : "#002080";
  909.  
  910. var drc_point = new OpenLayers.Geometry.Point(sr_x, sr_y );
  911. var drc_circle = new OpenLayers.Geometry.Polygon.createRegularPolygon( drc_point, radius, 10 * W.map.getZoom() );
  912. var drc_feature = new OpenLayers.Feature.Vector(drc_circle, {labelText: "", labelColor: "#000000", strokeColor: drc_color, });
  913. drc_features.push(drc_feature);
  914.  
  915.  
  916. if (numNodes >= 2 && numNodes <= 4 && W.map.getZoom() >= 5) {
  917. for(let i=0; i<nodes_x.length; i++) {
  918. let ix = nodes_x[i];
  919. let iy = nodes_y[i];
  920. let startPt = new OpenLayers.Geometry.Point( sr_x, sr_y );
  921. let endPt = new OpenLayers.Geometry.Point( ix, iy );
  922. let line = new OpenLayers.Geometry.LineString([startPt, endPt]);
  923. let style = {strokeColor:drc_color, strokeWidth:2};
  924. let fea = new OpenLayers.Feature.Vector(line, {}, style);
  925. drc_features.push(fea);
  926. }
  927.  
  928. var angles_int = [];
  929. var angles_float = [];
  930. var angles_sum = 0;
  931.  
  932. for(let i=0; i<angles.length - 1; i++) {
  933.  
  934. var ang = angles[i+1] - angles[i+0];
  935. if (ang < 0) ang += 360.0;
  936. if (ang < 0) ang += 360.0;
  937.  
  938. if (ang < 135.0)
  939. ang = ang - 90.0;
  940. else
  941. ang = ang - 180.0;
  942.  
  943. angles_sum += parseInt(ang);
  944.  
  945. angles_float.push( ang );
  946. angles_int.push( parseInt(ang) );
  947. }
  948.  
  949. if (angles_sum > 45) angles_sum -= 90;
  950. if (angles_sum > 45) angles_sum -= 90;
  951. if (angles_sum > 45) angles_sum -= 90;
  952. if (angles_sum > 45) angles_sum -= 90;
  953. if (angles_sum < -45) angles_sum += 90;
  954. if (angles_sum < -45) angles_sum += 90;
  955. if (angles_sum < -45) angles_sum += 90;
  956. if (angles_sum < -45) angles_sum += 90;
  957. if (angles_sum != 0) {
  958. for(let i=0; i<angles_int.length; i++) {
  959. let a = angles_int[i];
  960. let af = angles_float[i] - angles_int[i];
  961. if ( (a < 10 || a > 20) && (af < -0.5 || af > 0.5)){
  962. angles_int[i] += -angles_sum;
  963.  
  964. break;
  965. }
  966. }
  967. }
  968.  
  969. if (numNodes == 2) {
  970. angles_int[1] = -angles_int[0];
  971. angles_float[1] = -angles_float[0];
  972. }
  973.  
  974. for(let i=0; i<angles.length - 1; i++) {
  975. let arad = (angles[i+0] + angles[i+1]) * 0.5 * Math.PI / 180.0;
  976. let ex = sr_x + Math.cos (arad) * radius * 0.5;
  977. let ey = sr_y + Math.sin (arad) * radius * 0.5;
  978.  
  979. //*** Angle Display Rounding ***
  980. let angint = Math.round(angles_float[i] * 100)/100;
  981.  
  982. let kolor = "#004000";
  983. if (angint <= -15 || angint >= 15) kolor = "#FF0000";
  984. else if (angint <= -13 || angint >= 13) kolor = "#FFC000";
  985.  
  986. let pt = new OpenLayers.Geometry.Point(ex, ey);
  987. drc_features.push(new OpenLayers.Feature.Vector( pt, {labelText: (angint + "°"), labelColor: kolor } ));
  988. //drc_features.push(new OpenLayers.Feature.Vector( pt, {labelText: (+angles_float[i].toFixed(2) + "°"), labelColor: kolor } ));
  989. }
  990. }
  991. else {
  992. for(let i=0; i < nodes_x.length; i++) {
  993. let ix = nodes_x[i];
  994. let iy = nodes_y[i];
  995. let startPt = new OpenLayers.Geometry.Point( sr_x, sr_y );
  996. let endPt = new OpenLayers.Geometry.Point( ix, iy );
  997. let line = new OpenLayers.Geometry.LineString([startPt, endPt]);
  998. let style = {strokeColor:drc_color, strokeWidth:2};
  999. let fea = new OpenLayers.Feature.Vector(line, {}, style);
  1000. drc_features.push(fea);
  1001. }
  1002. }
  1003.  
  1004. let p1 = new OpenLayers.Geometry.Point( nodes_x[r_ix], nodes_y[r_ix] );
  1005. let p2 = new OpenLayers.Geometry.Point( sr_x, sr_y );
  1006. let line = new OpenLayers.Geometry.LineString([p1, p2]);
  1007. let geo_radius = line.getGeodesicLength(W.map.getProjectionObject());
  1008.  
  1009. let diam = geo_radius * 2.0;
  1010. let pt = new OpenLayers.Geometry.Point(sr_x, sr_y);
  1011. drc_features.push(new OpenLayers.Feature.Vector( pt, {labelText: (diam.toFixed(0) + "m"), labelColor: "#000000" } ));
  1012.  
  1013. }
  1014.  
  1015. }
  1016.  
  1017. drc_layer.removeAllFeatures();
  1018. drc_layer.addFeatures(drc_features);
  1019. }
  1020.  
  1021. function injectCss() {
  1022. var css = [
  1023. '.btnMoveNode {width=25px; height=25px; background-color:#92C3D3; cursor:pointer; padding:5px; font-size:14px; border:thin outset black; border-style:solid; border-width: 1px;border-radius:50%; -moz-border-radius:50%; -webkit-border-radius:50%; box-shadow:inset 0px 0px 20px -14px rgba(0,0,0,1); -moz-box-shadow:inset 0px 0px 20px -14px rgba(0,0,0,1); -webkit-box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);}',
  1024. '.btnRotate { width=45px; height=45px; background-color:#92C3D3; cursor:pointer; padding: 5px; font-size:14px; border:thin outset black; border-style:solid; border-width: 1px;border-radius: 50%;-moz-border-radius: 50%;-webkit-border-radius: 50%;box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);-moz-box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);-webkit-box-shadow: inset 0px 0px 20px -14px rgba(0,0,0,1);}'
  1025. ].join(' ');
  1026. $('<style type="text/css">' + css + '</style>').appendTo('head');
  1027. }
  1028.  
  1029. })();
  1030.