WME Poland Groups Overlay

Creates polygons for MapRaid groups in a WME "Poland Groups" layer

// ==UserScript==
// @name                WME Poland Groups Overlay
// @namespace           https://greasyfork.org/en/users/8063-mo
// @description         Creates polygons for MapRaid groups in a WME "Poland Groups" layer
// @include             https://www.waze.com/editor/*
// @include             https://www.waze.com/*/editor/*
// @include             https://editor-beta.waze.com/*
// @version             2.2
// @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 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();
						
			}	
			setTimeout(function(){$('#topbar-container > div > div.location-info-region > div').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","__Polandgroups");
        
    var raid_mapLayer = new mro_OL.Layer.Vector("Poland groups", {
        displayInLayerSwitcher: true,
        uniqueName: "__Polandgroups"
    });
        
    I18n.translations.en.layers.name["__Polandgroups"] = "Poland groups";
    mro_Map.addLayer(raid_mapLayer);
    raid_mapLayer.setVisibility(true);
    

var V1 = [{lon:'17.9499074',lat:'54.8953043'},{lon:'14.3054589',lat:'54.1715052'},{lon:'14.0929666',lat:'52.83464540000001'},{lon:'18.0635503',lat:'52.9616181'},{lon:'17.9499074',lat:'54.8953043'}];
AddRaidPolygon(raid_mapLayer, V1,"#7C3592","1");

var V4 = [{lon:'14.0929666',lat:'52.83464540000001'},{lon:'14.8399301',lat:'51.285578400000006'},{lon:'18.1258537',lat:'51.225351'},{lon:'18.0764579',lat:'52.6319169'},{lon:'18.0635503',lat:'52.9616181'},{lon:'14.0929666',lat:'52.83464540000001'}];
AddRaidPolygon(raid_mapLayer, V4,"#4186F0","4");

var V6 = [{lon:'14.774012099999997',lat:'50.8714492'},{lon:'18.8085938',lat:'49.396675099999996'},{lon:'20.148925799999997',lat:'49.09545219999999'},{lon:'20.095367400000004',lat:'51.14575580000001'},{lon:'18.1258537',lat:'51.225351'},{lon:'14.8399301',lat:'51.285578400000006'},{lon:'14.774012099999997',lat:'50.8714492'}];
AddRaidPolygon(raid_mapLayer, V6,"#7C3592","6");

var V7 = [{lon:'20.148925799999997',lat:'49.09545219999999'},{lon:'21.4948947',lat:'49.3816344'},{lon:'22.903297199999997',lat:'48.9696098'},{lon:'22.740822799999997',lat:'49.53637710000001'},{lon:'24.2028809',lat:'50.555325'},{lon:'24.1597939',lat:'50.8701115'},{lon:'20.095367400000004',lat:'51.14575580000001'},{lon:'20.148925799999997',lat:'49.09545219999999'}];
AddRaidPolygon(raid_mapLayer, V7,"#F8971B","7");

var V5 = [{lon:'24.1597939',lat:'50.8701115'},{lon:'23.716804300000003',lat:'51.4817996'},{lon:'23.7302051',lat:'52.0980517'},{lon:'20.561903999999995',lat:'52.05568639999999'},{lon:'18.0764579',lat:'52.6319169'},{lon:'18.1258537',lat:'51.225351'},{lon:'20.095367400000004',lat:'51.14575580000001'},{lon:'24.1597939',lat:'50.8701115'}];
AddRaidPolygon(raid_mapLayer, V5,"#A61B4A","5");

var V2 = [{lon:'17.9499074',lat:'54.8953043'},{lon:'18.0635503',lat:'52.9616181'},{lon:'18.0764579',lat:'52.6319169'},{lon:'20.561903999999995',lat:'52.05568639999999'},{lon:'21.472327999999997',lat:'54.36284549999999'},{lon:'17.9499074',lat:'54.8953043'}];
AddRaidPolygon(raid_mapLayer, V2,"#FFDD5E","2");

var V3 = [{lon:'21.472327999999997',lat:'54.36284549999999'},{lon:'20.561903999999995',lat:'52.05568639999999'},{lon:'23.7302051',lat:'52.0980517'},{lon:'23.7854004',lat:'52.1402312'},{lon:'23.3129883',lat:'52.2614336'},{lon:'24.122514000000006',lat:'52.736724800000005'},{lon:'23.5986328',lat:'54.162434'},{lon:'22.9064941',lat:'54.41893000000001'},{lon:'21.472327999999997',lat:'54.36284549999999'}];
AddRaidPolygon(raid_mapLayer, V3,"#7C3592","3");


    
	
	
    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);});
       
       
}