WME NC Mapraid Overlay

Creates polygons for MapRaid groups in a WME "NC Mapraid Groups" layer

  1. https://greasyfork.org/en/scripts/20147-wme-nc-mapraid-overlay// ==UserScript==
  2. // @name WME NC Mapraid Overlay
  3. // @namespace https://greasyfork.org/users/5252
  4. // @description Creates polygons for MapRaid groups in a WME "NC Mapraid Groups" layer
  5. // @include https://www.waze.com/editor/*
  6. // @include https://www.waze.com/*/editor/*
  7. // @include https://editor-beta.waze.com/*
  8. // @version 2.4
  9. // @grant none
  10. // @copyright 2014 davielde
  11. // ==/UserScript==
  12.  
  13.  
  14. //---------------------------------------------------------------------------------------
  15.  
  16.  
  17. //generated by rickzabel's overlay generator
  18.  
  19. //RZ RaidName will be replaced by the name of the layer in your KML file
  20. //RZ RaidNameNoSpaces will be replaced by the name of the layer in your KML file
  21. //RZ AreaPoints will be replaced by the names, colors, and area points from your KML file
  22.  
  23. setTimeout(InitMapRaidOverlay, 1000);
  24.  
  25. function AddRaidPolygon(raidLayer,groupPoints,groupColor,groupNumber){
  26. var mro_Map = Waze.map;
  27. var mro_OL = OpenLayers;
  28. var raidGroupLabel = 'Raid Group ' + groupNumber;
  29. var groupName = 'RaidGroup' + groupNumber;
  30. var style = {
  31. strokeColor: groupColor,
  32. strokeOpacity: .8,
  33. strokeWidth: 3,
  34. fillColor: groupColor,
  35. fillOpacity: 0.15,
  36. label: raidGroupLabel,
  37. labelOutlineColor: "black",
  38. labelOutlineWidth: 3,
  39. fontSize: 14,
  40. fontColor: groupColor,
  41. fontOpacity: .85,
  42. fontWeight: "bold"
  43. };
  44. var attributes = {
  45. name: groupName,
  46. number: groupNumber
  47. };
  48. var pnt= [];
  49. for(i=0;i<groupPoints.length;i++){
  50. convPoint = new OpenLayers.Geometry.Point(groupPoints[i].lon,groupPoints[i].lat).transform(new OpenLayers.Projection("EPSG:4326"), mro_Map.getProjectionObject());
  51. //console.log('MapRaid: ' + JSON.stringify(groupPoints[i]) + ', ' + groupPoints[i].lon + ', ' + groupPoints[i].lat);
  52. pnt.push(convPoint);
  53. }
  54. var ring = new mro_OL.Geometry.LinearRing(pnt);
  55. var polygon = new mro_OL.Geometry.Polygon([ring]);
  56. var feature = new mro_OL.Feature.Vector(polygon,attributes,style);
  57. raidLayer.addFeatures([feature]);
  58.  
  59. }
  60.  
  61. function CurrentRaidLocation(raid_mapLayer){
  62. var mro_Map = Waze.map;
  63.  
  64. for(i=0;i<raid_mapLayer.features.length;i++){
  65. var raidMapCenter = mro_Map.getCenter();
  66. var raidCenterPoint = new OpenLayers.Geometry.Point(raidMapCenter.lon,raidMapCenter.lat);
  67. var raidCenterCheck = raid_mapLayer.features[i].geometry.components[0].containsPoint(raidCenterPoint);
  68. var holes = raid_mapLayer.features[i].attributes.holes;
  69. if(raidCenterCheck === true){
  70.  
  71. //var str = $('#topbar-container > div > div.location-info-region > div').text();
  72. var str = $('#topbar-container > div > div.topbar > div.location-info-region > div.location-info').text();
  73. var n2 = str.indexOf(" - ");
  74. if(n2 > 0){
  75. var n = str.length;
  76. var res = str.substring(n2+2, n);
  77. var rescount = res.indexOf(" - ");
  78. if(rescount>0){
  79. var n3 = res.length;
  80. var res2 = res.substring(rescount+2, n3);
  81. }
  82. var raidLocationLabel = '[Raid Group - ' + raid_mapLayer.features[i].attributes.number + '] - ' + res2;
  83.  
  84. } else {
  85. //var raidLocationLabel = '[Raid Group - ' + raid_mapLayer.features[i].attributes.number + '] - ' + $('#topbar-container > div > div.location-info-region > div').text();
  86. var raidLocationLabel = '[Raid Group - ' + raid_mapLayer.features[i].attributes.number + '] - ' + $('#topbar-container > div > div.topbar > div.location-info-region > div.location-info').text();
  87. }
  88. //setTimeout(function(){$('#topbar-container > div > div.location-info-region > div').text(raidLocationLabel);},200);
  89. setTimeout(function(){$('#topbar-container > div > div.topbar > div.location-info-region > div.location-info').text(raidLocationLabel);},200);
  90. if (holes === "false") { break; }
  91. }
  92. }
  93. }
  94.  
  95. function InitMapRaidOverlay(){
  96.  
  97. var mro_Map = Waze.map;
  98. var mro_OL = OpenLayers;
  99.  
  100. //if (!mro_Map) return;
  101. //if (!mro_OL) return;
  102.  
  103. var mro_mapLayers = mro_Map.getLayersBy("uniqueName","__NCMapraid");
  104. var raid_mapLayer = new mro_OL.Layer.Vector("NC Mapraid", {
  105. displayInLayerSwitcher: true,
  106. uniqueName: "__NCMapraid"
  107. });
  108. I18n.translations.en.layers.name["__NCMapraid"] = "NC Mapraid";
  109. mro_Map.addLayer(raid_mapLayer);
  110. raid_mapLayer.setVisibility(true);
  111.  
  112. var VGroup1 = [{lon:'-81.059443',lat:'35.150727'},{lon:'-81.057746',lat:'35.065674'},{lon:'-81.042125',lat:'35.043523'},{lon:'-80.934878',lat:'35.106269'},{lon:'-80.783243',lat:'34.934155'},{lon:'-80.798001',lat:'34.819592'},{lon:'-80.561969',lat:'34.81747'},{lon:'-80.027264',lat:'36.542498'},{lon:'-81.676827',lat:'36.59675'},{lon:'-81.978462',lat:'36.236953'},{lon:'-82.367441',lat:'36.122428'},{lon:'-82.51733',lat:'36.007336'},{lon:'-82.669942',lat:'36.123741'},{lon:'-83.027261',lat:'35.853236'},{lon:'-83.337334',lat:'35.674791'},{lon:'-83.492849',lat:'35.586006'},{lon:'-83.640883',lat:'35.587602'},{lon:'-83.874756',lat:'35.538777'},{lon:'-84.026033',lat:'35.429328'},{lon:'-84.053799',lat:'35.314633'},{lon:'-84.104812',lat:'35.258138'},{lon:'-84.224241',lat:'35.270471'},{lon:'-84.290599',lat:'35.226946'},{lon:'-84.322133',lat:'34.988508'},{lon:'-83.619899',lat:'34.985325'},{lon:'-83.026198',lat:'34.995119'},{lon:'-82.26198',lat:'35.198455'},{lon:'-81.059443',lat:'35.150727'}];
  113. AddRaidPolygon(raid_mapLayer, VGroup1,"#F9F7A6","Group 1");
  114.  
  115. var VGroup2 = [{lon:'-78.546137',lat:'33.849692'},{lon:'-77.900403',lat:'36.545496'},{lon:'-80.027264',lat:'36.542498'},{lon:'-80.561969',lat:'34.81747'},{lon:'-79.6748988',lat:'34.80483'},{lon:'-78.546137',lat:'33.849692'}];
  116. AddRaidPolygon(raid_mapLayer, VGroup2,"#DB4436","Group 2");
  117.  
  118. var VGroup3 = [{lon:'-77.882331',lat:'33.833427'},{lon:'-75.27102',lat:'35.206776'},{lon:'-75.665655',lat:'36.568631'},{lon:'-77.900403',lat:'36.545496'},{lon:'-78.546137',lat:'33.849692'},{lon:'-77.882331',lat:'33.833427'}];
  119. AddRaidPolygon(raid_mapLayer, VGroup3,"#4186F0","Group 3");
  120.  
  121.  
  122. setTimeout(function(){CurrentRaidLocation(raid_mapLayer);},3000);
  123. mro_Map.events.register("moveend", Waze.map, function(){ setTimeout(function(){CurrentRaidLocation(raid_mapLayer);},1500);});
  124. mro_Map.events.register("zoomend", Waze.map, function(){ setTimeout(function(){CurrentRaidLocation(raid_mapLayer);},1500);});
  125. }