WME South Carolina Overlay 6-21-2015

Creates polygons for MapRaid groups in a WME "South Carolina Groups" layer

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

var V01HiltonHead = [{lon:'-80.7563782',lat:'32.0319453'},{lon:'-80.5922699',lat:'32.196533'},{lon:'-80.6573003',lat:'32.2502585'},{lon:'-80.7451851',lat:'32.346410600000006'},{lon:'-80.795517',lat:'32.3915583'},{lon:'-80.8291626',lat:'32.517289'},{lon:'-80.9699249',lat:'32.6116164'},{lon:'-81.0633087',lat:'32.3915584'},{lon:'-81.1241788',lat:'32.3061292'},{lon:'-81.1194416',lat:'32.2862622'},{lon:'-80.888109',lat:'32.035867700000004'},{lon:'-80.7563782',lat:'32.0319453'}];
AddRaidPolygon(raid_mapLayer, V01HiltonHead,"#7C3592","01-Hilton Head");

var V02Beaufort = [{lon:'-80.3711701',lat:'32.3602433'},{lon:'-80.4693603',lat:'32.4831216'},{lon:'-80.6584223',lat:'32.6162443'},{lon:'-80.6856537',lat:'32.6636565'},{lon:'-80.8669281',lat:'32.7353065'},{lon:'-80.9699249',lat:'32.6116164'},{lon:'-80.8291626',lat:'32.517289'},{lon:'-80.795517',lat:'32.3915583'},{lon:'-80.7451851',lat:'32.346410600000006'},{lon:'-80.7370658',lat:'32.35514880000001'},{lon:'-80.7270572',lat:'32.3566356'},{lon:'-80.7116835',lat:'32.3625237'},{lon:'-80.6869438',lat:'32.3680067'},{lon:'-80.6792289',lat:'32.3634454'},{lon:'-80.6590808',lat:'32.3435623'},{lon:'-80.6573003',lat:'32.2502585'},{lon:'-80.5922699',lat:'32.196533'},{lon:'-80.3711701',lat:'32.3602433'}];
AddRaidPolygon(raid_mapLayer, V02Beaufort,"#4186F0","02-Beaufort");

var V03WalterboroEdistoIsland = [{lon:'-80.8669281',lat:'32.7353065'},{lon:'-80.6856537',lat:'32.6636565'},{lon:'-80.6584223',lat:'32.6162443'},{lon:'-80.4693603',lat:'32.4831216'},{lon:'-80.3711701',lat:'32.3602433'},{lon:'-80.2928925',lat:'32.4112697'},{lon:'-80.1219177',lat:'32.5178681'},{lon:'-80.2681732',lat:'32.6231835'},{lon:'-80.2356176',lat:'32.6786748'},{lon:'-80.1789684',lat:'32.7182616'},{lon:'-80.162296',lat:'32.748731500000005'},{lon:'-80.1381611',lat:'32.7486616'},{lon:'-80.1280976',lat:'32.7748627'},{lon:'-80.243454',lat:'32.9089917'},{lon:'-80.2963257',lat:'32.9885077'},{lon:'-80.6932068',lat:'32.97526'},{lon:'-80.8669281',lat:'32.7353065'}];
AddRaidPolygon(raid_mapLayer, V03WalterboroEdistoIsland,"#7C3592","03-Walterboro/Edisto Island");

var V04Charleston = [{lon:'-79.671308',lat:'32.753706599999994'},{lon:'-79.7607421',lat:'32.9948429'},{lon:'-79.9214172',lat:'32.9464538'},{lon:'-80.0257874',lat:'32.9743959'},{lon:'-80.243454',lat:'32.9089917'},{lon:'-80.1881355',lat:'32.8402097'},{lon:'-80.1280976',lat:'32.7748627'},{lon:'-80.1381611',lat:'32.7486616'},{lon:'-80.162296',lat:'32.748731500000005'},{lon:'-80.1789684',lat:'32.7182616'},{lon:'-80.2356176',lat:'32.6786748'},{lon:'-80.2681732',lat:'32.6231835'},{lon:'-80.1219177',lat:'32.5178681'},{lon:'-79.671308',lat:'32.753706599999994'}];
AddRaidPolygon(raid_mapLayer, V04Charleston,"#4186F0","04-Charleston");

var V05SummervilleMoncksCorner = [{lon:'-80.0704193',lat:'33.4595156'},{lon:'-80.1432038',lat:'33.2455789'},{lon:'-80.541715',lat:'33.4295101'},{lon:'-80.6718709',lat:'33.1835456'},{lon:'-80.37323',lat:'33.06162230000001'},{lon:'-80.2963257',lat:'32.9885077'},{lon:'-80.243454',lat:'32.9089917'},{lon:'-80.0257874',lat:'32.9743959'},{lon:'-79.9214172',lat:'32.9464538'},{lon:'-79.8168696',lat:'33.3951999'},{lon:'-80.0704193',lat:'33.4595156'}];
AddRaidPolygon(raid_mapLayer, V05SummervilleMoncksCorner,"#A61B4A","05-Summerville/Moncks Corner");

