// ==UserScript==
// @name WME MeMMR India May 2016 Overlay
// @namespace https://greasyfork.org/users/5252
// @description Creates polygons for MapRaid groups in a WME "MeMMR India May 2016 Groups" layer
// @include https://www.waze.com/editor/*
// @include https://www.waze.com/*/editor/*
// @version 2.3.2
// @copyright 2014 davielde
// ==/UserScript==
/* 2.3.2 modified to work with new WME update
*/
//---------------------------------------------------------------------------------------
//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 > div.location-info-region > div').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 > div.location-info-region > div').text();
}
setTimeout(function(){$('#topbar-container > div > div > div.location-info-region > div').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","__MeMMRIndiaMay2016");
var raid_mapLayer = new mro_OL.Layer.Vector("MeMMR India May 2016", {
displayInLayerSwitcher: true,
uniqueName: "__MeMMRIndiaMay2016"
});
I18n.translations.en.layers.name["__MeMMRIndiaMay2016"] = "MeMMR India May 2016";
mro_Map.addLayer(raid_mapLayer);
raid_mapLayer.setVisibility(true);
var V04Trivandrum = [{lon:'77.5112844',lat:'8.0293047'},{lon:'79.6083194',lat:'9.1617473'},{lon:'79.5954772',lat:'10.0887488'},{lon:'76.1434657',lat:'9.592636700000002'},{lon:'76.8905469',lat:'8.3161281'},{lon:'77.5112844',lat:'8.0293047'}];
AddRaidPolygon(raid_mapLayer, V04Trivandrum,"#7C3592","04-Trivandrum");
var V03Cochin = [{lon:'75.6889344',lat:'11.273366400000002'},{lon:'76.1434657',lat:'9.592636700000002'},{lon:'79.5954772',lat:'10.0887488'},{lon:'77.9027254',lat:'11.1620765'},{lon:'75.6889344',lat:'11.273366400000002'}];
AddRaidPolygon(raid_mapLayer, V03Cochin,"#A61B4A","03-Cochin");
var V05Salem = [{lon:'77.9215622',lat:'12.5505421'},{lon:'77.9027254',lat:'11.1620765'},{lon:'79.5954772',lat:'10.0887488'},{lon:'79.9506219',lat:'10.2584608'},{lon:'80.19344770000001',lat:'12.434898500000001'},{lon:'77.9215622',lat:'12.5505421'}];
AddRaidPolygon(raid_mapLayer, V05Salem,"#4186F0","05-Salem");
var V02Mysore = [{lon:'74.4831848',lat:'13.0099099'},{lon:'75.6889344',lat:'11.273366400000002'},{lon:'77.9027254',lat:'11.1620765'},{lon:'77.9215622',lat:'12.5505421'},{lon:'74.4831848',lat:'13.0099099'}];
AddRaidPolygon(raid_mapLayer, V02Mysore,"#7C3592","02-Mysore");
var V06Chennai = [{lon:'80.4886944',lat:'13.2405582'},{lon:'80.2077211',lat:'14.1179624'},{lon:'77.9122925',lat:'14.380146000000002'},{lon:'77.9215622',lat:'12.5505421'},{lon:'80.19344770000001',lat:'12.434898500000001'},{lon:'80.4886944',lat:'13.2405582'}];
AddRaidPolygon(raid_mapLayer, V06Chennai,"#A61B4A","06-Chennai");
var V01Bangalore = [{lon:'74.5257568',lat:'13.683350599999999'},{lon:'74.4831848',lat:'13.0099099'},{lon:'77.9215622',lat:'12.5505421'},{lon:'77.9122925',lat:'14.380146000000002'},{lon:'74.5257568',lat:'13.683350599999999'}];
AddRaidPolygon(raid_mapLayer, V01Bangalore,"#4186F0","01-Bangalore");
var V07Hyderabad = [{lon:'77.6348877',lat:'18.1093082'},{lon:'77.8216553',lat:'16.1619209'},{lon:'79.6742249',lat:'15.9512611'},{lon:'80.222168',lat:'17.8794314'},{lon:'77.6348877',lat:'18.1093082'}];
AddRaidPolygon(raid_mapLayer, V07Hyderabad,"#7C3592","07-Hyderabad");
var V08Vijaywada = [{lon:'79.6742249',lat:'15.9512611'},{lon:'80.9157104',lat:'15.6605815'},{lon:'82.5034224',lat:'16.5684705'},{lon:'82.6807023',lat:'17.2931179'},{lon:'80.222168',lat:'17.8794314'},{lon:'79.6742249',lat:'15.9512611'}];
AddRaidPolygon(raid_mapLayer, V08Vijaywada,"#A61B4A","08-Vijaywada");
var V09Nellore = [{lon:'80.9157104',lat:'15.6605815'},{lon:'79.6742249',lat:'15.9512611'},{lon:'77.8216553',lat:'16.1619209'},{lon:'77.9122925',lat:'14.380146000000002'},{lon:'80.2077211',lat:'14.1179624'},{lon:'80.9157104',lat:'15.6605815'}];
AddRaidPolygon(raid_mapLayer, V09Nellore,"#4186F0","09-Nellore");
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);});
}