Greasy Fork镜像 支持简体中文。

WME Route Speeds (MapOMatic fork)

Shows segment speeds in a route.

目前為 2019-10-30 提交的版本,檢視 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址