// ==UserScript==
// @name WME MMR 3 - Thailand Overlay
// @namespace https://greasyfork.org/users/5252
// @description Creates polygons for MapRaid groups in a WME "MMR 3 - Thailand 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","__MMR3-Thailand");
var raid_mapLayer = new mro_OL.Layer.Vector("MMR 3 - Thailand ", {
displayInLayerSwitcher: true,
uniqueName: "__MMR3-Thailand"
});
I18n.translations.en.layers.name["__MMR3-Thailand"] = "MMR 3 - Thailand ";
mro_Map.addLayer(raid_mapLayer);
raid_mapLayer.setVisibility(true);
var V01ChiangMai_1 = [{lon:'99.1625977',lat:'20.1474954'},{lon:'99.0527344',lat:'20.1204186'},{lon:'98.9675903',lat:'19.7847957'},{lon:'98.8467407',lat:'19.8364764'},{lon:'98.4461516',lat:'19.703479700000003'},{lon:'98.5640538',lat:'19.5013375'},{lon:'98.5652161',lat:'19.3720452'},{lon:'99.4221496',lat:'18.968636500000002'},{lon:'99.3562317',lat:'19.255404799999997'},{lon:'99.3081665',lat:'19.5015477'},{lon:'99.3424988',lat:'19.5352015'},{lon:'99.27520750000001',lat:'19.6257728'},{lon:'99.433136',lat:'19.8080541'},{lon:'99.3974304',lat:'19.8700598'},{lon:'99.4812012',lat:'20.0223874'},{lon:'99.5910645',lat:'20.1075233'},{lon:'99.5223999',lat:'20.1629657'},{lon:'99.3988037',lat:'20.1023648'},{lon:'99.1625977',lat:'20.1474954'}];
AddRaidPolygon(raid_mapLayer, V01ChiangMai_1,"#A61B4A","01 - Chiang Mai_1");
var V02ChiangMai_2 = [{lon:'99.4221496',lat:'18.968636500000002'},{lon:'98.5652161',lat:'19.3720452'},{lon:'98.5665894',lat:'19.1996473'},{lon:'98.6146545',lat:'19.152951999999996'},{lon:'98.6380005',lat:'19.082884400000005'},{lon:'98.4072876',lat:'19.0478394'},{lon:'98.3317566',lat:'19.1646271'},{lon:'98.2479858',lat:'19.1763013'},{lon:'98.0584717',lat:'18.8439132'},{lon:'98.0810401',lat:'18.6319866'},{lon:'98.20513970000002',lat:'18.5734947'},{lon:'98.6888123',lat:'18.3310622'},{lon:'99.1378784',lat:'18.674869300000005'},{lon:'99.3191528',lat:'18.5056567'},{lon:'99.3795776',lat:'18.6176162'},{lon:'99.390564',lat:'18.8335154'},{lon:'99.4221496',lat:'18.968636500000002'}];
AddRaidPolygon(raid_mapLayer, V02ChiangMai_2,"#7C3592","02 - Chiang Mai_2");
var V03ChiangMai_3 = [{lon:'98.6888123',lat:'18.3310622'},{lon:'98.20513970000002',lat:'18.5734947'},{lon:'98.0419922',lat:'18.437924699999996'},{lon:'98.1820679',lat:'18.304988199999997'},{lon:'98.1079102',lat:'18.284126200000003'},{lon:'98.1738281',lat:'18.075368'},{lon:'98.2507324',lat:'18.0701458'},{lon:'98.2232666',lat:'18.0205277'},{lon:'97.9595947',lat:'17.923862700000004'},{lon:'98.1188965',lat:'17.7669967'},{lon:'98.1216431',lat:'17.680661599999997'},{lon:'98.0776978',lat:'17.5995211'},{lon:'98.1381226',lat:'17.513105699999997'},{lon:'98.2781982',lat:'17.5314397'},{lon:'98.2946777',lat:'17.4292697'},{lon:'98.25897220000002',lat:'17.4004421'},{lon:'98.3825684',lat:'17.2221348'},{lon:'98.6022949',lat:'17.282464'},{lon:'98.5198975',lat:'17.8036111'},{lon:'98.6105347',lat:'17.756534'},{lon:'98.86871340000002',lat:'17.790535400000003'},{lon:'98.9016724',lat:'17.868975300000002'},{lon:'98.7835693',lat:'18.2710861'},{lon:'98.6888123',lat:'18.3310622'}];
AddRaidPolygon(raid_mapLayer, V03ChiangMai_3,"#A61B4A","03 - Chiang Mai_3");
var V04ChangwatUdonThani_1 = [{lon:'102.4881975',lat:'17.2458345'},{lon:'103.34255',lat:'17.566793399999998'},{lon:'103.3919907',lat:'17.5815213'},{lon:'103.4093026',lat:'17.6156488'},{lon:'103.4318161',lat:'17.856558000000003'},{lon:'103.3403658',lat:'17.868893199999995'},{lon:'103.23625990000001',lat:'17.8965583'},{lon:'102.8409576',lat:'17.9088357'},{lon:'102.7963257',lat:'17.7251424'},{lon:'102.6644897',lat:'17.638787199999996'},{lon:'102.573469',lat:'17.777473499999996'},{lon:'102.3998475',lat:'17.913455499999998'},{lon:'102.0822144',lat:'18.1301912'},{lon:'101.9970703',lat:'18.0361981'},{lon:'101.9943237',lat:'17.620464100000003'},{lon:'102.29644780000001',lat:'17.625699500000003'},{lon:'102.3677032',lat:'17.4174463'},{lon:'102.4142456',lat:'17.2752704'},{lon:'102.4881975',lat:'17.2458345'}];
AddRaidPolygon(raid_mapLayer, V04ChangwatUdonThani_1,"#7C3592","04 - Changwat Udon Thani_1");
var V05ChangwatUdonThani_2 = [{lon:'102.4881975',lat:'17.2458345'},{lon:'102.505188',lat:'17.0725385'},{lon:'102.8649902',lat:'16.804541100000005'},{lon:'103.4857177',lat:'16.7782463'},{lon:'103.7384034',lat:'17.0882912'},{lon:'103.5436753',lat:'17.2470822'},{lon:'103.3293961',lat:'17.3086561'},{lon:'103.34255',lat:'17.566793399999998'},{lon:'102.4881975',lat:'17.2458345'}];
AddRaidPolygon(raid_mapLayer, V05ChangwatUdonThani_2,"#A61B4A","05 - Changwat Udon Thani_2");
var V06NakhonRatchasima_1 = [{lon:'102.2991943',lat:'15.8609576'},{lon:'102.0739746',lat:'15.734101199999998'},{lon:'101.9641113',lat:'15.5066191'},{lon:'101.3433838',lat:'15.395431800000004'},{lon:'102.6672363',lat:'14.857195700000002'},{lon:'102.9940796',lat:'15.172879300000002'},{lon:'103.0462646',lat:'15.461621999999997'},{lon:'102.8485107',lat:'15.593938600000003'},{lon:'102.708435',lat:'15.779038600000005'},{lon:'102.4035645',lat:'15.7473191'},{lon:'102.2991943',lat:'15.8609576'}];
AddRaidPolygon(raid_mapLayer, V06NakhonRatchasima_1,"#7C3592","06 - Nakhon Ratchasima_1");
var V07NakhonRatchasima_2 = [{lon:'102.6672363',lat:'14.857195700000002'},{lon:'101.3433838',lat:'15.395431800000004'},{lon:'101.3502915',lat:'15.1488701'},{lon:'101.41204830000001',lat:'14.886396000000001'},{lon:'101.1428833',lat:'14.7616033'},{lon:'101.1621094',lat:'14.485212199999996'},{lon:'101.4235311',lat:'14.363360399999998'},{lon:'101.8267822',lat:'14.248411099999998'},{lon:'102.1715183',lat:'14.0890029'},{lon:'102.4420166',lat:'14.088629300000001'},{lon:'102.741394',lat:'14.3069695'},{lon:'102.6150513',lat:'14.519780000000003'},{lon:'102.5244141',lat:'14.5623177'},{lon:'102.51068120000001',lat:'14.7669151'},{lon:'102.6672363',lat:'14.857195700000002'}];
AddRaidPolygon(raid_mapLayer, V07NakhonRatchasima_2,"#A61B4A","07 - Nakhon Ratchasima_2");
var V08Nonthaburi = [{lon:'100.2536774',lat:'13.866080299999998'},{lon:'100.4916006',lat:'13.8712469'},{lon:'100.5599213',lat:'13.984710999999999'},{lon:'100.7954407',lat:'13.970718499999998'},{lon:'100.6430054',lat:'14.216463699999998'},{lon:'100.2584839',lat:'14.1552187'},{lon:'100.2536774',lat:'13.866080299999998'}];
AddRaidPolygon(raid_mapLayer, V08Nonthaburi,"#7C3592","08 - Nonthaburi");
var V09Bangkonk = [{lon:'100.2536774',lat:'13.866080299999998'},{lon:'100.3065491',lat:'13.6219641'},{lon:'100.9025573',lat:'13.690689200000001'},{lon:'100.9561157',lat:'13.822078200000002'},{lon:'100.9190369',lat:'13.9633887'},{lon:'100.5599213',lat:'13.984710999999999'},{lon:'100.4916006',lat:'13.8712469'},{lon:'100.2536774',lat:'13.866080299999998'}];
AddRaidPolygon(raid_mapLayer, V09Bangkonk,"#A61B4A","09 - Bangkonk");
var V10MueangSamutPrakan = [{lon:'100.3065491',lat:'13.6219641'},{lon:'100.353241',lat:'13.4590796'},{lon:'100.6155396',lat:'13.5058201'},{lon:'100.8049736',lat:'13.496538200000002'},{lon:'100.9870147',lat:'13.6626677'},{lon:'100.9025573',lat:'13.690689200000001'},{lon:'100.3065491',lat:'13.6219641'}];
AddRaidPolygon(raid_mapLayer, V10MueangSamutPrakan,"#7C3592","10 - Mueang Samut Prakan");
var V11ChonBuri_1 = [{lon:'100.8049736',lat:'13.496538200000002'},{lon:'101.6591743',lat:'12.771687200000002'},{lon:'101.8459421',lat:'13.1250215'},{lon:'101.6426903',lat:'13.576652100000004'},{lon:'101.20872370000001',lat:'13.862152300000002'},{lon:'100.8049736',lat:'13.496538200000002'}];
AddRaidPolygon(raid_mapLayer, V11ChonBuri_1,"#A61B4A","11 - Chon Buri_1");
var V12ChonBuri_2 = [{lon:'101.6619873',lat:'12.7689464'},{lon:'100.8078003',lat:'13.493802000000002'},{lon:'100.7336426',lat:'13.1115801'},{lon:'100.8078003',lat:'12.5920935'},{lon:'101.4395142',lat:'12.5786906'},{lon:'101.6619873',lat:'12.7689464'}];
AddRaidPolygon(raid_mapLayer, V12ChonBuri_2,"#7C3592","12 - Chon Buri_2");
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);});
}