WME GLR MapRaid Areas Overlay

Creates polygons for MapRaid groups in a WME "GLR MapRaid Areas Groups" layer

// ==UserScript==
// @name                WME GLR MapRaid Areas Overlay
// @namespace           https://greasyfork.org/users/5252
// @description         Creates polygons for MapRaid groups in a WME "GLR MapRaid Areas Groups" layer
// @include             https://www.waze.com/editor/*
// @include             https://www.waze.com/*/editor/*
// @include             https://editor-beta.waze.com/*
// @version             2.4
// @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);
		var holes = raid_mapLayer.features[i].attributes.holes
		
        
        if(raidCenterCheck === true){

			//var str = $('#topbar-container > div > div.location-info-region > div').text();
			var str = $('#topbar-container > div > div.topbar > div.location-info-region > div.location-info').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 + '] - ' + $('#topbar-container > div > div.location-info-region > div').text();
				var raidLocationLabel = '[Raid Group - ' + raid_mapLayer.features[i].attributes.number + '] - ' + $('#topbar-container > div > div.topbar > div.location-info-region > div.location-info').text();
						
			}	
			//setTimeout(function(){$('#topbar-container > div > div.location-info-region > div').text(raidLocationLabel);},200);
			setTimeout(function(){$('#topbar-container > div > div.topbar > div.location-info-region > div.location-info').text(raidLocationLabel);},200);
			 if (holes === "false") { break; }
		}
    }
}

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","__GLRMapRaidAreas");
        
    var raid_mapLayer = new mro_OL.Layer.Vector("GLR MapRaid Areas", {
        displayInLayerSwitcher: true,
        uniqueName: "__GLRMapRaidAreas"
    });
        
    I18n.translations.en.layers.name["__GLRMapRaidAreas"] = "GLR MapRaid Areas";
    mro_Map.addLayer(raid_mapLayer);
    raid_mapLayer.setVisibility(true);
    

var VProposedMapRaidArea = [{lon:'-87.525673',lat:'40.76728200000001'},{lon:'-86.837068',lat:'40.763179'},{lon:'-86.49154',lat:'40.759208'},{lon:'-86.147983',lat:'40.758367'},{lon:'-84.802094',lat:'40.773262'},{lon:'-84.802094',lat:'41.75902'},{lon:'-87.52533',lat:'41.75902000000001'},{lon:'-87.525673',lat:'40.76728200000001'}];
AddRaidPolygon(raid_mapLayer, VProposedMapRaidArea,"#000000","Proposed Map Raid Area");

var VArea1 = [{lon:'-87.52533',lat:'41.75902000000001'},{lon:'-87.528076',lat:'41.253032'},{lon:'-86.845894',lat:'41.259743'},{lon:'-86.852417',lat:'41.767215'},{lon:'-87.52533',lat:'41.75902000000001'}];
AddRaidPolygon(raid_mapLayer, VArea1,"#4186F0","Area 1");

var VArea2 = [{lon:'-86.852417',lat:'41.767215'},{lon:'-86.845894',lat:'41.259743'},{lon:'-86.163368',lat:'41.26219499999999'},{lon:'-86.165772',lat:'41.76721500000001'},{lon:'-86.852417',lat:'41.767215'}];
AddRaidPolygon(raid_mapLayer, VArea2,"#A61B4A","Area 2");

var VArea3 = [{lon:'-86.163368',lat:'41.26219499999999'},{lon:'-85.481358',lat:'41.260517'},{lon:'-85.4846191',lat:'41.7651661'},{lon:'-86.165772',lat:'41.76721500000001'},{lon:'-86.163368',lat:'41.26219499999999'}];
AddRaidPolygon(raid_mapLayer, VArea3,"#4186F0","Area 3");

var VArea4 = [{lon:'-85.4846191',lat:'41.7651661'},{lon:'-85.481358',lat:'41.260517'},{lon:'-84.806213',lat:'41.255097'},{lon:'-84.802094',lat:'41.75902'},{lon:'-85.4846191',lat:'41.7651661'}];
AddRaidPolygon(raid_mapLayer, VArea4,"#A61B4A","Area 4");

var VArea5 = [{lon:'-86.845894',lat:'41.259743'},{lon:'-87.528076',lat:'41.253032'},{lon:'-87.525673',lat:'40.76728200000001'},{lon:'-86.837068',lat:'40.763179'},{lon:'-86.845894',lat:'41.259743'}];
AddRaidPolygon(raid_mapLayer, VArea5,"#A61B4A","Area 5");

var VArea6 = [{lon:'-86.845894',lat:'41.259743'},{lon:'-86.837068',lat:'40.763179'},{lon:'-86.147983',lat:'40.758367'},{lon:'-86.163368',lat:'41.26219499999999'},{lon:'-86.845894',lat:'41.259743'}];
AddRaidPolygon(raid_mapLayer, VArea6,"#4186F0","Area 6");

var VArea7 = [{lon:'-86.163368',lat:'41.26219499999999'},{lon:'-86.147983',lat:'40.758367'},{lon:'-85.46814',lat:'40.767022'},{lon:'-85.481358',lat:'41.260517'},{lon:'-86.163368',lat:'41.26219499999999'}];
AddRaidPolygon(raid_mapLayer, VArea7,"#A61B4A","Area 7");

var VArea8 = [{lon:'-85.481358',lat:'41.260517'},{lon:'-85.46814',lat:'40.767022'},{lon:'-84.802094',lat:'40.773262'},{lon:'-84.806213',lat:'41.255097'},{lon:'-85.481358',lat:'41.260517'}];
AddRaidPolygon(raid_mapLayer, VArea8,"#4186F0","Area 8");


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