WME MMR VENEZUELA 2015 Overlay

Creates polygons for MapRaid groups in a WME "MMR VENEZUELA 2015 Groups" layer

// ==UserScript==
// @name                WME MMR VENEZUELA 2015 Overlay
// @namespace           https://greasyfork.org/users/5252
// @description         Creates polygons for MapRaid groups in a WME "MMR VENEZUELA 2015 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","__MMRVENEZUELA2015");
        
    var raid_mapLayer = new mro_OL.Layer.Vector("MMR VENEZUELA 2015", {
        displayInLayerSwitcher: true,
        uniqueName: "__MMRVENEZUELA2015"
    });
        
    I18n.translations.en.layers.name["__MMRVENEZUELA2015"] = "MMR VENEZUELA 2015";
    mro_Map.addLayer(raid_mapLayer);
    raid_mapLayer.setVisibility(true);
    

var V1Maracaibo = [{lon:'-71.3230983',lat:'11.8705605'},{lon:'-72.007032',lat:'11.660818100000002'},{lon:'-72.2734616',lat:'11.2004445'},{lon:'-72.4931992',lat:'11.1734983'},{lon:'-72.9279495',lat:'10.4847596'},{lon:'-73.193599',lat:'9.5903334'},{lon:'-73.4449127',lat:'9.1404659'},{lon:'-72.8205573',lat:'9.056956300000003'},{lon:'-72.6731082',lat:'8.6182311'},{lon:'-72.4548348',lat:'8.4001175'},{lon:'-72.3676822',lat:'8.5591163'},{lon:'-72.0243945',lat:'8.5807736'},{lon:'-72.0136923',lat:'8.671888'},{lon:'-71.8429899',lat:'8.7237693'},{lon:'-71.7414848',lat:'8.660031400000003'},{lon:'-71.2359735',lat:'9.047086900000002'},{lon:'-71.1262297',lat:'9.0440458'},{lon:'-71.236232',lat:'9.1742397'},{lon:'-71.6015568',lat:'9.053236400000003'},{lon:'-71.6169183',lat:'9.057575100000003'},{lon:'-71.613527',lat:'9.065253999999996'},{lon:'-71.6144273',lat:'9.0744586'},{lon:'-71.6222808',lat:'9.0795946'},{lon:'-71.6289329',lat:'9.0791366'},{lon:'-71.703865',lat:'9.0851652'},{lon:'-71.7419593',lat:'9.1621699'},{lon:'-71.713032',lat:'9.344960000000004'},{lon:'-71.7006614',lat:'9.3586401'},{lon:'-71.7212503',lat:'9.3892577'},{lon:'-71.9272808',lat:'9.529037'},{lon:'-71.9680642',lat:'9.6170787'},{lon:'-72.1133029',lat:'9.8167981'},{lon:'-71.8983363',lat:'10.1148789'},{lon:'-71.8356189',lat:'10.2100612'},{lon:'-71.7903769',lat:'10.3214602'},{lon:'-71.71056970000001',lat:'10.389347700000002'},{lon:'-71.6279859',lat:'10.4369527'},{lon:'-71.5770142',lat:'10.5775217'},{lon:'-71.5740829',lat:'10.7248381'},{lon:'-71.6403476',lat:'10.7872408'},{lon:'-71.5184686',lat:'10.8991955'},{lon:'-71.5199254',lat:'10.9317252'},{lon:'-71.5287644',lat:'10.9404892'},{lon:'-71.5347709',lat:'10.9797602'},{lon:'-71.7982815',lat:'11.1276889'},{lon:'-71.9603378',lat:'11.4616849'},{lon:'-71.9356173',lat:'11.598940600000004'},{lon:'-71.4137404',lat:'11.7280604'},{lon:'-71.32584530000001',lat:'11.806041300000002'},{lon:'-71.3230983',lat:'11.8705605'}];
AddRaidPolygon(raid_mapLayer, V1Maracaibo,"#0BA9CC","1- Maracaibo");

