// ==UserScript==
// @name WME MapRaid Colombia Andina 2019
// @namespace https://greasyfork.org/es/users/33476-kahl-colimon
// @description Delimita zona de edición MapRaid Colombia Andina
// @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @version 4.1.
// @grant none
// @author Kahl Colimon
// @copyright 2019 Kahlcolimon, based on work by 2015 rickzabel, based on work by 2014 davielde
// ==/UserScript==
setTimeout(initMapRaidOverlay, 1000);
var mapLayer;
function convertPoints(list) {
return list.map(function(point) {
return new OL.Geometry.Point(point[0], point[1]).transform(new OL.Projection("EPSG:4326"), Waze.map.getProjectionObject());
});
}
function addRaidPolygon(raidLayer, groupPoints, color, name) {
var style = {
strokeColor: color,
strokeOpacity: 0.8,
strokeWidth: 3,
fillColor: color,
fillOpacity: 0.4,
label: name,
labelOutlineColor: "Black",
labelOutlineWidth: 3,
fontSize: 14,
fontColor: color,
fontOpacity: 0.85,
fontWeight: "bold"
};
var ring = new OL.Geometry.LinearRing(convertPoints(groupPoints));
var polygon = new OL.Geometry.Polygon([ ring ]);
var feature = new OL.Feature.Vector(polygon, { name: name }, style);
raidLayer.addFeatures([ feature ]);
}
function createLayerToggler(parentGroup, checked, name, toggleCallback) {
var normalizedName = name.toLowerCase().replace(/\s/g, '');
var group = document.createElement('li');
var groupToggler = document.createElement('div');
groupToggler.className = 'controls-container toggler';
var groupSwitch = document.createElement('input');
groupSwitch.id = 'layer-switcher-group_' + normalizedName;
groupSwitch.className = 'layer-switcher-group_' + normalizedName + ' toggle';
groupSwitch.type = 'checkbox';
groupSwitch.checked = checked;
groupSwitch.addEventListener('click', function() { toggleCallback(groupSwitch.checked); });
groupToggler.appendChild(groupSwitch);
var groupLabel = document.createElement('label');
groupLabel.htmlFor = groupSwitch.id;
groupLabel.style.display = 'block';
var groupLabelText = document.createElement('div');
groupLabelText.className = 'label-text';
groupLabelText.style.textOverflow = 'ellipsis';
groupLabelText.style.overflowX = 'hidden';
groupLabelText.appendChild(document.createTextNode(name));
groupLabel.appendChild(groupLabelText);
groupToggler.appendChild(groupLabel);
group.appendChild(groupToggler);
if (parentGroup !== null) {
parentGroup.querySelector('input.toggle').addEventListener('click', function(e) {
groupSwitch.disabled = !e.target.checked;
if (toggleCallback) {
toggleCallback(groupSwitch.checked && e.target.checked);
}
});
parentGroup.querySelector('ul.children').appendChild(group);
} else {
group.className = 'group';
groupToggler.classList.add('main');
var groupChildren = document.createElement('ul');
groupChildren.className = 'children';
group.appendChild(groupChildren);
document.querySelector('.list-unstyled.togglers').appendChild(group);
}
return group;
}
function displayCurrentRaidLocation() {
var raidMapCenter = Waze.map.getCenter();
var raidCenterPoint = new OL.Geometry.Point(raidMapCenter.lon, raidMapCenter.lat);
var locationDiv = document.querySelector('#topbar-container > div > div > div.location-info-region > div');
var mapRaidDiv = locationDiv.querySelector('strong');
if (mapRaidDiv === null) {
mapRaidDiv = document.createElement('strong');
mapRaidDiv.style.marginLeft = '5px';
locationDiv.appendChild(mapRaidDiv);
}
for (i = 0; i < mapLayer.features.length; i++) {
if (mapLayer.features[i].geometry.components[0].containsPoint(raidCenterPoint)) {
mapRaidDiv.textContent = '[' + mapLayer.features[i].attributes.name + ']';
return;
}
}
mapRaidDiv.textContent = '';
}
function initMapRaidOverlay() {
if (typeof Waze === 'undefined' || typeof Waze.map === 'undefined' || !document.querySelector('#topbar-container > div > div > div.location-info-region > div') || !document.getElementById('layer-switcher-group_display')) {
setTimeout(initMapRaidOverlay, 800);
return;
}
if (localStorage.MapRaidBogotaVisible === undefined) {
localStorage.MapRaidBogotaVisible = true;
}
createLayerToggler(document.getElementById('layer-switcher-group_display').parentNode.parentNode, localStorage.MapRaidChinaVisible == "true", 'MapRaid Colombia Andina', function(checked) {
localStorage.MapRaidBogotaVisible = checked;
mapLayer.setVisibility(checked);
});
mapLayer = new OL.Layer.Vector("Bogota MapRaid Regions", {
uniqueName: "__BogotaMapRaid"
});
addRaidPolygon(mapLayer, [
[-76.41969429711122,8.885675499521398],[-77.04511004105996,8.570499504562001],[-76.98872517826965,8.077847398541024],[-77.1363358021199,7.833713676060964],[-77.14982319607049,7.735753056914883],[-76.7511610143548,7.1218127245489615],[-77.02307263544856,6.802832661846012],[-76.811813822153,6.119859971761529],[-76.1606827504338,5.934753469408781],[-76.2925186879338,5.25138107173869],[-76.06581670288926,5.015234435801119],[-76.04215925111782,4.938280930829813],[-75.98448102846157,4.8534475472371374],[-75.917040461515,4.849290784307223],[-76.14003754911778,3.0757532092776607],[-75.87691221556804,2.607953785050766],[-76.63771543822429,2.1386924439034014],[-76.64870176634929,1.8477312134698454],[-76.41524229369304,1.5567223087069986],[-76.0697750484992,1.4927768448210779],[-75.34691888342036,2.049087221248203],[-74.53551038207178,3.264842989530088],[-74.45311292113428,3.5883598116082496],[-74.15363731890818,3.9514522819913616],[-73.73590216850937,4.183629543132998],[-73.11230070659121,4.19286996294349],[-73.0215361587355,4.66762991000377],[-72.88944553958663,5.069226760274201],[-72.13662738137526,5.5689925231256305],[-71.94643219654432,7.012616510395616],[-72.29095939050586,8.284078448568588],[-72.79281283123663,9.363030207331402],[-73.44847486571734,9.291330627844179],[-73.71901319579547,8.899440495611987],[-74.03086018101527,7.539537349934082],[-74.77117396311007,8.376577355531882],[-75.42782691792473,7.950948752345284],[-75.89767850535281,7.431978902684552],[-76.4026764423241,7.408604269917467],[-76.12974752812295,8.431833901849211],[-76.16819967656045,8.684762337999194],[-76.41969429711122,8.885675499521398]
], '#A61B4A', 'Polígono Zona Andina');
Waze.map.addLayer(mapLayer);
mapLayer.setVisibility(localStorage.MapRaidBogotaVisible == "true");
displayCurrentRaidLocation();
Waze.map.events.register("moveend", null, displayCurrentRaidLocation);
Waze.map.events.register("zoomend", null, displayCurrentRaidLocation);
}