WME PlaceNames

Show area and point place names in WME, color and highlight places by type and properties

  1. // ==UserScript==
  2. // @name WME PlaceNames
  3. // @version 0.81
  4. // @description Show area and point place names in WME, color and highlight places by type and properties
  5. // @include https://www.waze.com/editor*
  6. // @include https://www.waze.com/*/editor*
  7. // @include https://beta.waze.com/editor*
  8. // @include https://beta.waze.com/*/editor*
  9. // @copyright 2017, ragacs
  10. // @namespace https://gf.qytechs.cn/users/6330
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. var wmepn_translations =
  15. {
  16. "en":
  17. {
  18. enable_script: "Enable script",
  19. enable_script_tooltip: "Toggle highlighting and place names layer\nUse the Layer selector or Shift+N hotkey to toggle names only",
  20. color_places: "Color places",
  21. color_places_tooltip: "Color the places like WMECH does",
  22. highlight_places: "Highlight places without name/HN",
  23. highlight_places_tooltip: "Highlight public places without name and private places without house number (yellow)",
  24. show: "Show",
  25. show_tooltip: "Select desired names to show",
  26. option_areaonly: "Area only",
  27. option_areapoint: "Area and Point",
  28. option_pointonly: "Point only",
  29. filter: "Filter",
  30. filter_tooltip: "Filter only the names containing this string (you could use regex e.g. /school/i)",
  31. show_locklevel: "Show lock level",
  32. show_locklevel_tooltip: "Display lock level after the name, like [L3] or [L4]",
  33. stop_over: "Stop over",
  34. stop_over_tooltip: "Limit displayed place names to the specified value",
  35. option_unlimited: "Unlimited",
  36. showing: "Showing",
  37. place_names_and: {
  38. one: "place name and",
  39. other: "place names and" },
  40. house_numbers: {
  41. one: "house number",
  42. other: "house numbers" },
  43. translator: "translated by [Your Waze Nickname]"
  44. },
  45. "hu":
  46. {
  47. enable_script: "Szkript engedélyezése",
  48. enable_script_tooltip: "A színezés, kiemelés és a Helynevek réteg bekapcsolása\nHasználd a rétegválasztót vagy a Shift+N forróbillentyűt, ha csak a neveket akarod kapcsolgatni",
  49. color_places: "Helyek színezése",
  50. color_places_tooltip: "Helyek színezése, ahogyan a WMECH teszi",
  51. highlight_places: "Név/hsz nélküli helyek kiemelése",
  52. highlight_places_tooltip: "Kiemeli (sárgával) a névtelen nyilvános helyeket és a házszám nélküli magánházakat",
  53. show: "Mutasd",
  54. show_tooltip: "Válaszd ki a megmutatni kívánt neveket",
  55. option_areaonly: "Csak terület",
  56. option_areapoint: "Terület és pont",
  57. option_pointonly: "Csak pont",
  58. filter: "Szűrő",
  59. filter_tooltip: "Csak azokat a neveket mutassa, amik ezt a szöveget tartalmazzák (reguláris kifejezések használhatók, pl. /iskola/i)",
  60. show_locklevel: "Védelem mutatása",
  61. show_locklevel_tooltip: "Mutassa a védelmi szintet is a név után, pl. [L3] vagy [L4]",
  62. stop_over: "Maximum",
  63. stop_over_tooltip: "A képernyőn egyszerre látható név-feliratok számát korlátozza",
  64. option_unlimited: "Korlátlan",
  65. showing: "Látható",
  66. place_names_and: "helynév és",
  67. house_numbers: "házszám",
  68. translator: "fordította ragacs"
  69. },
  70. "cs":
  71. {
  72. enable_script: "Povolit skript",
  73. enable_script_tooltip: "Přepínač zvýraznění a jmen míst\nPoužijte menu Vrstvy nebo klávesovou zkratku Shift+N, aby se zobrazila jen jména míst",
  74. color_places: "Barevné odlišení",
  75. color_places_tooltip: "Barevné odlišení jako WMECH",
  76. highlight_places: "Odlišit nepojmenovaná místa",
  77. highlight_places_tooltip: "Odlišit nepojmenovaná veřejná místa a soukromá místa bez čísla domu (žlutě)",
  78. show: "Zobrazit",
  79. show_tooltip: "Zobrazit požadovaná jména",
  80. option_areaonly: "Jen plochy",
  81. option_areapoint: "Plochy a body",
  82. option_pointonly: "Jen body",
  83. filter: "Filtr",
  84. filter_tooltip: "Filtrovat jen jména obsahující tento řetězec (lze použít regex např. /škola/i)",
  85. show_locklevel: "Ukázat zámek",
  86. show_locklevel_tooltip: "Zobrazit zámek za jménem místa (např. [L3] nebo [L4])",
  87. stop_over: "Omezení",
  88. stop_over_tooltip: "Omezit zobrazená místa na zadanou hodnotu",
  89. option_unlimited: "Bez omezení",
  90. showing: "Zobrazení",
  91. place_names_and: "jména míst a",
  92. house_numbers: "čísla domů",
  93. translator: "překládal bures"
  94. },
  95. "nl" :
  96. {
  97. enable_script: "Script inschakelen",
  98. enable_script_tooltip: "De laag voor het weergeven en markeren van plaatsnamen beheren\nGebruik de laagselector of Shift+N om enkel de namen te beheren",
  99. color_places: "Voeg kleur toe aan plaatsen",
  100. color_places_tooltip: "Kleur de plaatsen in zoals het WMECH-script dit doet",
  101. highlight_places: "Markeer plaatsen zonder naam of huisnummer",
  102. highlight_places_tooltip: "Markeer publieke plaatsen zonder naam en private plaatsen zonder huisnummer (geel)",
  103. show: "Weergave",
  104. show_tooltip: "Selecteer welke namen er moeten weergegeven worden",
  105. option_areaonly: "Enkel gebieden",
  106. option_areapoint: "Gebieden en punten",
  107. option_pointonly: "Enkel punten",
  108. filter: "Filter",
  109. filter_tooltip: "Toon enkel de plaatsen met de volgende naam (je kan ook een regex gebruiken zoals /school/i)",
  110. show_locklevel: "Lock-level weergeven",
  111. show_locklevel_tooltip: "Geef het lock-level weer achter de naam als [L3] of [L4]",
  112. stop_over: "Beperk aantal plaatsnamen",
  113. stop_over_tooltip: "Beperk het aantal weergegeven plaatsnamen tot dit aantal",
  114. option_unlimited: "Onbeperkt",
  115. showing: "Huidige weergave: ",
  116. place_names_and: {
  117. one: "plaatsnaam en",
  118. other: "plaatsnamen en" },
  119. house_numbers: {
  120. one: "huisnummer",
  121. other: "huisnummers" },
  122. translator: "vertaald door Glodenox"
  123. },
  124. "fr":
  125. {
  126. enable_script: "Activer le script",
  127. enable_script_tooltip: "Pour activer et désactiver le calque \n Utilisez le gestionnaire de calque ou Shift+N pour les noms seulement",
  128. color_places: "Colorer les lieux ",
  129. color_places_tooltip: "Colore comme WME Color Highlight",
  130. highlight_places: "Surbrillance les lieux sans nom/HN",
  131. highlight_places_tooltip: "Surbrillance (Jaune) pour les lieux publiques sans nom & les lieux résidentiels sans numéro ",
  132. show: "Afficher",
  133. show_tooltip: "Séléctione les noms à afficher",
  134. option_areaonly: "Zones seulement",
  135. option_areapoint: "Zones & lieux",
  136. option_pointonly: "Lieux seulement",
  137. filter: "Filtrer",
  138. filter_tooltip: "Filtre les noms contenant ces lettres/mots (utilisation possible de regex ex : /school/i )",
  139. show_locklevel: "Afficher le niveau de verouillage",
  140. show_locklevel_tooltip: "Affiche le niveau de vérouillage en fin de nom ex : [L3] ou [L4]",
  141. stop_over: "Limiter à",
  142. stop_over_tooltip: "Limite le nombre de noms de lieux affichés",
  143. option_unlimited: "Illimité",
  144. showing: "Afficher",
  145. place_names_and: {
  146. one: "nom de lieu et",
  147. other: "noms des lieux et" },
  148. house_numbers: {
  149. one: "numéro de rue",
  150. other: "numéros de rue" },
  151. translator: "adapté par no1ne"
  152. },
  153. "pl" :
  154. {
  155. enable_script: "Włącz skrypt",
  156. enable_script_tooltip: "Włącz podświetlanie i warstwę nazw Miejsc\nUżyj wyboru warstw lub kombinacji Shift+N, żeby włączyć tylko nazwy",
  157. color_places: "Kolory miejsc",
  158. color_places_tooltip: "Pokoloruj miejsca tak, jak robi to WME Color Highlight",
  159. highlight_places: "Podświetl miejsca bez nazwy/nr adresowego",
  160. highlight_places_tooltip: "Podświetl miejsca publiczne bez nazwy i budynki mieszkalne bez numeru domu (żółty)",
  161. show: "Pokaż",
  162. show_tooltip: "Wybierz wybrane nazwy do pokazania",
  163. option_areaonly: "Tylko obszary",
  164. option_areapoint: "Obszary i Punkty",
  165. option_pointonly: "Tylko punkty",
  166. filter: "Filtr",
  167. filter_tooltip: "Filtruj tylko nazwy zawierające ten ciąg znaków (możesz użyć regex np. /szkoł[ay]/i)",
  168. show_locklevel: "Pokaż poziom blokady",
  169. show_locklevel_tooltip: "Wyświetl poziom blokady po nazwie, np. [L3] lub [L4]",
  170. stop_over: "Zatrzymaj po",
  171. stop_over_tooltip: "Ogranicz wyświetlanie nazw miejsc do określonej ilości",
  172. option_unlimited: "Nieograniczone",
  173. showing: "Pokazywanie",
  174. place_names_and: {
  175. one: "nazwa miejsca",
  176. other: "nazwy miejsc" },
  177. house_numbers: {
  178. one: "numer domu",
  179. other: "numery domów" },
  180. translator: "przetłumaczone przez TCholewa"
  181. },
  182. "he" :
  183. {
  184. enable_script: "הפעל תוסף",
  185. enable_script_tooltip: "מציג שמות ומדגיש מקומות",
  186. color_places: "הדגש מקומות",
  187. color_places_tooltip: "מדגיש את המקומות כמו בתוסף WME Color Highlights",
  188. highlight_places: "הדגש מקומות ללא שם/מספר בית",
  189. highlight_places_tooltip: "מדגיש מקומות ציבוריים ללא שם ומקומות מגורים ללא מספר בית (צהוב)",
  190. show: "הצג",
  191. show_tooltip: "בחר שמות להצגה",
  192. option_areaonly: "איזור בלבד",
  193. option_areapoint: "איזור ונקודות",
  194. option_pointonly: "נקודות בלבד",
  195. filter: "סנן",
  196. filter_tooltip: "סנן מקומות אשר מכילים את השם הבא (לדוג'- בית ספר וכיוב)",
  197. show_locklevel: "הצג רמת נעילה",
  198. show_locklevel_tooltip: "מציג את דרגת הנעילה בהמשך לשם המקום",
  199. stop_over: " מקס' תוצאות להצגה",
  200. stop_over_tooltip: "מגביל את כמות התוצאות המתאימות לערך",
  201. option_unlimited: "ללא הגבלה",
  202. showing: "מציג",
  203. place_names_and: {
  204. one: "שם המקום ו",
  205. other: "שמות מקומות ו" },
  206. house_numbers: {
  207. one: "מספר בית",
  208. other: "מספרי בתים" },
  209. translator: "תורגם לעברית עי okrauss"
  210. },
  211. "es" :
  212. {
  213. enable_script: "Activar el script",
  214. enable_script_tooltip: "Para activar y desactivar el resaltado de la capa de Place Names\nUtiliza el selector de capas o el atajo de teclado Shift+N para activar/desactivar solo los nombres",
  215. color_places: "Colorear places",
  216. color_places_tooltip: "Colorear los places como lo hace WMECH",
  217. highlight_places: "Resaltar places sin nombre o número de casa",
  218. highlight_places_tooltip: "Resaltar places públicos sin nombre y places privados sin número de casa (en amarillo)",
  219. show: "Mostrar",
  220. show_tooltip: "Seleccionar los nombres que se desean mostrar",
  221. option_areaonly: "Sólo Area",
  222. option_areapoint: "Area y Punto",
  223. option_pointonly: "Sólo Punto",
  224. filter: "Filtar",
  225. filter_tooltip: "Filtrar solo los nombres que contienen este texto (puedes utilizar regex Ej: /escuela/i)",
  226. show_locklevel: "Mostrar el nivel de bloqueo",
  227. show_locklevel_tooltip: "Mostrar el nivel de bloqueo luego del nombre, como [L3] o [L4]",
  228. stop_over: "Limitar a",
  229. stop_over_tooltip: "Limitar Place Names a el valor especificado",
  230. option_unlimited: "Ilimitado",
  231. showing: "Mostrando",
  232. place_names_and: {
  233. one: "Place Name y",
  234. other: "Place Names y" },
  235. house_numbers: {
  236. one: "Número de casa",
  237. other: "Números de casa" },
  238. translator: "Traducido por ancho85"
  239. },
  240. "es-419" :
  241. {
  242. enable_script: "Activar el script",
  243. enable_script_tooltip: "Para activar y desactivar el resaltado de la capa de Place Names\nUtiliza el selector de capas o el atajo de teclado Shift+N para activar/desactivar solo los nombres",
  244. color_places: "Colorear places",
  245. color_places_tooltip: "Colorear los places como lo hace WMECH",
  246. highlight_places: "Resaltar places sin nombre o número de casa",
  247. highlight_places_tooltip: "Resaltar places públicos sin nombre y places privados sin número de casa (en amarillo)",
  248. show: "Mostrar",
  249. show_tooltip: "Seleccionar los nombres que se desean mostrar",
  250. option_areaonly: "Sólo Area",
  251. option_areapoint: "Area y Punto",
  252. option_pointonly: "Sólo Punto",
  253. filter: "Filtar",
  254. filter_tooltip: "Filtrar solo los nombres que contienen este texto (puedes utilizar regex Ej: /escuela/i)",
  255. show_locklevel: "Mostrar el nivel de bloqueo",
  256. show_locklevel_tooltip: "Mostrar el nivel de bloqueo luego del nombre, como [L3] o [L4]",
  257. stop_over: "Limitar a",
  258. stop_over_tooltip: "Limitar Place Names a el valor especificado",
  259. option_unlimited: "Ilimitado",
  260. showing: "Mostrando",
  261. place_names_and: {
  262. one: "Place Name y",
  263. other: "Place Names y" },
  264. house_numbers: {
  265. one: "Número de casa",
  266. other: "Números de casa" },
  267. translator: "Traducido por ancho85"
  268. },
  269. "pt-BR":
  270. {
  271. enable_script: "Habilitar script",
  272. enable_script_tooltip: "Destacar camadas e nomes de locais \nUse a marcação de camadas ou Shift+N para destacar nomes apenas",
  273. color_places: "Locais coloridos",
  274. color_places_tooltip: "Colirir os locais como WMECH faz",
  275. highlight_places: "Destaque locais sem nome/SN",
  276. highlight_places_tooltip: "Destacar locais público sem nome e locais privador sem numeração (amarelo)",
  277. show: "Mostrar",
  278. show_tooltip: "Escolha nomes desejados para mostrar",
  279. option_areaonly: "Apenas área",
  280. option_areapoint: "Área e ponto",
  281. option_pointonly: "Apenas ponto",
  282. filter: "Filtro",
  283. filter_tooltip: "Filtrar somente nomes que contenham esta string (você pde usar regex e.g. /school/i)",
  284. show_locklevel: "Mostrar nível de bloqueio",
  285. show_locklevel_tooltip: "Mostrar nível de bloqueio após o nome, tipo [L3] or [L4]",
  286. stop_over: "Limite",
  287. stop_over_tooltip: "Limite mostrado de nomes de lugares para o valor especificado",
  288. option_unlimited: "Sem limite",
  289. showing: "Mostrando",
  290. place_names_and: {
  291. one: "nome de local e",
  292. other: "nomes de locais e" },
  293. house_numbers: {
  294. one: "numeração de casa",
  295. other: "numerações de casas" },
  296. translator: "translated by GabiruDriverX"
  297. }
  298. };
  299.  
  300. // Using parts from highlight and route speed scripts by various authors
  301.  
  302. /* bootstrap, will call initialiseLandmarkNames() */
  303. function bootstrapLandmarkNames()
  304. {
  305. /* begin running the code! */
  306. setTimeout(initialiseLandmarkNames, 999);
  307. }
  308.  
  309. function wmepn_wordWrap(str, maxWidth) {
  310. function testWhite(x) {
  311. var white = new RegExp(/^[ \t\r\n\f]$/); // We are not using \s because it matches non-breaking space too
  312. return white.test(x.charAt(0));
  313. }
  314.  
  315. var newLineStr = "\n"; done = false; res = '';
  316. do {
  317. found = false;
  318. // Inserts new line at first whitespace of the line
  319. for (i = maxWidth - 1; i >= 0; i--) {
  320. if (testWhite(str.charAt(i))) {
  321. res = res + [str.slice(0, i), newLineStr].join('');
  322. str = str.slice(i + 1);
  323. found = true;
  324. break;
  325. }
  326. }
  327. // Inserts new line at maxWidth position, the word is too long to wrap
  328. if (!found && str.length > maxWidth) {
  329. res += [str.slice(0, maxWidth), newLineStr].join('');
  330. str = str.slice(maxWidth);
  331. }
  332.  
  333. if (str.length < maxWidth)
  334. {
  335. res = res + str;
  336. done = true;
  337. }
  338. } while (!done);
  339.  
  340. return res;
  341. }
  342.  
  343. function wmepn_resetLandmarks()
  344. {
  345. var venues = Waze.model.venues;
  346. for (var mark in venues.objects) {
  347. var venue = venues.get(mark);
  348. var poly = wmepn_getId(venue.geometry.id);
  349. if (poly !== null) {
  350. if (poly.getAttribute("stroke-opacity") != 1) {
  351. poly.setAttribute("fill","#d191d6");
  352. poly.setAttribute("stroke","#d191d6");
  353. poly.setAttribute("fill-opacity",0.3);
  354. poly.setAttribute("stroke-opacity",1);
  355. }
  356. }
  357. }
  358. wmepn_showLandmarkNames();
  359. }
  360.  
  361. function wmepn_showLandmarkNames() {
  362. wmepn_NameLayer.removeAllFeatures();
  363. if(wmepn_getId('sidepanel-landmarknames') === null) installLandmarkNamesTab();
  364. if(wmepn_getId('_cbLandmarkNamesEnable') === null) return;
  365. if (typeof Waze.model.venues == "undefined" || wmepn_getId('_cbLandmarkNamesEnable').checked === false) {
  366. wmepn_getId('_stLandmarkNumber').innerHTML = 0;
  367. wmepn_getId('_stLandmarkHNNumber').innerHTML = 0;
  368. return;
  369. }
  370. var venues = Waze.model.venues;
  371. var streets = Waze.model.streets;
  372. var map = Waze.map;
  373. var showNames = wmepn_NameLayer.getVisibility() && map.getLayersBy("uniqueName", "landmarks")[0].getVisibility();
  374. // if checkbox unticked, reset places to original style
  375. if (!showNames
  376. && !wmepn_getId('_cbLandmarkColors').checked
  377. && !wmepn_getId('_cbLandmarkHiliteNoName').checked) {
  378. for (var mark in venues.objects) {
  379. var venue = venues.get(mark);
  380. var poly = wmepn_getId(venue.geometry.id);
  381. if (poly !== null) {
  382. if (poly.getAttribute("stroke-opacity") != 1) {
  383. poly.setAttribute("fill","#d191d6");
  384. poly.setAttribute("stroke","#d191d6");
  385. poly.setAttribute("fill-opacity",0.3);
  386. poly.setAttribute("stroke-opacity",1);
  387. }
  388. }
  389. }
  390. wmepn_getId('_stLandmarkNumber').innerHTML = 0;
  391. wmepn_getId('_stLandmarkHNNumber').innerHTML = 0;
  392. return;
  393. }
  394.  
  395. var hiliteNoName = wmepn_getId('_cbLandmarkHiliteNoName').checked;
  396. var colorLandmarks = wmepn_getId('_cbLandmarkColors').checked;
  397. var showPoints = (wmepn_getId('_seLandmarkPoints').value == "all" || wmepn_getId('_seLandmarkPoints').value == "point");
  398. var showAreas = (wmepn_getId('_seLandmarkPoints').value == "all" || wmepn_getId('_seLandmarkPoints').value == "area");
  399. var showLockLevel = wmepn_getId('_cbLandmarkLockLevel').checked;
  400. var limitNames = wmepn_getId('_seLandmarkLimit').value;
  401. var nameFilterArray = wmepn_getId('_inLandmarkNameFilter').value.split("/");
  402. var nameFilter = (nameFilterArray.length > 1 ? nameFilterArray[1] : nameFilterArray[0]);
  403. var nameFilterOptions = nameFilterArray[2];
  404. var nameFilterRegEx = (nameFilterArray.length > 1 ? new RegExp(nameFilter, nameFilterOptions) : null);
  405. var doFilter = function (name) {
  406. if(nameFilter.length === 0)
  407. return true; // show all when no filter entered
  408. if(nameFilterRegEx === null)
  409. return (name.indexOf(nameFilter) >= 0);
  410. else
  411. return nameFilterRegEx.test(name);
  412. };
  413.  
  414. var drawnNames = 0;
  415. var drawnHNs = 0;
  416. for (var mark in venues.objects) {
  417. var venue = venues.get(mark);
  418. var poly = wmepn_getId(venue.geometry.id);
  419. var isPoint = venue.geometry.toString().match(/^POINT/);
  420. var isArea = venue.geometry.toString().match(/^POLYGON/);
  421. var trimmedName = venue.attributes.name.trim();
  422. var noTrName = (trimmedName.length == 0);
  423. if(showLockLevel) trimmedName += (noTrName ? "" : "\n") + "[L" + (venue.attributes.lockRank+1) + "]";
  424. var houseNumber = venue.attributes.houseNumber;
  425. if (poly !== null) {
  426. var venueStreet = streets.get(venue.attributes.streetID);
  427. var haveNoName = (venue.attributes.residential ? (houseNumber === undefined || houseNumber.length == 0) : noTrName);
  428.  
  429. if(showNames && (showAreas || showPoints) && (limitNames == 0 || drawnNames < limitNames))
  430. {
  431. var wrappedText = wmepn_wordWrap(trimmedName, 30);
  432. var filterMatched = (!noTrName && doFilter(trimmedName));
  433. if(showAreas && isArea && filterMatched)
  434. {
  435. // Add label texts
  436. var labelFeatures = [];
  437. var bounds = venue.geometry.bounds;
  438. var pt;
  439. //if(bounds.getWidth() * bounds.getHeight() * .3 > venue.geometry.getArea() && venue.attributes.entryExitPoints.length > 0)
  440. // pt = venue.attributes.entryExitPoints[0].point;
  441. //else
  442. pt = venue.geometry.getCentroid();
  443. var textFeature = new OpenLayers.Feature.Vector( pt, {labelText: wrappedText, fontColor: '#F0F0F0', pointRadius: 0 } );
  444. labelFeatures.push(textFeature);
  445. wmepn_NameLayer.addFeatures(labelFeatures);
  446. drawnNames++;
  447. }
  448. if(showPoints && isPoint && (filterMatched || (houseNumber !== undefined && houseNumber.length > 0)))
  449. {
  450. // Add label texts
  451. var labelFeatures = [];
  452. var pt = new OpenLayers.Geometry.Point(venue.geometry.x, venue.geometry.y);
  453. var isHouseNumber = !filterMatched;
  454. if(venue.attributes.residential)
  455. {
  456. // This will add house numbers to the hidden names to house numbers of residential places (user request)
  457. wrappedText = houseNumber + ' - (' + wrappedText + ')';
  458. }
  459. var textFeature = new OpenLayers.Feature.Vector( pt, {labelText: (isHouseNumber ? houseNumber : wrappedText), fontColor: '#F0F0F0', pointRadius: 0, yOffset: -15, style: (isHouseNumber ? "italic" : "normal") } );
  460. labelFeatures.push(textFeature);
  461. wmepn_NameLayer.addFeatures(labelFeatures);
  462. if(isHouseNumber) drawnHNs++;
  463. else drawnNames++;
  464. }
  465. }
  466.  
  467. wmepn_getId('_stLandmarkNumber').innerHTML = drawnNames;
  468. wmepn_getId('_stLandmarkHNNumber').innerHTML = drawnHNs;
  469.  
  470. // Production polygons: #d191d6, Beta editor polygons: #c290c6
  471. if ((poly.getAttribute("fill") == "#d191d6" || poly.getAttribute("fill") == "#c290c6") && poly.getAttribute("stroke-opacity") == 1) {
  472. var categories = venue.attributes.categories;
  473. var colored = false;
  474.  
  475. if(colorLandmarks)
  476. {
  477. // gas station = orange
  478. if (categories.indexOf("GAS_STATION") > -1) {
  479. poly.setAttribute("fill","#f90");
  480. poly.setAttribute("stroke","#f90");
  481. colored = true;
  482. }
  483.  
  484. // parking lot = cyan
  485. else if (categories.indexOf("PARKING_LOT") > -1) {
  486. poly.setAttribute("fill","#099");
  487. poly.setAttribute("stroke","#0cc");
  488. }
  489.  
  490. // water = blue
  491. else if (categories.indexOf("RIVER_STREAM") > -1 ||
  492. categories.indexOf("SEA_LAKE_POOL") > -1) {
  493. poly.setAttribute("fill","#09f");
  494. poly.setAttribute("stroke","#06c");
  495. colored = true;
  496. }
  497.  
  498. // park/grass/trees = green
  499. else if (categories.indexOf("PARK") > -1 ||
  500. categories.indexOf("FARM") > -1 ||
  501. categories.indexOf("FOREST_GROVE") > -1 ||
  502. categories.indexOf("GOLF_COURSE") > -1) {
  503. poly.setAttribute("fill","#4f4");
  504. poly.setAttribute("stroke","#6a6");
  505. colored = true;
  506. }
  507. }
  508.  
  509. poly.setAttribute("stroke-opacity",0.97);
  510.  
  511. // highlight places which have no name and not colored before
  512. if (hiliteNoName && haveNoName && colored === false) {
  513. poly.setAttribute("fill","#ff8");
  514. poly.setAttribute("stroke","#cc0");
  515. colored = true;
  516. }
  517. // if was yellow and now not yellow, reset
  518. else if (poly.getAttribute("fill") == "#ff8" && (!hiliteNoName || !haveNoName)) {
  519. poly.setAttribute("fill","#d191d6");
  520. poly.setAttribute("stroke","#d191d6");
  521. poly.setAttribute("stroke-opacity",1);
  522. }
  523. }
  524. }
  525. }
  526. wmepn_getId('_stLandmarkNumber').innerHTML = '<i>' + drawnNames + '</i> ' + I18n.t("wmepn.place_names_and", {count: drawnNames});
  527. wmepn_getId('_stLandmarkHNNumber').innerHTML = '<i>' + drawnHNs + '</i> ' + I18n.t("wmepn.house_numbers", {count: drawnHNs});
  528. //map.getLayersBy("name", "Place Names")[0].setZIndex(730);
  529. }
  530.  
  531. wmepn_NameLayer = undefined;
  532.  
  533. function wmepn_toggleOptions () {
  534. return false;
  535. }
  536.  
  537. /* helper function */
  538. function wmepn_getId(node) {
  539. return document.getElementById(node);
  540. }
  541.  
  542. function installLandmarkNamesTab()
  543. {
  544. if(wmepn_getId('sidepanel-landmarknames') !== null || wmepn_getId('user-info') === null) return;
  545. // helper fn
  546. function getElementsByClassName(classname, node) {
  547. if(!node) node = document.getElementsByTagName("body")[0];
  548. var a = [];
  549. var re = new RegExp('\\b' + classname + '\\b');
  550. var els = node.getElementsByTagName("*");
  551. for (var i=0,j=els.length; i<j; i++)
  552. if (re.test(els[i].className)) a.push(els[i]);
  553. return a;
  554. }
  555.  
  556. // Some internationalization
  557. I18n.translations[I18n.locale].wmepn = wmepn_translations[I18n.locale];
  558. if(wmepn_translations[I18n.locale] === undefined) I18n.translations[I18n.locale].wmepn = wmepn_translations[I18n.defaultLocale];
  559. I18n.translations[I18n.locale].layers.name.__DrawPlaceNames = 'Place Names';
  560.  
  561. // add new box to left of the map
  562. var addon = document.createElement('section');
  563. var translator="";
  564. addon.id = "landmarkname-addon";
  565.  
  566. if(I18n.defaultLocale != I18n.locale)
  567. translator = 'title="'+I18n.t("wmepn.translator")+'"';
  568.  
  569. //if (navigator.userAgent.match(/Chrome/)) { }
  570. addon.innerHTML = '<b>'
  571. + '<a href="https://www.waze.com/forum/viewtopic.php?f=819&t=116843" target="_blank" ' + translator + '>WME PlaceNames</a></b> &nbsp; v' + GM_info.script.version;
  572. if(wmepn_translations[I18n.locale] === undefined)
  573. addon.innerHTML += ' <small>[<a href="https://www.waze.com/forum/viewtopic.php?f=819&t=116843&p=1302802#p1302802" target="_blank">translate me!</a>]</small>';
  574.  
  575.  
  576. // highlight landmarks
  577. section = document.createElement('p');
  578. section.style.padding = "8px 16px";
  579. //section.style.textIndent = "-16px";
  580. section.id = "nameLandmarks";
  581. section.innerHTML = '<div title="'+I18n.t("wmepn.enable_script_tooltip")+'"><input type="checkbox" id="_cbLandmarkNamesEnable" /> <b>'+I18n.t("wmepn.enable_script")+'</b></div>'
  582. + '<div title="'+I18n.t("wmepn.color_places_tooltip")+'"><input type="checkbox" id="_cbLandmarkColors" /> <b>'+I18n.t("wmepn.color_places")+'</b></div>'
  583. + '<div title="'+I18n.t("wmepn.highlight_places_tooltip")+'"><input type="checkbox" id="_cbLandmarkHiliteNoName"/> <b>'+I18n.t("wmepn.highlight_places")+'</b></div>'
  584. + '<div title="'+I18n.t("wmepn.show_tooltip")+'"><b>'+I18n.t("wmepn.show")+'</b> <select id="_seLandmarkPoints">'
  585. + '<option value="area">'+I18n.t("wmepn.option_areaonly")+'</option>'
  586. + '<option value="all">'+I18n.t("wmepn.option_areapoint")+'</option>'
  587. + '<option value="point">'+I18n.t("wmepn.option_pointonly")+'</option></select></div>'
  588. + '<div title="'+I18n.t("wmepn.filter_tooltip")+'"><b>'+I18n.t("wmepn.filter")+':</b><input type="text" id="_inLandmarkNameFilter"/></div>'
  589. + '<div title="'+I18n.t("wmepn.show_locklevel_tooltip")+'"><input type="checkbox" id="_cbLandmarkLockLevel" /> <b>'+I18n.t("wmepn.show_locklevel")+'</b></div>'
  590. + '<div title="'+I18n.t("wmepn.stop_over_tooltip")+'"><b>'+I18n.t("wmepn.stop_over")+'</b> <select id="_seLandmarkLimit">'
  591. + '<option value="0">'+I18n.t("wmepn.option_unlimited")+'</option>'
  592. + '<option value="500">500</option>'
  593. + '<option value="200">200</option>'
  594. + '<option value="100">100</option>'
  595. + '<option value="50">50</option>'
  596. + '<option value="25">25</option>'
  597. + '<option value="10">10</option>'
  598. +'</select></div>'
  599. + '<div><small>'+I18n.t("wmepn.showing")+' <span id="_stLandmarkNumber"></span> <span id="_stLandmarkHNNumber"></span></small></div>';
  600. addon.appendChild(section);
  601.  
  602. var userTabs = wmepn_getId('user-info');
  603. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  604. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  605.  
  606. newtab = document.createElement('li');
  607. newtab.innerHTML = '<a href="#sidepanel-landmarknames" data-toggle="tab">PlaceNames</a>';
  608. navTabs.appendChild(newtab);
  609.  
  610. addon.id = "sidepanel-landmarknames";
  611. addon.className = "tab-pane";
  612. tabContent.appendChild(addon);
  613.  
  614. // setup onclick handlers for instant update:
  615. wmepn_getId('_cbLandmarkColors').onclick = wmepn_resetLandmarks;
  616. wmepn_getId('_cbLandmarkHiliteNoName').onclick = wmepn_resetLandmarks;
  617. wmepn_getId('_seLandmarkPoints').onchange = wmepn_resetLandmarks;
  618. wmepn_getId('_cbLandmarkNamesEnable').onclick = wmepn_resetLandmarks;
  619. wmepn_getId('_inLandmarkNameFilter').oninput = wmepn_showLandmarkNames;
  620. wmepn_getId('_cbLandmarkLockLevel').onclick = wmepn_showLandmarkNames;
  621. wmepn_getId('_seLandmarkLimit').onchange = wmepn_showLandmarkNames;
  622. // restore saved settings
  623. if (localStorage.WMELandmarkNamesScript) {
  624. console.log("WME LandmarkNames: loading options");
  625. options = JSON.parse(localStorage.WMELandmarkNamesScript);
  626.  
  627. wmepn_getId('_cbLandmarkColors').checked = options[1];
  628. wmepn_getId('_cbLandmarkHiliteNoName').checked = options[2];
  629. wmepn_getId('_seLandmarkPoints').value = options[3];
  630. wmepn_NameLayer.setVisibility(options[4]);
  631. if(options[5] !== undefined)
  632. wmepn_getId('_cbLandmarkNamesEnable').checked = options[5];
  633. else wmepn_NameLayer.setVisibility(true);
  634. if(options[6] !== undefined)
  635. wmepn_getId('_inLandmarkNameFilter').value = options[6];
  636. if(options[7] !== undefined)
  637. wmepn_getId('_cbLandmarkLockLevel').checked = options[7];
  638. if(options[8] !== undefined)
  639. wmepn_getId('_seLandmarkLimit').value = options[8];
  640. else
  641. wmepn_getId('_seLandmarkLimit').value = 100;
  642. } else {
  643. wmepn_getId('_cbLandmarkColors').checked = true;
  644. wmepn_getId('_cbLandmarkHiliteNoName').checked = true;
  645. wmepn_getId('_seLandmarkPoints').value = "area";
  646. wmepn_NameLayer.setVisibility(true);
  647. wmepn_getId('_cbLandmarkNamesEnable').checked = true;
  648. wmepn_getId('_cbLandmarkLockLevel').checked = false;
  649. wmepn_getId('_seLandmarkLimit').value = 100;
  650. }
  651. var layerItem = '<li><div class="controls-container toggler"><input class="layer-switcher-item_placenames toggle" id="layer-switcher-item_placenames" type="checkbox"><label for="layer-switcher-item_placenames"><span class="label-text">PlaceNames</span></label></div></li>';
  652. $("#layer-switcher-group_places").parent().parent().children("ul.children").append(layerItem);
  653. $("#layer-switcher-item_placenames").click(function() { wmepn_NameLayer.setVisibility(!wmepn_NameLayer.getVisibility()); });
  654. $("#layer-switcher-item_placenames").prop("checked", wmepn_NameLayer.getVisibility());
  655.  
  656. if (typeof Waze.model.venues == "undefined") {
  657. wmepn_getId('_cbLandmarkColors').checked = false;
  658. wmepn_getId('_cbLandmarkHiliteNoName').checked = false;
  659. wmepn_getId('_cbLandmarkColors').disabled = true;
  660. wmepn_getId('_cbLandmarkHiliteNoName').disabled = true;
  661. wmepn_getId('_seLandmarkPoints').disabled = true;
  662. wmepn_getId('_cbLandmarkLockLevel').disabled = true;
  663. wmepn_getId('_seLandmarkLimit').disabled = true;
  664. }
  665. }
  666.  
  667.  
  668. /* =========================================================================== */
  669.  
  670. function initialiseLandmarkNames()
  671. {
  672. // global variables
  673. wmepn_betaMode = location.hostname.match(/beta.waze.com/);
  674.  
  675. var map = Waze.map;
  676. // Create PlaceName layer
  677. var rlayers = map.getLayersBy("uniqueName","__DrawPlaceNames");
  678. if(rlayers.length === 0) {
  679. var lname = "Place Names";
  680. var style = new OpenLayers.Style({
  681. strokeDashstyle: 'solid',
  682. strokeColor : "${strokeColor}",
  683. strokeOpacity: 1.0,
  684. strokeWidth: "${strokeWidth}",
  685. fillColor: '#0040FF',
  686. fillOpacity: 1.0,
  687. pointRadius: "${pointRadius}",
  688. label : "${labelText}",
  689. fontFamily: "Tahoma, Arial, Verdana",
  690. labelOutlineColor: '#FFEEEE',
  691. labelOutlineWidth: 2,
  692. labelAlign: 'cm',
  693. fontColor: "#301130",
  694. fontOpacity: 1.0,
  695. fontSize: "11px",
  696. display: 'block',
  697. labelYOffset: "${yOffset}",
  698. fontStyle: "${style}"
  699. });
  700. var nameLayer = new OpenLayers.Layer.Vector(lname, {
  701. displayInLayerSwitcher: true,
  702. uniqueName: "__DrawPlaceNames",
  703. shortcutKey: "S+n",
  704. accelerator: "toggle" + lname.replace(/\s+/g,''),
  705. styleMap: new OpenLayers.StyleMap(style)
  706. });
  707. nameLayer.setVisibility(true);
  708. //drc_mapLayer1.moveLayerToTop();
  709. map.addLayer(nameLayer);
  710. //var zLandmarks = map.getLayersBy("uniqueName", "landmarks")[0].getZIndex();
  711. //var zPlaceNames = drc_mapLayer1.getZIndex();
  712. //map.getLayersBy("uniqueName", "landmarks")[0].setZIndex(zPlaceNames);
  713. //drc_mapLayer1.setZIndex(zLandmarks);
  714. wmepn_NameLayer = nameLayer;
  715. }
  716. else wmepn_NameLayer = rlayers[0];
  717.  
  718. installLandmarkNamesTab();
  719. // overload the WME exit function
  720. wmepn_saveLandmarkNamesOptions = function() {
  721. if (localStorage && wmepn_getId('_cbLandmarkColors') !== null) {
  722. console.log("WME LandmarkNames: saving options");
  723. var options = [];
  724.  
  725. // preserve previous options which may get lost after logout
  726. if (localStorage.WMELandmarkNamesScript)
  727. options = JSON.parse(localStorage.WMELandmarkNamesScript);
  728.  
  729. options[1] = wmepn_getId('_cbLandmarkColors').checked;
  730. options[2] = wmepn_getId('_cbLandmarkHiliteNoName').checked;
  731. options[3] = wmepn_getId('_seLandmarkPoints').value;
  732. options[4] = wmepn_NameLayer.getVisibility();
  733. options[5] = wmepn_getId('_cbLandmarkNamesEnable').checked;
  734. options[6] = wmepn_getId('_inLandmarkNameFilter').value;
  735. options[7] = wmepn_getId('_cbLandmarkLockLevel').checked;
  736. options[8] = wmepn_getId('_seLandmarkLimit').value;
  737.  
  738. localStorage.WMELandmarkNamesScript = JSON.stringify(options);
  739. }
  740. };
  741. window.addEventListener("beforeunload", wmepn_saveLandmarkNamesOptions, false);
  742. //window.setInterval(wmepn_saveLandmarkNamesOptions, 10000);
  743.  
  744. // begin periodic updates
  745. //window.setInterval(wmepn_showLandmarkNames,500);
  746.  
  747. // trigger code when page is fully loaded, to catch any missing bits
  748. window.addEventListener("load", function(e) {
  749. var mapProblems = wmepn_getId('map-problems-explanation');
  750. if (mapProblems !== null) mapProblems.style.display = "none";
  751. });
  752.  
  753. // register some events...
  754. map.events.register("zoomend", null, wmepn_showLandmarkNames);
  755. map.events.register("changelayer", null, wmepn_showLandmarkNames);
  756. map.events.register("mouseout", null, wmepn_showLandmarkNames);
  757. Waze.selectionManager.events.register("selectionchanged", null, wmepn_showLandmarkNames);
  758. }
  759.  
  760. /* engage! =================================================================== */
  761. bootstrapLandmarkNames();
  762.  
  763. /* end ======================================================================= */

QingJ © 2025

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