var V2Tachira = [{lon:'-72.4548348',lat:'8.4001175'},{lon:'-72.3242358',lat:'8.0740054'},{lon:'-72.4670586',lat:'7.9488955'},{lon:'-72.44783280000001',lat:'7.4943753'},{lon:'-72.4313533',lat:'7.401779100000002'},{lon:'-72.2033865',lat:'7.396331499999999'},{lon:'-71.9424605',lat:'7.330956800000001'},{lon:'-71.8161173',lat:'7.4290148'},{lon:'-71.3355936',lat:'7.463248800000001'},{lon:'-71.4947663',lat:'7.567892600000001'},{lon:'-71.5277249',lat:'7.940734000000001'},{lon:'-71.654068',lat:'7.9516149'},{lon:'-71.8929887',lat:'8.1990233'},{lon:'-71.7446726',lat:'8.4843638'},{lon:'-71.8215769',lat:'8.5848623'},{lon:'-71.7414848',lat:'8.660031400000003'},{lon:'-71.8429899',lat:'8.7237693'},{lon:'-72.0136923',lat:'8.671888'},{lon:'-72.0243945',lat:'8.5807736'},{lon:'-72.3676822',lat:'8.5591163'},{lon:'-72.4548348',lat:'8.4001175'}];
AddRaidPolygon(raid_mapLayer, V2Tachira,"#F9F7A6","2 - Tachira");

var V3Cabimas = [{lon:'-71.4701843',lat:'10.4824104'},{lon:'-71.48443220000001',lat:'10.3909093'},{lon:'-71.0458374',lat:'9.7090571'},{lon:'-71.0733032',lat:'9.6061661'},{lon:'-70.864563',lat:'9.5790843'},{lon:'-70.6287746',lat:'9.7865091'},{lon:'-70.6530762',lat:'9.8822755'},{lon:'-70.864563',lat:'10.0689244'},{lon:'-70.657196',lat:'10.291949799999996'},{lon:'-70.8329773',lat:'10.417585800000003'},{lon:'-70.97717290000001',lat:'10.4756585'},{lon:'-71.0760498',lat:'10.7523661'},{lon:'-71.2573242',lat:'10.9816389'},{lon:'-71.4372253',lat:'10.972201699999998'},{lon:'-71.5285492',lat:'10.9494501'},{lon:'-71.5271328',lat:'10.9412335'},{lon:'-71.5193652',lat:'10.9345337'},{lon:'-71.5168762',lat:'10.9115271'},{lon:'-71.4487267',lat:'10.902424800000002'},{lon:'-71.4430619',lat:'10.7945251'},{lon:'-71.51189700000002',lat:'10.803472900000001'},{lon:'-71.5954971',lat:'10.8019444'},{lon:'-71.5912025',lat:'10.7758075'},{lon:'-71.5439987',lat:'10.7358382'},{lon:'-71.5455437',lat:'10.546884000000002'},{lon:'-71.4701843',lat:'10.4824104'}];
AddRaidPolygon(raid_mapLayer, V3Cabimas,"#7C3592","3 - Cabimas");

var V4Merida = [{lon:'-71.8215769',lat:'8.5848623'},{lon:'-71.7446726',lat:'8.4843638'},{lon:'-71.8929887',lat:'8.1990233'},{lon:'-71.654068',lat:'7.9516149'},{lon:'-71.5277249',lat:'7.940734000000001'},{lon:'-71.4991197',lat:'7.617230600000001'},{lon:'-71.4629642',lat:'7.639885500000001'},{lon:'-71.4585658',lat:'7.747248900000001'},{lon:'-71.0506961',lat:'8.0546676'},{lon:'-70.99027100000002',lat:'8.2218822'},{lon:'-70.8982599',lat:'8.2735278'},{lon:'-70.8515677',lat:'8.5696785'},{lon:'-70.6991315',lat:'8.6104153'},{lon:'-70.7241979',lat:'8.7183475'},{lon:'-70.650039',lat:'8.7739986'},{lon:'-70.5366945',lat:'8.9949327'},{lon:'-70.5989068',lat:'9.0627381'},{lon:'-70.6923417',lat:'9.0159834'},{lon:'-70.7596328',lat:'9.082437'},{lon:'-70.879109',lat:'9.117693100000004'},{lon:'-70.9244275',lat:'9.3101838'},{lon:'-71.07274250000002',lat:'9.3318663'},{lon:'-71.1766719',lat:'9.255236300000004'},{lon:'-71.2092544',lat:'9.2196977'},{lon:'-71.236232',lat:'9.1742397'},{lon:'-71.1262297',lat:'9.0440458'},{lon:'-71.2359735',lat:'9.047086900000002'},{lon:'-71.7414848',lat:'8.660031400000003'},{lon:'-71.8215769',lat:'8.5848623'}];
AddRaidPolygon(raid_mapLayer, V4Merida,"#7C3592","4 - Merida");

