WME Color Highlights

Adds colours to road segments to show their status

当前为 2016-02-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME Color Highlights
  3. // @namespace http://userscripts.org/users/419370
  4. // @description Adds colours to road segments to show their status
  5. // @include https://www.waze.com/editor/*
  6. // @include https://www.waze.com/*/editor/*
  7. // @include https://editor-beta.waze.com/*
  8. // @version 2.6
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function()
  13. {
  14.  
  15. // global variables
  16. var wmech_version = "2.6"
  17.  
  18. var advancedMode = false;
  19. var betaMode = /editor-beta.waze.com/.test(location.hostname);
  20. var lastModified = false;
  21. var selectedLines = [];
  22. var wmechinit = false;
  23.  
  24. /* =========================================================================== */
  25. function highlightSegments(event) {
  26. var showLocked = getId('_cbHighlightLocked').checked;
  27. var showToll = getId('_cbHighlightToll').checked;
  28. var showNoCity = getId('_cbHighlightNoCity').checked;
  29. var showAltName = getId('_cbHighlightAltName').checked;
  30. var showNoName = getId('_cbHighlightUnnamed').checked;
  31. var showOneWay = getId('_cbHighlightOneWay').checked;
  32. var showNoDirection = getId('_cbHighlightNoDirection').checked;
  33. var showRestrictions = getId('_cbHighlightRestrictions').checked;
  34. var showSpeedLimits = getId('_cbHighlightSpeedLimits').checked;
  35. var plusStreets = getId('_cbHighlightPlusStreetLimits').checked;
  36. var specificCity = getId('_cbHighlightCity').checked;
  37. var specificCityInvert = getId('_cbHighlightCityInvert').checked;
  38. var specificRoadType = getId('_cbHighlightRoadType').checked;
  39. var showNoTerm = getId('_cbHighlightNoTerm').checked;
  40. var showRoutingPref = getId('_cbHighlightRoutingPref').checked;
  41. var showRecent = advancedMode ? getId('_cbHighlightRecent').checked : false;
  42. var specificEditor = getId('_cbHighlightEditor').checked;
  43.  
  44. // master switch when all options are off
  45. if (event && event.type && event.type == 'click') {
  46. if ( (showLocked | showToll | showNoCity | showNoName | showAltName | showOneWay | showNoDirection | showRestrictions
  47. | specificCity | specificEditor | specificRoadType | showNoTerm | showRecent | showSpeedLimits) == false) {
  48. for (var seg in Waze.model.segments.objects) {
  49. var segment = Waze.model.segments.get(seg);
  50. var line = getId(segment.geometry.id);
  51.  
  52. if (line === null) {
  53. continue;
  54. }
  55.  
  56. // turn off all highlights
  57. var opacity = line.getAttribute("stroke-opacity");
  58. if (opacity > 0.1 && opacity < 1) {
  59. line.setAttribute("stroke","#dd7700");
  60. line.setAttribute("stroke-opacity",0.001);
  61. line.setAttribute("stroke-dasharray", "none");
  62. }
  63. }
  64. return;
  65. }
  66. }
  67. var today = new Date();
  68. var recentDays;
  69. var selectedUserId = null;
  70. var selectedCityId = null;
  71. if (specificEditor) {
  72. var selectUser = getId('_selectUser');
  73. if (selectUser.selectedIndex >= 0)
  74. selectedUserId = selectUser.options[selectUser.selectedIndex].value;
  75. else
  76. specificEditor = false;
  77. }
  78.  
  79. if (specificCity) {
  80. var selectCity = getId('_selectCity');
  81. if (selectCity.selectedIndex >= 0)
  82. selectedCityId = selectCity.options[selectCity.selectedIndex].value;
  83. else
  84. specificCity = false;
  85. }
  86.  
  87. if (specificRoadType) {
  88. var selectRoadType = getId('_selectRoadType');
  89. if (selectRoadType.selectedIndex >= 0)
  90. selectedRoadType = selectRoadType.options[selectRoadType.selectedIndex].value;
  91. else
  92. specificRoadType = false;
  93. }
  94.  
  95. if (showRecent) {
  96. recentDays = getId('_numRecentDays').value;
  97. if (recentDays === undefined) recentDays = 0;
  98. }
  99.  
  100. // counters
  101. var numUserHighlighted = 0;
  102. var numCityHighlighted = 0;
  103.  
  104. for (var seg in Waze.model.segments.objects) {
  105. var segment = Waze.model.segments.get(seg);
  106. var attributes = segment.attributes;
  107. var line = getId(segment.geometry.id);
  108.  
  109. if (line === null) {
  110. continue;
  111. }
  112. var sid = attributes.primaryStreetID;
  113.  
  114. // check that WME hasn't highlighted this segment
  115. var opacity = line.getAttribute("stroke-opacity");
  116. var lineWidth = line.getAttribute("stroke-width");
  117. if (opacity == 1 || lineWidth == 9)
  118. continue;
  119. // turn off highlights when roads are no longer visible
  120. var roadType = attributes.roadType;
  121. if (Waze.map.zoom <= 3 && (roadType < 2 || roadType > 7) ) {
  122. if (opacity > 0.1) {
  123. line.setAttribute("stroke","#dd7700");
  124. line.setAttribute("stroke-opacity",0.001);
  125. line.setAttribute("stroke-dasharray", "none");
  126. }
  127. continue;
  128. }
  129.  
  130. // highlight all newly paved roads (or roads without any nodes)
  131. if (sid === null || (attributes.toNodeID === null && attributes.fromNodeID === null && roadType < 9)) {
  132. if (opacity < 0.1 && showNoName) {
  133. line.setAttribute("stroke","#f00");
  134. line.setAttribute("stroke-opacity",0.75);
  135. line.setAttribute("stroke-width", 10);
  136. }
  137. continue;
  138. }
  139. var street = Waze.model.streets.get(sid);
  140.  
  141. // get attributes for this segment
  142. var toll = attributes.fwdToll;
  143. var locked = attributes.lockRank !== null;
  144. var ranked = attributes.rank > 0 && attributes.lockRank === null;
  145. var noEdit = attributes.permissions == 0;
  146. var noName = (street != null) && street.isEmpty;
  147. var cityID = (street != null) && street.cityID;
  148. var noCity = false;
  149. var countryID = 0;
  150. if (cityID != null && Waze.model.cities.get(cityID) != null) {
  151. noCity = Waze.model.cities.get(cityID).isEmpty;
  152. countryID = Waze.model.cities.get(cityID).countryID;
  153. }
  154. var oneWay = ((attributes.fwdDirection + attributes.revDirection) == 1); // it is 1-way only if either is true
  155. var noDirection = (!attributes.fwdDirection && !attributes.revDirection); // Could use the .attribute.allowNoDirection?
  156. var hasRestrictions = (attributes.fwdRestrictions.length + attributes.revRestrictions.length > 0);
  157. var updatedBy = attributes.updatedBy;
  158. var roundabout = attributes.junctionID !== null;
  159. // get current state of the line
  160. var lineColor = line.getAttribute("stroke");
  161.  
  162. // default colours
  163. var newColor = "#dd7700";
  164. var newOpacity = 0.001;
  165. var newDashes = "none";
  166. var newWidth = 6;
  167.  
  168. // Recent Edits within X days, with decaying green opacity
  169. if (showRecent) {
  170. var editDays = (today.getTime() - attributes.createdOn) / 86400000;
  171. if (attributes.updatedOn !== null) {
  172. editDays = (today.getTime() - attributes.updatedOn) / 86400000;
  173. }
  174. if (recentDays >= 0 && editDays <= recentDays) {
  175. if ((updatedBy == selectedUserId) || (!specificEditor)) {
  176. //var heatScale = 0.75 / recentDays;
  177. //newColor = "#0f0";
  178. var shade = Math.floor(editDays * 128 / recentDays);
  179. newColor = "rgb(" + (0) + ", " + (255-shade) + ", " + (0) + ")";
  180. newOpacity = 0.5;
  181. //newOpacity = Math.min(0.999999, 1 - (editDays * heatScale));
  182. }
  183. }
  184. }
  185.  
  186. // Toll = Dashed
  187. else if (toll && showToll) {
  188. newColor = "#00f";
  189. newOpacity = 0.5;
  190. newDashes = "10 10";
  191. }
  192.  
  193. // No Edit = Black
  194. else if (noEdit && showLocked) {
  195. newColor = "#000";
  196. newOpacity = 0.75;
  197. newWidth = 3;
  198. }
  199.  
  200. // Locked = Red
  201. else if (locked && showLocked) {
  202. newColor = "#f00";
  203. newWidth = 6;
  204. newOpacity = 0.2 * Math.min(5, attributes.lockRank);
  205. }
  206.  
  207. else if (ranked && showLocked) {
  208. newColor = "#f00";
  209. newWidth = 6;
  210. newDashes = "2 8";
  211. newOpacity = 0.2 * Math.min(5, attributes.rank);
  212. }
  213.  
  214. else if (hasRestrictions && showRestrictions) {
  215. newColor = "#909";
  216. newDashes = "10 10";
  217. newOpacity = 0.5;
  218. }
  219.  
  220. // bad roundabouts = Lime
  221. //else if (roundabout && (!oneWay || !noName) && showNoTerm) {
  222. // newColor = "#BE0";
  223. // newOpacity = 0.5;
  224. //}
  225.  
  226. // alternate names
  227. else if (showAltName && attributes.streetIDs.length > 0) {
  228. newColor = "#9C0";
  229. newOpacity = 0.75;
  230. if (noName) {
  231. newDashes = "10 10";
  232. }
  233. }
  234.  
  235. // No Speed Limits = Orange
  236. else if (showSpeedLimits && (plusStreets || attributes.roadType > 1) && attributes.roadType != 5
  237. && attributes.roadType < 8 && attributes.junctionID == null
  238. && ((attributes.fwdDirection && (attributes.fwdMaxSpeed == null || attributes.fwdMaxSpeedUnverified)) ||
  239. (attributes.revDirection && (attributes.revMaxSpeed == null || attributes.revMaxSpeedUnverified)) )) {
  240. newColor = "#f80";
  241. newOpacity = 0.8;
  242. newWidth = 4;
  243. }
  244.  
  245. // Unnamed (No Name) = Orange
  246. // except roundabouts and non-Streets
  247. else if (noName && showNoName && !roundabout && attributes.roadType < 8) {
  248. newColor = "#fb0";
  249. newOpacity = 0.6;
  250. }
  251.  
  252. // No City = Gray
  253. else if (noCity && showNoCity) {
  254. newColor = "#888";
  255. newOpacity = 0.5;
  256. }
  257.  
  258. // No Direction = Cyan
  259. else if (noDirection && showNoDirection) {
  260. newColor = "#0ff";
  261. newOpacity = 0.3;
  262. newWidth = 4;
  263. }
  264.  
  265. // One Way = Blue
  266. else if (oneWay && showOneWay) {
  267. newColor = "#00f";
  268. newOpacity = 0.4;
  269. newWidth = 4;
  270. }
  271.  
  272. // Unterminated segments: no end node or not connected = Lime
  273. else if (showNoTerm && (attributes.toNodeID === null || attributes.fromNodeID === null || attributes.toNodeID === attributes.fromNodeID) && attributes.length > 10) {
  274. newColor = "#BE0";
  275. newOpacity = 0.5;
  276. }
  277.  
  278.  
  279. // segment with special flags
  280. else if (specificRoadType && (selectedRoadType & 64) > 0) {
  281. if (selectedRoadType == 64 && attributes.flags > 0) {
  282. newColor = "#909";
  283. newOpacity = 0.5;
  284. newWidth = 4;
  285. }
  286. // - tunnel
  287. else if (selectedRoadType == 65 && attributes.flags & 1) {
  288. newColor = "#909";
  289. newOpacity = 0.5;
  290. newWidth = 4;
  291. }
  292. }
  293.  
  294.  
  295. // selected road type = purple
  296. else if (specificRoadType && attributes.roadType == selectedRoadType) {
  297. newColor = "#909";
  298. newOpacity = 0.5;
  299. newWidth = 4;
  300. }
  301.  
  302. // special road types: non-drivable / non-routable
  303. else if (specificRoadType && selectedRoadType == 98 && nonRoutableTypes.contains(attributes.roadType)) {
  304. newColor = "#909";
  305. newOpacity = 0.5;
  306. newWidth = 4;
  307. }
  308. else if (specificRoadType && selectedRoadType == 99 && nonDrivableTypes.contains(attributes.roadType)) {
  309. newColor = "#909";
  310. newOpacity = 0.5;
  311. newWidth = 4;
  312. }
  313.  
  314. // highlight roads with a routing preferrence set
  315. else if (showRoutingPref && attributes.routingRoadType != null) {
  316. newColor = "#0ff";
  317. newOpacity = 0.5;
  318. newWidth = 6;
  319. }
  320.  
  321. // highlight segments by selected user, unless already highlighted
  322. if (specificEditor && !showRecent) {
  323. if (updatedBy == selectedUserId && newColor == "#dd7700") {
  324. newColor = "#00ff00";
  325. newOpacity = 0.5;
  326. numUserHighlighted++;
  327. }
  328. else if (selectedUserId < -1 && updatedBy != -selectedUserId && newColor == "#dd7700") {
  329. newColor = "#00ff00";
  330. newOpacity = 0.5;
  331. numUserHighlighted++;
  332. }
  333. else if (updatedBy != selectedUserId) {
  334. newColor = "#dd7700";
  335. newOpacity = 0.001;
  336. newDashes = "none";
  337. }
  338. }
  339.  
  340. // highlight segments by selected City, unless already highlighted
  341. // if city is only on an alternate street highlight it with dashes
  342. if (specificCity) {
  343. var altCityMatch = false;
  344. var specificCityMatch = (cityID == selectedCityId);
  345. if (specificCityInvert)
  346. specificCityMatch = (cityID != selectedCityId && !noCity);
  347.  
  348. if (!specificCityMatch) {
  349. // look for matching city in alternate streets
  350. for (var i in attributes.streetIDs) {
  351. var streetID = attributes.streetIDs[i];
  352. var currentStreet = Waze.model.streets.get(streetID);
  353. if (currentStreet == null)
  354. continue;
  355. var cityMatch = (currentStreet.cityID == selectedCityId);
  356. if (specificCityInvert)
  357. cityMatch = !cityMatch
  358. if (cityMatch) {
  359. altCityMatch = true;
  360. break;
  361. }
  362. }
  363. }
  364.  
  365. if (specificCityMatch && (newColor == "#dd7700" || newColor == "#888")) {
  366. newColor = "#ff0";
  367. newOpacity = 0.75;
  368. newDashes = "none";
  369. numCityHighlighted++;
  370. } else if (altCityMatch && (newColor == "#dd7700" || newColor == "#888")) {
  371. newColor = "#ffff01";
  372. newOpacity = 0.75;
  373. newDashes = "10 10";
  374. newWidth = 6;
  375. numCityHighlighted++;
  376. } else if (!specificCityMatch && !altCityMatch && !noCity) {
  377. newColor = "#dd7700";
  378. newOpacity = 0.001;
  379. newDashes = "none";
  380. }
  381. }
  382.  
  383. // if colour has changed, update the line attributes
  384. if (lineColor != newColor) {
  385. line.setAttribute("stroke", newColor);
  386. line.setAttribute("stroke-opacity", newOpacity);
  387. line.setAttribute("stroke-dasharray", newDashes);
  388. if (newColor != "#dd7700") { //default
  389. line.setAttribute("stroke-width", newWidth);
  390. } else {
  391. line.setAttribute("stroke-width", 6);
  392. }
  393. }
  394. } // end of loop
  395. numUserHighlightedText = getId('_numUserHighlighted');
  396. if (specificEditor)
  397. numUserHighlightedText.innerHTML = ' = ' + numUserHighlighted;
  398. else
  399. numUserHighlightedText.innerHTML = '';
  400.  
  401. numCityHighlightedText = getId('_numCityHighlighted');
  402. if (specificCity)
  403. numCityHighlightedText.innerHTML = ' = ' + numCityHighlighted;
  404. else
  405. numCityHighlightedText.innerHTML = '';
  406. } // end of function
  407.  
  408. function highlightPlaces(event) {
  409. if (typeof Waze.model.venues == "undefined") {
  410. return;
  411. }
  412. if (Waze.model.active == false) {
  413. return;
  414. }
  415. // refreshing, reset places to original style
  416. if (event && event.type && /click|change/.test(event.type)) {
  417. for (var mark in Waze.model.venues.objects) {
  418. var venue = Waze.model.venues.get(mark);
  419. var poly = getId(venue.geometry.id);
  420. if (poly !== null && poly.getAttribute("stroke-opacity") == 0.987) {
  421. if (venue.isPoint()) {
  422. poly.setAttribute("stroke","white");
  423. } else {
  424. poly.setAttribute("stroke","#ca9ace");
  425. poly.setAttribute("stroke-width",2);
  426. poly.setAttribute("stroke-dash-array","none");
  427. }
  428. poly.setAttribute("fill","#c290c6");
  429. poly.setAttribute("stroke-opacity", 1)
  430. }
  431. }
  432. }
  433.  
  434. // if option is disabled, stop now
  435. if (!getId('_cbHighlightPlaces').checked) {
  436. if (event && event.type && event.type == 'click') {
  437. getId('_cbHighlightLockedPlaces').disabled = true;
  438. getId('_cbHighlightIncompletePlaces').disabled = true;
  439. }
  440. return;
  441. } else {
  442. if (event && event.type && event.type == 'click') {
  443. getId('_cbHighlightLockedPlaces').disabled = false;
  444. getId('_cbHighlightIncompletePlaces').disabled = false;
  445. }
  446. }
  447. var showLocked = getId('_cbHighlightLockedPlaces').checked;
  448. var showIncomplete = getId('_cbHighlightIncompletePlaces').checked;
  449. var specificCity = getId('_cbHighlightCity').checked;
  450. var specificCityInvert = getId('_cbHighlightCityInvert').checked;
  451. var showRecent = advancedMode ? getId('_cbHighlightRecent').checked : false;
  452.  
  453. if (specificCity) {
  454. var selectCity = getId('_selectCity');
  455. if (selectCity.selectedIndex >= 0) {
  456. selectedCityId = selectCity.options[selectCity.selectedIndex].value;
  457. } else
  458. specificCity = false;
  459. }
  460.  
  461. var specificEditor = getId('_cbHighlightEditor').checked;
  462. if (specificEditor) {
  463. var selectEditor = getId('_selectUser');
  464. var selectedEditorId = 0;
  465. if (selectEditor.selectedIndex >= 0) {
  466. selectedEditorId = selectEditor.options[selectEditor.selectedIndex].value;
  467. } else
  468. specificEditor = false;
  469. }
  470.  
  471. if (showRecent) {
  472. recentDays = getId('_numRecentDays').value;
  473. if (recentDays === undefined) recentDays = 0;
  474. if (recentDays == 0) showRecent = false;
  475. }
  476.  
  477. var updates = 0;
  478. for (var mark in Waze.model.venues.objects) {
  479. var venue = Waze.model.venues.get(mark);
  480. var poly = getId(venue.geometry.id);
  481. // check that WME hasn't highlighted this object already
  482. if (poly == null || mark.state == "Update" || venue.selected) {
  483. continue;
  484. }
  485.  
  486. // if highlighted by mouse over, skip this one
  487. if (poly.getAttribute("fill") == poly.getAttribute("stroke")) {
  488. continue;
  489. }
  490. // if already highlighted by us, skip
  491. if (poly.getAttribute("stroke-opacity") == 0.987) {
  492. continue;
  493. }
  494. // flag this venue as highlighted so we don't update it next time
  495. poly.setAttribute("stroke-opacity", 0.987);
  496. updates++;
  497.  
  498. var categories = venue.attributes.categories;
  499. if (showIncomplete) {
  500. venueStreet = Waze.model.streets.get(venue.attributes.streetID);
  501. var incomplete = false;
  502. var colorhilite = false;
  503. // check for missing venue name
  504. if (venue.attributes.name == null || venue.attributes.name == "") {
  505. incomplete = !venue.attributes.residential;
  506. colorhilite = true;
  507. }
  508. // check for missing street name
  509. if (venueStreet == null || venueStreet.name == null || venueStreet.name == "") {
  510. incomplete = true;
  511. colorhilite = true;
  512. }
  513. // check for missing house number
  514. else if (venue.attributes.residential && venue.attributes.houseNumber == null) {
  515. incomplete = true;
  516. colorhilite = true;
  517. }
  518. // check for category group used as category
  519. else if (categories.length == 0
  520. || categories.indexOf("CAR_SERVICES") > -1
  521. || categories.indexOf("TRANSPORTATION") > -1
  522. || categories.indexOf("PROFESSIONAL_AND_PUBLIC") > -1
  523. || categories.indexOf("SHOPPING_AND_SERVICES") > -1
  524. || categories.indexOf("FOOD_AND_DRINK") > -1
  525. || categories.indexOf("CULTURE_AND_ENTERTAINMENT") > -1
  526. || categories.indexOf("OTHER") > -1
  527. || categories.indexOf("LODGING") > -1
  528. || categories.indexOf("OUTDOORS") > -1
  529. || categories.indexOf("NATURAL_FEATURES") > -1) {
  530. incomplete = (venue.attributes.lockRank == 0);
  531. }
  532. if (incomplete &&
  533. (categories.indexOf("JUNCTION_INTERCHANGE") > -1
  534. || categories.indexOf("CANAL") > -1
  535. || categories.indexOf("RIVER_STREAM") > -1
  536. || categories.indexOf("SEA_LAKE_POOL") > -1
  537. || categories.indexOf("PARK") > -1
  538. || categories.indexOf("SWAMP_MARSH") > -1
  539. || categories.indexOf("FOREST_GROVE") > -1
  540. || categories.indexOf("GOLF_COURSE") > -1) ) {
  541. incomplete = false;
  542. colorhilite = false;
  543. }
  544. if (incomplete) {
  545. if (colorhilite) {
  546. highlightAPlace(venue, "orange", "white");
  547. }
  548. if (venue.isPoint())
  549. poly.setAttribute("stroke-dasharray", "3 3");
  550. else {
  551. poly.setAttribute("stroke-dasharray", "3 6");
  552. poly.setAttribute("stroke-width", "3");
  553. }
  554. }
  555. }
  556.  
  557. // highlight places which have the City field set in the address = yellow
  558. if (specificCity) {
  559. venueStreet = Waze.model.streets.get(venue.attributes.streetID);
  560. selectedCityMatch = (specificCity && venueStreet.cityID == selectedCityId);
  561. if (specificCityInvert) selectedCityMatch = !selectedCityMatch;
  562.  
  563. if (selectedCityMatch) {
  564. highlightAPlace(venue, "#cc0", "#ff8");
  565. continue;
  566. }
  567. }
  568. // highlight places which have been edited by selected editor = green
  569. if (specificEditor) {
  570. var selectedEditorMatch = false
  571. if (selectedEditorId >= -1) {
  572. selectedEditorMatch = (selectedEditorId == venue.attributes.createdBy);
  573. if (typeof venue.attributes.updatedBy != 'undefined') {
  574. selectedEditorMatch = (selectedEditorId == venue.attributes.updatedBy);
  575. }
  576. }
  577. else {
  578. selectedEditorMatch = (selectedEditorId != -venue.attributes.createdBy);
  579. if (typeof venue.attributes.updatedBy != 'undefined') {
  580. selectedEditorMatch = (selectedEditorId != -venue.attributes.updatedBy);
  581. }
  582. }
  583. if (selectedEditorMatch) {
  584. highlightAPlace(venue, "#0f0", "#8f8");
  585. continue;
  586. }
  587. }
  588. // highlight places that have been edited recently
  589. if (showRecent) {
  590. var today = new Date();
  591. var editDays = (today.getTime() - venue.attributes.createdOn) / 86400000;
  592. if (typeof venue.attributes.updatedOn != 'undefined') {
  593. editDays = (today.getTime() - venue.attributes.updatedOn) / 86400000;
  594. }
  595. if (editDays <= recentDays) {
  596. var shade = Math.floor(editDays * 128 / recentDays);
  597. var colour = "rgb(" + (0) + ", " + (255-shade) + ", " + (0) + ")";
  598. highlightAPlace(venue, colour, colour);
  599. continue;
  600. }
  601. }
  602. // residential = cyan edges, like house numbers
  603. if (venue.attributes.residential) {
  604. highlightAPlace(venue, "#44afcf", "4ac");
  605. }
  606. // gas station = orange
  607. else if (categories.indexOf("GAS_STATION") > -1) {
  608. highlightAPlace(venue, "#f90", "#f91");
  609. }
  610.  
  611. // parking lot = cyan
  612. else if (categories.indexOf("PARKING_LOT") > -1) {
  613. highlightAPlace(venue, "#099", "#0cc");
  614. }
  615.  
  616. // water = blue
  617. else if (categories.indexOf("RIVER_STREAM") > -1 ||
  618. categories.indexOf("CANAL") > -1 ||
  619. categories.indexOf("SEA_LAKE_POOL") > -1) {
  620. highlightAPlace(venue, "#06c", "#09f");
  621. poly.setAttribute("stroke-dasharray", "none");
  622. }
  623.  
  624. // park/grass/trees = green
  625. else if (!showRecent && !specificEditor && (
  626. categories.indexOf("PARK") > -1 ||
  627. categories.indexOf("SWAMP_MARSH") > -1 ||
  628. categories.indexOf("FOREST_GROVE") > -1 ||
  629. categories.indexOf("GOLF_COURSE") > -1) ) {
  630. highlightAPlace(venue, "#0b0", "#4f4");
  631. poly.setAttribute("stroke-dasharray", "none");
  632. }
  633. // locked venues have red border (overrides all other options)
  634. if (showLocked && venue.attributes.lockRank > 0) {
  635. poly.setAttribute("stroke", "red");
  636. }
  637. } // for
  638. //if (updates > 0)
  639. // getId("wmedebug").innerText = updates;
  640. }
  641.  
  642. function highlightAPlace(venue, fg, bg) {
  643. var poly = getId(venue.geometry.id);
  644. if (venue.isPoint()) {
  645. poly.setAttribute("fill", fg);
  646. }
  647.  
  648. else { // area
  649. poly.setAttribute("stroke", fg);
  650. poly.setAttribute("fill", bg);
  651. }
  652. }
  653.  
  654. // used when clicking an option that affects both Segments and Places
  655. function highlightSegmentsAndPlaces(event) {
  656. highlightSegments(event);
  657. highlightPlaces(event);
  658. }
  659.  
  660. var lastSelected = null;
  661. function highlightSelectedNodes() {
  662. if (Waze.map.zoom <= 3 || !advancedMode)
  663. return true;
  664.  
  665. var showTurns = advancedMode ? getId('_cbHighlightTurns').checked : false;
  666.  
  667. // look for a selected node or segment (there can only be 1)
  668. var currentNodes = [];
  669. var selectType = '';
  670. if (Waze.selectionManager.selectedItems.length == 1){
  671. var selection = Waze.selectionManager.selectedItems[0].model;
  672. var selAttr = selection.attributes;
  673.  
  674. if (selection !== null){
  675. if (selection.state == "Update" && lastModified == false){
  676. lastSelected = null;
  677. lastModified = true;
  678. } else if (selection.state != "Update" && lastModified == true){
  679. lastSelected = null;
  680. lastModified = false;
  681. }
  682. selectType = selection.type;
  683. if (selection.type == "node"){
  684. currentNodes.push(selAttr.id);
  685. }else if (selection.type == "segment"){
  686. if (selAttr.fromNodeID !== null)
  687. currentNodes.push(selAttr.fromNodeID);
  688. if (selAttr.toNodeID !== null)
  689. currentNodes.push(selAttr.toNodeID);
  690. }
  691. }
  692. }
  693.  
  694. // selection changed, then reset previous highlights | selectType == 'node'
  695. if ((lastSelected != currentNodes[0] || !showTurns) && selectedLines.length > 0){
  696. for (var i = 0; i < selectedLines.length; i++){
  697. line = getId(selectedLines[i]);
  698. if (line !== null && line.getAttribute("stroke-width") == 8)
  699. line.setAttribute("stroke-opacity", 0.0001);
  700. }
  701. selectedLines = [];
  702. }
  703.  
  704. // no node selected, quit now
  705. if (currentNodes.length === 0){
  706. lastSelected = null;
  707. lastModified = false;
  708. return true;
  709. }
  710.  
  711. var numSoftTurns = 0;
  712. var numRevConns = 0;
  713. var numUTurns = 0;
  714. var showWarning = false;
  715.  
  716. for (var i = 0; i < currentNodes.length; i++){
  717. var currentNode = currentNodes[i];
  718. var node = Waze.model.nodes.get(currentNode);
  719. var nodeAttr = node.attributes;
  720. if (node === undefined) continue;
  721.  
  722. // ignore dead-end nodes
  723. if (nodeAttr.segIDs.length <= 1){
  724. lastSelected = currentNode[0];
  725. continue;
  726. }
  727. var newColor = null;
  728. var segmentColor = [];
  729. var segment1, segment2, seg1Attr, seg2Attr;
  730. // find segments that connect to this node
  731. for (var j = 0; j < nodeAttr.segIDs.length; j++){
  732. segment1 = Waze.model.segments.get(node.attributes.segIDs[j]);
  733. seg1Attr = segment1.attributes;
  734.  
  735. if (segment1 === undefined)
  736. continue;
  737. if (nonDrivableTypes.indexOf(seg1Attr.roadType) != -1)
  738. continue; // For look at all drivable road
  739.  
  740. // highlight U-turns
  741. if(segment1.isTurnAllowed(segment1, node)){
  742. segmentColor[j] = "#0ff";
  743. numUTurns++;
  744. }
  745.  
  746. // highlight soft-turns
  747. if (nodeAttr.id == seg1Attr.fromNodeID){
  748. var nodeLocked = (seg1Attr.revTurnsLocked);
  749. }else if (nodeAttr.id == seg1Attr.toNodeID){
  750. var nodeLocked = (seg1Attr.fwdTurnsLocked);
  751. }
  752. if (nodeLocked === false){
  753. segmentColor[j] = "#ff0";
  754. numSoftTurns++;
  755. }
  756. }
  757. for (var j = 0; j < nodeAttr.segIDs.length - 1; j++){
  758. segment1 = Waze.model.segments.get(node.attributes.segIDs[j]);
  759. seg1Attr = segment1.attributes;
  760.  
  761. if (nonDrivableTypes.indexOf(seg1Attr.roadType) != -1)
  762. continue; // For look at all drivable road
  763.  
  764. for (var k = 1; k < nodeAttr.segIDs.length; k++){
  765. segment2 = Waze.model.segments.get(node.attributes.segIDs[k]);
  766. seg2Attr = segment2.attributes;
  767.  
  768. if (nonDrivableTypes.indexOf(seg2Attr.roadType) != -1)
  769. continue; // For look at all drivable road
  770.  
  771. // highlight RevCons
  772. /******************************************************************************************************************
  773. | segment1.isTurnAllowed(segment2, node): --> Test if Turn to segment1 into segment2 at node is allowed |
  774. | node.isTurnAllowedBySegDirections(segment1, segment2): --> Test if Direction of segment1 into segment2 at node |
  775. ******************************************************************************************************************/
  776. if (seg1Attr.id != seg2Attr.id){
  777. if (segment1.isTurnAllowed(segment2, node) && !node.isTurnAllowedBySegDirections(segment1, segment2)){
  778. segmentColor[j] = "#f0f";
  779. numRevConns++;
  780. }
  781. if (segment2.isTurnAllowed(segment1, node) && !node.isTurnAllowedBySegDirections(segment2, segment1)){
  782. segmentColor[j] = "#f0f";
  783. numRevConns++;
  784. }
  785. }
  786. }
  787. }
  788. for (var j = 0; j < nodeAttr.segIDs.length; j++){
  789. var segment = Waze.model.segments.get(node.attributes.segIDs[j]);
  790. var segAttr = segment.attributes;
  791. var line = getId(segAttr.geometry.id);
  792. if (line === null) return;
  793. if (segmentColor[j]){
  794. newColor = segmentColor[j];
  795. } else newColor = null;
  796.  
  797. var oldOpacity = line.getAttribute("stroke-opacity");
  798. if (newColor !== null && oldOpacity < 1 && showTurns){
  799. line.setAttribute("stroke", newColor);
  800. line.setAttribute("stroke-opacity", 1);
  801. line.setAttribute("stroke-width", 8);
  802. line.setAttribute("stroke-dasharray", "none");
  803. selectedLines.push(segAttr.geometry.id);
  804. }
  805. if (newColor !== null) {
  806. showWarning = true;
  807. }
  808. }
  809. }
  810.  
  811. if (currentNodes.length > 0){
  812. var currentNode = currentNodes[0];
  813.  
  814. if (showWarning === true){
  815. // setup new box for warnings about this node
  816. var selectionBox;
  817. if (selectType == 'segment')
  818. selectionBox = getId('segment-edit-general');
  819. else
  820. selectionBox = getId('node-edit-general');
  821.  
  822. var nodeDetails = getId('nodeTipsBox');
  823. if (!nodeDetails){
  824. nodeDetails = document.createElement('div');
  825. nodeDetails.id = 'nodeTipsBox';
  826. selectionBox.appendChild(nodeDetails);
  827. } else{
  828. return;
  829. }
  830.  
  831. nodeHelp = '';
  832. if (numSoftTurns > 0){
  833. nodeText = document.createElement('div');
  834. if (selectType == 'node')
  835. nodeHelp = "Press <b>Q</b> and then re-enable each allowed turn.";
  836. else
  837. nodeHelp = "Select individual nodes to see details.";
  838. nodeText.style.padding = "4px 2px";
  839. nodeText.innerHTML = "<b>Warning:</b> " + selectType + " has " + numSoftTurns + " soft turns.";
  840. nodeText.style.backgroundColor = '#ffc';
  841. nodeDetails.appendChild(nodeText);
  842. }
  843. if (numRevConns > 0){
  844. nodeText = document.createElement('div');
  845. if (selectType == 'node')
  846. nodeHelp = "Press <b>Q</b> and then re-enable each allowed turn.";
  847. else
  848. nodeHelp = "Select individual nodes to see details.";
  849. nodeText.style.padding = "4px 2px";
  850. nodeText.innerHTML = "<b>Warning:</b> " + selectType + " has " + numRevConns + " reverse connections.";
  851. nodeText.style.backgroundColor = '#fcf';
  852. nodeDetails.appendChild(nodeText);
  853. }
  854. if (numUTurns > 0){
  855. nodeText = document.createElement('div');
  856. nodeText.title = "Use the U-Turn arrows to set when a U-Turn is allowed.";
  857. nodeText.style.padding = "4px 2px";
  858. nodeText.innerHTML = "<b>Notice:</b> " + selectType + " has " + numUTurns + " U-Turns enabled.";
  859. nodeText.style.backgroundColor = '#cff';
  860. nodeDetails.appendChild(nodeText);
  861. }
  862. nodeText = document.createElement('div');
  863. nodeText.style.padding = "4px 2px";
  864. nodeText.innerHTML = nodeHelp + '<br><i>For a full explanation, <a href="https://wiki.waze.com/wiki/Soft_and_hard_turns" target="_blank">see this page</a>.</i><br>';
  865. nodeDetails.appendChild(nodeText);
  866. }
  867. }
  868. lastSelected = currentNodes[0];
  869. return true;
  870. }
  871.  
  872. function highlightBadNodes() {
  873. if (Waze.map.zoom <= 3 || !advancedMode)
  874. return true;
  875.  
  876. var showTurns = advancedMode ? getId('_cbHighlightTurns').checked : false;
  877. var showRestrictions = getId('_cbHighlightRestrictions').checked;
  878.  
  879. for (var currentNode in Waze.model.nodes.objects){
  880. var node = Waze.model.nodes.get(currentNode);
  881. var nodeAttr = node.attributes;
  882. if (node === undefined) continue;
  883.  
  884. var numRestrictions = 0;
  885. var numSoftTurns = 0;
  886. var numRevConns = 0;
  887. var numUTurns = 0;
  888. var segment1, segment2, seg1Attr, seg2Attr;
  889.  
  890. // ignore dead-end nodes
  891. if (nodeAttr.segIDs.length <= 1) {
  892. continue;
  893. }
  894.  
  895. // find segments that connect to this node
  896. /******************************************************************************************************************
  897. | highlight RevCons |
  898. | |
  899. | segment1.isTurnAllowed(segment2, node): --> Test if Turn to segment1 into segment2 at node is allowed |
  900. | node.isTurnAllowedBySegDirections(segment1, segment2): --> Test if Direction of segment1 into segment2 at node |
  901. ******************************************************************************************************************/
  902. for (var j = 0; j < nodeAttr.segIDs.length - 1; j++){
  903. segment1 = Waze.model.segments.get(node.attributes.segIDs[j]);
  904. seg1Attr = segment1.attributes;
  905. if (nonDrivableTypes.indexOf(seg1Attr.roadType) == -1)
  906. continue;
  907.  
  908. for (var k = 1; k < nodeAttr.segIDs.length; k++){
  909. segment2 = Waze.model.segments.get(node.attributes.segIDs[k]);
  910. seg2Attr = segment2.attributes;
  911. if (nonDrivableTypes.indexOf(seg2Attr.roadType) == -1)
  912. continue; // For look at all drivable road
  913.  
  914. if (seg1Attr.id != seg2Attr.id){
  915. if (segment1.isTurnAllowed(segment2, node) && !node.isTurnAllowedBySegDirections(segment1, segment2)){
  916. numRevConns++;
  917. }
  918. if (segment2.isTurnAllowed(segment1, node) && !node.isTurnAllowedBySegDirections(segment2, segment1)){
  919. numRevConns++;
  920. }
  921. }
  922. }
  923. }
  924. //******************************************************************************************************************
  925. for (var j = 0; j < nodeAttr.segIDs.length; j++){
  926. segment1 = Waze.model.segments.get(node.attributes.segIDs[j]);
  927. seg1Attr = segment1.attributes;
  928. // count restictions
  929. if (showRestrictions) {
  930. if (nodeAttr.id == seg1Attr.fromNodeID){
  931. if (seg1Attr.fromRestrictions){
  932. for (key in seg1Attr.fromRestrictions){
  933. numRestrictions++;
  934. }
  935. }
  936. }
  937. if (nodeAttr.id == seg1Attr.toNodeID){
  938. if (seg1Attr.toRestrictions){
  939. for (key in seg1Attr.toRestrictions){
  940. numRestrictions++;
  941. }
  942. }
  943. }
  944. }
  945. if (majorRoadTypes.indexOf(seg1Attr.roadType) == -1)
  946. continue; // For look at all drivable road
  947.  
  948. // highlight U-turns
  949. if(segment1.isTurnAllowed(segment1, node)){
  950. numUTurns++;
  951. }
  952.  
  953. // highlight soft-turns
  954. if (nodeAttr.id == seg1Attr.fromNodeID){
  955. var nodeLocked = (seg1Attr.revTurnsLocked);
  956. } else if (nodeAttr.id == seg1Attr.toNodeID){
  957. var nodeLocked = (seg1Attr.fwdTurnsLocked);
  958. }
  959. if (nodeLocked === false){
  960. numSoftTurns++;
  961. }
  962. }
  963. var newColor = null;
  964. if (numUTurns > 0) newColor = "#0ff";
  965. else if (numSoftTurns > 0) newColor = "#ff0"; // yellow
  966. else if (numRevConns > 0) newColor = "#f0f";
  967. else if (numRestrictions > 0) newColor = "#909";
  968.  
  969. var circle = getId(nodeAttr.geometry.id);
  970. if (newColor != null && circle != null) {
  971. opacity = circle.getAttribute("fill-opacity");
  972. if (opacity < 0.1) {
  973. circle.setAttribute("fill-opacity", 0.75);
  974. circle.setAttribute("fill", newColor);
  975. }
  976. }
  977. }
  978. return true;
  979. }
  980.  
  981. // add logged in user to drop-down list
  982. function initUserList() {
  983. if (!advancedMode) return;
  984.  
  985. var thisUser = Waze.loginManager.user;
  986. if (thisUser === null) return;
  987.  
  988. var selectUser = getId('_selectUser');
  989. var usrOption = document.createElement('option');
  990. var usrRank = thisUser.normalizedLevel;
  991. var usrText = document.createTextNode(thisUser.userName + " (" + usrRank + ")");
  992. usrOption.setAttribute('value',thisUser.id);
  993. usrOption.appendChild(usrText);
  994. selectUser.appendChild(usrOption);
  995. console.log("WME Highlights: Init User list: " + thisUser.userName);
  996. }
  997.  
  998. // add current city in to drop-down list
  999. function initCityList() {
  1000. var thisCity = Waze.model.segments.topCityID;
  1001. if (thisCity === null) return;
  1002. var thisName = Waze.model.cities.get(thisCity).name;
  1003.  
  1004. var selectCity = getId('_selectCity');
  1005. var cityOption = document.createElement('option');
  1006. var cityText = document.createTextNode(thisName);
  1007. cityOption.appendChild(cityText);
  1008. cityOption.setAttribute('value',thisCity);
  1009. selectCity.appendChild(cityOption);
  1010. console.log("WME Highlights: Init City list: " + thisName);
  1011.  
  1012. // stop listening for this event
  1013. Waze.model.events.unregister("mergeend", null, initCityList);
  1014. }
  1015.  
  1016. // populate drop-down list of editors
  1017. function updateUserList() {
  1018. // update list of users - for high zoom and AMs only
  1019. if (!advancedMode)
  1020. return;
  1021.  
  1022. var selectUser = getId('_selectUser');
  1023. var numUsers = Waze.model.users.objects.length;
  1024. if (numUsers === 0)
  1025. return;
  1026.  
  1027. // preserve current selection
  1028. var currentId = null;
  1029. if (selectUser.selectedIndex >= 0)
  1030. currentId = selectUser.options[selectUser.selectedIndex].value;
  1031.  
  1032. // collect array of users who have edited segments
  1033. var editorIds = [];
  1034. for (var seg in Waze.model.segments.objects) {
  1035. var segment = Waze.model.segments.get(seg);
  1036. if (typeof segment == 'undefined')
  1037. continue;
  1038. var editedBy = segment.attributes.createdBy;
  1039. if (typeof segment.attributes.updatedBy != 'undefined') {
  1040. editedBy = segment.attributes.updatedBy;
  1041. }
  1042. if (editorIds.indexOf(editedBy) == -1)
  1043. editorIds.push(editedBy);
  1044. }
  1045. // collect array of users who have edited places
  1046. for (var ven in Waze.model.venues.objects) {
  1047. var venue = Waze.model.venues.get(ven);
  1048. if (typeof venue == 'undefined')
  1049. continue;
  1050. var editedBy = venue.attributes.createdBy;
  1051. if (typeof venue.attributes.updatedBy != 'undefined') {
  1052. editedBy = venue.attributes.updatedBy;
  1053. }
  1054. if (editorIds.indexOf(editedBy) == -1)
  1055. editorIds.push(editedBy);
  1056. }
  1057. if (editorIds.length === 0)
  1058. return;
  1059.  
  1060. // sort IDs by name
  1061. var editorList = [];
  1062. for (var i = 0; i < editorIds.length; i++) {
  1063. var id = editorIds[i];
  1064. var user = Waze.model.users.get(id);
  1065. if (user === null || typeof(user) === "undefined")
  1066. continue;
  1067. var name = user.userName;
  1068. editorList.push({ id: id, name: name});
  1069. }
  1070. editorList.sort(function (a, b) {
  1071. return a.name.localeCompare(b.name);
  1072. });
  1073.  
  1074. // reset list
  1075. selectUser.options.length = 0;
  1076.  
  1077. // add all users in field of view
  1078. for (var i = 0; i < editorList.length; i++) {
  1079. var id = editorList[i].id;
  1080. var user = Waze.model.users.get(id);
  1081. if (user === null || typeof(user) === "undefined")
  1082. continue;
  1083.  
  1084. var usrOption = document.createElement('option');
  1085. var usrRank = user.normalizedLevel;
  1086. var usrText = document.createTextNode(user.userName + " (" + usrRank + ")");
  1087. if (currentId !== null && id == currentId)
  1088. usrOption.setAttribute('selected',true);
  1089. usrOption.setAttribute('value',id);
  1090. usrOption.appendChild(usrText);
  1091. selectUser.appendChild(usrOption);
  1092. }
  1093. var thisUser = Waze.loginManager.user;
  1094. if (thisUser !== null) {
  1095. var usrOption = document.createElement('option');
  1096. var usrText = document.createTextNode("(all except me)");
  1097. if (currentId !== null && -thisUser.id == currentId)
  1098. usrOption.setAttribute('selected',true);
  1099. usrOption.setAttribute('value',-thisUser.id);
  1100. usrOption.appendChild(usrText);
  1101. selectUser.appendChild(usrOption);
  1102. }
  1103. }
  1104.  
  1105. // populate drop-down list of Cities
  1106. function updateCityList() {
  1107. var selectCity = getId('_selectCity');
  1108. var numCities = Waze.model.cities.objects.length;
  1109.  
  1110. if (numCities === 0)
  1111. return;
  1112.  
  1113. // preserve current selection
  1114. var currentId = null;
  1115. if (selectCity.selectedIndex >= 0)
  1116. currentId = selectCity.options[selectCity.selectedIndex].value;
  1117.  
  1118. // collect array of Cities
  1119. var cityIds = [];
  1120. var cityObjs = [];
  1121.  
  1122. //=========================================================================================
  1123. // This new block of code checks the following assumed conditions:
  1124. // * Every U.S. city should have an associated state
  1125. // * Every 'No city' U.S. city should be properly numbered (not an orphan blank city)
  1126. // * We only care about states if get.cities shows us close enough to the U.S. to matter
  1127. // * Any non US's city state code should be 99 (None/other)
  1128. //========================================================================================
  1129.  
  1130. // collect list if unique cities from the segments
  1131. for (var sid in Waze.model.streets.objects) {
  1132. var cid = Waze.model.streets.get(sid).cityID;
  1133. var city = Waze.model.cities.get(cid);
  1134. if (cityIds.indexOf(cid) == -1) {
  1135. cityIds.push(cid);
  1136. cityObjs.push({id: city.id, name: city.name, state: city.stateID, country: city.countryID});
  1137. }
  1138. }
  1139.  
  1140. if (cityIds.length === 0)
  1141. return;
  1142.  
  1143. // reset list
  1144. selectCity.options.length = 0;
  1145.  
  1146. // count how many (non empty) states there are here
  1147. var numStates = 0
  1148. for (var obj in Waze.model.states.objects) {
  1149. state = Waze.model.states.get(obj);
  1150. if (state.id != 1 && state.name != "")
  1151. numStates++;
  1152. }
  1153.  
  1154. // count how many countries there are here
  1155. var numCountries = 0;
  1156. for (var obj in Waze.model.countries.objects) {
  1157. numCountries++;
  1158. }
  1159.  
  1160. // add all cities in field of view
  1161. cityObjs.sort(function(a,b) {return a.name.localeCompare(b.name)});
  1162. for (var i = 0; i < cityObjs.length; i++) {
  1163. var cityID = cityObjs[i].id;
  1164. // "State-like CityIDs" to ignore. These are consistently over 100,000,000.
  1165. if (cityID > 100000000) continue;
  1166. var cityName = cityObjs[i].name;
  1167. var stateID = cityObjs[i].state;
  1168. var countryID = cityObjs[i].country;
  1169.  
  1170. if (countryID == 235) { // for U.S. only
  1171. // 'No City' segments in the U.S. should have an assigned state.
  1172. // This ID has a prescribed range. If not in this range, we get 'other' state pollution in map,
  1173. // or a bogus blank city associated to the state.
  1174.  
  1175. if (cityName === "") {
  1176. if (cityID >= 999900 && cityID <= 999999) {
  1177. cityName = "No City";
  1178. } else {
  1179. cityName = "EMPTY CITY";
  1180. }
  1181. }
  1182. }
  1183.  
  1184. else { // for non U.S. segments
  1185. if (cityName === "") cityName = "No City";
  1186. }
  1187.  
  1188. var stateObj = Waze.model.states.get(stateID);
  1189. var countryObj = Waze.model.countries.get(countryID);
  1190.  
  1191. // State handling. All cities should have an associated state. Throw an error if not.
  1192. if (numStates > 0) {
  1193. // If more than one state, we're appending it. No brainer.
  1194. if (numStates > 1) {
  1195. // ... and, if one of those states is 'Other', that's an error. Report it.
  1196. if (stateObj.id === 99) {
  1197. cityName += ", " + "NO STATE";
  1198. }
  1199. // If we get here, the state ID should be fine. Append it.
  1200. else {
  1201. cityName += ", " + stateObj.name;
  1202. }
  1203. }
  1204.  
  1205. // If we have more than one country and are in the US, append the state for sanity.
  1206. if (numStates == 1 && numCountries > 1) {
  1207. cityName += ", " + stateObj.name;
  1208. }
  1209. }
  1210.  
  1211. // If we're on a non-US street, state should always be 99, 'Other/none'.
  1212. // Append if this is the case. Otherwise don't add anything.
  1213. else if (stateID != 99 && stateID > 1) {
  1214. cityName += ", INVALID STATE";
  1215. }
  1216.  
  1217. if (numCountries > 1) {
  1218. cityName += ", " + countryObj.name.replace('United States', 'U.S.');
  1219. }
  1220.  
  1221. // create option in select menu
  1222. var cityOption = document.createElement('option');
  1223. var cityText = document.createTextNode(cityName);
  1224.  
  1225. if (currentId !== null && cityID == currentId)
  1226. cityOption.setAttribute('selected',true);
  1227. cityOption.setAttribute('value',cityID);
  1228. cityOption.appendChild(cityText);
  1229. selectCity.appendChild(cityOption);
  1230. }
  1231. }
  1232.  
  1233. var RoadTypes = {
  1234. 1: "Streets",
  1235. 98: "Non-Routable Roads", // --------------
  1236. 108: "- Dirt roads",
  1237. 120: "- Parking Lot Road",
  1238. 117: "- Private Road",
  1239. 114: "- Ferry",
  1240. 199: "Non-Drivable Roads", // --------------
  1241. 210: "- Pedestrian Bw",
  1242. 205: "- Walking Trails",
  1243. 216: "- Stairway",
  1244. 219: "- Runway/Taxiway",
  1245. // 2: "Primary Street",
  1246. // 3: "Freeways",
  1247. // 4: "Ramps",
  1248. // 6: "Major Highway",
  1249. // 7: "Minor Highway",
  1250. // 18: "Railroad",
  1251. // 14: "Ferry',
  1252. 364: "Special Flags", // --------------
  1253. 365: "- Tunnel",
  1254. };
  1255.  
  1256. var majorRoadTypes = new Array(2, 3, 4, 6, 7);
  1257. var nonRoutableTypes = new Array(8, 20, 17);
  1258. var nonDrivableTypes = new Array(5, 10, 16, 18, 19, 14);
  1259.  
  1260. // populate drop-down list of editors
  1261. function populateRoadTypes() {
  1262. var selectRoadType = getId('_selectRoadType');
  1263.  
  1264. for (var id in RoadTypes) {
  1265. var type = RoadTypes[id]
  1266. var usrOption = document.createElement('option');
  1267. var usrText = document.createTextNode(type);
  1268. if (id == 1)
  1269. usrOption.setAttribute('selected',true);
  1270. usrOption.setAttribute('value',id % 100);
  1271. usrOption.appendChild(usrText);
  1272. selectRoadType.appendChild(usrOption);
  1273. }
  1274. }
  1275.  
  1276. // enable advanced options if user is logged in and at least an AM
  1277. function enableAdvancedOptions()
  1278. {
  1279. if (advancedMode) return;
  1280.  
  1281. if (typeof Waze == 'undefined')
  1282. Waze = unsafeWindow.Waze;
  1283.  
  1284. if (typeof Waze.loginManager == 'undefined')
  1285. Waze.loginManager = unsafeWindow.Waze.loginManager;
  1286.  
  1287. if (typeof Waze.loginManager == 'undefined')
  1288. Waze.loginManager = unsafeWindow.loginManager;
  1289.  
  1290. if (Waze.loginManager !== null && Waze.loginManager.isLoggedIn()) {
  1291. thisUser = Waze.loginManager.user;
  1292. if (thisUser !== null && (thisUser.normalizedLevel >= 3 || thisUser.isAreaManager)) {
  1293. Waze.loginManager.events.unregister("afterloginchanged", null, enableAdvancedOptions);
  1294. console.log('WME Highlights: Advanced Options enabled for ' + thisUser.userName);
  1295. getId('advancedOptions').style.display = 'block';
  1296. advancedMode = true;
  1297. initUserList();
  1298. initCityList();
  1299. }
  1300. }
  1301. }
  1302.  
  1303. /* helper function */
  1304. function getElementsByClassName(classname, node) {
  1305. if(!node) node = document.getElementsByTagName("body")[0];
  1306. var a = [];
  1307. var re = new RegExp('\\b' + classname + '\\b');
  1308. var els = node.getElementsByTagName("*");
  1309. for (var i=0,j=els.length; i<j; i++)
  1310. if (re.test(els[i].className)) a.push(els[i]);
  1311. return a;
  1312. }
  1313.  
  1314. function getId(node) {
  1315. return document.getElementById(node);
  1316. }
  1317.  
  1318. /* =========================================================================== */
  1319. function initialiseHighlights()
  1320. {
  1321. if (wmechinit) {
  1322. return;
  1323. }
  1324.  
  1325. // init shortcuts
  1326. if(!window.Waze.map)
  1327. {
  1328. window.console.log("WME Color Highlights "
  1329. + ": waiting for WME...");
  1330. setTimeout(initialiseHighlights, 789);
  1331. return;
  1332. }
  1333. // add new box to left of the map
  1334. var addon = document.createElement('section');
  1335. addon.id = "highlight-addon";
  1336.  
  1337. // highlight segements
  1338. var section = document.createElement('p');
  1339. section.style.paddingTop = "0px";
  1340. //section.style.textIndent = "16px";
  1341. section.id = "hiliteOptions";
  1342. section.innerHTML = '<b>Highlight Segments</b><br>'
  1343. + '<input type="checkbox" id="_cbHighlightLocked" title="Locked Segments" /> '
  1344. + '<span title="Dotted = Automatic Locks (if available)">Locks*</span> (Red)<br>'
  1345. + '<input type="checkbox" id="_cbHighlightToll" /> '
  1346. + 'Toll (Dashed)<br>'
  1347. + '<input type="checkbox" id="_cbHighlightAltName" /> '
  1348. + '<span title="Dotted = No Name">Alternate Name</span> (Lime)<br>'
  1349. + '<input type="checkbox" id="_cbHighlightSpeedLimits" /> '
  1350. + '<span title="Segments with unverified speed limits">No Speed Limit</span>'
  1351. + ' <input type="checkbox" id="_cbHighlightPlusStreetLimits" /> '
  1352. + 'plus Streets (Orange)<br>'
  1353. + '<input type="checkbox" id="_cbHighlightUnnamed" /> '
  1354. + 'No Name (Orange)<br>'
  1355. + '<input type="checkbox" id="_cbHighlightNoCity" /> '
  1356. + 'No City (Gray)<br>'
  1357. + '<input type="checkbox" id="_cbHighlightOneWay" /> '
  1358. + 'One Way (Blue)<br>'
  1359. + '<input type="checkbox" id="_cbHighlightNoDirection" /> '
  1360. + 'Unknown Direction (Cyan)<br>'
  1361. + '<input type="checkbox" id="_cbHighlightRestrictions" /> '
  1362. + 'Time/Vehicle Restrictions (Purple)<br>'
  1363. + '<input type="checkbox" id="_cbHighlightNoTerm" /> '
  1364. + '<span title="*Dead-end roads should have terminating nodes on the end, or Waze cannot route to or from them.">Unterminated Roads* (Lime)</span><br>'
  1365. + '<input type="checkbox" id="_cbHighlightCity" /> '
  1366. + 'Filter by City (Yellow) &nbsp;'
  1367. + ' <input type="checkbox" id="_cbHighlightCityInvert" /> invert <br> '
  1368. + ' <select id="_selectCity" name="_selectCity" style="margin: 0 0 4px 16px"></select>'
  1369. + '<span id="_numCityHighlighted"></span><br>'
  1370. + '<input type="checkbox" id="_cbHighlightRoadType" /> Highlight a Road Type (Purple)<br> '
  1371. + ' <select id="_selectRoadType" name="_selectRoadType" style="margin: 0 0 4px 16px"></select><br>'
  1372. ;
  1373. addon.appendChild(section);
  1374.  
  1375. // advanced options
  1376. section = document.createElement('p');
  1377. section.style.paddingTop = "0px";
  1378. section.style.textIndent = "16px";
  1379. section.style.display = "none";
  1380. section.id = 'advancedOptions';
  1381. section.innerHTML = '<b>Advanced Options</b><br>'
  1382. + '<input type="checkbox" id="_cbHighlightRecent" /> Recently Edited (Green)<br> '
  1383. + ' <input type="number" min="0" max="365" size="3" id="_numRecentDays" style="margin: 0 0 4px 16px"/> days<br>'
  1384. + '<input type="checkbox" id="_cbHighlightEditor" /> Filter by Editor (Green)<br> '
  1385. + ' <select id="_selectUser" name="_selectUser" style="margin: 0 0 4px 16px"></select>'
  1386. + '<span id="_numUserHighlighted"></span><br>'
  1387. + '<input type="checkbox" id="_cbHighlightTurns" /> <span title="*Highlight turn errors when a segment or node is selected, and on major roads">Turn Warnings for Selected Nodes*</span><br>'
  1388. + '<input type="checkbox" id="_cbHighlightRoutingPref" /> Routing Preference (Cyan)<br>'
  1389. ;
  1390. addon.appendChild(section);
  1391.  
  1392. // highlight places
  1393. section = document.createElement('p');
  1394. section.id = "hilitePlaces";
  1395. section.innerHTML = '<input type="checkbox" id="_cbHighlightPlaces" /> <b title="'
  1396. + 'parks/trees = green, water = blue, parking lot = cyan, '
  1397. + 'everything else = pink">Highlight Places</b> '
  1398. + '<span id="wmedebug" style="color: gray"></span><br>'
  1399. + '<input type="checkbox" id="_cbHighlightLockedPlaces" /> Locked Places (Red)<br>'
  1400. + '<input type="checkbox" id="_cbHighlightIncompletePlaces" /> '
  1401. + '<span title="If blank name or street, or wrong category">Incomplete Places</span> (Dashed Orange)<br>'
  1402. ;
  1403. addon.appendChild(section);
  1404.  
  1405. if (/Chrome/.test(navigator.userAgent)) {
  1406. addon.innerHTML += '<b><a href="https://chrome.google.com/webstore/detail/wme-color-highlights/ijnldkoicbhinlgnoigchihmegdjobjc" target="_blank"><u>'
  1407. + 'WME Color Highlights</u></a></b> &nbsp; v' + wmech_version;
  1408. } else {
  1409. addon.innerHTML += '<b><a href="https://greasyfork.org/scripts/3206-wme-color-highlights" target="_blank"><u>'
  1410. + 'WME Color Highlights</u></a></b> &nbsp; v' + wmech_version;
  1411. + ' <a href="https://greasyfork.org/scripts/3206-wme-color-highlights" target="_blank">'
  1412. + '<img src="http://waze.cryosphere.co.uk/scripts/update.php?version=' + wmech_version + '" /></a>';
  1413. }
  1414.  
  1415. var userTabs = getId('user-info');
  1416. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  1417. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  1418. if (typeof navTabs === "undefined") {
  1419. console.log("WME Highlights: not logged in - will initialise later");
  1420. Waze.loginManager.events.register("login", null, initialiseHighlights);
  1421. return;
  1422. }
  1423.  
  1424. newtab = document.createElement('li');
  1425. newtab.innerHTML = '<a href="#sidepanel-highlights" data-toggle="tab">Highlight</a>';
  1426. navTabs.appendChild(newtab);
  1427.  
  1428. addon.id = "sidepanel-highlights";
  1429. addon.className = "tab-pane";
  1430. tabContent.appendChild(addon);
  1431.  
  1432. // check for AM or CM, and unhide Advanced options
  1433. enableAdvancedOptions();
  1434.  
  1435. // always populate road types
  1436. populateRoadTypes();
  1437.  
  1438. // setup onclick handlers for instant update:
  1439. getId('_cbHighlightLocked').onclick = highlightSegments;
  1440. getId('_cbHighlightToll').onclick = highlightSegments;
  1441. getId('_cbHighlightUnnamed').onclick = highlightSegments;
  1442. getId('_cbHighlightNoCity').onclick = highlightSegments;
  1443. getId('_cbHighlightOneWay').onclick = highlightSegments;
  1444. getId('_cbHighlightNoDirection').onclick = highlightSegments;
  1445. getId('_cbHighlightRestrictions').onclick = highlightSegments;
  1446. getId('_cbHighlightSpeedLimits').onclick = highlightSegments;
  1447. getId('_cbHighlightPlusStreetLimits').onclick = highlightSegments;
  1448. getId('_cbHighlightRoutingPref').onclick = highlightSegments;
  1449.  
  1450. getId('_cbHighlightRecent').onclick = highlightSegmentsAndPlaces;
  1451. getId('_cbHighlightEditor').onclick = highlightSegmentsAndPlaces;
  1452. getId('_cbHighlightCity').onclick = highlightSegmentsAndPlaces;
  1453. getId('_cbHighlightCityInvert').onclick = highlightSegmentsAndPlaces;
  1454. getId('_cbHighlightRoadType').onclick = highlightSegments;
  1455. getId('_cbHighlightNoTerm').onclick = highlightSegments;
  1456. getId('_cbHighlightTurns').onclick = highlightSelectedNodes;
  1457.  
  1458. getId('_selectUser').onfocus = updateUserList;
  1459. getId('_selectUser').onchange = highlightSegmentsAndPlaces;
  1460.  
  1461. getId('_selectCity').onfocus = updateCityList;
  1462. getId('_selectCity').onchange = highlightSegmentsAndPlaces;
  1463.  
  1464. getId('_numRecentDays').onchange = highlightSegmentsAndPlaces;
  1465. getId('_selectRoadType').onchange = highlightSegments;
  1466.  
  1467. getId('_cbHighlightPlaces').onclick = highlightPlaces;
  1468. getId('_cbHighlightLockedPlaces').onclick = highlightPlaces;
  1469. getId('_cbHighlightIncompletePlaces').onclick = highlightPlaces;
  1470.  
  1471.  
  1472. // restore saved settings
  1473. if (localStorage.WMEHighlightScript) {
  1474. console.log("WME Highlights: loading options");
  1475. options = JSON.parse(localStorage.WMEHighlightScript);
  1476.  
  1477. getId('_cbHighlightLocked').checked = (options[1] % 2 == 1);
  1478. getId('_cbHighlightToll').checked = options[2];
  1479. getId('_cbHighlightUnnamed').checked = options[3];
  1480. getId('_cbHighlightNoCity').checked = options[4];
  1481. getId('_cbHighlightOneWay').checked = options[5];
  1482. getId('_cbHighlightNoDirection').checked = options[6];
  1483. getId('_cbHighlightNoTerm').checked = options[14];
  1484. getId('_cbHighlightCity').checked = options[15];
  1485. getId('_cbHighlightRoadType').checked = options[16];
  1486. getId('_selectRoadType').selectedIndex = options[17];
  1487. getId('_cbHighlightPlaces').checked = options[7];
  1488. getId('_cbHighlightRestrictions').checked = options[19];
  1489. getId('_cbHighlightLockedPlaces').checked = options[20]; //(options[1] > 1);
  1490. getId('_cbHighlightIncompletePlaces').checked = options[21];
  1491. getId('_cbHighlightAltName').checked = options[22];
  1492. getId('_cbHighlightSpeedLimits').checked = options[23];
  1493. getId('_cbHighlightPlusStreetLimits').checked = options[24];
  1494. if (options[12] === undefined) options[12] = 7;
  1495. getId('_cbHighlightRecent').checked = options[11];
  1496. getId('_numRecentDays').value = options[12];
  1497. getId('_cbHighlightEditor').checked = options[13];
  1498. getId('_cbHighlightTurns').checked = options[18];
  1499. getId('_cbHighlightRoutingPref').checked = options[25];
  1500. } else {
  1501. getId('_cbHighlightPlaces').checked = true;
  1502. getId('_cbHighlightTurns').checked = true;
  1503. }
  1504.  
  1505. if (typeof Waze.model.venues == "undefined") {
  1506. getId('_cbHighlightPlaces').checked = false;
  1507. getId('_cbHighlightPlaces').disabled = true;
  1508. }
  1509.  
  1510. if (!getId('_cbHighlightPlaces').checked) {
  1511. getId('_cbHighlightLockedPlaces').disabled = true;
  1512. getId('_cbHighlightIncompletePlaces').disabled = true;
  1513. }
  1514.  
  1515. // overload the WME exit function
  1516. saveHighlightOptions = function() {
  1517. if (localStorage) {
  1518. console.log("WME Highlights: saving options");
  1519. var options = [];
  1520.  
  1521. // preserve previous options which may get lost after logout
  1522. if (localStorage.WMEHighlightScript)
  1523. options = JSON.parse(localStorage.WMEHighlightScript);
  1524.  
  1525. options[1] = 1 * getId('_cbHighlightLocked').checked + 2 * getId('_cbHighlightLockedPlaces').checked;
  1526. options[2] = getId('_cbHighlightToll').checked;
  1527. options[3] = getId('_cbHighlightUnnamed').checked;
  1528. options[4] = getId('_cbHighlightNoCity').checked;
  1529. options[5] = getId('_cbHighlightOneWay').checked;
  1530. options[6] = getId('_cbHighlightNoDirection').checked;
  1531. options[7] = getId('_cbHighlightPlaces').checked;
  1532. options[14] = getId('_cbHighlightNoTerm').checked;
  1533. options[15] = getId('_cbHighlightCity').checked;
  1534. options[16] = getId('_cbHighlightRoadType').checked;
  1535. options[17] = getId('_selectRoadType').selectedIndex;
  1536. options[19] = getId('_cbHighlightRestrictions').checked;
  1537. options[20] = getId('_cbHighlightLockedPlaces').checked;
  1538. options[21] = getId('_cbHighlightIncompletePlaces').checked;
  1539. options[22] = getId('_cbHighlightAltName').checked;
  1540. options[23] = getId('_cbHighlightSpeedLimits').checked;
  1541. options[24] = getId('_cbHighlightPlusStreetLimits').checked;
  1542. if (advancedMode) {
  1543. options[11] = getId('_cbHighlightRecent').checked;
  1544. options[12] = getId('_numRecentDays').value;
  1545. options[13] = getId('_cbHighlightEditor').checked;
  1546. options[18] = getId('_cbHighlightTurns').checked;
  1547. options[25] = getId('_cbHighlightRoutingPref').checked;
  1548. }
  1549.  
  1550. localStorage.WMEHighlightScript = JSON.stringify(options);
  1551. }
  1552. }
  1553. window.addEventListener("beforeunload", saveHighlightOptions, false);
  1554.  
  1555. // begin periodic updates
  1556. window.setInterval(highlightSegments,333);
  1557. window.setInterval(highlightPlaces,500);
  1558. window.setInterval(highlightBadNodes,444);
  1559. window.setInterval(highlightSelectedNodes,250);
  1560.  
  1561. // trigger code when page is fully loaded, to catch any missing bits
  1562. window.addEventListener("load", function(e) {
  1563. var mapProblems = getId('map-problems-explanation')
  1564. if (mapProblems !== null) mapProblems.style.display = "none";
  1565. enableAdvancedOptions();
  1566. });
  1567.  
  1568. // register some events...
  1569. Waze.map.events.register("zoomend", null, highlightSegments);
  1570. Waze.map.events.register("zoomend", null, highlightPlaces);
  1571. Waze.map.events.register("zoomend", null, highlightSelectedNodes);
  1572.  
  1573. Waze.selectionManager.events.register("selectionchanged", null, highlightSelectedNodes);
  1574.  
  1575. //Waze.loginManager.events.register("afterloginchanged", null, enableAdvancedOptions);
  1576. Waze.model.events.register("mergeend", null, initCityList);
  1577. wmechinit = true;
  1578. }
  1579.  
  1580. /* engage! =================================================================== */
  1581. setTimeout(initialiseHighlights, 789);
  1582.  
  1583. })();
  1584. /* end ======================================================================= */