WME MapRaid - PA Speed Limits Overlay

Creates polygons for MapRaid groups in a WME "MapRaid - PA Speed Limits Groups" layer

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

var V01Erie = [{lon:'-80.5191751',lat:'41.323209'},{lon:'-78.8694526',lat:'41.3737274'},{lon:'-78.8859313',lat:'41.99783790000001'},{lon:'-79.7634887',lat:'42.0003251'},{lon:'-79.7614289',lat:'42.2950879'},{lon:'-80.5193138',lat:'42.000006199999994'},{lon:'-80.5191751',lat:'41.323209'}];
AddRaidPolygon(raid_mapLayer, V01Erie,"#7C3592","01 - Erie");

var V02ElkStateForest = [{lon:'-78.8859313',lat:'41.99783790000001'},{lon:'-78.869453',lat:'41.37374330000001'},{lon:'-80.5191751',lat:'41.323209'},{lon:'-80.5191863',lat:'41.28238960000001'},{lon:'-80.519208',lat:'41.2415622'},{lon:'-80.5194437',lat:'41.1230503'},{lon:'-80.5190571',lat:'40.9798978'},{lon:'-78.8282551',lat:'40.9934067'},{lon:'-78.8253575',lat:'40.8779192'},{lon:'-77.2746944',lat:'40.9001676'},{lon:'-77.3012217',lat:'41.9997032'},{lon:'-78.8859313',lat:'41.99783790000001'}];
AddRaidPolygon(raid_mapLayer, V02ElkStateForest,"#4186F0","02 - Elk State Forest");

var V03Williamsport = [{lon:'-77.3011788',lat:'41.999304500000015'},{lon:'-77.2754288',lat:'40.9627895'},{lon:'-75.8056641',lat:'40.955011299999995'},{lon:'-75.762062',lat:'41.99802879999999'},{lon:'-77.3011788',lat:'41.999304500000015'}];
AddRaidPolygon(raid_mapLayer, V03Williamsport,"#7C3592","03 - Williamsport");

var V04Scranton = [{lon:'-75.762062',lat:'41.99802879999999'},{lon:'-75.8056641',lat:'40.955011299999995'},{lon:'-75.1313066',lat:'40.9813992'},{lon:'-75.1182948',lat:'40.997819899999996'},{lon:'-75.0271876',lat:'41.03846430000001'},{lon:'-74.9669197',lat:'41.0865733'},{lon:'-74.8800554',lat:'41.1836813'},{lon:'-74.79104670000001',lat:'41.3105964'},{lon:'-74.6905412',lat:'41.3597914'},{lon:'-74.6877568',lat:'41.3627839'},{lon:'-74.7389677',lat:'41.4330867'},{lon:'-74.8062593',lat:'41.4437853'},{lon:'-74.8887676',lat:'41.4537'},{lon:'-74.9132374',lat:'41.477731'},{lon:'-74.983709',lat:'41.5067976'},{lon:'-75.0288508',lat:'41.566184699999994'},{lon:'-75.0463121',lat:'41.7151134'},{lon:'-75.0519675',lat:'41.7555654'},{lon:'-75.0732176',lat:'41.8153075'},{lon:'-75.1168182',lat:'41.8471319'},{lon:'-75.146367',lat:'41.851582300000004'},{lon:'-75.1745572',lat:'41.8729078'},{lon:'-75.2184232',lat:'41.8698507'},{lon:'-75.2451475',lat:'41.914646'},{lon:'-75.2922402',lat:'41.9550755'},{lon:'-75.3400509',lat:'41.9934401'},{lon:'-75.3597536',lat:'41.9994507'},{lon:'-75.762062',lat:'41.99802879999999'}];
AddRaidPolygon(raid_mapLayer, V04Scranton,"#A61B4A","04 - Scranton");

var V05Pittsburgh = [{lon:'-80.5193139',lat:'39.721547'},{lon:'-79.7206902',lat:'39.720909999999996'},{lon:'-79.497303',lat:'39.7210328'},{lon:'-79.4469427',lat:'40.99140580000001'},{lon:'-80.5190571',lat:'40.9798978'},{lon:'-80.51919950000001',lat:'40.661635700000005'},{lon:'-80.5189161',lat:'40.3506653'},{lon:'-80.5193139',lat:'39.721547'}];
AddRaidPolygon(raid_mapLayer, V05Pittsburgh,"#A61B4A","05 - Pittsburgh");

var V06Altoona = [{lon:'-79.4469427',lat:'40.99140580000001'},{lon:'-79.497303',lat:'39.7210328'},{lon:'-78.3782034',lat:'39.72348130000001'},{lon:'-77.9532274',lat:'39.7227326'},{lon:'-77.5285924',lat:'39.720172999999996'},{lon:'-77.2531879',lat:'39.71996140000001'},{lon:'-77.27460850000001',lat:'40.9002325'},{lon:'-78.8252727',lat:'40.8779682'},{lon:'-78.82817030000001',lat:'40.9934557'},{lon:'-79.4469427',lat:'40.99140580000001'}];
AddRaidPolygon(raid_mapLayer, V06Altoona,"#7C3592","06 - Altoona");