var V5Trujillo = [{lon:'-71.0733032',lat:'9.6061661'},{lon:'-71.07274250000002',lat:'9.3318663'},{lon:'-70.9244275',lat:'9.3101838'},{lon:'-70.879109',lat:'9.117693100000004'},{lon:'-70.7596328',lat:'9.082437'},{lon:'-70.6923417',lat:'9.0159834'},{lon:'-70.5989068',lat:'9.0627381'},{lon:'-70.5366945',lat:'8.9949327'},{lon:'-70.208549',lat:'9.056297200000003'},{lon:'-70.0904463',lat:'9.3111655'},{lon:'-70.108299',lat:'9.384338200000004'},{lon:'-70.0094224',lat:'9.466977700000003'},{lon:'-70.1110456',lat:'9.560431199999996'},{lon:'-70.0876998',lat:'9.6755198'},{lon:'-69.9860765',lat:'9.705301'},{lon:'-69.9943163',lat:'9.7404936'},{lon:'-70.2071757',lat:'9.860932300000002'},{lon:'-70.35961040000001',lat:'9.916400600000001'},{lon:'-70.458487',lat:'9.890697'},{lon:'-70.5765898',lat:'10.0354226'},{lon:'-70.6219082',lat:'10.031365799999996'},{lon:'-70.6530762',lat:'9.8822755'},{lon:'-70.6287746',lat:'9.7865091'},{lon:'-70.864563',lat:'9.5790843'},{lon:'-71.0733032',lat:'9.6061661'}];
AddRaidPolygon(raid_mapLayer, V5Trujillo,"#F8971B","5 -Trujillo");

var V6Barinas = [{lon:'-70.208549',lat:'9.056297200000003'},{lon:'-70.5366945',lat:'8.9949327'},{lon:'-70.650039',lat:'8.7739986'},{lon:'-70.7241979',lat:'8.7183475'},{lon:'-70.6991315',lat:'8.6104153'},{lon:'-70.8515677',lat:'8.5696785'},{lon:'-70.8982599',lat:'8.2735278'},{lon:'-70.99027100000002',lat:'8.2218822'},{lon:'-71.0506961',lat:'8.0546676'},{lon:'-71.4585658',lat:'7.747248900000001'},{lon:'-71.4629642',lat:'7.639885500000001'},{lon:'-71.4991197',lat:'7.617230600000001'},{lon:'-71.4947663',lat:'7.567892600000001'},{lon:'-71.3355936',lat:'7.463248800000001'},{lon:'-70.7612239',lat:'7.289946400000001'},{lon:'-70.316285',lat:'7.5541283'},{lon:'-69.6763428',lat:'7.845358799999999'},{lon:'-69.382464',lat:'8.0112967'},{lon:'-68.7644934',lat:'7.8834519'},{lon:'-68.29208960000001',lat:'7.935142000000001'},{lon:'-67.5807374',lat:'7.9569076999999995'},{lon:'-67.6439087',lat:'8.095608399999996'},{lon:'-68.1657527',lat:'8.5412963'},{lon:'-68.3580098',lat:'8.535863'},{lon:'-68.7452692',lat:'8.2342553'},{lon:'-68.9732313',lat:'8.1961975'},{lon:'-69.1490091',lat:'8.533143'},{lon:'-69.4827146',lat:'8.6974323'},{lon:'-69.5795227',lat:'8.7802468'},{lon:'-69.7147964',lat:'8.740868300000004'},{lon:'-70.208549',lat:'9.056297200000003'}];
AddRaidPolygon(raid_mapLayer, V6Barinas,"#4186F0","6 - Barinas");




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