WME MapRaid 2 West Texas Overlay

Creates polygons for MapRaid groups in a WME "MapRaid 2 West Texas Groups" layer

// ==UserScript==
// @name                WME MapRaid 2 West Texas Overlay
// @namespace           https://greasyfork.org/users/5252
// @description         Creates polygons for MapRaid groups in a WME "MapRaid 2 West Texas Groups" layer
// @include             https://www.waze.com/editor/*
// @include             https://www.waze.com/*/editor/*
// @include             https://editor-beta.waze.com/*
// @version             1.8
// @grant               none
// @copyright           2014 davielde
// ==/UserScript==


//---------------------------------------------------------------------------------------


//generated by rickzabel's overlay generator

//RZ RaidName will be replaced by the name of the layer in your KML file
//RZ RaidNameNoSpaces will be replaced by the name of the layer in your KML file
//RZ AreaPoints will be replaced by the names, colors, and area points from your KML file

setTimeout(InitMapRaidOverlay, 1000);

function AddRaidPolygon(raidLayer,groupPoints,groupColor,groupNumber){
    
    var mro_Map = Waze.map;
    var mro_OL = OpenLayers;
    var raidGroupLabel = 'Raid Group ' + groupNumber;
    var groupName = 'RaidGroup' + groupNumber;
    
    var style = {
        strokeColor: groupColor,
        strokeOpacity: .8,
        strokeWidth: 3,
        fillColor: groupColor,
        fillOpacity: 0.15,
        label: raidGroupLabel,
        labelOutlineColor: "black",
        labelOutlineWidth: 3,
        fontSize: 14,
        fontColor: groupColor,
        fontOpacity: .85,
        fontWeight: "bold"  
    };
    
    var attributes = {
        name: groupName,
        number: groupNumber
    };
    
    var pnt= [];
    for(i=0;i<groupPoints.length;i++){
        convPoint = new OpenLayers.Geometry.Point(groupPoints[i].lon,groupPoints[i].lat).transform(new OpenLayers.Projection("EPSG:4326"), mro_Map.getProjectionObject());
        //console.log('MapRaid: ' + JSON.stringify(groupPoints[i]) + ', ' + groupPoints[i].lon + ', ' + groupPoints[i].lat);
        pnt.push(convPoint);
    }
		       
    var ring = new mro_OL.Geometry.LinearRing(pnt);
    var polygon = new mro_OL.Geometry.Polygon([ring]);
    
    var feature = new mro_OL.Feature.Vector(polygon,attributes,style);
    raidLayer.addFeatures([feature]);

}

function CurrentRaidLocation(raid_mapLayer){
    var mro_Map = Waze.map;

    for(i=0;i<raid_mapLayer.features.length;i++){
        var raidMapCenter = mro_Map.getCenter();
        var raidCenterPoint = new OpenLayers.Geometry.Point(raidMapCenter.lon,raidMapCenter.lat);
        var raidCenterCheck = raid_mapLayer.features[i].geometry.components[0].containsPoint(raidCenterPoint);
        //console.log('MapRaid: ' + raid_mapLayer.features[i].attributes.number + ': ' + raidCenterCheck);
        if(raidCenterCheck === true){
        	var raidLocationLabel = 'Raid Group ' + raid_mapLayer.features[i].attributes.number + ' - ' + $('.WazeControlLocationInfo').text();
    		//setTimeout(function(){$('.WazeControlLocationInfo').text(raidLocationLabel);},200);
			setTimeout(function(){$('.WazeControlLocationInfo').text(raidLocationLabel);},50);
			var str = $('.WazeControlLocationInfo').text();
			
			var n2 = str.indexOf(" - ");
			
			if(n2 > 0){
				var n = str.length;
				var res = str.substring(n2+2, n);
				var rescount = res.indexOf(" - ");
				if(rescount>0){
					var n3 = res.length;
					var res2 = res.substring(rescount+2, n3);
						
				}
				var raidLocationLabel = 'Raid Group ' + raid_mapLayer.features[i].attributes.number + ' - ' + res2;
			} else {
				var raidLocationLabel = 'Raid Group ' + raid_mapLayer.features[i].attributes.number + ' - ' + $('.WazeControlLocationInfo').text();
			}	
    		setTimeout(function(){$('.WazeControlLocationInfo').text(raidLocationLabel);},200);
		}
    }
}