var V06GeorgetownUS521 = [{lon:'-79.7482109',lat:'33.6922095'},{lon:'-79.9139011',lat:'33.7242894'},{lon:'-79.970508',lat:'33.785589'},{lon:'-80.1995493',lat:'33.8120219'},{lon:'-80.3703416',lat:'33.7885359'},{lon:'-80.5222231',lat:'33.7930739'},{lon:'-80.5258406',lat:'33.6359709'},{lon:'-80.2331543',lat:'33.6163347'},{lon:'-80.0704193',lat:'33.4595156'},{lon:'-79.8168696',lat:'33.3951999'},{lon:'-79.5284857',lat:'33.2535377'},{lon:'-79.7607421',lat:'32.9948429'},{lon:'-79.671308',lat:'32.753706599999994'},{lon:'-79.20387270000002',lat:'33.1007454'},{lon:'-79.0207113',lat:'33.4892185'},{lon:'-79.129715',lat:'33.5176407'},{lon:'-79.0905762',lat:'33.56657259999999'},{lon:'-79.0892029',lat:'33.6500651'},{lon:'-79.0307256',lat:'33.68491240000001'},{lon:'-79.1400147',lat:'33.7506061'},{lon:'-79.2608643',lat:'33.736902900000004'},{lon:'-79.3899536',lat:'33.4944525'},{lon:'-79.7482109',lat:'33.6922095'}];
AddRaidPolygon(raid_mapLayer, V06GeorgetownUS521,"#7C3592","06-Georgetown/US 521");

var V07GrandStrand = [{lon:'-79.0892029',lat:'33.6500651'},{lon:'-79.0905762',lat:'33.56657259999999'},{lon:'-79.129715',lat:'33.5176407'},{lon:'-79.0207113',lat:'33.4892185'},{lon:'-78.9779983',lat:'33.5362582'},{lon:'-78.8667298',lat:'33.64434899999999'},{lon:'-78.7273406',lat:'33.7377594'},{lon:'-78.498688',lat:'33.811102'},{lon:'-78.6258888',lat:'33.927836'},{lon:'-78.9072597',lat:'33.79784780000001'},{lon:'-79.0206602',lat:'33.73658'},{lon:'-79.0307256',lat:'33.68491240000001'},{lon:'-79.0892029',lat:'33.6500651'}];
AddRaidPolygon(raid_mapLayer, V07GrandStrand,"#4186F0","07-Grand Strand");

var V08SumterUS378 = [{lon:'-79.6865845',lat:'34.018518500000006'},{lon:'-79.8348999',lat:'33.9786699'},{lon:'-80.1963329',lat:'33.9937577'},{lon:'-80.4020691',lat:'34.057210500000004'},{lon:'-80.5627441',lat:'34.0173802'},{lon:'-80.5235964',lat:'33.7930739'},{lon:'-80.3717149',lat:'33.7885359'},{lon:'-80.2009226',lat:'33.8120219'},{lon:'-79.97188130000002',lat:'33.785589'},{lon:'-79.9152744',lat:'33.7242894'},{lon:'-79.7495842',lat:'33.6922095'},{lon:'-79.6861554',lat:'33.8072511'},{lon:'-79.4490051',lat:'33.793985'},{lon:'-79.2608643',lat:'33.736902900000004'},{lon:'-79.2951965',lat:'33.9205715'},{lon:'-79.5094299',lat:'34.0082735'},{lon:'-79.6865845',lat:'34.018518500000006'}];
AddRaidPolygon(raid_mapLayer, V08SumterUS378,"#4186F0","08-Sumter/US 378");

var V09Florence = [{lon:'-80.0803756',lat:'34.4423094'},{lon:'-80.2124931',lat:'34.3904386'},{lon:'-80.2024284',lat:'34.3592332'},{lon:'-80.1214518',lat:'34.27552380000001'},{lon:'-79.923022',lat:'34.2339351'},{lon:'-79.983902',lat:'34.1316999'},{lon:'-79.8335266',lat:'33.97866990000001'},{lon:'-79.6852112',lat:'34.0185185'},{lon:'-79.5094299',lat:'34.0082735'},{lon:'-79.5410156',lat:'34.2220225'},{lon:'-79.5932007',lat:'34.3457038'},{lon:'-79.7267533',lat:'34.2867226'},{lon:'-79.8664856',lat:'34.3491053'},{lon:'-80.0803756',lat:'34.4423094'}];
AddRaidPolygon(raid_mapLayer, V09Florence,"#7C3592","09-Florence");

var V10ConwayUS501 = [{lon:'-79.1400147',lat:'33.7506061'},{lon:'-79.0307256',lat:'33.68491240000001'},{lon:'-79.0206602',lat:'33.73658'},{lon:'-78.9072597',lat:'33.79784780000001'},{lon:'-78.9903259',lat:'33.9137338'},{lon:'-79.2897034',lat:'34.1618182'},{lon:'-79.3149914',lat:'34.2395488'},{lon:'-79.4448853',lat:'34.4171063'},{lon:'-79.5932007',lat:'34.3457038'},{lon:'-79.5410156',lat:'34.2220225'},{lon:'-79.5094299',lat:'34.0082735'},{lon:'-79.2951965',lat:'33.9205715'},{lon:'-79.2608643',lat:'33.736902900000004'},{lon:'-79.1400147',lat:'33.7506061'}];
AddRaidPolygon(raid_mapLayer, V10ConwayUS501,"#A61B4A","10-Conway/US 501");

var V11Hwy9 = [{lon:'-78.631382',lat:'33.9249873'},{lon:'-78.8749695',lat:'34.13340500000001'},{lon:'-79.3309021',lat:'34.5223986'},{lon:'-79.4448853',lat:'34.4171063'},{lon:'-79.3149914',lat:'34.2395488'},{lon:'-79.2897034',lat:'34.1618182'},{lon:'-78.9903259',lat:'33.9137338'},{lon:'-78.9072597',lat:'33.79784780000001'},{lon:'-78.631382',lat:'33.9249873'}];
AddRaidPolygon(raid_mapLayer, V11Hwy9,"#7C3592","11-Hwy 9");


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