WME Texas PUR Raid Overlay

Adds a group area overlay for the Texas PUR Raid (2018).

  1. // ==UserScript==
  2. // @name WME Texas PUR Raid Overlay
  3. // @namespace WazeDev
  4. // @version 2018.10.09.002
  5. // @description Adds a group area overlay for the Texas PUR Raid (2018).
  6. // @author MapOMatic, Dude495
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @require https://gf.qytechs.cn/scripts/24851-wazewrap/code/WazeWrap.js
  9. // @license GNU GPLv3
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const PROJECT_NAME = 'PUR Raid 2018';
  17. const STATE_ABBR = 'Texas';
  18. const VERSION = GM_info.script.version;
  19. var SCRIPT_NAME = GM_info.script.name;
  20. const UPDATE_ALERT = false;
  21. const UPDATE_NOTES = [
  22. SCRIPT_NAME + ' has been updated to v' + VERSION,
  23. ].join('\n');
  24.  
  25. const GROUPS = [
  26. {name: 'Western Division', fillColor:'#ff99e6', zoomTo: 0},
  27. {name: 'Eastern Division', fillColor:'#FF0000', zoomTo: 0},
  28. ];
  29.  
  30. const WKT_STRINGS = [
  31. 'POLYGON((-103.07433598219268 36.51617152487984,-103.05236332594268 31.99633816485509,-106.65587895094268 32.05222496018145,-106.67785160719268 31.828473434585696,-106.30431645094268 31.491827381929784,-105.97472660719268 31.37934142521581,-105.35949223219268 30.833763224128585,-104.92003910719268 30.550341802926432,-104.65636723219268 30.152158584453833,-104.67833988844268 29.77143575899671,-104.37072270094268 29.523186196143918,-104.12902348219268 29.408403332584417,-103.71154301344268 29.1784486399968,-103.29406254469268 29.005643526263025,-102.96447270094268 29.12087916350459,-102.78869145094268 29.427542829490623,-102.63488285719268 29.73328339001792,-102.30529301344268 29.866753099790245,-101.71203129469268 29.752361389705097,-101.38244145094268 29.73328339001792,-101.09679691969268 29.446678720476086,-100.72326176344268 29.140072573369583,-100.45958988844268 28.601307863716855,-100.22222342717174 28.09696467614576,-99.87066092717174 27.805823446051065,-99.69487967717174 27.49441068335823,-99.56304373967174 27.18211453048693,-99.23345389592174 26.633491122910563,-99.10161795842174 26.27940439230814,-98.26665702092174 26.00325376251035,-97.29986014592174 25.726452351164426,-97.05816092717174 25.924233836497038,-97.43169608342174 26.84933954087214,-97.38310273072864 27.290014984776075,-97.84452851197864 27.34370134791689,-97.92622205701116 29.617483911668888,-98.1853258662735 29.94296729451834,-98.6435386137241 34.155005472363875,-98.7643882230991 34.136820664682354,-98.9511558012241 34.200450361733374,-99.1763755277866 34.209536402077944,-99.2752524809116 34.41371313255305,-99.3851157621616 34.4590182616235,-99.4345542387241 34.386518267752145,-99.5718833402866 34.41824475068284,-99.6872397855991 34.372917521444165,-99.91025863630489 34.5868894985865,-100.01462875349239 34.591411712276845,-99.99629935638603 36.50553189336133,-103.07433598219268 36.51617152487984))',
  32. 'POLYGON((-98.66120489953965 34.16662372100617,-98.2025257003209 29.926646866697805,-97.93061407922715 29.578508131542065,-97.83723029016465 27.328134673707055,-97.06818732141465 27.28908714246825,-96.62873419641465 27.95101665967423,-96.03547247766465 28.319165899889576,-94.56330450891465 28.974781792397675,-93.83820685266465 29.49248020453784,-93.83820685266465 29.87426504269192,-93.72834357141465 30.349447616469256,-93.50861700891465 31.029670968840716,-93.75031622766465 31.55540183743336,-93.92609747766465 31.947768206061628,-93.92609747766465 33.57370023656958,-94.47541388391465 33.59200536673878,-94.84894904016465 33.774842902155044,-95.24445685266465 33.95729105010073,-95.72785529016465 33.86611571353214,-96.38703497766465 33.7200324804802,-96.60676154016465 33.90259755224774,-97.04621466516465 33.86611571353214,-97.22199591516465 33.774842902155044,-97.50764044641465 33.88435858289584,-97.70539435266465 33.95729105010073,-97.90314825891465 33.86611571353214,-98.03498419641465 34.06657260915332,-98.29865607141465 34.12116061622305,-98.49640997766465 34.13934879379409,-98.66120489953965 34.16662372100617))',
  33. ];
  34. const SETTINGS_STORE_NAME = '_wme_' + STATE_ABBR + '_mapraid';
  35. const DEFAULT_FILL_OPACITY = 0.3;
  36.  
  37. var _settings;
  38. var _layer;
  39.  
  40. if (UPDATE_ALERT) {
  41. SCRIPT_NAME = SCRIPT_NAME.replace( /\s/g, '') + 'VERSION';
  42. if (localStorage.getItem(SCRIPT_NAME) !== VERSION) {
  43. alert(UPDATE_NOTES);
  44. localStorage.setItem(SCRIPT_NAME, VERSION);
  45. }
  46. }
  47.  
  48. function loadSettingsFromStorage() {
  49. _settings = $.parseJSON(localStorage.getItem(SETTINGS_STORE_NAME));
  50. if(!_settings) {
  51. _settings = {
  52. layerVisible: true,
  53. hiddenAreas: []
  54. };
  55. } else {
  56. _settings.layerVisible = (_settings.layerVisible === true);
  57. _settings.hiddenAreas = _settings.hiddenAreas || [];
  58. }
  59. }
  60.  
  61. function saveSettingsToStorage() {
  62. if (localStorage) {
  63. var settings = {
  64. layerVisible: _layer.visibility,
  65. hiddenAreas: _settings.hiddenAreas
  66. };
  67. localStorage.setItem(SETTINGS_STORE_NAME, JSON.stringify(settings));
  68. }
  69. }
  70.  
  71. function updateDistrictNameDisplay(){
  72. $('.mapraid-region').remove();
  73. if (_layer !== null) {
  74. var mapCenter = new OpenLayers.Geometry.Point(W.map.center.lon,W.map.center.lat);
  75. for (var i=0;i<_layer.features.length;i++){
  76. var feature = _layer.features[i];
  77. var color;
  78. var text = '';
  79. if(feature.geometry.containsPoint(mapCenter)) {
  80. text = feature.attributes.name;
  81. color = '#ff0';
  82. var $div = $('<div>', {id:'mapraid', class:'mapraid-region', style:'display:inline-block;margin-left:10px;', title:'Click to toggle color on/off for this group'})
  83. .css({color:color, cursor:'pointer', fontWeight:'bold', fontSize:'14px'})
  84. .click(toggleAreaFill);
  85. var $span = $('<span>').css({display:'inline-block'});
  86. $span.text('Group: ' + text).appendTo($div);
  87. $('.location-info-region').parent().append($div);
  88. if (color) {
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. }
  95.  
  96. function toggleAreaFill() {
  97. var text = $('#mapraid span').text();
  98. if (text) {
  99. var match = text.match(/^Group: (.*)/);
  100. if (match.length > 1) {
  101. var areaName = match[1];
  102. var f = _layer.getFeaturesByAttribute('name', areaName)[0];
  103. var hide = f.attributes.fillOpacity !== 0;
  104. f.attributes.fillOpacity = hide ? 0 : DEFAULT_FILL_OPACITY;
  105. var idx = _settings.hiddenAreas.indexOf(areaName);
  106. if (hide) {
  107. if (idx === -1) _settings.hiddenAreas.push(areaName);
  108. } else {
  109. if (idx > -1) {
  110. _settings.hiddenAreas.splice(idx,1);
  111. }
  112. }
  113. saveSettingsToStorage();
  114. _layer.redraw();
  115. }
  116. }
  117. }
  118.  
  119. function layerToggled(visible) {
  120. _layer.setVisibility(visible);
  121. saveSettingsToStorage();
  122. }
  123.  
  124. function init() {
  125. loadSettingsFromStorage();
  126. let layerid = 'wme_' + STATE_ABBR + '_mapraid';
  127. let wkt = new OL.Format.WKT();
  128. let features = WKT_STRINGS.map(polyString => {
  129. var f = wkt.read(polyString);
  130. f.geometry.transform(W.map.displayProjection, W.map.projection);
  131. return f;
  132. });
  133. GROUPS.forEach((group, i) => {
  134. let f = features[i];
  135. f.attributes.name = group.name;
  136. f.attributes.fillColor = group.fillColor;
  137. f.attributes.fillOpacity = _settings.hiddenAreas.indexOf(group.name) > -1 ? 0 : DEFAULT_FILL_OPACITY;
  138. group.feature = f;
  139. });
  140.  
  141. let layerStyle = new OpenLayers.StyleMap({
  142. strokeDashstyle: 'solid',
  143. strokeColor: '#000000',
  144. strokeOpacity: 1,
  145. strokeWidth: 3,
  146. fillOpacity: '${fillOpacity}',
  147. fillColor: '${fillColor}',
  148. label: '${name}',
  149. fontOpacity: 0.9,
  150. fontSize: '20px',
  151. fontFamily: 'Arial',
  152. fontWeight: 'bold',
  153. fontColor: '#fff',
  154. labelOutlineColor: '#000',
  155. labelOutlineWidth: 2
  156. });
  157. _layer = new OL.Layer.Vector(STATE_ABBR + ' PUR Raid', {
  158. rendererOptions: { zIndexing: true },
  159. uniqueName: layerid,
  160. shortcutKey: 'S+' + 0,
  161. layerGroup: STATE_ABBR + '_mapraid',
  162. zIndex: -9999,
  163. displayInLayerSwitcher: true,
  164. visibility: _settings.layerVisible,
  165. styleMap: layerStyle
  166. });
  167. I18n.translations[I18n.locale].layers.name[layerid] = STATE_ABBR + ' MapRaid';
  168. _layer.addFeatures(features);
  169. W.map.addLayer(_layer);
  170. W.map.events.register('moveend', null, updateDistrictNameDisplay);
  171. window.addEventListener('beforeunload', function saveOnClose() { saveSettingsToStorage(); }, false);
  172. updateDistrictNameDisplay();
  173.  
  174. // Add the layer checkbox to the Layers menu.
  175. WazeWrap.Interface.AddLayerCheckbox('display', STATE_ABBR + ' PUR Raid', _settings.layerVisible, layerToggled);
  176.  
  177. initAreaJumper();
  178. }
  179.  
  180. function initAreaJumper() {
  181. let $areaJumper = $('#mapraidDropdown');
  182.  
  183. // If another script hasn't already created the dropdown, create it now.
  184. if (!$areaJumper.length) {
  185. let $areaJumperContainer = $('<div style="flex-grow: 1;padding-top: 6px;">').insertBefore('#edit-buttons');
  186. $areaJumper = $('<select id=mapraidDropdown style="margin-top: 4px;display: block;width: 80%;margin: 0 auto;">')
  187. .appendTo($areaJumperContainer)
  188. .append($('<option>', {value: 0}).text(PROJECT_NAME));
  189. }
  190.  
  191. // Append the groups to the dropdown.
  192. $areaJumper.append(
  193. $('<optgroup>', {label: STATE_ABBR}).append(GROUPS.map(group => {
  194. return $('<option>', {value: STATE_ABBR + group.name}).text(group.name);
  195. }))
  196. );
  197.  
  198. // Handle a group selection.
  199. $areaJumper.change(function() {
  200. let value = $(this).val();
  201. let group = GROUPS.find(group => STATE_ABBR + group.name === value);
  202. if (group) {
  203. W.map.moveTo(group.feature.geometry.getCentroid().toLonLat(), group.zoomTo);
  204. $areaJumper.val('0');
  205. }
  206. });
  207. }
  208.  
  209. function bootstrap() {
  210. if (W && W.loginManager && W.loginManager.user && $('#topbar-container > div > div > div.location-info-region > div').length && $('#layer-switcher-group_display').length && WazeWrap.Interface) {
  211. init();
  212. console.log(STATE_ABBR + ' Area Overlay:', 'Initialized');
  213. } else {
  214. console.log(STATE_ABBR + ' MR Overlay: ', 'Bootstrap failed. Trying again...');
  215. window.setTimeout(() => bootstrap(), 500);
  216. }
  217. }
  218.  
  219. bootstrap();
  220. })();

QingJ © 2025

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