WME Rhode Island Overlay

Creates polygons for MapRaid groups in a WME "Rhode Island Groups" layer

// ==UserScript==
// @name                WME Rhode Island Overlay
// @namespace           https://greasyfork.org/users/5252
// @description         Creates polygons for MapRaid groups in a WME "Rhode Island Groups" layer
// @include             https://www.waze.com/editor/*
// @include             https://www.waze.com/*/editor/*
// @include             https://editor-beta.waze.com/*
// @version             2.5
// @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","__RhodeIsland");
        
    var raid_mapLayer = new mro_OL.Layer.Vector("Rhode Island", {
        displayInLayerSwitcher: true,
        uniqueName: "__RhodeIsland"
    });
        
    I18n.translations.en.layers.name["__RhodeIsland"] = "Rhode Island";
    mro_Map.addLayer(raid_mapLayer);
    raid_mapLayer.setVisibility(true);
    

var VTeamNibbles = [{lon:'-71.7992592',lat:'42.0083614'},{lon:'-71.7929077',lat:'41.7953762'},{lon:'-71.61535700000002',lat:'41.7921422'},{lon:'-71.5902592',lat:'41.7842116'},{lon:'-71.53455680000002',lat:'41.7933807'},{lon:'-71.5096814',lat:'41.7881397'},{lon:'-71.4894491',lat:'41.7917105'},{lon:'-71.469223',lat:'41.798824'},{lon:'-71.4623974',lat:'41.80613'},{lon:'-71.442904',lat:'41.80766080000001'},{lon:'-71.4399784',lat:'41.8030403'},{lon:'-71.4375959',lat:'41.7902109'},{lon:'-71.4324996',lat:'41.7860439'},{lon:'-71.3931264',lat:'41.7863484'},{lon:'-71.3744701',lat:'41.7841087'},{lon:'-71.3968063',lat:'41.8124311'},{lon:'-71.39408590000001',lat:'41.816858'},{lon:'-71.3879585',lat:'41.8164892'},{lon:'-71.3852192',lat:'41.8232979'},{lon:'-71.3807583',lat:'41.8263973'},{lon:'-71.375437',lat:'41.83234'},{lon:'-71.3744074',lat:'41.85720609999999'},{lon:'-71.3338879',lat:'41.8623764'},{lon:'-71.3410823',lat:'41.8789888'},{lon:'-71.338298',lat:'41.8984151'},{lon:'-71.381513',lat:'41.8930505'},{lon:'-71.38177870000001',lat:'42.0188199'},{lon:'-71.49911960000001',lat:'42.0173393'},{lon:'-71.5148335',lat:'42.0155653'},{lon:'-71.7992592',lat:'42.0083614'}];
AddRaidPolygon(raid_mapLayer, VTeamNibbles,"#A61B4A","Team Nibbles");

var VTeamDels = [{lon:'-71.3338879',lat:'41.8623764'},{lon:'-71.3744074',lat:'41.85720609999999'},{lon:'-71.375437',lat:'41.83234'},{lon:'-71.3807583',lat:'41.8263973'},{lon:'-71.3852192',lat:'41.8232979'},{lon:'-71.3879585',lat:'41.8164892'},{lon:'-71.39408590000001',lat:'41.816858'},{lon:'-71.3968063',lat:'41.8124311'},{lon:'-71.3744701',lat:'41.7841087'},{lon:'-71.3781738',lat:'41.7629894'},{lon:'-71.3445282',lat:'41.7159803'},{lon:'-71.374054',lat:'41.6606012'},{lon:'-71.4070129',lat:'41.54713069999999'},{lon:'-71.4118195',lat:'41.4627974'},{lon:'-71.4516449',lat:'41.3762933'},{lon:'-71.478699',lat:'41.1372078'},{lon:'-71.0887723',lat:'41.430544399999995'},{lon:'-71.1211109',lat:'41.4927959'},{lon:'-71.1197805',lat:'41.4946281'},{lon:'-71.1206388',lat:'41.4971032'},{lon:'-71.1223984',lat:'41.52191299999999'},{lon:'-71.1316681',lat:'41.593717600000005'},{lon:'-71.13849160000001',lat:'41.6038909'},{lon:'-71.1402512',lat:'41.6045648'},{lon:'-71.1419678',lat:'41.6125868'},{lon:'-71.140337',lat:'41.6237196'},{lon:'-71.1354876',lat:'41.6283389'},{lon:'-71.1325693',lat:'41.6603127'},{lon:'-71.1759567',lat:'41.66819949999999'},{lon:'-71.1759996',lat:'41.6715014'},{lon:'-71.195569',lat:'41.6750916'},{lon:'-71.2609291',lat:'41.7521368'},{lon:'-71.3286066',lat:'41.780817'},{lon:'-71.330409',lat:'41.78494510000001'},{lon:'-71.3295078',lat:'41.78830500000001'},{lon:'-71.3316536',lat:'41.7896809'},{lon:'-71.3341856',lat:'41.7946723'},{lon:'-71.3392925',lat:'41.7960801'},{lon:'-71.3413954',lat:'41.7994714'},{lon:'-71.3387775',lat:'41.8083007'},{lon:'-71.347146',lat:'41.8229177'},{lon:'-71.3448715',lat:'41.8280024'},{lon:'-71.3351727',lat:'41.8355809'},{lon:'-71.3423395',lat:'41.8445012'},{lon:'-71.3338879',lat:'41.8623764'}];
AddRaidPolygon(raid_mapLayer, VTeamDels,"#F8971B","Team Dels");

