// ==UserScript==
// @name WME Counties District_of_Columbia Census 2014
// @namespace https://greasyfork.org/en/users/5920-rickzabel
// @description Creates polygons for MapRaid groups in a WME "District_of_Columbia 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 2015 rickzabel based off work by 2014 davielde
// ==/UserScript==
//---------------------------------------------------------------------------------------
//generated by rickzabel's overlay generator
//special thanks to t0cableguy for helping with the census data
//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 = groupNumber;
var groupName = groupNumber;
var style = {
strokeColor: "Pink",
strokeOpacity: .8,
strokeWidth: 3,
fillColor: groupColor,
fillOpacity: 0.00,
label: raidGroupLabel,
labelOutlineColor: "Black",
labelOutlineWidth: 3,
fontSize: 14,
fontColor: "Pink",
fontOpacity: .85,
fontWeight: "bold"
};
var attributes = {
name: groupName,
number: groupNumber,
holes: "false"
};
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 generateholes(mro_Map, raid_mapLayer, UntitledPolygon){
var mro_mapLayers = mro_Map.getLayersBy("uniqueName","__District_of_Columbia");
var raid_mapLayerLength = raid_mapLayer.features.length;
var style = raid_mapLayer.features[raid_mapLayerLength-2].style;
var attributes = raid_mapLayer.features[raid_mapLayerLength-2].attributes;
//console.dir(style);
//console.dir(attributes);
var newFeature = Subtract(raid_mapLayer.features[raid_mapLayerLength-2], raid_mapLayer.features[1]);
//console.dir(raid_mapLayer);
raid_mapLayer.addFeatures([newFeature]);
raid_mapLayer.features[raid_mapLayerLength-1].destroy();
raid_mapLayer.features[raid_mapLayerLength-2].destroy();
//console.dir(mro_mapLayers);
var mro_mapLayersFeaturesLength = mro_mapLayers[0].features.length;
mro_mapLayers[0].features[mro_mapLayersFeaturesLength-1].style = style;
mro_mapLayers[0].features[mro_mapLayersFeaturesLength-1].attributes = attributes;
mro_mapLayers[0].features[mro_mapLayersFeaturesLength-1].attributes.holes = "true";
//raid_mapLayer.features[1].style = {label: "Updated label"};
mro_mapLayers[0].redraw();
//console.dir(raid_mapLayer);
}
function Subtract(bigFeature, smallFeature) {
var newPolygon = new OpenLayers.Geometry.Polygon(bigFeature.geometry.components);
var newFeature = new OpenLayers.Feature.Vector(newPolygon);
newPolygon.addComponent(smallFeature.geometry.components[0]);
return newFeature;
}
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 = 'County - ' + raid_mapLayer.features[i].attributes.number + ' - ' + res2;
} else {
//var raidLocationLabel = 'County - ' + raid_mapLayer.features[i].attributes.number + ' - ' + $('#topbar-container > div > div.location-info-region > div').text();
var raidLocationLabel = 'County - ' + 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","__District_of_Columbia");
var raid_mapLayer = new mro_OL.Layer.Vector("District_of_Columbia Counties", {
displayInLayerSwitcher: true,
uniqueName: "__District_of_Columbia"
});
I18n.translations.en.layers.name["__District_of_Columbia"] = "District_of_Columbia Counties";
mro_Map.addLayer(raid_mapLayer);
raid_mapLayer.setVisibility(true);
var VDistrictofColumbia0 = [{lon:' -77.119759',lat:'38.934343'},{lon:'-77.1179',lat:'38.932411'},{lon:'-77.116816261811707',lat:'38.929493243339202'},{lon:'-77.1166',lat:'38.928911'},{lon:'-77.1134',lat:'38.925211'},{lon:'-77.107360506400894',lat:'38.920022139302198'},{lon:'-77.1063',lat:'38.919111'},{lon:'-77.105002725079999',lat:'38.916337515688397'},{lon:'-77.1034',lat:'38.912911'},{lon:'-77.1012',lat:'38.911111'},{lon:'-77.1010155931084',lat:'38.910983144555203'},{lon:'-77.100396988651696',lat:'38.9105542454652'},{lon:'-77.0937',lat:'38.905911'},{lon:'-77.0902',lat:'38.904211'},{lon:'-77.082839211732306',lat:'38.902094773373101'},{lon:'-77.0822',lat:'38.901911'},{lon:'-77.079297390379907',lat:'38.9016231616772'},{lon:'-77.078878018529593',lat:'38.901581574517401'},{lon:'-77.0783563148089',lat:'38.901529839581102'},{lon:'-77.077836496622695',lat:'38.9014782916244'},{lon:'-77.071054889157196',lat:'38.900805791090697'},{lon:'-77.070621701792803',lat:'38.900762833910498'},{lon:'-77.070099',lat:'38.900711'},{lon:'-77.069371196832606',lat:'38.900366251131203'},{lon:'-77.068199',lat:'38.899811'},{lon:'-77.067299',lat:'38.899211'},{lon:'-77.064657944525507',lat:'38.891843845255501'},{lon:'-77.063499',lat:'38.888611'},{lon:'-77.058254',lat:'38.880069'},{lon:'-77.055199',lat:'38.880012'},{lon:'-77.054099',lat:'38.879112'},{lon:'-77.051099',lat:'38.875212'},{lon:'-77.051299',lat:'38.873212'},{lon:'-77.049099',lat:'38.870712'},{lon:'-77.046299',lat:'38.871312'},{lon:'-77.046004192307706',lat:'38.8720279615384'},{lon:'-77.045599',lat:'38.873012'},{lon:'-77.046599',lat:'38.874912'},{lon:'-77.045399',lat:'38.875212'},{lon:'-77.043454092682893',lat:'38.874100624390202'},{lon:'-77.043299',lat:'38.874012'},{lon:'-77.041589912408796',lat:'38.872239612868299'},{lon:'-77.040599',lat:'38.871212'},{lon:'-77.039099',lat:'38.868112'},{lon:'-77.038899',lat:'38.865812'},{lon:'-77.039299',lat:'38.864312'},{lon:'-77.034004',lat:'38.857142'},{lon:'-77.031831738380106',lat:'38.850896512341599'},{lon:'-77.031698',lat:'38.850512'},{lon:'-77.034541',lat:'38.840473'},{lon:'-77.038549',lat:'38.839262'},{lon:'-77.041699',lat:'38.840212'},{lon:'-77.044199',lat:'38.840212'},{lon:'-77.044489288951794',lat:'38.839595135977298'},{lon:'-77.044999',lat:'38.838512'},{lon:'-77.044899',lat:'38.834712'},{lon:'-77.043499',lat:'38.833212'},{lon:'-77.042599',lat:'38.833812'},{lon:'-77.041199',lat:'38.833712'},{lon:'-77.039199',lat:'38.832212'},{lon:'-77.038098',lat:'38.828612'},{lon:'-77.039098',lat:'38.821413'},{lon:'-77.038788344509499',lat:'38.819616998155098'},{lon:'-77.038098',lat:'38.815613'},{lon:'-77.037356',lat:'38.814187'},{lon:'-77.037446963170694',lat:'38.8133980626165'},{lon:'-77.037999808574',lat:'38.808603150538801'},{lon:'-77.038195752156',lat:'38.806903702117999'},{lon:'-77.038800581262507',lat:'38.801657927494098'},{lon:'-77.038898',lat:'38.800813'},{lon:'-77.038904082038201',lat:'38.800296702537103'},{lon:'-77.038929172245602',lat:'38.798166822709703'},{lon:'-77.038969617554301',lat:'38.794733465390003'},{lon:'-77.038992785434104',lat:'38.792766769814001'},{lon:'-77.039006',lat:'38.791645'},{lon:'-77.037579715256499',lat:'38.792777714848'},{lon:'-77.024423651667504',lat:'38.803225887021597'},{lon:'-77.006821877075296',lat:'38.8172047166507'},{lon:'-77.001491820919298',lat:'38.821437695918'},{lon:'-77.001481076298305',lat:'38.821446228991'},{lon:'-77.001397',lat:'38.821513'},{lon:'-76.999997',lat:'38.821913'},{lon:'-76.999130853194202',lat:'38.822660496558399'},{lon:'-76.998458490566094',lat:'38.823240754716998'},{lon:'-76.996189772854393',lat:'38.825198689180503'},{lon:'-76.992939796838002',lat:'38.828003463002801'},{lon:'-76.992697',lat:'38.828213'},{lon:'-76.991343739779794',lat:'38.829197086731398'},{lon:'-76.989040541131402',lat:'38.830871965809003'},{lon:'-76.987330649544404',lat:'38.8321153937896'},{lon:'-76.984969314303896',lat:'38.833832549620901'},{lon:'-76.982271489101095',lat:'38.835794399933199'},{lon:'-76.979497',lat:'38.837812'},{lon:'-76.972843853797698',lat:'38.843149782504099'},{lon:'-76.972326515878294',lat:'38.843564839863603'},{lon:'-76.970851731409496',lat:'38.844748051308997'},{lon:'-76.970809393601897',lat:'38.844782018698503'},{lon:'-76.966570510714604',lat:'38.848182851060301'},{lon:'-76.965438274117801',lat:'38.8490912382373'},{lon:'-76.963472206273096',lat:'38.850668603625699'},{lon:'-76.961941486243404',lat:'38.851896691863097'},{lon:'-76.958148964388798',lat:'38.854939411230298'},{lon:'-76.958140102774607',lat:'38.854946520854497'},{lon:'-76.953696',lat:'38.858512'},{lon:'-76.949860966442898',lat:'38.861196523489902'},{lon:'-76.949696',lat:'38.861312'},{lon:'-76.946746183955099',lat:'38.863621777656299'},{lon:'-76.946701967384399',lat:'38.8636564003058'},{lon:'-76.943641272331604',lat:'38.866052998920097'},{lon:'-76.939490143742304',lat:'38.869303433495602'},{lon:'-76.935944196395397',lat:'38.872079996449799'},{lon:'-76.934971325738701',lat:'38.872841777818898'},{lon:'-76.933804814136295',lat:'38.873755184754799'},{lon:'-76.933718878799695',lat:'38.873822474211899'},{lon:'-76.9298866240579',lat:'38.876823222814899'},{lon:'-76.924034950179802',lat:'38.881405225682002'},{lon:'-76.923972437651798',lat:'38.8814541745108'},{lon:'-76.921584694546695',lat:'38.8833238353944'},{lon:'-76.920825111103696',lat:'38.883918607691399'},{lon:'-76.920195',lat:'38.884412'},{lon:'-76.919295',lat:'38.885112'},{lon:'-76.918550521543906',lat:'38.885690065624701'},{lon:'-76.918535662710696',lat:'38.885701603071702'},{lon:'-76.913303391762398',lat:'38.889764307572698'},{lon:'-76.913262575757599',lat:'38.889796'},{lon:'-76.912378388448403',lat:'38.890482545440101'},{lon:'-76.910795',lat:'38.891712'},{lon:'-76.909395',lat:'38.892812'},{lon:'-76.910850679128799',lat:'38.893973043012402'},{lon:'-76.910955802208093',lat:'38.894056888699403'},{lon:'-76.912298639399395',lat:'38.895127929498798'},{lon:'-76.912421224812405',lat:'38.895225703063304'},{lon:'-76.912871836033901',lat:'38.895585108511703'},{lon:'-76.9199019174646',lat:'38.901192269293297'},{lon:'-76.923451063194094',lat:'38.904023051687297'},{lon:'-76.923529268146595',lat:'38.904085427599597'},{lon:'-76.927557561849397',lat:'38.907298376224702'},{lon:'-76.931251468051201',lat:'38.910244618908997'},{lon:'-76.931565014869506',lat:'38.910494702416599'},{lon:'-76.931791668782907',lat:'38.910675480540903'},{lon:'-76.935096',lat:'38.913311'},{lon:'-76.941920456206901',lat:'38.918586026615301'},{lon:'-76.941921067989597',lat:'38.918586499498403'},{lon:'-76.943957421306905',lat:'38.920160517650402'},{lon:'-76.957531362067499',lat:'38.930652620847297'},{lon:'-76.957704907252193',lat:'38.930786764204797'},{lon:'-76.957718618064007',lat:'38.930797362103803'},{lon:'-76.958748660684705',lat:'38.931593543084901'},{lon:'-76.961374166883601',lat:'38.933622952412001'},{lon:'-76.963430253918403',lat:'38.9352122239235'},{lon:'-76.963435789814099',lat:'38.935216502945401'},{lon:'-76.966831323513205',lat:'38.937841112158601'},{lon:'-76.968158917514103',lat:'38.938867288234199'},{lon:'-76.973746208817303',lat:'38.943186036781803'},{lon:'-76.973887698849794',lat:'38.943295402812502'},{lon:'-76.977826303142507',lat:'38.946339783469597'},{lon:'-76.978434328903006',lat:'38.946809762611103'},{lon:'-76.985936949582396',lat:'38.952608982734901'},{lon:'-76.987925151061006',lat:'38.954145781477202'},{lon:'-76.989517122313103',lat:'38.955376310397199'},{lon:'-76.991892520544198',lat:'38.957212396454601'},{lon:'-76.997364490213499',lat:'38.961442006077498'},{lon:'-76.997492710321396',lat:'38.961541114997097'},{lon:'-76.999124025830696',lat:'38.962802055425001'},{lon:'-77.001649914165299',lat:'38.964754464201398'},{lon:'-77.002498',lat:'38.96541'},{lon:'-77.002589220168701',lat:'38.9654839197919'},{lon:'-77.002601759533803',lat:'38.965494081001602'},{lon:'-77.007774574197001',lat:'38.969685844607902'},{lon:'-77.008298',lat:'38.97011'},{lon:'-77.008589274640102',lat:'38.9703377238095'},{lon:'-77.011056734099299',lat:'38.972266828477601'},{lon:'-77.013798',lat:'38.97441'},{lon:'-77.015598',lat:'38.97591'},{lon:'-77.0173231309697',lat:'38.977226703025003'},{lon:'-77.018654553432199',lat:'38.978242908759398'},{lon:'-77.018706497583295',lat:'38.978282555036799'},{lon:'-77.020536715098601',lat:'38.979679465173596'},{lon:'-77.026590704025907',lat:'38.984300161036103'},{lon:'-77.026634552895203',lat:'38.984333628604602'},{lon:'-77.026696218486805',lat:'38.984380694753398'},{lon:'-77.031234921812697',lat:'38.987844851680599'},{lon:'-77.033707359689004',lat:'38.989731935321302'},{lon:'-77.036299',lat:'38.99171'},{lon:'-77.036461350189299',lat:'38.991827444817801'},{lon:'-77.036698115899',lat:'38.991998722139698'},{lon:'-77.040999',lat:'38.99511'},{lon:'-77.042388998663696',lat:'38.994064888222802'},{lon:'-77.046541251074402',lat:'38.990942893929002'},{lon:'-77.051662504310301',lat:'38.987092327586197'},{lon:'-77.052220061432294',lat:'38.986673111705002'},{lon:'-77.052937499620796',lat:'38.986133684495599'},{lon:'-77.054299',lat:'38.98511'},{lon:'-77.062564652888398',lat:'38.9787553946774'},{lon:'-77.066690519618703',lat:'38.9755834426199'},{lon:'-77.068951003066402',lat:'38.973845590771802'},{lon:'-77.069563580871105',lat:'38.973374643076397'},{lon:'-77.071640984008695',lat:'38.971777542736803'},{lon:'-77.077436698207094',lat:'38.967321817727402'},{lon:'-77.077441665345106',lat:'38.967317999008898'},{lon:'-77.0804181742635',lat:'38.965029669257902'},{lon:'-77.0822402534113',lat:'38.963628861117598'},{lon:'-77.082706082725693',lat:'38.9632707331536'},{lon:'-77.083839171090702',lat:'38.9623996187416'},{lon:'-77.085780121691698',lat:'38.9609074226397'},{lon:'-77.085812268288393',lat:'38.9608827084474'},{lon:'-77.091355285244902',lat:'38.956621256202702'},{lon:'-77.091399387458097',lat:'38.956587350573898'},{lon:'-77.0915',lat:'38.95651'},{lon:'-77.093866059016406',lat:'38.954555429508197'},{lon:'-77.098089871993395',lat:'38.951066192701099'},{lon:'-77.100526969660194',lat:'38.949052938106803'},{lon:'-77.1007',lat:'38.94891'},{lon:'-77.101277750604197',lat:'38.948529900918302'},{lon:'-77.1045',lat:'38.94641'},{lon:'-77.112478301097397',lat:'38.940100663913597'},{lon:'-77.112531800026701',lat:'38.940058356319398'},{lon:'-77.119759',lat:'38.934343'}];
AddRaidPolygon(raid_mapLayer, VDistrictofColumbia0,"#"," DistrictofColumbia");
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);});
}