Greasy Fork is available in English.

WME Philly MapRaid Overlay

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

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

var V03GroupC = [{lon:'-75.1241684',lat:'39.9652801'},{lon:'-75.2474213',lat:'40.1431897'},{lon:'-75.4116246',lat:'40.1054896'},{lon:'-75.1241684',lat:'39.9652801'}];
AddRaidPolygon(raid_mapLayer, V03GroupC,"#7C3592","03 Group C");

var V04GroupD = [{lon:'-75.1241684',lat:'39.9652801'},{lon:'-75.0602343',lat:'40.1837615'},{lon:'-75.2474213',lat:'40.1431897'},{lon:'-75.1241684',lat:'39.9652801'}];
AddRaidPolygon(raid_mapLayer, V04GroupD,"#4186F0","04 Group D");

var V05GroupE = [{lon:'-75.1241684',lat:'39.9652801'},{lon:'-75.0936127',lat:'39.972384299999995'},{lon:'-75.0791931',lat:'39.9797509'},{lon:'-75.0606537',lat:'39.9944817'},{lon:'-75.0541744',lat:'40.0062096'},{lon:'-75.0122429',lat:'40.0223405'},{lon:'-74.9663483',lat:'40.0535283'},{lon:'-74.9283133',lat:'40.0705053'},{lon:'-74.9078139',lat:'40.07159769999999'},{lon:'-74.8605285',lat:'40.0842397'},{lon:'-74.8568346',lat:'40.0918862'},{lon:'-74.8361037',lat:'40.1014874'},{lon:'-74.8280697',lat:'40.122640399999995'},{lon:'-74.9604507',lat:'40.139588'},{lon:'-75.0602343',lat:'40.1837615'},{lon:'-75.1241684',lat:'39.9652801'}];
AddRaidPolygon(raid_mapLayer, V05GroupE,"#7C3592","05 Group E");

var V02GroupB = [{lon:'-75.1241684',lat:'39.9652801'},{lon:'-75.4116246',lat:'40.1054896'},{lon:'-75.4108429',lat:'39.975015400000004'},{lon:'-75.1241684',lat:'39.9652801'}];
AddRaidPolygon(raid_mapLayer, V02GroupB,"#4186F0","02 Group B");

var V01GroupA = [{lon:'-75.1241684',lat:'39.9652801'},{lon:'-75.4108429',lat:'39.975015400000004'},{lon:'-75.4104997',lat:'39.8674559'},{lon:'-75.3717041',lat:'39.8272588'},{lon:'-75.3232956',lat:'39.8512481'},{lon:'-75.2536011',lat:'39.8515116'},{lon:'-75.2199662',lat:'39.8631796'},{lon:'-75.1897517',lat:'39.88089930000001'},{lon:'-75.1382446',lat:'39.8884017'},{lon:'-75.1286316',lat:'39.9139497'},{lon:'-75.1389313',lat:'39.9344865'},{lon:'-75.1358414',lat:'39.947911'},{lon:'-75.1241684',lat:'39.9652801'}];
AddRaidPolygon(raid_mapLayer, V01GroupA,"#7C3592","01 Group A");


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