WME Route Speeds (MapOMatic fork)

Shows segment speeds in a route.

2023/03/17のページです。最新版はこちら。

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name WME Route Speeds (MapOMatic fork)
  3. // @description Shows segment speeds in a route.
  4. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  5. // @version 2023.03.17.002
  6. // @grant none
  7. // @namespace https://greasyfork.org/en/scripts/369630-wme-route-speeds-mapomatic-fork
  8. // @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
  9. // @author wlodek76 (forked by MapOMatic)
  10. // @copyright 2014, 2015 wlodek76
  11. // @contributor 2014, 2015 FZ69617
  12. // ==/UserScript==
  13.  
  14. /* global W */
  15. /* global OpenLayers */
  16.  
  17. /* eslint-disable */
  18. /*Version history:
  19. * 2020.09.10.001
  20. - Updating viewPortDiv references and minor code cleanup
  21. * 2020.07.27.001
  22. - WME map object references.
  23. * 2020.05.22.001
  24. - Change OL to OpenLayers.
  25. * 2019.12.11.001
  26. - Minor update to fix bug for WazeWrap not being ready before full init.
  27. * 2019.11.21.001
  28. - Minor update to support change in WME v2.43-40-gf367bffa4
  29. * 2019.10.30.001
  30. * - Minor update to support change to WazeWrap registration of events in W.map.
  31. * 2019.07.25.001
  32. * - Minor update to support change from W.model.countries.top to W.model.getTopCountry()
  33. * 2019.03.05.001
  34. * - New: support for vehicle types
  35. * - New: pass/permit support
  36. * - Remove shortest route option- no longer supported by routing server
  37. * - Include server support for Puerto Rico
  38. *
  39. * 2017.12.09.001 (20171209)
  40. * - New: Added Avoid Ferries option (tonestertm)
  41. * Fixed longstanding bug which never allowed U-turns
  42. *
  43. * 2017.11.15.001 (20171115)
  44. * - New: Added Avoid Difficult Turns option (tonestertm)
  45. * - New: Added a checkbox and functionality to place results in Livemap's natural sort order, to help with troubleshooting around penalties.
  46. * Note that when Routing Order is checked, the Try More option is ignored, to better approximate Livemap results (tonestertm)
  47. *
  48. * 2017.11.10.001 (20171011)
  49. * - Changing to use WazeWrap.Interface.Tab to load the Route Speeds tab so it can recover from changing the map units (Imperial/Metric)
  50. * and coming back from event mode
  51. *
  52. * 1.4.8-momfork (20170123)
  53. * - Updated formatting in options panel to fix checkbox alignment issues.
  54. *
  55. * 1.4.7-momfork (20170118)
  56. * - [FIXED] International translations set to english by default. Causing critical failures.
  57. *
  58. * 1.4.6-momfork (20170104)
  59. * - Restored original marker functionality (*HUGE* thanks to JustinS83 for doing ALL the work to figure out a workaround).
  60. *
  61. * 1.4.5-momfork (20161228)
  62. * - Fixed @include so script will work in WME Beta again.
  63. *
  64. * 1.4.4-momfork (20161228)
  65. * - This is a temporary fix to restore some basic functionality. The original script may work again if Waze
  66. * devs fix an issue on their end. Had to remove markers for now.
  67. *
  68. *
  69. * 1.4.3 (20150505)
  70. * - script didn't work when only WME Route Speeds was installed (removed unnecessary unsafeWindow definition)
  71. *
  72. * 1.4.2 (20150424)
  73. * - Added: Paste LiveMap permalink into A/B marker input.
  74. * - Improved: 'Reset to Livemap Route' did not reset correctly when Shortest route was selected.
  75. * - Fixed: Layout of A-B button accordingly to browser's size.
  76. * - Fixed: Translation of internal AVOID_TRAILS option to Dirt roads.
  77. *
  78. * 1.4.1.1 (20150424)
  79. * - Improvement: Fixed options styling minor issues.
  80. * - Minor Fix: Drawing two-way traffic on segments with sharp angle
  81. *
  82. * 1.4.0 (20150424)
  83. * - New: Displaying traffic on two-way segments
  84. * - Improved: Faster display of recalculated routes
  85. * - Improved: First route is selected always by default
  86. * - Gui: Reorganize of options
  87. * - Fixed: Waiting for WME initialization
  88. * - Added: Option for ALLOW_UTURNS
  89. *
  90. * 1.3.0 (20150421)
  91. * - Fix: ALLOW UTURNS in routes
  92. *
  93. * 1.2.9.1 (20150419)
  94. * - Fix: Road Closures icons hides Route Speeds speed/time info
  95. *
  96. * 1.2.9 (20150114)
  97. * - New: Centering the map on the A/B markers.
  98. * - New: Routing options reset to the Livemap Route equivalents.
  99. * - New: Experimental "Fastest (no history)" route type option.
  100. *
  101. * 1.2.8.1 (20150102)
  102. * - Bug fix: Routing request options fixed.
  103. *
  104. * 1.2.8 (20150101)
  105. * - New: Added "Route type" routing option.
  106. * - New: Added "Try more" alternative routes option.
  107. * - Change: Controls' styling.
  108. * - Improvement: Route list sorting.
  109. * - Improvement: Route list selection can now be toggled.
  110. * - Improvement: Better handling of route request errors.
  111. * - Other: Minor code changes.
  112. *
  113. * 1.2.7.1 (20141211)
  114. * - Bug fix: Routing request options corrected.
  115. *
  116. * 1.2.7 (20141210)
  117. * - New: Added "Avoid toll roads" routing option.
  118. * - New: Added "Avoid freeways" routing option.
  119. * - New: Added "Allow dirt roads" routing option.
  120. * - Other: Minor code improvements.
  121. *
  122. * 1.2.6.1 (20141001)
  123. * - Fix for new WME by tkr85.
  124. */
  125.  
  126. (function () {
  127. "use strict";
  128.  
  129. const SCRIPT_STORE = 'wme_routespeeds';
  130. const DEFAULT_SETTINGS = {
  131. passes: []
  132. }
  133.  
  134. let _settings;
  135. let _modelPasses = [];
  136.  
  137. var wmech_version = GM_info.script.version;
  138.  
  139. var epsg900913 = new OpenLayers.Projection("EPSG:900913");
  140. var epsg4326 = new OpenLayers.Projection("EPSG:4326");
  141.  
  142. var selected = 0;
  143. var routewsp1 = [];
  144. var routewsp2 = [];
  145. var routewsp3 = [];
  146. var routewsp4 = [];
  147. var routewsp5 = [];
  148. var routeodc1 = [];
  149. var routeodc2 = [];
  150. var routeodc3 = [];
  151. var routeodc4 = [];
  152. var routeodc5 = [];
  153.  
  154. var routewait = 0;
  155. var routeSelected = 1;
  156. var routeSelectedLast = 0;
  157.  
  158. var markerA;
  159. var markerB;
  160. var markerA_offset_click = [0, 0];
  161. var markerB_offset_click = [0, 0];
  162.  
  163. var routespeedsoption1 = false;
  164. var routespeedsoption2 = false;
  165. var routespeedsoption3 = false;
  166. var routespeedsoption4 = false;
  167. var routespeedsoption5 = false;
  168. var routespeedsoption6 = 3;
  169. var routespeedsoption7 = true;
  170. var routespeedsoption8 = false;
  171. var routespeedsoption9 = false;
  172. var routespeedsoption10 = false;
  173. var routespeedsoption11 = false;
  174. var routespeedsoption12 = false;
  175. var routespeedsoption13 = 1;
  176. var routespeedsoption14 = true;
  177. var routespeedsoption15 = false;
  178. var routespeedsoption16 = false;
  179. var routespeedsoption17 = false;
  180. var routespeedsoption18 = 'PRIVATE';
  181.  
  182. var lastmapcenter = [0, 0];
  183. var panningX = 0;
  184. var panningY = 0;
  185. var acceleration = 1.6;
  186. var accelerationmin = 10;
  187. var accelerationmax = 200;
  188. var accelerationmargin = 30;
  189. var accelerationbackstop = 3;
  190.  
  191. var koloractive = [
  192. "#808080", // 0 km/h
  193. "#271308", // 10 km/h
  194. "#813b27", // 20 km/h
  195. "#e22700", // 30 km/h
  196. "#ef7200", // 40 km/h
  197. "#ffd307", // 50 km/h
  198. "#6cf104", // 60 km/h
  199. "#2fa035", // 70 km/h
  200. "#0bbbe9", // 80 km/h
  201. "#0f77e0", // 90 km/h
  202. "#0346fc", // 100 km/h
  203. "#3918d7", // 110 km/h
  204. "#8c07f7", // 120 km/h
  205. "#ea0ae7", // 130 km/h
  206. "#b00094", // 140 km/h
  207. "#670055" // 200 km/h
  208. ];
  209.  
  210. var jqueryinfo = 0;
  211. var tabswitched = 0;
  212. var closurelayer = null;
  213. var closurelayerZINDEX = [];
  214. var leftHand = false;
  215.  
  216. function log(msg) {
  217. console.log('WME Route Speeds:', msg);
  218. }
  219. //------------------------------------------------------------------------------------------------
  220. async function bootstrapWMERouteSpeeds(tries = 1) {
  221. // Need to wait for countries to load, otherwise restrictionSubscriptions are not available yet.
  222. if (W && W.loginManager && W.map && W.loginManager.user && W.model && W.model.countries.getObjectArray().length && WazeWrap.Ready) {
  223. log('Initializing...');
  224. await initialiseWMERouteSpeeds();
  225. log(wmech_version + " loaded.");
  226. } else {
  227. if (tries === 100) {
  228. log('Bootstrap timeout. Script has failed to load.');
  229. return;
  230. } else if (tries % 10 === 0) {
  231. log('Bootstrap failed. Trying again...');
  232. }
  233. setTimeout(() => bootstrapWMERouteSpeeds(++tries), 300);
  234. }
  235. }
  236. //------------------------------------------------------------------------------------------------
  237. function panningWMERouteSpeeds() {
  238. var WM = window.W.map;
  239.  
  240. //var operationPending = W.vent._events.listeners.operationPending[0];
  241. //if (operationPending == undefined) return;
  242. //var pending = operationPending.obj.pending[0];
  243.  
  244. //var lastcenterX = lastmapcenter[0];
  245. //var lastcenterY = lastmapcenter[1];
  246. //var centerX = WM.getCenter().lon;
  247. //var centerY = WM.getCenter().lat;
  248.  
  249. //if (lastcenterX == 0) lastcenterX = centerX;
  250. //if (lastcenterY == 0) lastcenterY = centerY;
  251.  
  252. //if ( lastcenterX==centerX && lastcenterY==centerY && pending == undefined ) {
  253. if (panningX || panningY) {
  254. var accelX = panningX;
  255. var accelY = panningY;
  256.  
  257. if (accelX < 0) accelX = -Math.pow(Math.abs(accelX), acceleration) - accelerationmin;
  258. if (accelX > 0) accelX = Math.pow(Math.abs(accelX), acceleration) + accelerationmin;
  259.  
  260. if (accelY < 0) accelY = -Math.pow(Math.abs(accelY), acceleration) - accelerationmin;
  261. if (accelY > 0) accelY = Math.pow(Math.abs(accelY), acceleration) + accelerationmin;
  262.  
  263. if (accelX < -accelerationmax) accelX = -accelerationmax;
  264. if (accelY < -accelerationmax) accelY = -accelerationmax;
  265. if (accelX > accelerationmax) accelX = accelerationmax;
  266. if (accelY > accelerationmax) accelY = accelerationmax;
  267.  
  268. WM.pan(accelX, accelY);
  269. }
  270. //}
  271. }
  272. //------------------------------------------------------------------------------------------------
  273. function saveRouteSpeedsOptions() {
  274.  
  275. var obj1 = getId('routespeeds-option1');
  276. var obj2 = getId('routespeeds-option2');
  277. var obj3 = getId('routespeeds-option3');
  278. var obj4 = getId('routespeeds-option4');
  279. var obj5 = getId('routespeeds-option5');
  280. var obj6 = getId('routespeeds-option6');
  281. var obj7 = getId('routespeeds-option7');
  282. var obj8 = getId('routespeeds-option8');
  283. var obj9 = getId('routespeeds-option9');
  284. var obj10 = getId('routespeeds-option10');
  285. var obj11 = getId('routespeeds-option11');
  286. var obj12 = getId('routespeeds-option12');
  287. var obj13 = getId('routespeeds-option13');
  288. var obj14 = getId('routespeeds-option14');
  289. var obj15 = getId('routespeeds-option15');
  290. var obj16 = getId('routespeeds-option16');
  291. var obj17 = getId('routespeeds-option17');
  292. var obj18 = getId('routespeeds-option18');
  293.  
  294. if (obj1 !== undefined) {
  295. localStorage.setItem("RouteSpeedsOption1", obj1.checked);
  296. localStorage.setItem("RouteSpeedsOption2", obj2.checked);
  297. localStorage.setItem("RouteSpeedsOption3", obj3.checked);
  298. localStorage.setItem("RouteSpeedsOption4", obj4.checked);
  299. localStorage.setItem("RouteSpeedsOption5", obj5.checked);
  300. localStorage.setItem("RouteSpeedsOption6", obj6.value);
  301. localStorage.setItem("RouteSpeedsOption7", obj7.checked);
  302. localStorage.setItem("RouteSpeedsOption8", obj8.checked);
  303. localStorage.setItem("RouteSpeedsOption9", obj9.checked);
  304. localStorage.setItem("RouteSpeedsOption10", obj10.checked);
  305. localStorage.setItem("RouteSpeedsOption11", obj11.checked);
  306. localStorage.setItem("RouteSpeedsOption12", obj12.checked);
  307. localStorage.setItem("RouteSpeedsOption13", obj13.value);
  308. localStorage.setItem("RouteSpeedsOption14", true); // ALLOW_UTURNS is by default always true
  309. localStorage.setItem("RouteSpeedsOption15", obj15.checked);
  310. localStorage.setItem("RouteSpeedsOption16", obj16.checked);
  311. localStorage.setItem("RouteSpeedsOption17", obj17.checked);
  312. localStorage.setItem("RouteSpeedsOption18", obj18.value);
  313. }
  314.  
  315. localStorage.setItem(SCRIPT_STORE, JSON.stringify(_settings));
  316. }
  317. //---------------------------------------------------------------------------------------
  318. function loadRouteSpeedsOptions() {
  319.  
  320. if (localStorage.RouteSpeedsOption1) routespeedsoption1 = (localStorage.RouteSpeedsOption1 == "true");
  321. if (localStorage.RouteSpeedsOption2) routespeedsoption2 = (localStorage.RouteSpeedsOption2 == "true");
  322. if (localStorage.RouteSpeedsOption3) routespeedsoption3 = (localStorage.RouteSpeedsOption3 == "true");
  323. if (localStorage.RouteSpeedsOption4) routespeedsoption4 = (localStorage.RouteSpeedsOption4 == "true");
  324. if (localStorage.RouteSpeedsOption5) routespeedsoption5 = (localStorage.RouteSpeedsOption5 == "true");
  325. if (localStorage.RouteSpeedsOption6) routespeedsoption6 = (localStorage.RouteSpeedsOption6);
  326. if (localStorage.RouteSpeedsOption7) routespeedsoption7 = (localStorage.RouteSpeedsOption7 == "true");
  327. if (localStorage.RouteSpeedsOption8) routespeedsoption8 = (localStorage.RouteSpeedsOption8 == "true");
  328. if (localStorage.RouteSpeedsOption9) routespeedsoption9 = (localStorage.RouteSpeedsOption9 == "true");
  329. if (localStorage.RouteSpeedsOption10) routespeedsoption10 = (localStorage.RouteSpeedsOption10 == "true");
  330. if (localStorage.RouteSpeedsOption11) routespeedsoption11 = (localStorage.RouteSpeedsOption11 == "true");
  331. if (localStorage.RouteSpeedsOption12) routespeedsoption12 = (localStorage.RouteSpeedsOption12 == "true");
  332. if (localStorage.RouteSpeedsOption13) routespeedsoption13 = (localStorage.RouteSpeedsOption13);
  333. if (localStorage.RouteSpeedsOption14) routespeedsoption14 = (localStorage.RouteSpeedsOption14 == "true");
  334. if (localStorage.RouteSpeedsOption15) routespeedsoption15 = (localStorage.RouteSpeedsOption15 == "true");
  335. if (localStorage.RouteSpeedsOption16) routespeedsoption16 = (localStorage.RouteSpeedsOption16 == "true");
  336. if (localStorage.RouteSpeedsOption17) routespeedsoption17 = (localStorage.RouteSpeedsOption17 == "true");
  337. if (localStorage.RouteSpeedsOption18) routespeedsoption18 = (localStorage.RouteSpeedsOption18);
  338.  
  339.  
  340. getId('routespeeds-option1').checked = routespeedsoption1;
  341. getId('routespeeds-option2').checked = routespeedsoption2;
  342. getId('routespeeds-option3').checked = routespeedsoption3;
  343. getId('routespeeds-option4').checked = routespeedsoption4;
  344. getId('routespeeds-option5').checked = routespeedsoption5;
  345. getId('routespeeds-option6').value = routespeedsoption6;
  346. getId('routespeeds-option7').checked = routespeedsoption7;
  347. getId('routespeeds-option8').checked = routespeedsoption8;
  348. getId('routespeeds-option9').checked = routespeedsoption9;
  349. getId('routespeeds-option10').checked = routespeedsoption10;
  350. getId('routespeeds-option11').checked = routespeedsoption11;
  351. getId('routespeeds-option12').checked = routespeedsoption12;
  352. getId('routespeeds-option13').value = routespeedsoption13;
  353. getId('routespeeds-option14').checked = routespeedsoption14;
  354. getId('routespeeds-option15').checked = routespeedsoption15;
  355. getId('routespeeds-option16').checked = routespeedsoption16;
  356. getId('routespeeds-option17').checked = routespeedsoption17;
  357. getId('routespeeds-option18').value = routespeedsoption18;
  358.  
  359. // Create the global object where settings will be stored in memory.
  360. _settings = $.parseJSON(localStorage.getItem(SCRIPT_STORE)) || {};
  361.  
  362. // Fill in any missing settings from the DEFAULT_SETTINGS object
  363. for (let prop in DEFAULT_SETTINGS) {
  364. if (!_settings.hasOwnProperty(prop)) {
  365. _settings[prop] = DEFAULT_SETTINGS[prop];
  366. }
  367. }
  368.  
  369. update_adv_switches();
  370. }
  371. //---------------------------------------------------------------------------------------
  372. function update_adv_switches() {
  373.  
  374. getId('routespeeds-option5-span').style.display = routespeedsoption5 ? 'inline' : 'none';
  375. // getId('routespeeds-option5-span').style.display = routespeedsoption15 ? 'none' : 'inline'; // FIXIT
  376. getId('routespeeds-option10-span').style.display = routespeedsoption10 ? 'inline' : 'inline';
  377. }
  378. //---------------------------------------------------------------------------------------
  379. function getRoutingManager() {
  380. if (W.model.countries.getObjectById(235) || W.model.countries.getObjectById(40) || W.model.countries.getObjectById(182)) { // US, Canada, & PR
  381. return '/RoutingManager/routingRequest';
  382. } else if (W.model.countries.getObjectById(106)) { // Israel
  383. return '/il-RoutingManager/routingRequest';
  384. } else {
  385. return '/row-RoutingManager/routingRequest'; // ROW
  386. }
  387. }
  388. //------------------------------------------------------------------------------------------------
  389. function getSegmentMidPoint(seg, end) {
  390.  
  391. var points, p1, p2, dx, dy, x, y;
  392. points = seg.geometry.components.length;
  393.  
  394. if (points == 2) {
  395. p1 = seg.geometry.components[0];
  396. p2 = seg.geometry.components[1];
  397.  
  398. x = p1.x + (p2.x - p1.x) * 0.5;
  399. y = p1.y + (p2.y - p1.y) * 0.5;
  400. return OpenLayers.Layer.SphericalMercator.inverseMercator(x, y);
  401. }
  402.  
  403. var length = 0;
  404. for (var i = 0; i < points - 1; i++) {
  405. p1 = seg.geometry.components[i + 0];
  406. p2 = seg.geometry.components[i + 1];
  407. dx = p2.x - p1.x;
  408. dy = p2.y - p1.y;
  409. length += Math.sqrt(dx * dx + dy * dy);
  410. }
  411. var midlen = length / 2.0;
  412.  
  413. var length1 = 0;
  414. var length2 = 0;
  415. for (i = 0; i < points - 1; i++) {
  416. p1 = seg.geometry.components[i + 0];
  417. p2 = seg.geometry.components[i + 1];
  418. dx = p2.x - p1.x;
  419. dy = p2.y - p1.y;
  420. length1 = length2;
  421. length2 = length2 + Math.sqrt(dx * dx + dy * dy);
  422.  
  423. if (midlen >= length1 && midlen < length2) {
  424. var proc = (midlen - length1) / (length2 - length1);
  425. x = p1.x + (p2.x - p1.x) * proc;
  426. y = p1.y + (p2.y - p1.y) * proc;
  427. return OpenLayers.Layer.SphericalMercator.inverseMercator(x, y);
  428. }
  429. }
  430.  
  431. if (end === 0) {
  432. p1 = seg.geometry.components[0];
  433. p2 = seg.geometry.components[1];
  434. }
  435. else {
  436. p1 = seg.geometry.components[points - 2];
  437. p2 = seg.geometry.components[points - 1];
  438. }
  439.  
  440. x = p1.x + (p2.x - p1.x) * 0.5;
  441. y = p1.y + (p2.y - p1.y) * 0.5;
  442. return OpenLayers.Layer.SphericalMercator.inverseMercator(x, y);
  443. }
  444. //------------------------------------------------------------------------------------------------
  445. function getColor(speed) {
  446. if (speed === 0) return koloractive[0];
  447. var k = parseInt(speed / 10.0) + 1;
  448. if (k > 15) k = 15;
  449. return koloractive[k];
  450. }
  451. //-----------------------------------------------------------------------------------------------
  452. function updatePassesLabel() {
  453. let count = _modelPasses.filter(pass => _settings.passes.indexOf(pass.key) > -1).length;
  454. $('#routespeeds-passes-label').text(`Passes & Permits (${count} of ${_modelPasses.length})`);
  455. }
  456. //------------------------------------------------------------------------------------------------
  457. function addLabel(lines, speedtekst, routespeedsoption2, odctime, odclen, routespeedsoption4, id) {
  458.  
  459. var speed = parseInt(speedtekst);
  460.  
  461. var kolor1 = '#F0F0F0';
  462. var kolor2 = '#000000';
  463. var p1, p2, pt, textFeature, k, sx, sy;
  464. if (speed >= 40 && speed < 50) { kolor1 = '#404040'; kolor2 = '#FFFFFF'; }
  465. if (speed >= 50 && speed < 60) { kolor1 = '#404040'; kolor2 = '#FFFFFF'; }
  466.  
  467. if (routespeedsoption4) speedtekst = parseInt(speedtekst / 1.609 + 0.5);
  468. if (speedtekst === 0) speedtekst = "?";
  469.  
  470. var numlines = lines.length;
  471. if (numlines >= 2) {
  472. var line;
  473. var ps = parseInt(numlines) >> 1;
  474. p1 = lines[ps].components[0];
  475. p2 = lines[ps].components[1];
  476. var proc = 0.5;
  477.  
  478. var dist = [];
  479. var dsum = 0;
  480. for (k = 0; k < numlines; k++) {
  481. line = lines[k];
  482. var d = line.getGeodesicLength(epsg900913);
  483. dsum += d;
  484. dist.push(d);
  485. }
  486. var dmid = dsum / 2.0;
  487. var d1 = 0;
  488. var d2 = 0;
  489. for (k = 0; k < numlines; k++) {
  490. line = lines[k];
  491. d1 = d2;
  492. d2 += dist[k];
  493. if (dmid >= d1 && dmid < d2) {
  494. p1 = lines[k].components[0];
  495. p2 = lines[k].components[1];
  496. proc = (dmid - d1) / (d2 - d1);
  497. }
  498. }
  499.  
  500. sx = p1.x + (p2.x - p1.x) * proc;
  501. sy = p1.y + (p2.y - p1.y) * proc;
  502.  
  503. if (routespeedsoption2) speedtekst = odctime + "s ";
  504.  
  505. pt = new OpenLayers.Geometry.Point(sx, sy);
  506. textFeature = new OpenLayers.Feature.Vector(pt, { labelText: speedtekst, fontColor: kolor1, pointRadius: 0 });
  507. return textFeature;
  508. }
  509. else if (numlines == 1) {
  510. p1 = lines[0].components[0];
  511. p2 = lines[0].components[1];
  512.  
  513. sx = (p1.x + p2.x) * 0.5;
  514. sy = (p1.y + p2.y) * 0.5;
  515.  
  516. if (routespeedsoption2) speedtekst = odctime + "s ";
  517.  
  518. pt = new OpenLayers.Geometry.Point(sx, sy);
  519. textFeature = new OpenLayers.Feature.Vector(pt, { labelText: speedtekst, fontColor: kolor1, pointRadius: 0 });
  520. return textFeature;
  521. }
  522. else return null;
  523. }
  524. //------------------------------------------------------------------------------------------------
  525. function panmap(draggingobj, x, y) {
  526. let viewPortDiv = draggingobj.map.getViewport();
  527. let maxX = viewPortDiv.clientWidth;
  528. let maxY = viewPortDiv.clientHeight;
  529. let lastx = draggingobj.last.x;
  530. let lasty = draggingobj.last.y;
  531. let mx = x - lastx;
  532. let my = y - lasty;
  533.  
  534. if (x < accelerationmargin) {
  535. if (mx < 0) panningX = x - accelerationmargin;
  536. if (mx > accelerationbackstop) panningX = 0;
  537. }
  538. else if (x > maxX - accelerationmargin) {
  539. if (mx > 0) panningX = x - (maxX - accelerationmargin);
  540. if (mx < -accelerationbackstop) panningX = 0;
  541. }
  542. else panningX = 0;
  543.  
  544. if (y < accelerationmargin) {
  545. if (my < 0) panningY = y - (accelerationmargin);
  546. if (my > accelerationbackstop) panningY = 0;
  547. }
  548. else if (y > maxY - accelerationmargin - 25) {
  549. if (my > 0) panningY = y - (maxY - accelerationmargin - 25);
  550. if (my < -accelerationbackstop) panningY = 0;
  551. }
  552. else panningY = 0;
  553. }
  554. //------------------------------------------------------------------------------------------------
  555. function createMarkers(lon1, lat1, lon2, lat2, disp) {
  556.  
  557. var WM = window.W.map;
  558.  
  559. var mlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeedsMarkers");
  560. var markerLayer = mlayers[0];
  561. var p1, p2, lonlat;
  562.  
  563. if (markerA === undefined && markerB === undefined) {
  564. var di = WazeWrap.Require.DivIcon;
  565. var iconA = new di("routespeedsmarkerA");
  566. var iconB = new di("routespeedsmarkerB");
  567.  
  568. p1 = new OpenLayers.Geometry.Point(lon1, lat1).transform(epsg4326, epsg900913);
  569. p2 = new OpenLayers.Geometry.Point(lon2, lat2).transform(epsg4326, epsg900913);
  570.  
  571. var lonlatA = new OpenLayers.LonLat(p1.x, p1.y);
  572. var lonlatB = new OpenLayers.LonLat(p2.x, p2.y);
  573.  
  574. markerA = new OpenLayers.Marker(lonlatA, iconA);
  575. markerB = new OpenLayers.Marker(lonlatB, iconB);
  576.  
  577. var wh = WazeWrap.Require.DragElement();//require("Waze/Handler/DragElement");
  578. markerA.dragging = new wh(WM);
  579. markerB.dragging = new wh(WM);
  580.  
  581. markerA.dragging.down = function (e) {
  582. lonlat = this.map.getLonLatFromViewPortPx(e.xy);
  583. if (lonlat === null) return;
  584. markerA_offset_click[0] = markerA.lonlat.lon - lonlat.lon;
  585. markerA_offset_click[1] = markerA.lonlat.lat - lonlat.lat;
  586. };
  587. markerB.dragging.down = function (e) {
  588. lonlat = this.map.getLonLatFromViewPortPx(e.xy);
  589. if (lonlat === null) return;
  590. markerB_offset_click[0] = markerB.lonlat.lon - lonlat.lon;
  591. markerB_offset_click[1] = markerB.lonlat.lat - lonlat.lat;
  592. };
  593.  
  594. markerA.dragging.move = function (e) {
  595. lonlat = this.map.getLonLatFromViewPortPx(e.xy);
  596. markerA.lonlat.lon = lonlat.lon + markerA_offset_click[0];
  597. markerA.lonlat.lat = lonlat.lat + markerA_offset_click[1];
  598. markerLayer.drawMarker(markerA);
  599. panmap(this, e.xy.x, e.xy.y);
  600. };
  601. markerB.dragging.move = function (e) {
  602. lonlat = this.map.getLonLatFromViewPortPx(e.xy);
  603. markerB.lonlat.lon = lonlat.lon + markerB_offset_click[0];
  604. markerB.lonlat.lat = lonlat.lat + markerB_offset_click[1];
  605. markerLayer.drawMarker(markerB);
  606. panmap(this, e.xy.x, e.xy.y);
  607. };
  608.  
  609. markerA.dragging.done = function (e) {
  610.  
  611. if (routespeedsoption1) return;
  612.  
  613. panningX = 0;
  614. panningY = 0;
  615.  
  616. var lonlatA = new OpenLayers.LonLat(markerA.lonlat.lon, markerA.lonlat.lat).transform(epsg900913, epsg4326);
  617. var lonlatB = new OpenLayers.LonLat(markerB.lonlat.lon, markerB.lonlat.lat).transform(epsg900913, epsg4326);
  618.  
  619. lon1 = parseInt(lonlatA.lon * 1000000.0 + 0.5) / 1000000.0;
  620. lat1 = parseInt(lonlatA.lat * 1000000.0 + 0.5) / 1000000.0;
  621. lon2 = parseInt(lonlatB.lon * 1000000.0 + 0.5) / 1000000.0;
  622. lat2 = parseInt(lonlatB.lat * 1000000.0 + 0.5) / 1000000.0;
  623.  
  624. if (getId('sidepanel-routespeeds-a') !== undefined) {
  625. getId('sidepanel-routespeeds-a').value = lon1 + ", " + lat1;
  626. getId('sidepanel-routespeeds-b').value = lon2 + ", " + lat2;
  627. }
  628.  
  629. var objprog1 = getId('routespeeds-button-livemap');
  630. if (objprog1.style.backgroundColor === '') objprog1.style.backgroundColor = '#FF8000';
  631.  
  632. requestRouteFromLiveMap(lon1, lat1, lon2, lat2);
  633. };
  634. markerB.dragging.done = function (e) {
  635.  
  636. if (routespeedsoption1) return;
  637.  
  638. panningX = 0;
  639. panningY = 0;
  640.  
  641. var lonlatA = new OpenLayers.LonLat(markerA.lonlat.lon, markerA.lonlat.lat).transform(epsg900913, epsg4326);
  642. var lonlatB = new OpenLayers.LonLat(markerB.lonlat.lon, markerB.lonlat.lat).transform(epsg900913, epsg4326);
  643.  
  644. lon1 = parseInt(lonlatA.lon * 1000000.0 + 0.5) / 1000000.0;
  645. lat1 = parseInt(lonlatA.lat * 1000000.0 + 0.5) / 1000000.0;
  646. lon2 = parseInt(lonlatB.lon * 1000000.0 + 0.5) / 1000000.0;
  647. lat2 = parseInt(lonlatB.lat * 1000000.0 + 0.5) / 1000000.0;
  648.  
  649. if (getId('sidepanel-routespeeds-a') !== undefined) {
  650. getId('sidepanel-routespeeds-a').value = lon1 + ", " + lat1;
  651. getId('sidepanel-routespeeds-b').value = lon2 + ", " + lat2;
  652. }
  653.  
  654. var objprog1 = getId('routespeeds-button-livemap');
  655. if (objprog1.style.backgroundColor === '') objprog1.style.backgroundColor = '#FF8000';
  656.  
  657. requestRouteFromLiveMap(lon1, lat1, lon2, lat2);
  658. };
  659.  
  660. markerA.dragging.activate(iconA.$div);
  661. markerB.dragging.activate(iconB.$div);
  662.  
  663. markerA.display(disp);
  664. markerB.display(disp);
  665.  
  666. markerLayer.addMarker(markerA);
  667. markerLayer.addMarker(markerB);
  668. }
  669. else {
  670. p1 = new OpenLayers.Geometry.Point(lon1, lat1).transform(epsg4326, epsg900913);
  671. p2 = new OpenLayers.Geometry.Point(lon2, lat2).transform(epsg4326, epsg900913);
  672.  
  673. markerA.lonlat.lon = p1.x;
  674. markerA.lonlat.lat = p1.y;
  675. markerB.lonlat.lon = p2.x;
  676. markerB.lonlat.lat = p2.y;
  677.  
  678. markerA.display(disp);
  679. markerB.display(disp);
  680.  
  681. markerLayer.drawMarker(markerA);
  682. markerLayer.drawMarker(markerB);
  683. }
  684.  
  685. markerA.created = disp;
  686. markerB.created = disp;
  687. }
  688. //------------------------------------------------------------------------------------------------
  689. function showLayers(disp) {
  690. var WM = window.W.map;
  691.  
  692. var rlayers1 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  693. var rlayers2 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds2");
  694. var rlayers3 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds3");
  695. var rlayers4 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds4");
  696. var rlayers5 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds5");
  697. var routeLayer1 = rlayers1[0];
  698. var routeLayer2 = rlayers2[0];
  699. var routeLayer3 = rlayers3[0];
  700. var routeLayer4 = rlayers4[0];
  701. var routeLayer5 = rlayers5[0];
  702.  
  703. if (routeLayer1 === undefined) return;
  704. if (routeLayer2 === undefined) return;
  705. if (routeLayer3 === undefined) return;
  706. if (routeLayer4 === undefined) return;
  707. if (routeLayer5 === undefined) return;
  708.  
  709. routeLayer1.setVisibility(disp);
  710. routeLayer2.setVisibility(disp);
  711. routeLayer3.setVisibility(disp);
  712. routeLayer4.setVisibility(disp);
  713. routeLayer5.setVisibility(disp);
  714. }
  715. //--------------------------------------------------------------------------------------------------------
  716. function showMarkers(disp) {
  717. var WM = window.W.map;
  718.  
  719. var mlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeedsMarkers");
  720. var markerLayer = mlayers[0];
  721.  
  722. if (markerLayer === undefined) return false;
  723. if (markerA === undefined) return false;
  724. if (markerB === undefined) return false;
  725.  
  726. if (markerA.created) markerA.display(disp);
  727. if (markerB.created) markerB.display(disp);
  728.  
  729. return (markerA.created && markerB.created);
  730. }
  731. //------------------------------------------------------------------------------------------------
  732. function reverseMarkers() {
  733. var WM = window.W.map;
  734.  
  735. var mlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeedsMarkers");
  736. var markerLayer = mlayers[0];
  737.  
  738. if (markerLayer === undefined) return;
  739. if (markerA === undefined || !markerA.created) return;
  740. if (markerB === undefined || !markerB.created) return;
  741.  
  742. var copy = markerA.lonlat;
  743. markerA.lonlat = markerB.lonlat;
  744. markerB.lonlat = copy;
  745.  
  746. markerLayer.drawMarker(markerA);
  747. markerLayer.drawMarker(markerB);
  748. }
  749. //------------------------------------------------------------------------------------------------
  750. function loopWMERouteSpeeds() {
  751.  
  752. if (routespeedsoption1) return;
  753.  
  754. var tabOpen = $('#routespeeds-tab-label').parent().parent().attr('aria-expanded') == "true";
  755. if (!tabOpen) {
  756. if (tabswitched !== 1) {
  757. tabswitched = 1;
  758. showLayers(false);
  759. showMarkers(false);
  760. showClosures(0);
  761. }
  762. return;
  763. }
  764. else {
  765. if (tabswitched !== 2) {
  766. tabswitched = 2;
  767. showLayers(true);
  768. showMarkers(true);
  769. showClosures(1);
  770. }
  771. }
  772.  
  773. //var routespeedsbutton = getId('routespeeds-button-livemap');
  774. //if (routespeedsbutton == 'undefined') return;
  775. //var routespeedsbutton_ofsW = routespeedsbutton.offsetWidth;
  776. //var routespeedsbutton_ofsH = routespeedsbutton.offsetHeight;
  777. //console.log(routespeedsbutton_ofsW, routespeedsbutton_ofsH);
  778. //if (routespeedsbutton_ofsW == 0 || routespeedsbutton_ofsH==0) return;
  779.  
  780.  
  781. var WM = window.W.map;
  782.  
  783. var rlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  784. if (rlayers.length === 0) {
  785.  
  786. var drc_style1 = new OpenLayers.Style({
  787. strokeDashstyle: 'solid',
  788. strokeColor: "${strokeColor}",
  789. strokeOpacity: 1.0,
  790. strokeWidth: "${strokeWidth}",
  791. fillColor: '#0040FF',
  792. fillOpacity: 1.0,
  793. pointRadius: "${pointRadius}",
  794. label: "${labelText}",
  795. fontFamily: "Tahoma, Courier New",
  796. labelOutlineColor: '#FFFFFF',
  797. labelOutlineWidth: 0,
  798. fontColor: "${fontColor}",
  799. fontOpacity: 1.0,
  800. fontSize: "10px",
  801. display: 'block'
  802. });
  803.  
  804. var drc_style2 = new OpenLayers.Style({
  805. strokeDashstyle: 'solid',
  806. strokeColor: "${strokeColor}",
  807. strokeOpacity: 1.0,
  808. strokeWidth: "${strokeWidth}",
  809. fillColor: '#0040FF',
  810. fillOpacity: 1.0,
  811. pointRadius: "${pointRadius}",
  812. label: "${labelText}",
  813. fontFamily: "Tahoma, Courier New",
  814. labelOutlineColor: '#FFFFFF',
  815. labelOutlineWidth: 0,
  816. fontColor: "${fontColor}",
  817. fontOpacity: 1.0,
  818. fontSize: "10px",
  819. display: 'block'
  820. });
  821.  
  822. var drc_style3 = new OpenLayers.Style({
  823. strokeDashstyle: 'solid',
  824. strokeColor: "${strokeColor}",
  825. strokeOpacity: 1.0,
  826. strokeWidth: "${strokeWidth}",
  827. fillColor: '#0040FF',
  828. fillOpacity: 1.0,
  829. pointRadius: "${pointRadius}",
  830. label: "${labelText}",
  831. fontFamily: "Tahoma, Courier New",
  832. labelOutlineColor: '#FFFFFF',
  833. labelOutlineWidth: 0,
  834. fontColor: "${fontColor}",
  835. fontOpacity: 1.0,
  836. fontSize: "10px",
  837. display: 'block'
  838. });
  839.  
  840. var drc_style4 = new OpenLayers.Style({
  841. strokeDashstyle: 'solid',
  842. strokeColor: "${strokeColor}",
  843. strokeOpacity: 1.0,
  844. strokeWidth: "${strokeWidth}",
  845. fillColor: '#0040FF',
  846. fillOpacity: 1.0,
  847. pointRadius: "${pointRadius}",
  848. label: "${labelText}",
  849. fontFamily: "Tahoma, Courier New",
  850. labelOutlineColor: '#FFFFFF',
  851. labelOutlineWidth: 0,
  852. fontColor: "${fontColor}",
  853. fontOpacity: 1.0,
  854. fontSize: "10px",
  855. display: 'block'
  856. });
  857.  
  858. var drc_style5 = new OpenLayers.Style({
  859. strokeDashstyle: 'solid',
  860. strokeColor: "${strokeColor}",
  861. strokeOpacity: 1.0,
  862. strokeWidth: "${strokeWidth}",
  863. fillColor: '#0040FF',
  864. fillOpacity: 1.0,
  865. pointRadius: "${pointRadius}",
  866. label: "${labelText}",
  867. fontFamily: "Tahoma, Courier New",
  868. labelOutlineColor: '#FFFFFF',
  869. labelOutlineWidth: 0,
  870. fontColor: "${fontColor}",
  871. fontOpacity: 1.0,
  872. fontSize: "10px",
  873. display: 'block'
  874. });
  875.  
  876. var drc_mapLayer1 = new OpenLayers.Layer.Vector("Route Speeds", {
  877. displayInLayerSwitcher: true,
  878. uniqueName: "__DrawRouteSpeeds1",
  879. styleMap: new OpenLayers.StyleMap(drc_style1)
  880. });
  881.  
  882. var drc_mapLayer2 = new OpenLayers.Layer.Vector("Route Speeds 2", {
  883. displayInLayerSwitcher: false,
  884. uniqueName: "__DrawRouteSpeeds2",
  885. styleMap: new OpenLayers.StyleMap(drc_style2)
  886. });
  887.  
  888. var drc_mapLayer3 = new OpenLayers.Layer.Vector("Route Speeds 3", {
  889. displayInLayerSwitcher: false,
  890. uniqueName: "__DrawRouteSpeeds3",
  891. styleMap: new OpenLayers.StyleMap(drc_style3)
  892. });
  893.  
  894. var drc_mapLayer4 = new OpenLayers.Layer.Vector("Route Speeds 4", {
  895. displayInLayerSwitcher: false,
  896. uniqueName: "__DrawRouteSpeeds4",
  897. styleMap: new OpenLayers.StyleMap(drc_style4)
  898. });
  899.  
  900. var drc_mapLayer5 = new OpenLayers.Layer.Vector("Route Speeds 5", {
  901. displayInLayerSwitcher: false,
  902. uniqueName: "__DrawRouteSpeeds5",
  903. styleMap: new OpenLayers.StyleMap(drc_style5)
  904. });
  905.  
  906. I18n.translations[I18n.currentLocale()].layers.name["__DrawRouteSpeeds1"] = "Route Speeds";
  907. I18n.translations[I18n.currentLocale()].layers.name["__DrawRouteSpeeds2"] = "Route Speeds 2";
  908. I18n.translations[I18n.currentLocale()].layers.name["__DrawRouteSpeeds3"] = "Route Speeds 3";
  909. I18n.translations[I18n.currentLocale()].layers.name["__DrawRouteSpeeds4"] = "Route Speeds 4";
  910. I18n.translations[I18n.currentLocale()].layers.name["__DrawRouteSpeeds5"] = "Route Speeds 5";
  911.  
  912. drc_mapLayer1.setVisibility(true);
  913. drc_mapLayer2.setVisibility(true);
  914. drc_mapLayer3.setVisibility(true);
  915. drc_mapLayer4.setVisibility(true);
  916. drc_mapLayer5.setVisibility(true);
  917.  
  918. WM.addLayer(drc_mapLayer1);
  919. WM.addLayer(drc_mapLayer2);
  920. WM.addLayer(drc_mapLayer3);
  921. WM.addLayer(drc_mapLayer4);
  922. WM.addLayer(drc_mapLayer5);
  923.  
  924. return;
  925. }
  926.  
  927. var mlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeedsMarkers");
  928. if (mlayers.length === 0) {
  929.  
  930. var drc_mapLayer = new OpenLayers.Layer.Markers("Route Speeds Markers", {
  931. displayInLayerSwitcher: false,
  932. uniqueName: "__DrawRouteSpeedsMarkers"
  933. });
  934.  
  935. I18n.translations[I18n.currentLocale()].layers.name["__DrawRouteSpeedsMarkers"] = "Route Speeds Markers";
  936. WM.addLayer(drc_mapLayer);
  937. drc_mapLayer.setVisibility(true);
  938.  
  939. createMarkers(16, 52, 17, 53, false);
  940.  
  941. return;
  942. }
  943.  
  944. if (jqueryinfo === 1) {
  945. jqueryinfo = 2;
  946. console.log('WME Route Speeds: jQuery reloaded ver. ' + jQuery.fn.jquery);
  947. }
  948. if (jqueryinfo === 0) {
  949. if (typeof jQuery === 'undefined') {
  950. console.log('WME Route Speeds: jQuery current ver. ' + jQuery.fn.jquery);
  951.  
  952. var script = document.createElement('script');
  953. script.type = "text/javascript";
  954. script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js";
  955. //script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js";
  956. document.getElementsByTagName('head')[0].appendChild(script);
  957. jqueryinfo = 1;
  958. }
  959. }
  960.  
  961.  
  962. var rlayers1 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  963. var rlayers2 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds2");
  964. var rlayers3 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds3");
  965. var rlayers4 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds4");
  966. var rlayers5 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds5");
  967. var routeLayer1 = rlayers1[0];
  968. var routeLayer2 = rlayers2[0];
  969. var routeLayer3 = rlayers3[0];
  970. var routeLayer4 = rlayers4[0];
  971. var routeLayer5 = rlayers5[0];
  972. if (routeLayer1 === undefined) return;
  973. if (routeLayer2 === undefined) return;
  974. if (routeLayer3 === undefined) return;
  975. if (routeLayer4 === undefined) return;
  976. if (routeLayer5 === undefined) return;
  977.  
  978. if (routeLayer1.getVisibility() === false) {
  979. if (routeLayer2.getVisibility() === true) {
  980. routeLayer2.setVisibility(false);
  981. routeLayer3.setVisibility(false);
  982. routeLayer4.setVisibility(false);
  983. routeLayer5.setVisibility(false);
  984. }
  985. }
  986. else {
  987. if (routeLayer2.getVisibility() === false) {
  988. routeLayer2.setVisibility(true);
  989. routeLayer3.setVisibility(true);
  990. routeLayer4.setVisibility(true);
  991. routeLayer5.setVisibility(true);
  992. }
  993. }
  994.  
  995. var numSelected = WazeWrap.getSelectedFeatures().length;
  996. var seg1 = WazeWrap.getSelectedFeatures()[0];
  997. var seg2 = WazeWrap.getSelectedFeatures()[1];
  998.  
  999. if (seg1 !== undefined && seg2 !== undefined) {
  1000. if (!selected) {
  1001. selected = 1;
  1002.  
  1003. var coords1 = getSegmentMidPoint(seg1, 0);
  1004. var coords2 = getSegmentMidPoint(seg2, 1);
  1005.  
  1006. var lon1 = parseInt(coords1.lon * 1000000.0 + 0.5) / 1000000.0;
  1007. var lat1 = parseInt(coords1.lat * 1000000.0 + 0.5) / 1000000.0;
  1008. var lon2 = parseInt(coords2.lon * 1000000.0 + 0.5) / 1000000.0;
  1009. var lat2 = parseInt(coords2.lat * 1000000.0 + 0.5) / 1000000.0;
  1010.  
  1011. if (getId('sidepanel-routespeeds-a') !== undefined) {
  1012. getId('sidepanel-routespeeds-a').value = lon1 + ", " + lat1;
  1013. getId('sidepanel-routespeeds-b').value = lon2 + ", " + lat2;
  1014. }
  1015.  
  1016. createMarkers(lon1, lat1, lon2, lat2, true);
  1017.  
  1018. leftHand = false;
  1019. if (seg1.model.model.isLeftHand) leftHand = true;
  1020. if (seg2.model.model.isLeftHand) leftHand = true;
  1021.  
  1022. requestRouteFromLiveMap(lon1, lat1, lon2, lat2);
  1023. }
  1024. }
  1025. else {
  1026. if (seg1 !== undefined || seg2 !== undefined) {
  1027. if (selected) {
  1028. selected = 0;
  1029.  
  1030. routeLayer1.removeAllFeatures();
  1031. routeLayer2.removeAllFeatures();
  1032. routeLayer3.removeAllFeatures();
  1033. routeLayer4.removeAllFeatures();
  1034. routeLayer5.removeAllFeatures();
  1035.  
  1036. getId('routespeeds-summary1').style.visibility = 'hidden';
  1037. getId('routespeeds-summary2').style.visibility = 'hidden';
  1038. getId('routespeeds-summary3').style.visibility = 'hidden';
  1039. getId('routespeeds-summary4').style.visibility = 'hidden';
  1040. getId('routespeeds-summary5').style.visibility = 'hidden';
  1041.  
  1042. getId('routespeeds-summary1').className = 'routespeeds_summary_classA';
  1043. getId('routespeeds-summary2').className = 'routespeeds_summary_classA';
  1044. getId('routespeeds-summary3').className = 'routespeeds_summary_classA';
  1045. getId('routespeeds-summary4').className = 'routespeeds_summary_classA';
  1046. getId('routespeeds-summary5').className = 'routespeeds_summary_classA';
  1047. }
  1048. }
  1049. }
  1050. }
  1051. //--------------------------------------------------------------------------------------------------------
  1052. function createRouteFeatures(id, routewsp, routeodc) {
  1053.  
  1054. var WM = window.W.map;
  1055.  
  1056. var rlayers;
  1057. if (id == 1) rlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  1058. if (id == 2) rlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds2");
  1059. if (id == 3) rlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds3");
  1060. if (id == 4) rlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds4");
  1061. if (id == 5) rlayers = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds5");
  1062. var routeLayer = rlayers[0];
  1063. if (routeLayer === undefined) return;
  1064.  
  1065. var lineFeatures = [];
  1066. var labelFeatures = [];
  1067. var lines = [];
  1068. var outlinepoints = [];
  1069.  
  1070. var odc = 0;
  1071. var odclen = routeodc[odc].length;
  1072. var odctime = 0;
  1073. if (routespeedsoption7) odctime = routeodc[odc].crossTime;
  1074. else odctime = routeodc[odc].crossTimeWithoutRealTime;
  1075. var odcx = 0;
  1076. var odcy = 0;
  1077. if (odc + 1 < routeodc.length) {
  1078. odcx = routeodc[odc + 1].path.x;
  1079. odcy = routeodc[odc + 1].path.y;
  1080. }
  1081.  
  1082. var speed = 0;
  1083. if (odctime > 0) speed = 3.6 * odclen / odctime;
  1084. var speedtekst = parseInt(speed);
  1085. var kolor = getColor(speed);
  1086.  
  1087. var ptA = new OpenLayers.Geometry.Point(0, 0);
  1088. var ptB = new OpenLayers.Geometry.Point(0, 0);
  1089.  
  1090. var doubletraffic = false;
  1091. var p1 = null;
  1092. var p2 = null;
  1093. var doublepoints = {};
  1094. var wsp1, wsp2, dlon, dlat, dx, dy, label, len, i;
  1095.  
  1096.  
  1097. //wykrycie czy trasa przechodzi dwa razy przez te same punkty, jeżeli tak to rysowanie trasy z odstępem, aby był widoczny przebieg trasy
  1098. //(detection whether the route passes through the same points twice, if so drawing the route with a gap to make the route visible)
  1099. for (i = 0; i < routewsp.length - 1; i++) {
  1100. wsp1 = routewsp[i + 0];
  1101. wsp2 = routewsp[i + 1];
  1102.  
  1103. dlon = Math.abs(wsp1.x - wsp2.x);
  1104. dlat = Math.abs(wsp1.y - wsp2.y);
  1105.  
  1106. if (dlon < 0.0000001 && dlat < 0.0000001) continue;
  1107.  
  1108. var s1 = parseInt(wsp1.x * 10000000 + 0.5) + ',' + parseInt(wsp1.y * 10000000 + 0.5);
  1109. var s2 = parseInt(wsp2.x * 10000000 + 0.5) + ',' + parseInt(wsp2.y * 10000000 + 0.5);
  1110.  
  1111. if (s1 === s2) continue;
  1112.  
  1113. if (doublepoints[s1] === undefined) doublepoints[s1] = 0;
  1114. if (doublepoints[s2] === undefined) doublepoints[s2] = 0;
  1115. doublepoints[s1]++;
  1116. doublepoints[s2]++;
  1117.  
  1118. if (doublepoints[s2] >= 2) {
  1119. doubletraffic = true;
  1120. break;
  1121. }
  1122. }
  1123.  
  1124. var doubletrafficoffset = 0;
  1125. if (doubletraffic) {
  1126. doubletrafficoffset = 11 * Math.pow(2.0, 5 - W.map.getZoom());
  1127. }
  1128.  
  1129.  
  1130. for (i = 0; i < routewsp.length - 1; i++) {
  1131. wsp1 = routewsp[i + 0];
  1132. wsp2 = routewsp[i + 1];
  1133.  
  1134. if (i === 0) {
  1135. ptA.x = wsp1.x;
  1136. ptA.y = wsp1.y;
  1137. ptA = ptA.transform(epsg4326, epsg900913);
  1138. //var p = new drc_OpenLayers.Geometry.Point(wsp1.x, wsp1.y).transform(epsg4326, epsg900913);
  1139. //var pt = new drc_OpenLayers.Geometry.Point(p.x, p.y);
  1140. //var textFeature = new drc_OpenLayers.Feature.Vector( ptA, {labelText: "A", pointRadius: 8, fontColor: '#FFFFFF' } );
  1141. //labelFeatures.push(textFeature);
  1142. }
  1143. if (i === routewsp.length - 2) {
  1144. ptB.x = wsp2.x;
  1145. ptB.y = wsp2.y;
  1146. ptB = ptB.transform(epsg4326, epsg900913);
  1147. //var p = new drc_OpenLayers.Geometry.Point(wsp2.x, wsp2.y).transform(epsg4326, epsg900913);
  1148. //var pt = new drc_OpenLayers.Geometry.Point(p.x, p.y);
  1149. //var textFeature = new drc_OpenLayers.Feature.Vector( ptB, {labelText: "B", pointRadius: 8, fontColor: '#FFFFFF' } );
  1150. //labelFeatures.push(textFeature);
  1151. }
  1152.  
  1153. dx = Math.abs(wsp1.x - odcx);
  1154. dy = Math.abs(wsp1.y - odcy);
  1155.  
  1156. //console.log(wsp1, odcx, odcy, dx, dy);
  1157.  
  1158. if (dx < 0.000001 && dy < 0.000001) {
  1159.  
  1160. if (!routespeedsoption3) {
  1161. label = addLabel(lines, speedtekst, routespeedsoption2, odctime, odclen, routespeedsoption4, id);
  1162. if (label !== null) labelFeatures.push(label);
  1163. }
  1164. while (lines.length > 0) lines.pop();
  1165.  
  1166. if (odc + 1 < routeodc.length) {
  1167. odc++;
  1168. odclen = routeodc[odc].length;
  1169. if (routespeedsoption7) odctime = routeodc[odc].crossTime;
  1170. else odctime = routeodc[odc].crossTimeWithoutRealTime;
  1171. if (odc + 1 < routeodc.length) {
  1172. odcx = routeodc[odc + 1].path.x;
  1173. odcy = routeodc[odc + 1].path.y;
  1174. }
  1175.  
  1176. speed = 0;
  1177. if (odctime > 0) speed = 3.6 * odclen / odctime;
  1178. speedtekst = parseInt(speed);
  1179. kolor = getColor(speed);
  1180.  
  1181. }
  1182. }
  1183.  
  1184. dlon = Math.abs(wsp1.x - wsp2.x);
  1185. dlat = Math.abs(wsp1.y - wsp2.y);
  1186.  
  1187. if (dlon < 0.0000001 && dlat < 0.0000001) continue;
  1188.  
  1189. var p3 = new OpenLayers.Geometry.Point(wsp1.x, wsp1.y).transform(epsg4326, epsg900913);
  1190. var p4 = new OpenLayers.Geometry.Point(wsp2.x, wsp2.y).transform(epsg4326, epsg900913);
  1191.  
  1192. if (doubletraffic) {
  1193. dx = p4.x - p3.x;
  1194. dy = p4.y - p3.y;
  1195. var r = Math.sqrt(dx * dx + dy * dy);
  1196. var angle = Math.acos(dx / r);
  1197. if (dy < 0) angle = -angle;
  1198. angle = angle - 0.5 * Math.PI;
  1199. if (leftHand) angle += Math.PI;
  1200.  
  1201. p3.x += doubletrafficoffset * Math.cos(angle) * 0.6;
  1202. p3.y += doubletrafficoffset * Math.sin(angle) * 0.6;
  1203. p4.x += doubletrafficoffset * Math.cos(angle) * 0.6;
  1204. p4.y += doubletrafficoffset * Math.sin(angle) * 0.6;
  1205.  
  1206. if (p1 !== null && p2 !== null) {
  1207.  
  1208. var Ax = p1.x;
  1209. var Ay = p1.y;
  1210. var Bx = p2.x;
  1211. var By = p2.y;
  1212. var Cx = p3.x;
  1213. var Cy = p3.y;
  1214. var Dx = p4.x;
  1215. var Dy = p4.y;
  1216.  
  1217. dx = Cx - Bx;
  1218. dy = Cy - By;
  1219.  
  1220. var delta = Math.sqrt(dx * dx + dy * dy);
  1221.  
  1222. var mx = ((By - Ay) * (Dx - Cx) - (Dy - Cy) * (Bx - Ax));
  1223. var my = ((Dy - Cy) * (Bx - Ax) - (By - Ay) * (Dx - Cx));
  1224.  
  1225. if (Math.abs(mx) > 0.000000001 && Math.abs(my) > 0.000000001 && delta > 0.1) {
  1226.  
  1227. var x = ((Bx - Ax) * (Dx * Cy - Dy * Cx) - (Dx - Cx) * (Bx * Ay - By * Ax)) / mx;
  1228. var y = ((Dy - Cy) * (Bx * Ay - By * Ax) - (By - Ay) * (Dx * Cy - Dy * Cx)) / my;
  1229.  
  1230. var dx2 = x - Bx;
  1231. var dy2 = y - By;
  1232. var delta2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
  1233.  
  1234. if (delta2 < 1000) { // checking if point of crossing is close to segments
  1235.  
  1236. len = lineFeatures.length;
  1237. if (len > 0) {
  1238. var lf = lineFeatures[len - 1];
  1239. lf.geometry.components[1].x = x;
  1240. lf.geometry.components[1].y = y;
  1241. }
  1242.  
  1243. p3.x = x;
  1244. p3.y = y;
  1245. }
  1246. }
  1247. }
  1248. }
  1249.  
  1250. outlinepoints.push(p3);
  1251. outlinepoints.push(p4);
  1252.  
  1253. let points = [];
  1254. points.push(p3);
  1255. points.push(p4);
  1256.  
  1257. let line = new OpenLayers.Geometry.LineString(points);
  1258. lines.push(line);
  1259.  
  1260. let lineFeature = new OpenLayers.Feature.Vector(line, { strokeColor: kolor, labelText: '', strokeWidth: 10 });
  1261.  
  1262. lineFeatures.push(lineFeature);
  1263.  
  1264. p1 = p3;
  1265. p2 = p4;
  1266. }
  1267.  
  1268. if (!routespeedsoption3) {
  1269. label = addLabel(lines, speedtekst, routespeedsoption2, odctime, odclen, routespeedsoption4, id);
  1270. if (label !== null) labelFeatures.push(label);
  1271. }
  1272. while (lines.length > 0) lines.pop();
  1273.  
  1274. let outlinestring = new OpenLayers.Geometry.LineString(outlinepoints);
  1275. let outlineFeature = new OpenLayers.Feature.Vector(outlinestring, { strokeColor: '#404040', labelText: '', strokeWidth: 12 });
  1276. routeLayer.addFeatures(outlineFeature);
  1277.  
  1278. routeLayer.addFeatures(lineFeatures);
  1279. routeLayer.addFeatures(labelFeatures);
  1280.  
  1281.  
  1282.  
  1283. let summarylen = 0;
  1284. let summarysec = 0;
  1285. if (routespeedsoption7) {
  1286. for (let i = 0; i < routeodc.length; i++) {
  1287. summarylen += routeodc[i].length;
  1288. summarysec += routeodc[i].crossTime;
  1289. }
  1290. }
  1291. else {
  1292. for (let i = 0; i < routeodc.length; i++) {
  1293. summarylen += routeodc[i].length;
  1294. summarysec += routeodc[i].crossTimeWithoutRealTime;
  1295. }
  1296. }
  1297. len = summarylen / 1000.0;
  1298. let sec = summarysec % 60;
  1299. let min = (summarysec - sec) % 3600;
  1300. let hou = (summarysec - sec - min) % 216000;
  1301. min = (min / 60) % 60;
  1302. hou = (hou / 3600);
  1303.  
  1304. let t = '';
  1305. if (hou < 10) t += '0' + hou + ":"; else t += hou + ":";
  1306. if (min < 10) t += '0' + min + ":"; else t += min + ":";
  1307. if (sec < 10) t += '0' + sec;
  1308. else t += sec;
  1309.  
  1310. let lenmph = len / 1.609;
  1311.  
  1312. let avgspeed = (summarylen / 1000.0) / (summarysec / 3600.0);
  1313. if (routespeedsoption4) avgspeed = avgspeed / 1.609;
  1314.  
  1315. let summaryobj;
  1316. if (id == 1) summaryobj = getId('routespeeds-summary1');
  1317. if (id == 2) summaryobj = getId('routespeeds-summary2');
  1318. if (id == 3) summaryobj = getId('routespeeds-summary3');
  1319. if (id == 4) summaryobj = getId('routespeeds-summary4');
  1320. if (id == 5) summaryobj = getId('routespeeds-summary5');
  1321.  
  1322. let html;
  1323. if (id == 1) html = '<div class=routespeeds_header style="background: #4d4dcd; color: #e0e0e0; "></div>' + '<span style="color: #404040;">Route 1</span> ';
  1324. if (id == 2) html = '<div class=routespeeds_header style="background: #d34f8a; color: #e0e0e0; "></div>' + '<span style="color: #404040;">Route 2</span> ';
  1325. if (id == 3) html = '<div class=routespeeds_header style="background: #188984; color: #e0e0e0; "></div>' + '<span style="color: #404040;">Route 3</span> ';
  1326. if (id == 4) html = '<div class=routespeeds_header style="background: #cafa27; color: #404040; "></div>' + '<span style="color: #404040;">Route 4</span> ';
  1327. if (id == 5) html = '<div class=routespeeds_header style="background: #ffca3f; color: #e0e0e0; "></div>' + '<span style="color: #404040;">Route 5</span> ';
  1328.  
  1329. let lenstr = precFloat(len, 2);
  1330. let u1 = 'km';
  1331. let u2 = 'km&#47;h';
  1332. if (routespeedsoption4) {
  1333. lenstr = precFloat(lenmph, 2);
  1334. u1 = 'miles';
  1335. u2 = 'mph';
  1336. }
  1337.  
  1338. html += '<div style="min-width:50px; display:inline-block; text-align:right;" ><b>' + lenstr + '</b></div>';
  1339. html += '<span style="font-size:11px;"> ' + u1 + '</span> &nbsp;<b>' + t + '</b>';
  1340. html += '<div style="display:inline-block; min-width:40px; text-align:right; color:#404040" >' + precFloat(avgspeed, 1) + '</div> <span style="font-size:11px;">' + u2 + '</span>';
  1341.  
  1342. summaryobj.innerHTML = html;
  1343.  
  1344. if (id === routeSelected) summaryobj.className = 'routespeeds_summary_classB';
  1345. summaryobj.style.visibility = 'visible';
  1346. }
  1347. //--------------------------------------------------------------------------------------------------------
  1348. function precFloat(f, prec) {
  1349. if (!isFinite(f)) return "&mdash;";
  1350.  
  1351. if (f < 0)
  1352. f -= Math.pow(0.1, prec) * 0.5;
  1353. else
  1354. f += Math.pow(0.1, prec) * 0.5;
  1355.  
  1356. let ipart = parseInt(f);
  1357. let fpart = Math.abs(f - ipart);
  1358. f = ipart;
  1359.  
  1360. if (fpart === '0') fpart = '0.0';
  1361. fpart += '0000000000000000';
  1362. if (prec) f += fpart.substr(1, prec + 1);
  1363.  
  1364. return f;
  1365. }
  1366. //--------------------------------------------------------------------------------------------------------
  1367. function getElementsByClassName(classname, node) {
  1368. if (!node) node = document.getElementsByTagName("body")[0];
  1369. var a = [];
  1370. var re = new RegExp('\\b' + classname + '\\b');
  1371. var els = node.getElementsByTagName("*");
  1372. for (var i = 0, j = els.length; i < j; i++)
  1373. if (re.test(els[i].className)) a.push(els[i]);
  1374. return a;
  1375. }
  1376. //--------------------------------------------------------------------------------------------------------
  1377. function getId(node) {
  1378. return document.getElementById(node);
  1379. }
  1380. //--------------------------------------------------------------------------------------------------------
  1381. function getnowtoday() {
  1382. let hour = getId('routespeeds-hour').value;
  1383. let day = getId('routespeeds-day').value;
  1384. if (hour === '---') hour = 'now';
  1385. if (day === '---') day = 'today';
  1386. if (hour === '') hour = 'now';
  1387. if (day === '') day = 'today';
  1388.  
  1389. let t = new Date();
  1390. let thour = (t.getHours() * 60) + t.getMinutes();
  1391. let tnow = (t.getDay() * 1440) + thour;
  1392. let tsel = tnow;
  1393.  
  1394. if (hour === 'now') {
  1395. if (day === "0") tsel = (parseInt(day) * 1440) + thour;
  1396. if (day === "1") tsel = (parseInt(day) * 1440) + thour;
  1397. if (day === "2") tsel = (parseInt(day) * 1440) + thour;
  1398. if (day === "3") tsel = (parseInt(day) * 1440) + thour;
  1399. if (day === "4") tsel = (parseInt(day) * 1440) + thour;
  1400. if (day === "5") tsel = (parseInt(day) * 1440) + thour;
  1401. if (day === "6") tsel = (parseInt(day) * 1440) + thour;
  1402. }
  1403. else {
  1404. if (day === "today") tsel = (t.getDay() * 1440) + parseInt(hour);
  1405. if (day === "0") tsel = (parseInt(day) * 1440) + parseInt(hour);
  1406. if (day === "1") tsel = (parseInt(day) * 1440) + parseInt(hour);
  1407. if (day === "2") tsel = (parseInt(day) * 1440) + parseInt(hour);
  1408. if (day === "3") tsel = (parseInt(day) * 1440) + parseInt(hour);
  1409. if (day === "4") tsel = (parseInt(day) * 1440) + parseInt(hour);
  1410. if (day === "5") tsel = (parseInt(day) * 1440) + parseInt(hour);
  1411. if (day === "6") tsel = (parseInt(day) * 1440) + parseInt(hour);
  1412. }
  1413.  
  1414. //console.log(tsel, tnow, tsel-tnow);
  1415.  
  1416. return tsel - tnow;
  1417. }
  1418. //--------------------------------------------------------------------------------------------------------
  1419. function requestRouteFromLiveMap(x1, y1, x2, y2) {
  1420. var atTime = getnowtoday();
  1421.  
  1422. var numRoutes = 1;
  1423. if (routespeedsoption5) numRoutes = parseInt(routespeedsoption6);
  1424. var numPaths = (routespeedsoption5 && routespeedsoption12 && !routespeedsoption15) ? numRoutes * 10 : numRoutes; //Routing Order - last condition disables Try More option
  1425.  
  1426. var routeType = (routespeedsoption13 === 3) ? "TIME" : "HISTORIC_TIME";
  1427.  
  1428. var avoidTollRoads = routespeedsoption8;
  1429. var avoidPrimaries = routespeedsoption9;
  1430. var avoidTrails = routespeedsoption10;
  1431. var avoidLongTrails = routespeedsoption11;
  1432. var allowUTurns = routespeedsoption14;
  1433. var avoidDifficult = routespeedsoption16;
  1434. var avoidFerries = routespeedsoption17;
  1435. var vehType = routespeedsoption18;
  1436.  
  1437. var options = {
  1438. data: [],
  1439. add: function (name, value, defaultValue) {
  1440. if (value !== defaultValue) {
  1441. this.data.push(name + (value ? ":t" : ":f"));
  1442. }
  1443. },
  1444. put: function (name, value) {
  1445. this.data.push(name + (value ? ":t" : ":f"));
  1446. },
  1447. get: function () {
  1448. return this.data.join(",");
  1449. }
  1450. };
  1451.  
  1452. options.add("AVOID_TOLL_ROADS", avoidTollRoads, false);
  1453. options.add("AVOID_PRIMARIES", avoidPrimaries, false);
  1454. options.add("AVOID_DANGEROUS_TURNS", avoidDifficult, false);
  1455. options.add("AVOID_FERRIES", avoidFerries, false);
  1456. options.add("ALLOW_UTURNS", allowUTurns, true);
  1457.  
  1458. if (avoidLongTrails) { options.put("AVOID_LONG_TRAILS", true); }
  1459. else if (avoidTrails) { options.put("AVOID_TRAILS", true); }
  1460. else { options.put("AVOID_LONG_TRAILS", false); }
  1461.  
  1462.  
  1463. var url = getRoutingManager();
  1464. let expressPass = _settings.passes.map(key => key);
  1465. var data = {
  1466. from: "x:" + x1 + " y:" + y1,
  1467. to: "x:" + x2 + " y:" + y2,
  1468. returnJSON: true,
  1469. returnGeometries: true,
  1470. returnInstructions: true,
  1471. timeout: 60000,
  1472. at: atTime,
  1473. type: routeType,
  1474. nPaths: numPaths,
  1475. clientVersion: '4.0.0',
  1476. options: options.get(),
  1477. vehicleType: vehType,
  1478. subscription: expressPass
  1479. };
  1480.  
  1481. routewait = 1;
  1482.  
  1483. getId('routespeeds-error').innerHTML = "";
  1484.  
  1485. console.time('WME Route Speeds: routing time');
  1486.  
  1487. $.ajax({
  1488. dataType: "json",
  1489. cache: false,
  1490. url: url,
  1491. data: data,
  1492. traditional: true,
  1493. dataFilter: function (data, dataType) {
  1494. return data.replace(/NaN/g, '0');
  1495. },
  1496. error: function (req, textStatus, errorThrown) {
  1497. let str = "Route request failed" + (textStatus !== null ? " with " + textStatus : "") + "!";
  1498. str += "<br>" + errorThrown;
  1499. handleRouteRequestError(str);
  1500. },
  1501. success: function (json) {
  1502. if (json.error !== undefined) {
  1503. let str = json.error;
  1504. str = str.replace("|", "<br>");
  1505. handleRouteRequestError(str);
  1506. }
  1507. else {
  1508.  
  1509. routewsp1 = [];
  1510. routeodc1 = [];
  1511. routewsp2 = [];
  1512. routeodc2 = [];
  1513. routewsp3 = [];
  1514. routeodc3 = [];
  1515. routewsp4 = [];
  1516. routeodc4 = [];
  1517. routewsp5 = [];
  1518. routeodc5 = [];
  1519.  
  1520.  
  1521.  
  1522. if (json.coords !== undefined) {
  1523. console.log("WME Route Speeds: 1 route received" + " (" + numPaths + " requested)");
  1524.  
  1525. if (routeSelected > 1) routeSelected = 1;
  1526.  
  1527. routewsp1 = json.coords;
  1528. routeodc1 = json.response.results;
  1529.  
  1530. }
  1531. if (json.alternatives !== undefined) {
  1532. console.log("WME Route Speeds: " + json.alternatives.length + " routes received" + " (" + numPaths + " requested)");
  1533.  
  1534. var sortByField = (routespeedsoption13 === 2) ? "length" : routespeedsoption7 ? "crossTime" : "crossTimeWithoutRealTime";
  1535.  
  1536. if (!routespeedsoption15) { // Routing Order
  1537. json.alternatives.sort(function (a, b) {
  1538. let valField = "total_" + sortByField;
  1539. let val = function (r) {
  1540. if (r[valField] !== undefined) return r[valField];
  1541. let val = 0;
  1542. for (let i = 0; i < r.results.length; ++i) {
  1543. val += r.results[i][sortByField];
  1544. }
  1545. return r[valField] = val;
  1546. };
  1547. return val(a.response) - val(b.response);
  1548. });
  1549. }
  1550.  
  1551.  
  1552. if (json.alternatives.length > numRoutes) {
  1553. json.alternatives = json.alternatives.slice(0, numRoutes);
  1554. }
  1555.  
  1556. if (routeSelectedLast) routeSelected = routeSelectedLast;
  1557. if (routeSelected > json.alternatives.length) routeSelected = json.alternatives.length;
  1558.  
  1559. for (let n = 0; n < json.alternatives.length; n++) {
  1560.  
  1561. if (n === 0) routewsp1 = json.alternatives[n].coords;
  1562. if (n === 0) routeodc1 = json.alternatives[n].response.results;
  1563.  
  1564.  
  1565. if (n === 1) routewsp2 = json.alternatives[n].coords;
  1566. if (n === 1) routeodc2 = json.alternatives[n].response.results;
  1567.  
  1568. if (n === 2) routewsp3 = json.alternatives[n].coords;
  1569. if (n === 2) routeodc3 = json.alternatives[n].response.results;
  1570.  
  1571. if (n === 3) routewsp4 = json.alternatives[n].coords;
  1572. if (n === 3) routeodc4 = json.alternatives[n].response.results;
  1573.  
  1574. if (n === 4) routewsp5 = json.alternatives[n].coords;
  1575. if (n === 4) routeodc5 = json.alternatives[n].response.results;
  1576. }
  1577. }
  1578.  
  1579. rezoom();
  1580. }
  1581.  
  1582. getId('routespeeds-button-livemap').style.backgroundColor = '';
  1583. getId('routespeeds-button-reverse').style.backgroundColor = '';
  1584. },
  1585. complete: function () {
  1586. console.timeEnd('WME Route Speeds: routing time');
  1587. routewait = 0;
  1588. }
  1589. });
  1590. }
  1591. //--------------------------------------------------------------------------------------------------------
  1592. function handleRouteRequestError(message) {
  1593. console.log("WME Route Speeds: route request error: " + message.replace("<br>", "\n"));
  1594.  
  1595. getId('routespeeds-button-livemap').style.backgroundColor = '';
  1596. getId('routespeeds-button-reverse').style.backgroundColor = '';
  1597.  
  1598. getId('routespeeds-summary1').innerHTML = '';
  1599. getId('routespeeds-summary2').innerHTML = '';
  1600. getId('routespeeds-summary3').innerHTML = '';
  1601. getId('routespeeds-summary4').innerHTML = '';
  1602. getId('routespeeds-summary5').innerHTML = '';
  1603.  
  1604. getId('routespeeds-summary1').style.visibility = 'hidden';
  1605. getId('routespeeds-summary2').style.visibility = 'hidden';
  1606. getId('routespeeds-summary3').style.visibility = 'hidden';
  1607. getId('routespeeds-summary4').style.visibility = 'hidden';
  1608. getId('routespeeds-summary5').style.visibility = 'hidden';
  1609.  
  1610. let WM = window.W.map;
  1611. let rlayers1 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  1612. let rlayers2 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds2");
  1613. let rlayers3 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds3");
  1614. let rlayers4 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds4");
  1615. let rlayers5 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds5");
  1616. let routeLayer1 = rlayers1[0];
  1617. let routeLayer2 = rlayers2[0];
  1618. let routeLayer3 = rlayers3[0];
  1619. let routeLayer4 = rlayers4[0];
  1620. let routeLayer5 = rlayers5[0];
  1621. if (routeLayer1 !== undefined) routeLayer1.removeAllFeatures();
  1622. if (routeLayer2 !== undefined) routeLayer2.removeAllFeatures();
  1623. if (routeLayer3 !== undefined) routeLayer3.removeAllFeatures();
  1624. if (routeLayer4 !== undefined) routeLayer4.removeAllFeatures();
  1625. if (routeLayer5 !== undefined) routeLayer5.removeAllFeatures();
  1626.  
  1627. getId('routespeeds-error').innerHTML = "<br>" + message;
  1628. }
  1629. //--------------------------------------------------------------------------------------------------------
  1630. function livemapRouteClick() {
  1631. routeSelected = 1;
  1632. routeSelectedLast = 0;
  1633.  
  1634. livemapRoute();
  1635. }
  1636. //--------------------------------------------------------------------------------------------------------
  1637. function get_coords_from_livemap_link(link) {
  1638. let lon1 = '';
  1639. let lat1 = '';
  1640. let lon2 = '';
  1641. let lat2 = '';
  1642.  
  1643. let opt = link.split('&');
  1644. for (let i = 0; i < opt.length; i++) {
  1645. let o = opt[i];
  1646.  
  1647. if (o.indexOf('from_lon=') === 0) lon1 = o.substring(9, 30);
  1648. if (o.indexOf('from_lat=') === 0) lat1 = ', ' + o.substring(9, 30);
  1649. if (o.indexOf('to_lon=') === 0) lon2 = o.substring(7, 30);
  1650. if (o.indexOf('to_lat=') === 0) lat2 = ', ' + o.substring(7, 30);
  1651. }
  1652.  
  1653. getId('sidepanel-routespeeds-a').value = lon1 + lat1;
  1654. getId('sidepanel-routespeeds-b').value = lon2 + lat2;
  1655. }
  1656. //--------------------------------------------------------------------------------------------------------
  1657. function livemapRoute() {
  1658.  
  1659. if (routespeedsoption1) return;
  1660. if (routewait) return;
  1661.  
  1662. routewsp1 = [];
  1663. routeodc1 = [];
  1664. routewsp2 = [];
  1665. routeodc2 = [];
  1666. routewsp3 = [];
  1667. routeodc3 = [];
  1668. routewsp4 = [];
  1669. routeodc4 = [];
  1670. routewsp5 = [];
  1671. routeodc5 = [];
  1672.  
  1673. let stra = getId('sidepanel-routespeeds-a').value;
  1674. let strb = getId('sidepanel-routespeeds-b').value;
  1675.  
  1676. let pastedlink = false;
  1677.  
  1678. //sprawdzenie czy wklejono link z LiveMap, jeżeli tak to sparsowanie i przeformatowanie współrzędnych oraz przeniesienie widoku mapy na miejsce wklejonej trasy
  1679. //(checking if the link from LiveMap has been pasted, if yes, paring and reformatting the coordinates and moving the map view to the location of the pasted route)
  1680. if (stra.indexOf('livemap?') >= 0 || stra.indexOf('livemap/?') >= 0) {
  1681. get_coords_from_livemap_link(stra);
  1682. stra = getId('sidepanel-routespeeds-a').value;
  1683. strb = getId('sidepanel-routespeeds-b').value;
  1684. pastedlink = true;
  1685. }
  1686. else if (strb.indexOf('livemap?') >= 0 || strb.indexOf('livemap/?') >= 0) {
  1687. get_coords_from_livemap_link(strb);
  1688. stra = getId('sidepanel-routespeeds-a').value;
  1689. strb = getId('sidepanel-routespeeds-b').value;
  1690. pastedlink = true;
  1691. }
  1692.  
  1693. stra = getId('sidepanel-routespeeds-a').value;
  1694. strb = getId('sidepanel-routespeeds-b').value;
  1695. if (stra === "") return;
  1696. if (strb === "") return;
  1697.  
  1698. let p1 = stra.split(",");
  1699. let p2 = strb.split(",");
  1700.  
  1701. if (p1.length < 2) return;
  1702. if (p2.length < 2) return;
  1703.  
  1704. let x1 = p1[0].trim();
  1705. let y1 = p1[1].trim();
  1706. let x2 = p2[0].trim();
  1707. let y2 = p2[1].trim();
  1708.  
  1709. x1 = parseFloat(x1);
  1710. y1 = parseFloat(y1);
  1711. x2 = parseFloat(x2);
  1712. y2 = parseFloat(y2);
  1713.  
  1714. if (isNaN(x1)) return;
  1715. if (isNaN(y1)) return;
  1716. if (isNaN(x2)) return;
  1717. if (isNaN(y2)) return;
  1718.  
  1719. if (x1 < -180 || x1 > 180) x1 = 0;
  1720. if (x2 < -180 || x2 > 180) x2 = 0;
  1721. if (y1 < -90 || y1 > 90) y1 = 0;
  1722. if (y2 < -90 || y2 > 90) y2 = 0;
  1723.  
  1724. let objprog1 = getId('routespeeds-button-livemap');
  1725. objprog1.style.backgroundColor = '#FF8000';
  1726.  
  1727. createMarkers(x1, y1, x2, y2, true);
  1728.  
  1729. if (pastedlink) {
  1730. clickA();
  1731. }
  1732.  
  1733. requestRouteFromLiveMap(x1, y1, x2, y2);
  1734. }
  1735. //--------------------------------------------------------------------------------------------------------
  1736. function reverseRoute() {
  1737.  
  1738. if (routespeedsoption1) return;
  1739. if (routewait) return;
  1740.  
  1741. routewsp1 = [];
  1742. routeodc1 = [];
  1743. routewsp2 = [];
  1744. routeodc2 = [];
  1745. routewsp3 = [];
  1746. routeodc3 = [];
  1747. routewsp4 = [];
  1748. routeodc4 = [];
  1749. routewsp5 = [];
  1750. routeodc5 = [];
  1751.  
  1752. let stra = getId('sidepanel-routespeeds-b').value;
  1753. let strb = getId('sidepanel-routespeeds-a').value;
  1754. if (stra === "") return;
  1755. if (strb === "") return;
  1756.  
  1757. getId('sidepanel-routespeeds-a').value = stra;
  1758. getId('sidepanel-routespeeds-b').value = strb;
  1759.  
  1760. let p1 = stra.split(",");
  1761. let p2 = strb.split(",");
  1762.  
  1763. if (p1.length < 2) return;
  1764. if (p2.length < 2) return;
  1765.  
  1766. let x1 = p1[0].trim();
  1767. let y1 = p1[1].trim();
  1768. let x2 = p2[0].trim();
  1769. let y2 = p2[1].trim();
  1770.  
  1771. x1 = parseFloat(x1);
  1772. y1 = parseFloat(y1);
  1773. x2 = parseFloat(x2);
  1774. y2 = parseFloat(y2);
  1775.  
  1776. if (isNaN(x1)) return;
  1777. if (isNaN(y1)) return;
  1778. if (isNaN(x2)) return;
  1779. if (isNaN(y2)) return;
  1780.  
  1781. if (x1 < -180 || x1 > 180) x1 = 0;
  1782. if (x2 < -180 || x2 > 180) x2 = 0;
  1783. if (y1 < -90 || y1 > 90) y1 = 0;
  1784. if (y2 < -90 || y2 > 90) y2 = 0;
  1785.  
  1786. let objprog2 = getId('routespeeds-button-reverse');
  1787. objprog2.style.backgroundColor = '#FF8000';
  1788.  
  1789. createMarkers(x1, y1, x2, y2, true);
  1790.  
  1791. requestRouteFromLiveMap(x1, y1, x2, y2);
  1792. }
  1793. //--------------------------------------------------------------------------------------------------------
  1794. function resetOptions() {
  1795.  
  1796. getId('routespeeds-option5').checked = routespeedsoption5 = true;
  1797. getId('routespeeds-option6').value = routespeedsoption6 = 3;
  1798. getId('routespeeds-option12').checked = routespeedsoption12 = false;
  1799.  
  1800. getId('routespeeds-option7').checked = routespeedsoption7 = false;
  1801.  
  1802. getId('routespeeds-option13').value = routespeedsoption13 = 1;
  1803.  
  1804. getId('routespeeds-option8').checked = routespeedsoption8 = false;
  1805. getId('routespeeds-option9').checked = routespeedsoption9 = false;
  1806. getId('routespeeds-option10').checked = routespeedsoption10 = true;
  1807. getId('routespeeds-option11').checked = routespeedsoption11 = false;
  1808. getId('routespeeds-option14').checked = routespeedsoption14 = true;
  1809. getId('routespeeds-option15').checked = routespeedsoption15 = true;
  1810. getId('routespeeds-option16').checked = routespeedsoption16 = false;
  1811. getId('routespeeds-option17').checked = routespeedsoption17 = false;
  1812. getId('routespeeds-option18').value = routespeedsoption18 = 'PRIVATE';
  1813.  
  1814. update_adv_switches();
  1815. }
  1816. //--------------------------------------------------------------------------------------------------------
  1817. function resetOptionsToLivemapRouteClick() {
  1818. if (routewait) return;
  1819.  
  1820. resetOptions();
  1821.  
  1822. _modelPasses.forEach(pass => (getId(`routespeeds-pass-${pass.key}`).checked = false));
  1823. _settings.passes = [];
  1824.  
  1825. livemapRoute();
  1826. }
  1827. //--------------------------------------------------------------------------------------------------------
  1828. function hourChange() {
  1829.  
  1830. livemapRoute();
  1831. }
  1832. //--------------------------------------------------------------------------------------------------------
  1833. function dayChange() {
  1834.  
  1835. livemapRoute();
  1836. }
  1837. //--------------------------------------------------------------------------------------------------------
  1838. function clickA() { gotoMarker(markerA); }
  1839. function clickB() { gotoMarker(markerB); }
  1840. //--------------------------------------------------------------------------------------------------------
  1841. function gotoMarker(marker) {
  1842.  
  1843. if (routespeedsoption1 || marker === undefined || !marker.created) return;
  1844.  
  1845. let pt = marker.lonlat;
  1846. let zoom = W.map.getZoom();
  1847.  
  1848. W.map.getOLMap().setCenter([pt.lon, pt.lat], zoom);
  1849. }
  1850. //--------------------------------------------------------------------------------------------------------
  1851. function clickOption1() {
  1852. var WM = window.W.map;
  1853.  
  1854. routespeedsoption1 = (getId('routespeeds-option1').checked === true);
  1855.  
  1856. if (routespeedsoption1) {
  1857. getId('sidepanel-routespeeds').style.color = "#A0A0A0";
  1858.  
  1859. getId('routespeeds-summary1').innerHTML = '';
  1860. getId('routespeeds-summary2').innerHTML = '';
  1861. getId('routespeeds-summary3').innerHTML = '';
  1862. getId('routespeeds-summary4').innerHTML = '';
  1863. getId('routespeeds-summary5').innerHTML = '';
  1864.  
  1865. getId('routespeeds-summary1').style.visibility = 'hidden';
  1866. getId('routespeeds-summary2').style.visibility = 'hidden';
  1867. getId('routespeeds-summary3').style.visibility = 'hidden';
  1868. getId('routespeeds-summary4').style.visibility = 'hidden';
  1869. getId('routespeeds-summary5').style.visibility = 'hidden';
  1870.  
  1871. let rlayers1 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  1872. let rlayers2 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds2");
  1873. let rlayers3 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds3");
  1874. let rlayers4 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds4");
  1875. let rlayers5 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds5");
  1876. let routeLayer1 = rlayers1[0];
  1877. let routeLayer2 = rlayers2[0];
  1878. let routeLayer3 = rlayers3[0];
  1879. let routeLayer4 = rlayers4[0];
  1880. let routeLayer5 = rlayers5[0];
  1881.  
  1882. if (routeLayer1 !== undefined) routeLayer1.removeAllFeatures();
  1883. if (routeLayer2 !== undefined) routeLayer2.removeAllFeatures();
  1884. if (routeLayer3 !== undefined) routeLayer3.removeAllFeatures();
  1885. if (routeLayer4 !== undefined) routeLayer4.removeAllFeatures();
  1886. if (routeLayer5 !== undefined) routeLayer5.removeAllFeatures();
  1887.  
  1888. showMarkers(false);
  1889. showClosures(0);
  1890. }
  1891. else {
  1892. getId('sidepanel-routespeeds').style.color = "";
  1893.  
  1894. if (showMarkers(true)) livemapRoute();
  1895. showClosures(1);
  1896. }
  1897. }
  1898. //--------------------------------------------------------------------------------------------------------
  1899. function clickOption2() {
  1900. routespeedsoption2 = (getId('routespeeds-option2').checked === true);
  1901. livemapRoute();
  1902. }
  1903. //--------------------------------------------------------------------------------------------------------
  1904. function clickOption3() {
  1905. routespeedsoption3 = (getId('routespeeds-option3').checked === true);
  1906. livemapRoute();
  1907. }
  1908. //--------------------------------------------------------------------------------------------------------
  1909. function clickOption4() {
  1910. routespeedsoption4 = (getId('routespeeds-option4').checked === true);
  1911. livemapRoute();
  1912. }
  1913. //--------------------------------------------------------------------------------------------------------
  1914. function clickOption5() {
  1915. routeSelected = 1;
  1916. routeSelectedLast = 0;
  1917.  
  1918. routespeedsoption5 = (getId('routespeeds-option5').checked === true);
  1919. getId('routespeeds-option5-span').style.display = routespeedsoption5 ? 'inline' : 'none';
  1920. livemapRoute();
  1921. }
  1922. //--------------------------------------------------------------------------------------------------------
  1923. function clickOption6() {
  1924. routespeedsoption5 = (getId('routespeeds-option5').checked === true);
  1925. update_adv_switches();
  1926.  
  1927. routespeedsoption6 = parseInt(getId('routespeeds-option6').value);
  1928. livemapRoute();
  1929. }
  1930. //--------------------------------------------------------------------------------------------------------
  1931. function clickOption7() {
  1932. routespeedsoption7 = (getId('routespeeds-option7').checked === true);
  1933. livemapRoute();
  1934. }
  1935. //--------------------------------------------------------------------------------------------------------
  1936. function clickOption8() {
  1937. routespeedsoption8 = (getId('routespeeds-option8').checked === true);
  1938. livemapRoute();
  1939. }
  1940. //--------------------------------------------------------------------------------------------------------
  1941. function clickOption9() {
  1942. routespeedsoption9 = (getId('routespeeds-option9').checked === true);
  1943. livemapRoute();
  1944. }
  1945. //--------------------------------------------------------------------------------------------------------
  1946. function clickOption10() {
  1947. routespeedsoption10 = (getId('routespeeds-option10').checked === true);
  1948.  
  1949. routespeedsoption11 = false;
  1950. getId('routespeeds-option11').checked = false;
  1951.  
  1952. update_adv_switches();
  1953. livemapRoute();
  1954. }
  1955. //--------------------------------------------------------------------------------------------------------
  1956. function clickOption11() {
  1957. routespeedsoption11 = (getId('routespeeds-option11').checked === true);
  1958.  
  1959. routespeedsoption10 = false;
  1960. getId('routespeeds-option10').checked = false;
  1961.  
  1962. update_adv_switches();
  1963. livemapRoute();
  1964. }
  1965. //--------------------------------------------------------------------------------------------------------
  1966. function clickOption12() {
  1967. routespeedsoption12 = (getId('routespeeds-option12').checked === true);
  1968. livemapRoute();
  1969. }
  1970. //--------------------------------------------------------------------------------------------------------
  1971. function clickOption13() {
  1972. routespeedsoption13 = parseInt(getId('routespeeds-option13').value);
  1973. livemapRoute();
  1974. }
  1975. //--------------------------------------------------------------------------------------------------------
  1976. function clickOption14() {
  1977. routespeedsoption14 = (getId('routespeeds-option14').checked === true);
  1978. livemapRoute();
  1979. }
  1980. //--------------------------------------------------------------------------------------------------------
  1981. function clickOption15() {
  1982. routespeedsoption15 = (getId('routespeeds-option15').checked === true);
  1983. livemapRoute();
  1984. }
  1985. //--------------------------------------------------------------------------------------------------------
  1986. function clickOption16() {
  1987. routespeedsoption16 = (getId('routespeeds-option16').checked === true);
  1988. livemapRoute();
  1989. }
  1990. //--------------------------------------------------------------------------------------------------------
  1991. function clickOption17() {
  1992. routespeedsoption17 = (getId('routespeeds-option17').checked === true);
  1993. livemapRoute();
  1994. }
  1995. //--------------------------------------------------------------------------------------------------------
  1996. function clickOption18() {
  1997. routespeedsoption18 = (getId('routespeeds-option18').value);
  1998. livemapRoute();
  1999. }
  2000. //--------------------------------------------------------------------------------------------------------
  2001. function clickPassOption() {
  2002. let passKey = this.id.match(/^routespeeds-pass-(.*)/i)[1];
  2003. if (this.checked) {
  2004. _settings.passes.push(passKey);
  2005. } else {
  2006. _settings.passes = _settings.passes.filter(key => key !== passKey)
  2007. }
  2008. updatePassesLabel();
  2009. livemapRoute();
  2010. }
  2011. //--------------------------------------------------------------------------------------------------------
  2012. function clickRoute1() { toggleRoute(1); }
  2013. function clickRoute2() { toggleRoute(2); }
  2014. function clickRoute3() { toggleRoute(3); }
  2015. function clickRoute4() { toggleRoute(4); }
  2016. function clickRoute5() { toggleRoute(5); }
  2017. //--------------------------------------------------------------------------------------------------------
  2018. function toggleRoute(routeNo) {
  2019. if (routeSelected === routeNo) routeNo = 0;
  2020. routeSelectedLast = routeSelected = routeNo;
  2021. switchRoute();
  2022. }
  2023. //--------------------------------------------------------------------------------------------------------
  2024. function switchRoute() {
  2025. var WM = window.W.map;
  2026.  
  2027. if (routeSelected == 1) getId('routespeeds-summary1').className = 'routespeeds_summary_classB';
  2028. else getId('routespeeds-summary1').className = 'routespeeds_summary_classA';
  2029. if (routeSelected == 2) getId('routespeeds-summary2').className = 'routespeeds_summary_classB';
  2030. else getId('routespeeds-summary2').className = 'routespeeds_summary_classA';
  2031. if (routeSelected == 3) getId('routespeeds-summary3').className = 'routespeeds_summary_classB';
  2032. else getId('routespeeds-summary3').className = 'routespeeds_summary_classA';
  2033. if (routeSelected == 4) getId('routespeeds-summary4').className = 'routespeeds_summary_classB';
  2034. else getId('routespeeds-summary4').className = 'routespeeds_summary_classA';
  2035. if (routeSelected == 5) getId('routespeeds-summary5').className = 'routespeeds_summary_classB';
  2036. else getId('routespeeds-summary5').className = 'routespeeds_summary_classA';
  2037.  
  2038. let rlayers1 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  2039. let rlayers2 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds2");
  2040. let rlayers3 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds3");
  2041. let rlayers4 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds4");
  2042. let rlayers5 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds5");
  2043. let routeLayer1 = rlayers1[0];
  2044. let routeLayer2 = rlayers2[0];
  2045. let routeLayer3 = rlayers3[0];
  2046. let routeLayer4 = rlayers4[0];
  2047. let routeLayer5 = rlayers5[0];
  2048. if (routeLayer1 === undefined) return;
  2049. if (routeLayer2 === undefined) return;
  2050. if (routeLayer3 === undefined) return;
  2051. if (routeLayer4 === undefined) return;
  2052. if (routeLayer5 === undefined) return;
  2053.  
  2054. let style1 = routeLayer1.styleMap.styles.default.defaultStyle;
  2055. let style2 = routeLayer2.styleMap.styles.default.defaultStyle;
  2056. let style3 = routeLayer3.styleMap.styles.default.defaultStyle;
  2057. let style4 = routeLayer4.styleMap.styles.default.defaultStyle;
  2058. let style5 = routeLayer5.styleMap.styles.default.defaultStyle;
  2059.  
  2060. let s1 = style1.strokeColor;
  2061. let s2 = style2.strokeColor;
  2062. let s3 = style3.strokeColor;
  2063. let s4 = style4.strokeColor;
  2064. let s5 = style5.strokeColor;
  2065.  
  2066. let t1 = style1.label;
  2067. let t2 = style2.label;
  2068. let t3 = style3.label;
  2069. let t4 = style4.label;
  2070. let t5 = style5.label;
  2071.  
  2072. style1.strokeColor = '#4d4dcd';
  2073. style2.strokeColor = '#d34f8a';
  2074. style3.strokeColor = '#188984';
  2075. style4.strokeColor = '#cafa27';
  2076. style5.strokeColor = '#ffca3f';
  2077. //style1.strokeColor = '#76768f';
  2078. //style2.strokeColor = '#917682';
  2079. //style3.strokeColor = '#6b8a88';
  2080. //style4.strokeColor = '#998f73';
  2081. //style5.strokeColor = '#769178';
  2082. //style1.strokeColor = '#7070a0';
  2083. //style2.strokeColor = '#a07070';
  2084. //style3.strokeColor = '#70a070';
  2085. //style4.strokeColor = '#a0a070';
  2086. //style5.strokeColor = '#a070a0';
  2087. style1.strokeWidth = 5;
  2088. style2.strokeWidth = 5;
  2089. style3.strokeWidth = 5;
  2090. style4.strokeWidth = 5;
  2091. style5.strokeWidth = 5;
  2092. style1.label = '';
  2093. style2.label = '';
  2094. style3.label = '';
  2095. style4.label = '';
  2096. style5.label = '';
  2097.  
  2098. if (routeSelected === 0 || routeSelected === 1) { style1.strokeColor = '${strokeColor}'; style1.strokeWidth = '${strokeWidth}'; style1.label = '${labelText}'; }
  2099. if (routeSelected === 0 || routeSelected === 2) { style2.strokeColor = '${strokeColor}'; style2.strokeWidth = '${strokeWidth}'; style2.label = '${labelText}'; }
  2100. if (routeSelected === 0 || routeSelected === 3) { style3.strokeColor = '${strokeColor}'; style3.strokeWidth = '${strokeWidth}'; style3.label = '${labelText}'; }
  2101. if (routeSelected === 0 || routeSelected === 4) { style4.strokeColor = '${strokeColor}'; style4.strokeWidth = '${strokeWidth}'; style4.label = '${labelText}'; }
  2102. if (routeSelected === 0 || routeSelected === 5) { style5.strokeColor = '${strokeColor}'; style5.strokeWidth = '${strokeWidth}'; style5.label = '${labelText}'; }
  2103.  
  2104. let z1 = parseInt(routeLayer1.getZIndex());
  2105. let z2 = parseInt(routeLayer2.getZIndex());
  2106. let z3 = parseInt(routeLayer3.getZIndex());
  2107. let z4 = parseInt(routeLayer4.getZIndex());
  2108. let z5 = parseInt(routeLayer5.getZIndex());
  2109. let z;
  2110.  
  2111. if (z1 > z2) { z = z1; z1 = z2; z2 = z; }
  2112. if (z1 > z3) { z = z1; z1 = z3; z3 = z; }
  2113. if (z1 > z4) { z = z1; z1 = z4; z4 = z; }
  2114. if (z1 > z5) { z = z1; z1 = z5; z5 = z; }
  2115. if (z2 > z3) { z = z2; z2 = z3; z3 = z; }
  2116. if (z2 > z4) { z = z2; z2 = z4; z4 = z; }
  2117. if (z2 > z5) { z = z2; z2 = z5; z5 = z; }
  2118. if (z3 > z4) { z = z3; z3 = z4; z4 = z; }
  2119. if (z3 > z5) { z = z3; z3 = z5; z5 = z; }
  2120. if (z4 > z5) { z = z4; z4 = z5; z5 = z; }
  2121.  
  2122. //wlodek76: finding closure layer and changing its zindex to hide it under Route Speeds layer
  2123. // we cannot easily set route speed layer over markers because it will block access to elements on these layers
  2124. let clayers = WM.getLayersBy("uniqueName", "closures");
  2125. if (clayers[0] !== undefined && closurelayer === null) {
  2126.  
  2127. closurelayer = clayers[0];
  2128. closurelayerZINDEX[0] = clayers[0].getZIndex();
  2129. closurelayerZINDEX[1] = z1 - 5;
  2130.  
  2131. closurelayer.setZIndex(closurelayerZINDEX[1]);
  2132. closurelayer.redraw();
  2133. }
  2134.  
  2135. if (routeSelected <= 1) { routeLayer1.setZIndex(z5); routeLayer2.setZIndex(z4); routeLayer3.setZIndex(z3); routeLayer4.setZIndex(z2); routeLayer5.setZIndex(z1); }
  2136. if (routeSelected === 2) { routeLayer1.setZIndex(z4); routeLayer2.setZIndex(z5); routeLayer3.setZIndex(z3); routeLayer4.setZIndex(z2); routeLayer5.setZIndex(z1); }
  2137. if (routeSelected === 3) { routeLayer1.setZIndex(z4); routeLayer2.setZIndex(z3); routeLayer3.setZIndex(z5); routeLayer4.setZIndex(z2); routeLayer5.setZIndex(z1); }
  2138. if (routeSelected === 4) { routeLayer1.setZIndex(z4); routeLayer2.setZIndex(z3); routeLayer3.setZIndex(z2); routeLayer4.setZIndex(z5); routeLayer5.setZIndex(z1); }
  2139. if (routeSelected === 5) { routeLayer1.setZIndex(z4); routeLayer2.setZIndex(z3); routeLayer3.setZIndex(z2); routeLayer4.setZIndex(z1); routeLayer5.setZIndex(z5); }
  2140.  
  2141. if (t1 !== style1.label || s1 !== style1.strokeColor) routeLayer1.redraw();
  2142. if (t2 !== style2.label || s2 !== style2.strokeColor) routeLayer2.redraw();
  2143. if (t3 !== style3.label || s3 !== style3.strokeColor) routeLayer3.redraw();
  2144. if (t4 !== style4.label || s4 !== style4.strokeColor) routeLayer4.redraw();
  2145. if (t5 !== style5.label || s5 !== style5.strokeColor) routeLayer5.redraw();
  2146. }
  2147. //--------------------------------------------------------------------------------------------------------
  2148. function showClosures(mode) {
  2149. if (closurelayer !== null && closurelayerZINDEX.length == 2) {
  2150. closurelayer.setZIndex(closurelayerZINDEX[mode]);
  2151. closurelayer.redraw();
  2152. }
  2153. }
  2154. //--------------------------------------------------------------------------------------------------------
  2155. function rezoom() {
  2156.  
  2157. var WM = window.W.map;
  2158.  
  2159. var rlayers1 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds1");
  2160. var rlayers2 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds2");
  2161. var rlayers3 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds3");
  2162. var rlayers4 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds4");
  2163. var rlayers5 = WM.getLayersBy("uniqueName", "__DrawRouteSpeeds5");
  2164.  
  2165. var routeLayer1 = rlayers1[0];
  2166. var routeLayer2 = rlayers2[0];
  2167. var routeLayer3 = rlayers3[0];
  2168. var routeLayer4 = rlayers4[0];
  2169. var routeLayer5 = rlayers5[0];
  2170.  
  2171. if (routeLayer1 !== undefined) routeLayer1.removeAllFeatures();
  2172. if (routeLayer2 !== undefined) routeLayer2.removeAllFeatures();
  2173. if (routeLayer3 !== undefined) routeLayer3.removeAllFeatures();
  2174. if (routeLayer4 !== undefined) routeLayer4.removeAllFeatures();
  2175. if (routeLayer5 !== undefined) routeLayer5.removeAllFeatures();
  2176.  
  2177. getId('routespeeds-summary1').innerHTML = '';
  2178. getId('routespeeds-summary2').innerHTML = '';
  2179. getId('routespeeds-summary3').innerHTML = '';
  2180. getId('routespeeds-summary4').innerHTML = '';
  2181. getId('routespeeds-summary5').innerHTML = '';
  2182.  
  2183. getId('routespeeds-summary1').className = 'routespeeds_summary_classA';
  2184. getId('routespeeds-summary2').className = 'routespeeds_summary_classA';
  2185. getId('routespeeds-summary3').className = 'routespeeds_summary_classA';
  2186. getId('routespeeds-summary4').className = 'routespeeds_summary_classA';
  2187. getId('routespeeds-summary5').className = 'routespeeds_summary_classA';
  2188.  
  2189. getId('routespeeds-summary1').style.visibility = 'hidden';
  2190. getId('routespeeds-summary2').style.visibility = 'hidden';
  2191. getId('routespeeds-summary3').style.visibility = 'hidden';
  2192. getId('routespeeds-summary4').style.visibility = 'hidden';
  2193. getId('routespeeds-summary5').style.visibility = 'hidden';
  2194.  
  2195. switchRoute();
  2196.  
  2197. if (routewsp1.length >= 2 && routeodc1.length >= 1) {
  2198. createRouteFeatures(1, routewsp1, routeodc1);
  2199. }
  2200.  
  2201. if (routewsp2.length >= 2 && routeodc2.length >= 1) {
  2202. createRouteFeatures(2, routewsp2, routeodc2);
  2203. }
  2204.  
  2205. if (routewsp3.length >= 2 && routeodc3.length >= 1) {
  2206. createRouteFeatures(3, routewsp3, routeodc3);
  2207. }
  2208.  
  2209. if (routewsp4.length >= 2 && routeodc4.length >= 1) {
  2210. createRouteFeatures(4, routewsp4, routeodc4);
  2211. }
  2212.  
  2213. if (routewsp5.length >= 2 && routeodc5.length >= 1) {
  2214. createRouteFeatures(5, routewsp5, routeodc5);
  2215.  
  2216. }
  2217. }
  2218. //--------------------------------------------------------------------------------------------------------
  2219. function enterAB(ev) {
  2220. if (ev.keyCode === 13) {
  2221. livemapRoute();
  2222. }
  2223. }
  2224. //--------------------------------------------------------------------------------------------------------
  2225. function getCheckboxHtml(idSuffix, text, title, divCss = {}, labelCss = {}) {
  2226. let id = 'routespeeds-' + idSuffix;
  2227. return $('<div>', { class: 'controls-container' }).append(
  2228. $('<input>', { id: id, type: 'checkbox', title: title }),
  2229. $('<label>', { for: id }).text(text).css(labelCss)
  2230. ).css(divCss)[0].outerHTML;
  2231. }
  2232. //--------------------------------------------------------------------------------------------------------
  2233. async function initialiseWMERouteSpeeds() {
  2234. var line_div_break = '<br>';
  2235. line_div_break += '</div>';
  2236. line_div_break += '<div style="margin-left:55px">';
  2237.  
  2238. if (typeof W === 'undefined') W = window.W;
  2239. if (typeof W.loginManager === 'undefined') W.loginManager = window.W.loginManager;
  2240. if (typeof W.loginManager === 'undefined') W.loginManager = window.loginManager;
  2241. if (W.loginManager !== null && W.loginManager.user) {
  2242. var user = W.loginManager.user;
  2243. //console.log(user);
  2244.  
  2245. //wlodek76: I prefer more condensed lines for avoid options, so I've added a personal switch here
  2246. if (user !== null) {
  2247. if (user.userName === "wlodek76" && user.id === 203457007) {
  2248. line_div_break = '';
  2249. }
  2250. }
  2251. }
  2252.  
  2253. var addon = document.createElement('section');
  2254. addon.id = "routespeeds-addon";
  2255. addon.innerHTML = '' +
  2256. '<div id="sidepanel-routespeeds" style="margin: 0px 8px; width: auto;">' +
  2257. '<div style="margin-bottom:4px; padding:0px;"><a href="https://greasyfork.org/en/scripts/369630-wme-route-speeds-mapomatic-fork" target="_blank">' +
  2258. '<span style="font-weight:bold; text-decoration:underline">WME Route Speeds</span></a><span style="margin-left:6px; color:#888; font-size:11px;">v' + wmech_version + '</span>' +
  2259. '</div>' +
  2260. '<style>\n' +
  2261. '#sidepanel-routespeeds select { margin-left:20px; font-size:12px; height:22px; border:1px solid; border-color:rgb(169, 169, 169); border-radius:4px; border: 1px solid; border-color: rgb(169, 169, 169); -webkit-border-radius:4px; -moz-border-radius:4px; }\n' +
  2262. '#sidepanel-routespeeds select, #sidepanel-routespeeds input { margin-top:2px; margin-bottom:2px; width:initial; }\n' +
  2263. '#sidepanel-routespeeds input[type="checkbox"] { margin-bottom:0px; }\n' +
  2264. '#sidepanel-routespeeds label ~ label, #sidepanel-routespeeds span label { margin-left:20px; }\n' +
  2265. '#sidepanel-routespeeds .controls-container { padding:0px; }\n' +
  2266. '#sidepanel-routespeeds label { font-weight:normal; }\n' +
  2267. '</style>' +
  2268. '<div style="float:left; display:inline-block;">' +
  2269. '<a id="routespeeds-button-A" onclick="return false;" style="cursor:pointer; width:20px; display:inline-block; vertical-align:middle;" title="Center map on A marker">A:</a>' +
  2270. '<input id="sidepanel-routespeeds-a" class="form-control" style="width:165px; padding:6px; margin:0px; display:inline; height:24px" type="text" name=""/>' +
  2271. '<br><div style="height: 4px;"></div>' +
  2272. '<a id="routespeeds-button-B" onclick="return false;" style="cursor:pointer; width:20px; display:inline-block; vertical-align:middle;" title="Center map on B marker">B:</a>' +
  2273. '<input id="sidepanel-routespeeds-b" class="form-control" style="width:165px; padding:6px; margin:0px; display:inline; height:24px" type="text" name=""/>' +
  2274. '</div>' +
  2275. '<div style="float:right; padding-right:20px; padding-top:6%; ">' +
  2276. '<button id=routespeeds-button-reverse class="waze-btn waze-btn-blue waze-btn-smaller" style="padding-left:15px; padding-right:15px;" title="Calculate reverse route" >A &#8596; B</button></div>' +
  2277. '<div style="clear:both; "></div>' +
  2278.  
  2279. '<div style="margin-top:8px;">' +
  2280. '<select id=routespeeds-hour>' +
  2281. '<option value="now">Now</option>' +
  2282. '<option value="0" >00:00</option>' +
  2283. '<option value="30" >00:30</option>' +
  2284. '<option value="60" >01:00</option>' +
  2285. '<option value="90" >01:30</option>' +
  2286. '<option value="120">02:00</option>' +
  2287. '<option value="150">02:30</option>' +
  2288. '<option value="180">03:00</option>' +
  2289. '<option value="210">03:30</option>' +
  2290. '<option value="240">04:00</option>' +
  2291. '<option value="270">04:30</option>' +
  2292. '<option value="300">05:00</option>' +
  2293. '<option value="330">05:30</option>' +
  2294. '<option value="360">06:00</option>' +
  2295. '<option value="390">06:30</option>' +
  2296. '<option value="420">07:00</option>' +
  2297. '<option value="450">07:30</option>' +
  2298. '<option value="480">08:00</option>' +
  2299. '<option value="510">08:30</option>' +
  2300. '<option value="540">09:00</option>' +
  2301. '<option value="570">09:30</option>' +
  2302. '<option value="600">10:00</option>' +
  2303. '<option value="630">10:30</option>' +
  2304. '<option value="660">11:00</option>' +
  2305. '<option value="690">11:30</option>' +
  2306. '<option value="720">12:00</option>' +
  2307. '<option value="750">12:30</option>' +
  2308. '<option value="780">13:00</option>' +
  2309. '<option value="810">13:30</option>' +
  2310. '<option value="840">14:00</option>' +
  2311. '<option value="870">14:30</option>' +
  2312. '<option value="900">15:00</option>' +
  2313. '<option value="930">15:30</option>' +
  2314. '<option value="960">16:00</option>' +
  2315. '<option value="990">16:30</option>' +
  2316. '<option value="1020">17:00</option>' +
  2317. '<option value="1050">17:30</option>' +
  2318. '<option value="1080">18:00</option>' +
  2319. '<option value="1110">18:30</option>' +
  2320. '<option value="1140">19:00</option>' +
  2321. '<option value="1170">19:30</option>' +
  2322. '<option value="1200">20:00</option>' +
  2323. '<option value="1230">20:30</option>' +
  2324. '<option value="1260">21:00</option>' +
  2325. '<option value="1290">21:30</option>' +
  2326. '<option value="1320">22:00</option>' +
  2327. '<option value="1350">22:30</option>' +
  2328. '<option value="1380">23:00</option>' +
  2329. '<option value="1410">23:30</option>' +
  2330. '</select>' +
  2331. '<select id=routespeeds-day style="margin-left:5px;" >' +
  2332. '<option value="today">Today</option>' +
  2333. '<option value="1">Monday</option>' +
  2334. '<option value="2">Tuesday</option>' +
  2335. '<option value="3">Wednesday</option>' +
  2336. '<option value="4">Thursday</option>' +
  2337. '<option value="5">Friday</option>' +
  2338. '<option value="6">Saturday</option>' +
  2339. '<option value="0">Sunday</option>' +
  2340. '</select>' +
  2341. '</div>' +
  2342.  
  2343. '<div style="padding-top:8px; padding-bottom:6px;">' +
  2344. '<button id=routespeeds-button-livemap class="waze-btn waze-btn-blue waze-btn-smaller" style="width:100%;">Calculate Route</button>' +
  2345. '</div>' +
  2346. '<b><div id=routespeeds-error style="color:#FF0000"></div></b>' +
  2347. '<div id=routespeeds-summary1 class=routespeeds_summary_classA></div>' +
  2348. '<div id=routespeeds-summary2 class=routespeeds_summary_classA></div>' +
  2349. '<div id=routespeeds-summary3 class=routespeeds_summary_classA></div>' +
  2350. '<div id=routespeeds-summary4 class=routespeeds_summary_classA></div>' +
  2351. '<div id=routespeeds-summary5 class=routespeeds_summary_classA></div>' +
  2352.  
  2353. '<div style="margin-bottom:4px;">' +
  2354. '<b>Options:</b>' +
  2355. '<a id="routespeeds-reset-options-to-livemap-route" onclick="return false;" style="cursor:pointer; float:right; margin-right:20px;" title="Reset routing options to the Livemap Route equivalents">Reset to Livemap Route</a>' +
  2356. '</div>' +
  2357.  
  2358. getCheckboxHtml('option1', 'Disable script') +
  2359. getCheckboxHtml('option3', 'Hide labels') +
  2360. getCheckboxHtml('option2', 'Show cross-times through segments') +
  2361. getCheckboxHtml('option4', 'Speed in mph') +
  2362.  
  2363. '<div>' +
  2364. getCheckboxHtml('option5', 'Alternative routes', '', { display: 'inline-block' }) +
  2365. '<select id=routespeeds-option6 style="margin-left:10px; display:inline-block; height:18px;" >' +
  2366. '<option id=routespeeds-option6 value="1">1</option>' +
  2367. '<option id=routespeeds-option6 value="2">2</option>' +
  2368. '<option id=routespeeds-option6 value="3">3</option>' +
  2369. '<option id=routespeeds-option6 value="4">4</option>' +
  2370. '<option id=routespeeds-option6 value="5">5</option>' +
  2371. '</select>' +
  2372.  
  2373. '<span id="routespeeds-option5-span" style="display:none;">' +
  2374. getCheckboxHtml('option12', 'Try more', 'When enabled, ten times more alternative routes are requested from the routing server.&#13;This usually increases the request time, but sometimes provides interesting routes...',
  2375. { display: 'inline-block' }, { marginLeft: '10px', paddingLeft: '17px' }) +
  2376. '</span>' +
  2377. '</div>' +
  2378.  
  2379. getCheckboxHtml('option7', 'Real-Time Traffic', 'note: this only seems to affect routes within the last 30-60 minutes, up to Now') +
  2380. getCheckboxHtml('option15', 'Use Routing Order', 'Sorts routes in the same order they would appear in the app or livemap') +
  2381.  
  2382. '<div>' +
  2383. '<label class="" style="display:inline-block;">' +
  2384. 'Route type:<select id=routespeeds-option13 style="margin-left:10px;" >' +
  2385. '<option value="1">Fastest</option>' +
  2386. '<option value="3">Fastest (no history)</option>' +
  2387. '</select>' +
  2388. '<br>' +
  2389. 'Vehicle type:<select id=routespeeds-option18 style="margin-left:10px;" >' +
  2390. '<option id=routespeeds-option18 value="PRIVATE">Private</option>' +
  2391. '<option id=routespeeds-option18 value="TAXI">Taxi</option>' +
  2392. '<option id=routespeeds-option18 value="MOTORCYCLE">Motorcycle</option>' +
  2393. '</select>' +
  2394. '</div>' +
  2395.  
  2396. '<table><tbody><tr><td style="vertical-align:top; padding-right:4px;"><b>Avoid:</b></td><td>' +
  2397. getCheckboxHtml('option8', 'Tolls') +
  2398. getCheckboxHtml('option9', 'Freeways') +
  2399. getCheckboxHtml('option16', 'Difficult turns') +
  2400. getCheckboxHtml('option17', 'Ferries') +
  2401. getCheckboxHtml('option10', 'Unpaved') +
  2402. '<div id="routespeeds-option10-span" style="display:none;">' +
  2403. getCheckboxHtml('option11', 'Long unpaved roads', '', { marginLeft: '10px' }) +
  2404. '</div>' +
  2405. '</td></tr></tbody></table>' +
  2406.  
  2407. '<table style="margin-top:3px;"><tbody><tr><td style="vertical-align:top; padding-right:4px;"><b>Allow:</b></td><td>' +
  2408. getCheckboxHtml('option14', 'U-Turns') +
  2409. '</td></tr></tbody></table>' +
  2410. '<div id="routespeeds-passes-container"></div>' +
  2411. '<style>' +
  2412. '.routespeedsmarkerA { display:block; width:27px; height:36px; margin-left:-13px; margin-top:-34px; }' +
  2413. '.routespeedsmarkerB { display:block; width:27px; height:36px; margin-left:-13px; margin-top:-34px; }' +
  2414. //+ '.routespeedsmarkerA { background:url("http://341444cc-a-62cb3a1a-s-sites.googlegroups.com/site/wazeaddons/routespeeds_marker_a.png"); }'
  2415. //+ '.routespeedsmarkerB { background:url("http://341444cc-a-62cb3a1a-s-sites.googlegroups.com/site/wazeaddons/routespeeds_marker_b.png"); }'
  2416. '.routespeedsmarkerA { background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAkCAYAAAB4+EEtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAD/mlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjajZTPbxRlGMc/u/POrAk4B1MBi8G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over { cursor:move }' +
  2420. '.routespeeds_summary_classA { visibility:hidden; display:inline-block; color:#000000; margin:2px 0px 2px 0px; padding:2px 6px 2px 4px; border:1px solid #c0c0c0; background:#F8F8F8; border-radius:4px; vertical-align:middle; white-space:nowrap; }' +
  2421. '.routespeeds_summary_classB { visibility:hidden; display:inline-block; color:#000000; margin:2px 0px 2px 0px; padding:2px 6px 2px 4px; border:1px solid #c0c0c0; background:#d0fffe; border-radius:4px; vertical-align:middle; white-space:nowrap; }' +
  2422. '.routespeeds_summary_classA:hover { cursor:pointer; border:1px solid #808080; xbackground:#a0fffd; }' +
  2423. '.routespeeds_summary_classB:hover { cursor:pointer; border:1px solid #808080; xbackground:#a0fffd; }' +
  2424. '.routespeeds_header { display:inline-block; width:14px; height:14px; text-align:center; border-radius:2px; margin-right:2px; position:relative; top:2px; }' +
  2425. '</style>' +
  2426. '</div>';
  2427.  
  2428. /*var userTabs = getId('user-info');
  2429. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  2430. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  2431.  
  2432. newtab = document.createElement('li');
  2433. newtab.innerHTML = '<a id=sidepanel-routespeeds href="#sidepanel-routespeeds" data-toggle="tab" style="" >Route Speeds</a>';
  2434. navTabs.appendChild(newtab);
  2435.  
  2436. addon.id = "sidepanel-routespeeds";
  2437. addon.className = "tab-pane";
  2438. tabContent.appendChild(addon);*/
  2439.  
  2440. $('head').append([
  2441. '<style>',
  2442. 'label[for^="routespeeds-"] { margin-right: 10px;padding-left: 19px; }',
  2443. '.hidden { display:none; }',
  2444. '</style>'
  2445. ].join('\n'));
  2446.  
  2447. WazeWrap.Interface.Tab('Route Speeds', addon.innerHTML, init, '<span id="routespeeds-tab-label">Route Speeds</span>');
  2448.  
  2449. window.addEventListener("beforeunload", saveRouteSpeedsOptions, true);
  2450. }
  2451.  
  2452. let _lastTopCountryId;
  2453. function buildPassesDiv() {
  2454. $('#routespeeds-passes-container').empty();
  2455. let passesObj = W.model.getTopCountry().restrictionSubscriptions;
  2456. if (passesObj) {
  2457. _modelPasses = Object.keys(passesObj).map(key => { return { key: key, name: passesObj[key] } }).sort((a, b) => {
  2458. if (a.name > b.name) {
  2459. return 1;
  2460. } else if (a.name < b.name) {
  2461. return -1;
  2462. }
  2463. return 0;
  2464. });
  2465. } else {
  2466. _modelPasses = [];
  2467. }
  2468.  
  2469. if (_modelPasses.length) {
  2470. $('#routespeeds-passes-container').append(
  2471. '<fieldset style="border:1px solid silver;padding:8px;border-radius:4px;-webkit-padding-before: 0;">' +
  2472. ' <legend id="routespeeds-passes-legend" style="margin-bottom:0px;border-bottom-style:none;width:auto;">' +
  2473. ' <i class="fa fa-fw fa-chevron-down" style="cursor: pointer;font-size: 12px;margin-right: 4px"></i>' +
  2474. ' <span id="routespeeds-passes-label" style="font-size:14px;font-weight:600; cursor: pointer">Passes & Permits</span>' +
  2475. ' </legend>' +
  2476. ' <div id="routespeeds-passes-internal-container" style="padding-top:0px;">' +
  2477. _modelPasses.map(pass => {
  2478. let id = 'routespeeds-pass-' + pass.key;
  2479. return ' <div class="controls-container" style="padding-top:2px;display:block;">' +
  2480. ' <input id="' + id + '" type="checkbox" class="routespeeds-pass-checkbox">' +
  2481. ' <label for="' + id + '" style="white-space:pre-line">' + pass.name + '</label>' +
  2482. ' </div>';
  2483. }).join(' ') +
  2484. ' </div>' +
  2485. '</fieldset>'
  2486. );
  2487.  
  2488. _modelPasses.forEach(pass => {
  2489. $(`#routespeeds-pass-${pass.key}`).click(clickPassOption);
  2490. });
  2491.  
  2492. $('#routespeeds-passes-legend').click(function () {
  2493. let $this = $(this);
  2494. let $chevron = $($this.children()[0]);
  2495. $chevron
  2496. .toggleClass('fa fa-fw fa-chevron-down')
  2497. .toggleClass('fa fa-fw fa-chevron-right');
  2498. let collapse = $chevron.hasClass('fa-chevron-right');
  2499. let checkboxDivs = $('input.routespeeds-pass-checkbox:not(:checked)').parent();
  2500. if (collapse) {
  2501. checkboxDivs.addClass('hidden');
  2502. } else {
  2503. checkboxDivs.removeClass('hidden');
  2504. }
  2505. // $($this.children()[0])
  2506. // .toggleClass('fa fa-fw fa-chevron-down')
  2507. // .toggleClass('fa fa-fw fa-chevron-right');
  2508. // $($this.siblings()[0]).toggleClass('collapse');
  2509. })
  2510.  
  2511. _modelPasses.forEach(pass => $(`#routespeeds-pass-${pass.key}`).prop('checked', _settings.passes.indexOf(pass.key) > -1));
  2512. updatePassesLabel();
  2513. }
  2514. }
  2515.  
  2516.  
  2517. function onModelMergeEnd() {
  2518. // Detect when the "top" country changes and update the list of passes.
  2519. try {
  2520. const topCountry = W.model.getTopCountry();
  2521. if (topCountry && topCountry.id !== _lastTopCountryId) {
  2522. _lastTopCountryId = topCountry.id;
  2523. buildPassesDiv();
  2524. }
  2525. } catch (ex) {
  2526. console.error('WME Route Speeds error: ', ex);
  2527. }
  2528. }
  2529.  
  2530. function init() {
  2531. resetOptions();
  2532. loadRouteSpeedsOptions();
  2533.  
  2534. if (routespeedsoption1) getId('sidepanel-routespeeds').style.color = "#A0A0A0";
  2535. else getId('sidepanel-routespeeds').style.color = "";
  2536.  
  2537. getId('routespeeds-option6').value = routespeedsoption6;
  2538. getId('routespeeds-option13').value = routespeedsoption13;
  2539. getId('routespeeds-option18').value = routespeedsoption18;
  2540.  
  2541. getId('routespeeds-option1').onclick = clickOption1;
  2542. getId('routespeeds-option2').onclick = clickOption2;
  2543. getId('routespeeds-option3').onclick = clickOption3;
  2544. getId('routespeeds-option4').onclick = clickOption4;
  2545. getId('routespeeds-option5').onclick = clickOption5;
  2546. getId('routespeeds-option6').onchange = clickOption6;
  2547. getId('routespeeds-option7').onclick = clickOption7;
  2548. getId('routespeeds-option8').onclick = clickOption8;
  2549. getId('routespeeds-option9').onclick = clickOption9;
  2550. getId('routespeeds-option10').onclick = clickOption10;
  2551. getId('routespeeds-option11').onclick = clickOption11;
  2552. getId('routespeeds-option12').onclick = clickOption12;
  2553. getId('routespeeds-option13').onchange = clickOption13;
  2554. getId('routespeeds-option14').onclick = clickOption14;
  2555. getId('routespeeds-option15').onclick = clickOption15;
  2556. getId('routespeeds-option16').onclick = clickOption16;
  2557. getId('routespeeds-option17').onclick = clickOption17;
  2558. getId('routespeeds-option18').onchange = clickOption18;
  2559.  
  2560. getId('routespeeds-summary1').onclick = clickRoute1;
  2561. getId('routespeeds-summary2').onclick = clickRoute2;
  2562. getId('routespeeds-summary3').onclick = clickRoute3;
  2563. getId('routespeeds-summary4').onclick = clickRoute4;
  2564. getId('routespeeds-summary5').onclick = clickRoute5;
  2565.  
  2566. getId('sidepanel-routespeeds-a').onkeydown = enterAB;
  2567. getId('sidepanel-routespeeds-b').onkeydown = enterAB;
  2568.  
  2569. getId('routespeeds-button-livemap').onclick = livemapRouteClick;
  2570. getId('routespeeds-button-reverse').onclick = reverseRoute;
  2571. getId('routespeeds-reset-options-to-livemap-route').onclick = resetOptionsToLivemapRouteClick;
  2572.  
  2573. getId('routespeeds-hour').onchange = hourChange;
  2574. getId('routespeeds-day').onchange = dayChange;
  2575.  
  2576. getId('routespeeds-button-A').onclick = clickA;
  2577. getId('routespeeds-button-B').onclick = clickB;
  2578.  
  2579. const topCountry = W.model.getTopCountry();
  2580. if (topCountry) {
  2581. _lastTopCountryId = topCountry.id;
  2582. buildPassesDiv();
  2583. }
  2584.  
  2585. // window.W.map.events.register("zoomend", null, rezoom);
  2586. WazeWrap.Events.register('zoomend', null, rezoom);
  2587. W.model.events.register('mergeend', null, onModelMergeEnd);
  2588.  
  2589. window.setInterval(loopWMERouteSpeeds, 500);
  2590. window.setInterval(panningWMERouteSpeeds, 100);
  2591. }
  2592. //--------------------------------------------------------------------------------------------------------------
  2593. bootstrapWMERouteSpeeds();
  2594. })();