function InitMapRaidOverlay(){

    var mro_Map = Waze.map;
    var mro_OL = OpenLayers;

    //if (!mro_Map) return;
	
    //if (!mro_OL) return;

    var mro_mapLayers = mro_Map.getLayersBy("uniqueName","__MapRaid2WestTexas");
        
    var raid_mapLayer = new mro_OL.Layer.Vector("MapRaid 2 West Texas", {
        displayInLayerSwitcher: true,
        uniqueName: "__MapRaid2WestTexas"
    });
        
    I18n.translations.en.layers.name["__MapRaid2WestTexas"] = "MapRaid 2 West Texas";
    mro_Map.addLayer(raid_mapLayer);
    raid_mapLayer.setVisibility(true);
    

var VGroup1 = [{lon:'-103.041887',lat:'36.500391'},{lon:'-103.0411144',lat:'35.616'},{lon:'-101.6259092',lat:'35.6222593'},{lon:'-101.0831456',lat:'35.6202746'},{lon:'-101.075592',lat:'36.062422'},{lon:'-101.628253',lat:'36.062431'},{lon:'-101.627569',lat:'36.49963199999999'},{lon:'-103.041887',lat:'36.500391'}];
AddRaidPolygon(raid_mapLayer, VGroup1,"#F8971B","Group 1");

var VGroup2 = [{lon:'-100.000305',lat:'36.499563'},{lon:'-100.8146233',lat:'36.501256'},{lon:'-101.627569',lat:'36.49963199999999'},{lon:'-101.628253',lat:'36.062431'},{lon:'-101.075592',lat:'36.062422'},{lon:'-101.0831456',lat:'35.6202746'},{lon:'-100.5412834',lat:'35.619001'},{lon:'-99.999618',lat:'35.616558'},{lon:'-100.000305',lat:'36.499563'}];
AddRaidPolygon(raid_mapLayer, VGroup2,"#A61B4A","Group 2");

var VGroup3 = [{lon:'-103.0411138',lat:'35.6159651'},{lon:'-103.0428304',lat:'34.74806610000001'},{lon:'-101.620789',lat:'34.74863009999999'},{lon:'-101.0824802',lat:'34.7496221'},{lon:'-101.0865782',lat:'35.1827531'},{lon:'-101.620752',lat:'35.1861311'},{lon:'-101.6259092',lat:'35.6222593'},{lon:'-103.0411138',lat:'35.6159651'}];
AddRaidPolygon(raid_mapLayer, VGroup3,"#F9F7A6","Group 3");

var VGroup4 = [{lon:'-101.6259092',lat:'35.6222593'},{lon:'-101.620752',lat:'35.186166'},{lon:'-101.086578',lat:'35.182788'},{lon:'-101.08248',lat:'34.74965699999999'},{lon:'-99.997559',lat:'34.75035799999999'},{lon:'-99.999618',lat:'35.616558'},{lon:'-100.8127585',lat:'35.619011199999996'},{lon:'-101.6259092',lat:'35.6222593'}];
AddRaidPolygon(raid_mapLayer, VGroup4,"#4186F0","Group 4");

var VGroup5 = [{lon:'-103.042831',lat:'34.74810099999999'},{lon:'-103.046935',lat:'33.828118'},{lon:'-101.555557',lat:'33.823368'},{lon:'-101.560364',lat:'34.31395'},{lon:'-101.494446',lat:'34.315084'},{lon:'-101.497192',lat:'34.748877'},{lon:'-103.042831',lat:'34.74810099999999'}];
AddRaidPolygon(raid_mapLayer, VGroup5,"#A61B4A","Group 5");

var VGroup6 = [{lon:'-100.3985174',lat:'34.75056360000001'},{lon:'-101.4972283',lat:'34.74830680000001'},{lon:'-101.4944824',lat:'34.3145138'},{lon:'-101.5604',lat:'34.3133798'},{lon:'-101.555557',lat:'33.823368'},{lon:'-100.5160141',lat:'33.8230482'},{lon:'-100.519967',lat:'34.3106857'},{lon:'-100.4034098',lat:'34.3088427'},{lon:'-100.3985174',lat:'34.75056360000001'}];
AddRaidPolygon(raid_mapLayer, VGroup6,"#7C3592","Group 6");

var VGroup7 = [{lon:'-99.99831200000001',lat:'34.7505688'},{lon:'-100.3992052',lat:'34.7514169'},{lon:'-100.4040547',lat:'34.3096607'},{lon:'-100.520656',lat:'34.311539'},{lon:'-100.5127164',lat:'33.3867553'},{lon:'-99.481887',lat:'33.388916'},{lon:'-99.5447181',lat:'34.41140600000001'},{lon:'-99.569745',lat:'34.419314'},{lon:'-99.5803224',lat:'34.4162576'},{lon:'-99.5843398',lat:'34.4045875'},{lon:'-99.58458',lat:'34.39065120000001'},{lon:'-99.5905522',lat:'34.3843088'},{lon:'-99.60345400000001',lat:'34.37451599999999'},{lon:'-99.6075613',lat:'34.3769451'},{lon:'-99.6144152',lat:'34.37484020000001'},{lon:'-99.6267498',lat:'34.3743131'},{lon:'-99.6459274',lat:'34.38147390000001'},{lon:'-99.6618438',lat:'34.3733307'},{lon:'-99.6769011',lat:'34.3796368'},{lon:'-99.695088',lat:'34.3783618'},{lon:'-99.6980469',lat:'34.3825763'},{lon:'-99.7009202',lat:'34.3848072'},{lon:'-99.7039983',lat:'34.3859669'},{lon:'-99.7060465',lat:'34.3857099'},{lon:'-99.712804',lat:'34.3907206'},{lon:'-99.7223311',lat:'34.4068725'},{lon:'-99.753712',lat:'34.421357099999994'},{lon:'-99.7722715',lat:'34.441947'},{lon:'-99.78603',lat:'34.4497931'},{lon:'-99.8075526',lat:'34.4684808'},{lon:'-99.8167229',lat:'34.4899971'},{lon:'-99.8555338',lat:'34.51439909999999'},{lon:'-99.8905933',lat:'34.551240899999996'},{lon:'-99.9189434',lat:'34.5673955'},{lon:'-99.9260127',lat:'34.5756314'},{lon:'-99.9466782',lat:'34.5796576'},{lon:'-99.9733448',lat:'34.5628497'},{lon:'-100.0013738',lat:'34.5607347'},{lon:'-99.99831200000001',lat:'34.7505688'}];
AddRaidPolygon(raid_mapLayer, VGroup7,"#A61B4A","Group 7");

var VGroup8 = [{lon:'-103.064691',lat:'32.523219'},{lon:'-101.6978634',lat:'32.5245256'},{lon:'-101.698208',lat:'32.9571136'},{lon:'-102.082214',lat:'32.96258600000001'},{lon:'-102.085648',lat:'33.824223'},{lon:'-103.046935',lat:'33.828118'},{lon:'-103.064691',lat:'32.523219'}];
AddRaidPolygon(raid_mapLayer, VGroup8,"#4186F0","Group 8");

var VGroup9 = [{lon:'-102.0855212',lat:'33.8245439'},{lon:'-102.0810579',lat:'32.9646359'},{lon:'-101.1770859',lat:'32.9456219'},{lon:'-101.0651715',lat:'32.9663139'},{lon:'-101.0301423',lat:'32.9548409'},{lon:'-100.51414850000002',lat:'32.9594578'},{lon:'-100.5120244',lat:'33.3867358'},{lon:'-100.5158864',lat:'33.8233514'},{lon:'-101.0366653',lat:'33.824259'},{lon:'-101.2999355',lat:'33.82423380000001'},{lon:'-101.5614611',lat:'33.82337'},{lon:'-102.0855212',lat:'33.8245439'}];
AddRaidPolygon(raid_mapLayer, VGroup9,"#F9F7A6","Group 9");

var VGroup10 = [{lon:'-101.698208',lat:'32.9571136'},{lon:'-101.6993579',lat:'32.0918482'},{lon:'-100.1496851',lat:'32.09336170000001'},{lon:'-100.1345984',lat:'32.5154601'},{lon:'-100.1501225',lat:'32.9603537'},{lon:'-101.0301423',lat:'32.9548409'},{lon:'-101.0651715',lat:'32.9663139'},{lon:'-101.1770859',lat:'32.9456219'},{lon:'-101.698208',lat:'32.9571136'}];
AddRaidPolygon(raid_mapLayer, VGroup10,"#A61B4A","Group 10");

var VGroup11 = [{lon:'-100.5120274',lat:'33.3864723'},{lon:'-100.5144098',lat:'32.9592087'},{lon:'-100.1501225',lat:'32.9603537'},{lon:'-100.1315044',lat:'32.5110247'},{lon:'-100.1490055',lat:'32.092929600000005'},{lon:'-99.1032946',lat:'32.0875016'},{lon:'-99.1154856',lat:'32.5154746'},{lon:'-99.0849566',lat:'32.5139096'},{lon:'-99.116561',lat:'32.957025'},{lon:'-99.4743919',lat:'32.9577097'},{lon:'-99.4812014',lat:'33.388633'},{lon:'-100.5120274',lat:'33.3864723'}];
AddRaidPolygon(raid_mapLayer, VGroup11,"#F8971B","Group 11");


    
	
    setTimeout(function(){CurrentRaidLocation(raid_mapLayer);},3000);
    mro_Map.events.register("moveend", Waze.map, function(){CurrentRaidLocation(raid_mapLayer);});
    mro_Map.events.register("zoomend", Waze.map, function(){CurrentRaidLocation(raid_mapLayer);});
       
}