Greasy Fork is available in English.

WME Route Speeds (MapOMatic fork)

Shows segment speeds in a route.

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

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