// ==UserScript==
// @name WME Ohio Mini-Mapraid, May-June 2015 Overlay
// @namespace https://gf.qytechs.cn/users/5252
// @description Creates polygons for MapRaid groups in a WME "Ohio Mini-Mapraid, May-June 2015 Groups" layer
// @include https://www.waze.com/editor/*
// @include https://www.waze.com/*/editor/*
// @include https://editor-beta.waze.com/*
// @version 1.9
// @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","__OhioMini-Mapraid,May-June2015");
var raid_mapLayer = new mro_OL.Layer.Vector("Ohio Mini-Mapraid, May-June 2015", {
displayInLayerSwitcher: true,
uniqueName: "__OhioMini-Mapraid,May-June2015"
});
I18n.translations.en.layers.name["__OhioMini-Mapraid,May-June2015"] = "Ohio Mini-Mapraid, May-June 2015";
mro_Map.addLayer(raid_mapLayer);
raid_mapLayer.setVisibility(true);
var VArea1W = [{lon:'-81.845061',lat:'40.448034'},{lon:'-81.527181',lat:'40.44699'},{lon:'-81.53266400000001',lat:'40.645851'},{lon:'-81.850539',lat:'40.642733'},{lon:'-81.845061',lat:'40.448034'}];
AddRaidPolygon(raid_mapLayer, VArea1W,"#4186F0","Area 1W");
var VArea1E = [{lon:'-81.221517',lat:'40.650167'},{lon:'-81.533927',lat:'40.649128'},{lon:'-81.528449',lat:'40.45026699999999'},{lon:'-81.213979',lat:'40.451831'},{lon:'-81.221517',lat:'40.650167'}];
AddRaidPolygon(raid_mapLayer, VArea1E,"#DB4436","Area 1E");
var VArea2W = [{lon:'-81.84556',lat:'40.448167000000005'},{lon:'-81.838712',lat:'40.25133'},{lon:'-81.522882',lat:'40.251329'},{lon:'-81.527679',lat:'40.447123'},{lon:'-81.84556',lat:'40.448167000000005'}];
AddRaidPolygon(raid_mapLayer, VArea2W,"#DB4436","Area 2W");
var VArea2E = [{lon:'-81.212606',lat:'40.45157'},{lon:'-81.527744',lat:'40.450722000000006'},{lon:'-81.522951',lat:'40.254928'},{lon:'-81.20569900000001',lat:'40.252945'},{lon:'-81.212606',lat:'40.45157'}];
AddRaidPolygon(raid_mapLayer, VArea2E,"#4186F0","Area 2E");
var VArea3W = [{lon:'-81.523377',lat:'40.251573'},{lon:'-81.839209',lat:'40.251574'},{lon:'-81.837131',lat:'40.056654'},{lon:'-81.519093',lat:'40.056519'},{lon:'-81.523377',lat:'40.251573'}];
AddRaidPolygon(raid_mapLayer, VArea3W,"#4186F0","Area 3W");
var VArea3E = [{lon:'-81.20569900000001',lat:'40.252945'},{lon:'-81.522925',lat:'40.25399000000001'},{lon:'-81.518646',lat:'40.058936'},{lon:'-81.199214',lat:'40.057997'},{lon:'-81.20569900000001',lat:'40.252945'}];
AddRaidPolygon(raid_mapLayer, VArea3E,"#DB4436","Area 3E");
var VArea4W = [{lon:'-81.5203606',lat:'40.056581'},{lon:'-81.8381606',lat:'40.056385'},{lon:'-81.8331076',lat:'39.861441'},{lon:'-81.5165906',lat:'39.861428'},{lon:'-81.5203606',lat:'40.056581'}];
AddRaidPolygon(raid_mapLayer, VArea4W,"#DB4436","Area 4W");
var VArea4E = [{lon:'-81.199214',lat:'40.057997'},{lon:'-81.519517',lat:'40.059112000000006'},{lon:'-81.515904',lat:'39.861428'},{lon:'-81.202303',lat:'39.864221'},{lon:'-81.199214',lat:'40.057997'}];
AddRaidPolygon(raid_mapLayer, VArea4E,"#4186F0","Area 4E");
var VArea5W = [{lon:'-81.832421',lat:'39.861441000000006'},{lon:'-81.831738',lat:'39.667114'},{lon:'-81.515724',lat:'39.666863'},{lon:'-81.515904',lat:'39.861428'},{lon:'-81.832421',lat:'39.861441000000006'}];
AddRaidPolygon(raid_mapLayer, VArea5W,"#4186F0","Area 5W");
var VArea5E = [{lon:'-81.515904',lat:'39.861428'},{lon:'-81.515358',lat:'39.668025'},{lon:'-81.20053400000002',lat:'39.66756'},{lon:'-81.203175',lat:'39.865189'},{lon:'-81.515904',lat:'39.861428'}];
AddRaidPolygon(raid_mapLayer, VArea5E,"#DB4436","Area 5E");
var VArea6W = [{lon:'-81.515358',lat:'39.668025'},{lon:'-81.831377',lat:'39.668274999999994'},{lon:'-81.828296',lat:'39.473397000000006'},{lon:'-81.515356',lat:'39.472346'},{lon:'-81.515358',lat:'39.668025'}];
AddRaidPolygon(raid_mapLayer, VArea6W,"#DB4436","Area 6W");
var VArea6E = [{lon:'-81.20053400000002',lat:'39.66756'},{lon:'-81.515358',lat:'39.668025'},{lon:'-81.515356',lat:'39.472346'},{lon:'-81.200004',lat:'39.474174'},{lon:'-81.20053400000002',lat:'39.66756'}];
AddRaidPolygon(raid_mapLayer, VArea6E,"#4186F0","Area 6E");
var VArea7 = [{lon:'-81.515356',lat:'39.472346'},{lon:'-81.828296',lat:'39.473397000000006'},{lon:'-81.825485',lat:'39.308268999999996'},{lon:'-81.56868',lat:'39.307205999999994'},{lon:'-81.553929',lat:'39.350758'},{lon:'-81.504822',lat:'39.371464'},{lon:'-81.481485',lat:'39.394816'},{lon:'-81.44577',lat:'39.412855'},{lon:'-81.41143800000002',lat:'39.390571'},{lon:'-81.360626',lat:'39.409672'},{lon:'-81.35788',lat:'39.473305'},{lon:'-81.515356',lat:'39.472346'}];
AddRaidPolygon(raid_mapLayer, VArea7,"#7C3592","Area 7");
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);});
}