var VTeamQuahog = [{lon:'-71.374054',lat:'41.6606012'},{lon:'-71.3445282',lat:'41.7159803'},{lon:'-71.3781738',lat:'41.7629894'},{lon:'-71.3744701',lat:'41.7841087'},{lon:'-71.3931264',lat:'41.7863484'},{lon:'-71.4324996',lat:'41.7860439'},{lon:'-71.4375959',lat:'41.7902109'},{lon:'-71.4399784',lat:'41.8030403'},{lon:'-71.442904',lat:'41.80766080000001'},{lon:'-71.4623974',lat:'41.80613'},{lon:'-71.469223',lat:'41.798824'},{lon:'-71.4894491',lat:'41.7917105'},{lon:'-71.5096814',lat:'41.7881397'},{lon:'-71.53455680000002',lat:'41.7933807'},{lon:'-71.5902592',lat:'41.7842116'},{lon:'-71.61535700000002',lat:'41.7921422'},{lon:'-71.7929077',lat:'41.7953762'},{lon:'-71.7893887',lat:'41.596574000000004'},{lon:'-71.4846897',lat:'41.602607299999995'},{lon:'-71.4861488',lat:'41.6090251'},{lon:'-71.4882088',lat:'41.61544229999999'},{lon:'-71.4791107',lat:'41.62955790000001'},{lon:'-71.460228',lat:'41.638154'},{lon:'-71.4521599',lat:'41.6296862'},{lon:'-71.4415169',lat:'41.6461077'},{lon:'-71.42263410000001',lat:'41.6545733'},{lon:'-71.4099312',lat:'41.655342899999994'},{lon:'-71.374054',lat:'41.6606012'}];
AddRaidPolygon(raid_mapLayer, VTeamQuahog,"#7C3592","Team Quahog");

var VTeamSwampYankee = [{lon:'-71.7893887',lat:'41.596574000000004'},{lon:'-71.7975426',lat:'41.4163415'},{lon:'-71.8015766',lat:'41.415376'},{lon:'-71.8033791',lat:'41.417500100000005'},{lon:'-71.8070698',lat:'41.416599000000005'},{lon:'-71.8127346',lat:'41.419495399999995'},{lon:'-71.8192577',lat:'41.4198172'},{lon:'-71.8237209',lat:'41.4171139'},{lon:'-71.8248367',lat:'41.4147324'},{lon:'-71.827755',lat:'41.4144749'},{lon:'-71.8342781',lat:'41.4116426'},{lon:'-71.838913',lat:'41.4126082'},{lon:'-71.842432',lat:'41.410677'},{lon:'-71.8437195',lat:'41.4046258'},{lon:'-71.8414021',lat:'41.402952000000006'},{lon:'-71.8408012',lat:'41.3989603'},{lon:'-71.8423462',lat:'41.396063'},{lon:'-71.8385696',lat:'41.3907187'},{lon:'-71.8347073',lat:'41.3893664'},{lon:'-71.8323898',lat:'41.3829912'},{lon:'-71.8306732',lat:'41.3787407'},{lon:'-71.8329048',lat:'41.3759713'},{lon:'-71.8315315',lat:'41.3699812'},{lon:'-71.8375397',lat:'41.365601'},{lon:'-71.8379688',lat:'41.3596744'},{lon:'-71.8361664',lat:'41.3540694'},{lon:'-71.8306732',lat:'41.3505902'},{lon:'-71.8291283',lat:'41.3422136'},{lon:'-71.8381405',lat:'41.33441590000001'},{lon:'-71.8474102',lat:'41.3295177'},{lon:'-71.8566799',lat:'41.32113840000001'},{lon:'-71.8667221',lat:'41.3192045'},{lon:'-71.891613',lat:'41.330549'},{lon:'-71.9069767',lat:'41.3046344'},{lon:'-71.7029572',lat:'41.0902198'},{lon:'-71.478699',lat:'41.1372078'},{lon:'-71.4516449',lat:'41.3762933'},{lon:'-71.4118195',lat:'41.4627974'},{lon:'-71.4070129',lat:'41.54713069999999'},{lon:'-71.374054',lat:'41.6606012'},{lon:'-71.42263410000001',lat:'41.6545733'},{lon:'-71.4415169',lat:'41.6461077'},{lon:'-71.4521599',lat:'41.6296862'},{lon:'-71.460228',lat:'41.638154'},{lon:'-71.4791107',lat:'41.62955790000001'},{lon:'-71.4882088',lat:'41.61544229999999'},{lon:'-71.4846897',lat:'41.602607299999995'},{lon:'-71.7893887',lat:'41.596574000000004'}];
AddRaidPolygon(raid_mapLayer, VTeamSwampYankee,"#DB4436","Team Swamp Yankee");


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