var V07Harrisburg = [{lon:'-77.275858',lat:'40.96288669999999'},{lon:'-77.2532738',lat:'39.7199128'},{lon:'-77.0385841',lat:'39.7200415'},{lon:'-76.9313194',lat:'39.7208653'},{lon:'-76.8238823',lat:'39.7205339'},{lon:'-76.5578944',lat:'39.7215373'},{lon:'-76.4264837',lat:'39.7213161'},{lon:'-76.1373612',lat:'39.7212248'},{lon:'-75.8581924',lat:'39.72195599999999'},{lon:'-75.8056641',lat:'40.955011299999995'},{lon:'-77.275858',lat:'40.96288669999999'}];
AddRaidPolygon(raid_mapLayer, V07Harrisburg,"#A61B4A","07 - Harrisburg");

var V08Philadelphia = [{lon:'-75.8581924',lat:'39.72195599999999'},{lon:'-75.7735968',lat:'39.721969'},{lon:'-75.7603178',lat:'39.7464321'},{lon:'-75.7442825',lat:'39.76785710000001'},{lon:'-75.6983193',lat:'39.803472500000005'},{lon:'-75.641259',lat:'39.8278727'},{lon:'-75.5846413',lat:'39.8376965'},{lon:'-75.5194658',lat:'39.8359259'},{lon:'-75.4624246',lat:'39.82286010000001'},{lon:'-75.4201708',lat:'39.8033786'},{lon:'-75.3278183',lat:'39.8403259'},{lon:'-75.227665',lat:'39.8621005'},{lon:'-75.1295598',lat:'39.8944824'},{lon:'-75.1360885',lat:'39.934604099999994'},{lon:'-75.1297429',lat:'39.9611678'},{lon:'-75.0763414',lat:'39.9780093'},{lon:'-75.0233615',lat:'40.0186159'},{lon:'-74.9461573',lat:'40.0623582'},{lon:'-74.8675067',lat:'40.0826611'},{lon:'-74.8389142',lat:'40.0988173'},{lon:'-74.8218076',lat:'40.1262298'},{lon:'-74.7864918',lat:'40.11884740000001'},{lon:'-74.738496',lat:'40.135308'},{lon:'-74.7207583',lat:'40.1527343'},{lon:'-74.7340309',lat:'40.1739042'},{lon:'-74.7536373',lat:'40.1842311'},{lon:'-74.7801288',lat:'40.220907999999994'},{lon:'-74.8407965',lat:'40.2489384'},{lon:'-74.8519226',lat:'40.2621672'},{lon:'-74.8740475',lat:'40.2991007'},{lon:'-74.8920203',lat:'40.31166230000001'},{lon:'-74.92030060000002',lat:'40.3221248'},{lon:'-74.9393193',lat:'40.33637960000001'},{lon:'-74.945641',lat:'40.3527265'},{lon:'-74.9692706',lat:'40.4008065'},{lon:'-74.9961436',lat:'40.40972120000001'},{lon:'-75.0065947',lat:'40.4071753'},{lon:'-75.0285454',lat:'40.4030578'},{lon:'-75.0594059',lat:'40.4203057'},{lon:'-75.0683415',lat:'40.443049'},{lon:'-75.0656064',lat:'40.46526980000001'},{lon:'-75.06769460000001',lat:'40.5407902'},{lon:'-75.1017887',lat:'40.56880949999999'},{lon:'-75.1416529',lat:'40.5755583'},{lon:'-75.1593738',lat:'40.5644033'},{lon:'-75.1765769',lat:'40.564720799999996'},{lon:'-75.1905234',lat:'40.5735046'},{lon:'-75.1912542',lat:'40.58600380000001'},{lon:'-75.1880627',lat:'40.6226907'},{lon:'-75.1981753',lat:'40.6511706'},{lon:'-75.1766724',lat:'40.6764806'},{lon:'-75.1941449',lat:'40.68083000000001'},{lon:'-75.2042385',lat:'40.690648800000005'},{lon:'-75.1944086',lat:'40.711423100000005'},{lon:'-75.1825212',lat:'40.729012999999995'},{lon:'-75.1736766',lat:'40.77499449999999'},{lon:'-75.1316859',lat:'40.7720554'},{lon:'-75.0994322',lat:'40.7975454'},{lon:'-75.1000215',lat:'40.8053315'},{lon:'-75.0896233',lat:'40.8149364'},{lon:'-75.0832441',lat:'40.8263507'},{lon:'-75.0880649',lat:'40.8319856'},{lon:'-75.0739793',lat:'40.8454553'},{lon:'-75.0662429',lat:'40.84671579999999'},{lon:'-75.0562088',lat:'40.8571789'},{lon:'-75.051068',lat:'40.8712267'},{lon:'-75.0787309',lat:'40.9152055'},{lon:'-75.089675',lat:'40.9220781'},{lon:'-75.1318764',lat:'40.982390300000006'},{lon:'-75.8056641',lat:'40.955011299999995'},{lon:'-75.8581924',lat:'39.72195599999999'}];
AddRaidPolygon(raid_mapLayer, V08Philadelphia,"#7C3592","08 - Philadelphia");


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