// ==UserScript==
// @name WME Draw Borders France
// @namespace Sebiseba
// @version 2024.07.10.002
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAOxAAADsQBlSsOGwAABCJJREFUWIWtl09oHFUcx7/fN7vJ1jSlrUp2c2oCPRjddGcGoV5sqBSk0IKCh4JF0RwC2grVIP6B1pOIIJWIlygIWkEsUvVYWrGnXmYmzcqqKK0HkdWW7aFKd5PZ9/WQ3WWzyW4nyf5gYd7v/d77fub33vzePiKheZ53GsCJRnMuDMN3ko7tZU6SINd1jxtjPiR5X+M3lc1mr5fL5cWtApgkQSQPreN70ff93FYBEmUgm80WSB7oANgj6ZVcLrc/l8vFQ0NDv1cqlfpGAVJJgkjebm9LugbgNwBHSB4GcHjHjh0V3/e/qtfr3xhjTgI4BOCGpBNRFF3qOve9xPP5/Hg6nb4GYIjkrKQoDMMrAOKJiYndmUzmGIDnAfgk18wn6Q7J8SAIbm0GgJ7nXSY5Za09F0XRs90CJycnH3Ec5zmSp0iu2lvW2qNRFH2/3riem9B13ZdITkkq12q1k71iFxcXf4qiaBbAr+1+SarX6ze6jesKkM/nx0m+K0nW2plSqVTpBdAmeELSnTbXv3Ec/7VRAKbT6U9Jbpf05cLCwrdJxAEgiqJLJMettUcl/UhyOJPJvN8tft094Lruy8aYOUnlarX6cNK377RCobDXGLMIYFDSVBRFVzpj1tSBfD4/7jjOeQBpa+3xYrG4sBlxACiXy5XR0VFD8iCA/bt27Zq/efPmqlrRWgLP8057nndrYGDgl82kvpvdvXv3PUk/k3xo27Ztr3f2G2Cl1pM8Q/J+AOlG3+WtigNAqVRakjQjyUp6s1Ao7F0D0KXWT/UDAAAaa/8ZyYwxZt513SO+7z/QApC05jtdz7cVq1ars42qeMAY852k667rPmEAII7js5Jam03SQhzHZ/sJkEqlRgFsb7ZJDpOcMwBQLBZvA3gVAKy1V8MwfLTh65s5jjO2zlkx1voKrLUjDbI/AMT9FAeApaWlBUnqcF9sHcckswAg6e9+iwPA4ODgGZKUVG2Kx3E83Q4wAgDGmHK/xX3fnwbwgqT/SD4WBEGx2dcCkDRCEtbavmbA8zxf0tyKhGbCMCy297f2QDMD/VyCiYmJ3QDOk8xI+jiKoi86Y9YAGGP6BWAymcw5knustVdrtdqpdYOaD5KyALC8vNwXANd1T5N8UtI/cRw/UyqVlnoBkOSDkjQwMLBlgEKhcJjk25JiAMeKxeKf3WJTAJDP58ewcghVgiBY3qRuyvO8xyXtJDnf+F/4VhAEPQ81ep53EMAFksOSRPKDIAhe24jyvn37djqO8wPJQpv7QhAETwPoLD6rqQF8RHIYWFkHSadc1x0HkDgTJMc6xGGtXbyXeBNgrGMyknwqqXgvqCRxKQAXARxpOhpH5gw2kAFrrWuMeaPdJ+liIoA4jqdTqdQnaLtKhWHY9SrVxb72PK+Gtut7FEWfJxn4P1GVx29d/9ycAAAAAElFTkSuQmCC
// @description Affiche les limites des villes et départements français
// @include https://www.waze.com/editor*
// @include https://www.waze.com/*/editor*
// @include https://beta.waze.com/*
// @exclude https://www.waze.com/user/*editor/*
// @exclude https://www.waze.com/*/user/*editor/*
// @author Sebiseba & Electrochock1974
// @copyright Sebiseba 2017-2024 (Inspired by Draw Border - ©giovanni-cortinovis)
// @grant Window
// @grant GM_xmlhttpRequest
// @grant GM_addElement
// @connect wmebookmarks.free.fr
// @connect radars.securite-routiere.gouv.fr
// @connect api.wazefrance.com
// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// ==/UserScript==
/* global W, WazeWrap, $, I18n, OpenLayers, require */
/* jshint -W097 */
'use strict';
// **********************************
// ** DOWNLOAD HELPER BY DUMMYD2 **
// **********************************
/******** AUTO INJECTED PART ***************/
function DBDLHelperInjected() {
window.DBDLHelper = {
jobs: [], _waitForData: function (id) {
if (this.jobs.length <= id) {
this.jobs[id].callback({ url: null, data: null, callback: this.jobs[id].callback, status: "error", error: "Request not found" });
} else {
if (this.jobs[id].status == "success" || this.jobs[id].status == "error") {
this.jobs[id].callback(this.jobs[id]);
} else {
if (this.jobs[id].status == "downloading" && this.jobs[id].progressCallback) {
this.jobs[id].progressCallback(this.jobs[id]);
}
var _this = this;
window.setTimeout(function () {
_this._waitForData(id);
}, 500);
}
}
}, add: function (url, method, datas, callback, progressCallback) {
this.jobs.push({ method: method, url: url, datas: datas, data: null, callback: callback, progressCallback: progressCallback, status: "added", progression: 0, error: "" });
var _this = this;
window.setTimeout(function () {
_this._waitForData(_this.jobs.length - 1);
}, 500);
}
};
}
let DBDLHelperInjectedScript = GM_addElement('script', {
textContent: "" + DBDLHelperInjected.toString() + " \n" + "DBDLHelperInjected();"
});
if (typeof unsafeWindow === "undefined") {
unsafeWindow = function () {
var dummyElem = document.createElement("p");
dummyElem.setAttribute("onclick", "return window;");
return dummyElem.onclick();
}();
}
/******** SANDBOX PART ***************/
function lookForDLHelperJob() {
for (var i = 0; i < unsafeWindow.DBDLHelper.jobs.length; i++) {
if (unsafeWindow.DBDLHelper.jobs[i].status == "added") {
unsafeWindow.DBDLHelper.jobs[i].status = cloneInto("downloading", unsafeWindow.DBDLHelper.jobs[i]);
var f = function () {
var job = i;
GM_xmlhttpRequest({
method: unsafeWindow.DBDLHelper.jobs[job].method, data: unsafeWindow.DBDLHelper.jobs[job].datas, headers: { "Content-Type": "application/x-www-form-urlencoded" }, synchronous: false, timeout: 10000, url: unsafeWindow.DBDLHelper.jobs[job].url, onerror: function (r) {
unsafeWindow.DBDLHelper.jobs[job].status = cloneInto("error", unsafeWindow.DBDLHelper.jobs[job]);
}, ontimeout: function (r) {
console.debug("Timeout while getting area from server: ", r);
unsafeWindow.DBDLHelper.jobs[job].status = cloneInto("error", unsafeWindow.DBDLHelper.jobs[job]);
}, onload: function (r) {
unsafeWindow.DBDLHelper.jobs[job].status = cloneInto("success", unsafeWindow.DBDLHelper.jobs[job]);
unsafeWindow.DBDLHelper.jobs[job].data = cloneInto(r.responseText, unsafeWindow.DBDLHelper.jobs[job]);
}, onprogress: function (r) {
unsafeWindow.DBDLHelper.jobs[job].progression = cloneInto(r.total == 0 ? 0 : r.loaded / r.total, unsafeWindow.DBDLHelper.jobs[job]);
}
});
}();
}
}
window.setTimeout(lookForDLHelperJob, 2000);
}
window.setTimeout(lookForDLHelperJob);
/*******************/
function run_DBF() {
var DBF_Version = '2024.07.10.002', DBFhandleClass, DBFhandleClass2, CitiesOld = [], StatesOld = [], StatesPROld = [], Cty_Layer = [], Dpt_Layer = [], PR_Layer = [], Cam_Layer = [], Ban_Layer = [], debug = '';
var icon_DrB = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAOxAAADsQBlSsOGwAABCJJREFUWIWtl09oHFUcx7/fN7vJ1jSlrUp2c2oCPRjddGcGoV5sqBSk0IKCh4JF0RwC2grVIP6B1pOIIJWIlygIWkEsUvVYWrGnXmYmzcqqKK0HkdWW7aFKd5PZ9/WQ3WWzyW4nyf5gYd7v/d77fub33vzePiKheZ53GsCJRnMuDMN3ko7tZU6SINd1jxtjPiR5X+M3lc1mr5fL5cWtApgkQSQPreN70ff93FYBEmUgm80WSB7oANgj6ZVcLrc/l8vFQ0NDv1cqlfpGAVJJgkjebm9LugbgNwBHSB4GcHjHjh0V3/e/qtfr3xhjTgI4BOCGpBNRFF3qOve9xPP5/Hg6nb4GYIjkrKQoDMMrAOKJiYndmUzmGIDnAfgk18wn6Q7J8SAIbm0GgJ7nXSY5Za09F0XRs90CJycnH3Ec5zmSp0iu2lvW2qNRFH2/3riem9B13ZdITkkq12q1k71iFxcXf4qiaBbAr+1+SarX6ze6jesKkM/nx0m+K0nW2plSqVTpBdAmeELSnTbXv3Ec/7VRAKbT6U9Jbpf05cLCwrdJxAEgiqJLJMettUcl/UhyOJPJvN8tft094Lruy8aYOUnlarX6cNK377RCobDXGLMIYFDSVBRFVzpj1tSBfD4/7jjOeQBpa+3xYrG4sBlxACiXy5XR0VFD8iCA/bt27Zq/efPmqlrRWgLP8057nndrYGDgl82kvpvdvXv3PUk/k3xo27Ztr3f2G2Cl1pM8Q/J+AOlG3+WtigNAqVRakjQjyUp6s1Ao7F0D0KXWT/UDAAAaa/8ZyYwxZt513SO+7z/QApC05jtdz7cVq1ars42qeMAY852k667rPmEAII7js5Jam03SQhzHZ/sJkEqlRgFsb7ZJDpOcMwBQLBZvA3gVAKy1V8MwfLTh65s5jjO2zlkx1voKrLUjDbI/AMT9FAeApaWlBUnqcF9sHcckswAg6e9+iwPA4ODgGZKUVG2Kx3E83Q4wAgDGmHK/xX3fnwbwgqT/SD4WBEGx2dcCkDRCEtbavmbA8zxf0tyKhGbCMCy297f2QDMD/VyCiYmJ3QDOk8xI+jiKoi86Y9YAGGP6BWAymcw5knustVdrtdqpdYOaD5KyALC8vNwXANd1T5N8UtI/cRw/UyqVlnoBkOSDkjQwMLBlgEKhcJjk25JiAMeKxeKf3WJTAJDP58ewcghVgiBY3qRuyvO8xyXtJDnf+F/4VhAEPQ81ep53EMAFksOSRPKDIAhe24jyvn37djqO8wPJQpv7QhAETwPoLD6rqQF8RHIYWFkHSadc1x0HkDgTJMc6xGGtXbyXeBNgrGMyknwqqXgvqCRxKQAXARxpOhpH5gw2kAFrrWuMeaPdJ+liIoA4jqdTqdQnaLtKhWHY9SrVxb72PK+Gtut7FEWfJxn4P1GVx29d/9ycAAAAAElFTkSuQmCC";
function getId(node) { return document.getElementById(node); }
function getElementsByClassName(classname, node) {
node || (node = document.getElementsByTagName('body')[0]);
for (var a = [], re = new RegExp('\\b' + classname + '\\b'), els = node.getElementsByTagName('*'), i = 0, j = els.length; i < j; i++) { re.test(els[i].className) && a.push(els[i]); }
return a;
}
function isJsonString(str) {
try { JSON.parse(str); }
catch (e) { return false; }
return true;
}
function deltaDate(adresseDate) {
let diffTime = Math.abs(new Date().valueOf() - new Date(adresseDate).valueOf());
let days = diffTime / (24*60*60*1000);
let hours = (days % 1) * 24;
let minutes = (hours % 1) * 60;
[days, hours, minutes] = [Math.floor(days), Math.floor(hours), Math.floor(minutes)]
var delta = days + 'j ' + hours + 'h '+ minutes + 'm';
return delta;
}
function DBF_bootstrap() {
console.log('WME Draw Borders France : ' + DBF_Version + ' starting');
DBFstep1();
}
function addScriptsMenu() {
if (typeof getElementsByClassName('collapsible-GROUP__SCRIPTS', getId('layer-switcher-region')) [0] != 'object') {
if ('undefined' === typeof localStorage.posScriptMenu) { localStorage.setItem('posScriptMenu', '["top"]'); }
var menuParent = getElementsByClassName('togglers', getId('layer-switcher-region')) [0];
var scriptMenu = document.createElement('li');
scriptMenu.className="group";
var scriptMenuContent = document.createElement('div');
scriptMenuContent.className='layer-switcher-toggler-tree-category';
scriptMenuContent.innerHTML='<wz-button id="developScript" color="clear-icon" size="xs"><i class="toggle-category w-icon w-icon-caret-down"></i></wz-button>'+
'<wz-toggle-switch disabled="false" checked id="layer-switcher-group__scripts" class="layer-switcher-group__scripts" tabindex="0" name="" value=""></wz-toggle-switch>'+
'<label class="label-text" for="layer-switcher-group__scripts">Scripts</label>';
scriptMenu.appendChild(scriptMenuContent);
var groupScripts = document.createElement('ul');
groupScripts.className="collapsible-GROUP__SCRIPTS";
scriptMenu.appendChild(groupScripts);
if (JSON.parse(localStorage.posScriptMenu)[0] == 'top') { menuParent.insertBefore(scriptMenu, menuParent.firstChild); }
else { menuParent.appendChild(scriptMenu); }
getId('developScript').addEventListener('click', function(e) {
if (groupScripts.className == 'collapsible-GROUP__SCRIPTS') {
groupScripts.className='collapsible-GROUP__SCRIPTS collapse-layer-switcher-group';
this.innerHTML='<i class="toggle-category w-icon w-icon-caret-down upside-down"></i>';
} else {
groupScripts.className='collapsible-GROUP__SCRIPTS';
this.innerHTML='<i class="toggle-category w-icon w-icon-caret-down"></i>';
}
});
getId('layer-switcher-group__scripts').addEventListener('click', function(e) {
if (groupScripts.className == 'collapsible-GROUP__SCRIPTS') {
groupScripts.className='collapsible-GROUP__SCRIPTS collapse-layer-switcher-group';
getId('developScript').innerHTML='<i class="toggle-category w-icon w-icon-caret-down upside-down"></i>';
} else {
groupScripts.className='collapsible-GROUP__SCRIPTS';
getId('developScript').innerHTML='<i class="toggle-category w-icon w-icon-caret-down"></i>';
}
});
var lng = I18n.locale;
if (lng == 'fr') { var title="Position menu des scripts", top="En haut", bottom="En bas"; }
else if (lng == 'es') { var title="Posición del menú de script", top="En alto", bottom="Abajo"; }
else { var title="Scripts menu position", top="On top", bottom="On bottom"; }
var optionPosMenu=document.createElement('div');
optionPosMenu.className='settings__form-group';
optionPosMenu.innerHTML='<wz-label html-for="">'+title+'</wz-label><span style="padding-right:15px;">'+bottom+' </span><wz-toggle-switch name="posScriptMenu" id="posScriptMenu" checked='+(JSON.parse(localStorage.posScriptMenu)[0] == 'top' ? "true":"false")+' class="alert-settings-visibility-toggle" tabindex="0" value=""> '+top+'<input type="checkbox" name="posScriptMenu" value="" style="display: none; visibility: hidden;"></wz-toggle-switch>';
getElementsByClassName('settings__form', getId('sidepanel-prefs')) [0].appendChild(optionPosMenu);
getId('posScriptMenu').addEventListener('click', function(e) {
menuParent.removeChild(scriptMenu);
if (getId('posScriptMenu').checked == true) {
menuParent.insertBefore(scriptMenu, menuParent.firstChild);
localStorage.setItem('posScriptMenu', JSON.stringify(["top"]));
} else {
menuParent.appendChild(scriptMenu);
localStorage.setItem('posScriptMenu', JSON.stringify(["bottom"]));
}
})
if ('undefined' === typeof localStorage.posScriptMenu || !isJsonString(localStorage.posScriptMenu)) { localStorage.setItem('posScriptMenu', '[]'); }
}
}
function addTooltipToCheckbox(checkboxId, tooltipText) {
var checkbox = document.getElementById(checkboxId);
if (checkbox) {
// Création du conteneur div qui utilisera Flexbox pour aligner le texte et l'icône
var container = document.createElement('div');
container.style.display = 'flex';
container.style.alignItems = 'center';
container.style.justifyContent = 'space-between';
// Assurez-vous que le texte actuel est enveloppé dans un élément, par exemple un span
var textSpan = document.createElement('span');
textSpan.textContent = checkbox.textContent;
checkbox.textContent = ''; // Enlever le texte actuel du checkbox
// Création du tooltip avec l'icône d'information
var tooltipContainer = document.createElement('wz-rich-tooltip');
tooltipContainer.className = "sc-wz-rich-tooltip-h sc-wz-rich-tooltip-s";
tooltipContainer.setAttribute("hide-delay-ms", "200");
var tooltip = document.createElement('wz-tooltip');
tooltip.className = "sc-wz-rich-tooltip sc-wz-rich-tooltip-s";
var tooltipSource = document.createElement('wz-tooltip-source');
tooltipSource.className = "sc-wz-tooltip-source-h sc-wz-tooltip-source-s";
var tooltipTarget = document.createElement('wz-tooltip-target');
tooltipTarget.className = "sc-wz-tooltip-target-h sc-wz-tooltip-target-s";
var infoIcon = document.createElement('i');
infoIcon.className = "w-icon w-icon-info layer-selector-info-icon";
infoIcon.title = tooltipText;
tooltipTarget.appendChild(infoIcon);
tooltipSource.appendChild(tooltipTarget);
tooltip.appendChild(tooltipSource);
tooltipContainer.appendChild(tooltip);
// Ajout du texte et du tooltip au conteneur
container.appendChild(textSpan); // Ajoutez le texte en premier
container.appendChild(tooltipContainer); // Ensuite, ajoutez l'icône d'information
// Ajout du conteneur dans le checkbox
checkbox.appendChild(container);
}
}
function insertScriptHTML() {
var Scss = document.createElement('style');
Scss.type = 'text/css';
var css = '.DBFlegend {float:left; clear:both; margin: 0 8px 10px 0;}'
+'.infoState {float:left; height:24px; border:1px solid #d5d7db; border-radius:12px; font-size:12px; font-weight:600; margin:0 8px 10px; padding-left:11px; padding-top:2px; cursor:pointer;}'
Scss.innerHTML = css;
document.body.appendChild(Scss);
//Create content in CErrors's tab
var DBFnewtab=document.createElement('li');
DBFnewtab.innerHTML="<a href='#sidepanel-DrawBordersFR' data-toggle='tab'><img src="+icon_DrB+" style='height:16px;'></a>"; //<span class='fa fa-globe' title='Draw Borders FR'></span>
DBFhandleClass.appendChild(DBFnewtab);
var DBFcontent='<div style="float:left; margin-left:5px;padding-bottom:10px;"><b><a href="https://greasyfork.org/fr/scripts/8138-wme-draw-borders-france" target="_blank"><u>WME Draw Borders France</u></a></b> v'+ DBF_Version +'</div>'
+'<wz-label html-for="">Infos BAN</wz-label>'
+'<div id="layerBanVisib" class="infoState" style="width:100px;">Calque BAN</div>'
+'<div id="layerHNVisib" class="infoState" style="width:90px;">Calque HN</div>'
+'<div id="zoomBanValue" class="infoState" style="width:80px;"></div>'
+'<div id="loadBanData" class="infoState" style="width:36px; float:right; margin-right:10px;"><i class="fa fa-refresh" aria-hidden="true"></i></div>'
+'<wz-label html-for="">Limites, PR, Radars</wz-label>'
+'<div id="zoomMiscValue" class="infoState" style="width:80px;"></div>'
+'<div id="loadMiscData" class="infoState" style="width:36px; float:right; margin-right:10px;"><i class="fa fa-refresh" aria-hidden="true"></i></div>'
+'<wz-label html-for="" style="margin-top:15px;">Légende</wz-label>'
+'<div class="DBFlegend" style="color:#ff0000; font-size:11px; font-family:Webdings;">n</div><div style="float:left;"> Non certifié</div>'
+'<div class="DBFlegend" style="color:#00dd00; font-size:11px; font-family:Webdings;">n</div><div style="float:left;"> Certifié</div>'
+'<div class="DBFlegend" style="color:#ff8000;">Non présent sur WME</div>'
+'<div class="DBFlegend" style="color:#44aadd;">Présent sur WME</div>'
+'<wz-label html-for="" style="margin-top:15px;">Options</wz-label><div class="settings__form-group">'
+'<wz-checkbox name="optionDBF0" checked="false" id="optionDBF0" value="on">Afficher uniquement les n° non renseignés dans WME<input type="checkbox" name="optionDBF0" value="on" style="display: none; visibility: hidden;"></wz-checkbox>'
+'<wz-checkbox name="optionDBF1" checked="false" id="optionDBF1" value="on">Afficher uniquement les données certifiées<input type="checkbox" name="optionDBF1" value="on" style="display: none; visibility: hidden;"></wz-checkbox>'
+'<wz-checkbox name="optionDBF2" checked="false" id="optionDBF2" value="on">Afficher les anciens noms de communes<input type="checkbox" name="optionDBF2" value="on" style="display: none; visibility: hidden;"></wz-checkbox>'
+'<wz-checkbox name="optionDBF6" checked="false" id="optionDBF6" value="on">Masquer le nom de la commune<input type="checkbox" name="optionDBF2" value="on" style="display: none; visibility: hidden;"></wz-checkbox>'
+'<wz-checkbox name="optionDBF3" checked="false" id="optionDBF3" value="on">Afficher l\'ancienneté des données<input type="checkbox" name="optionDBF6" value="on" style="display: none; visibility: hidden;"></wz-checkbox>'
+'<wz-checkbox name="optionDBF4" checked="false" id="optionDBF4" value="on">Déplacement de la carte initialise les données<input type="checkbox" name="optionDBF4" value="on" style="display: none; visibility: hidden;"></wz-checkbox></div>'
+'<wz-label html-for="" style="margin-top:15px;">Filtres</wz-label><div class="settings__form-group">'
+'<wz-checkbox name="optionDBF5" checked="false" id="optionDBF5" value="on">Afficher uniquement les infos d\'une rue<input type="checkbox" name="optionDBF5" value="on" style="display: none; visibility: hidden;"></wz-checkbox></div>'
+'<wz-checkbox name="optionDBF7" checked="false" id="optionDBF7" value="on">Afficher uniquement les lieux-dits<input type="checkbox" name="optionDBF7" value="on" style="display: none; visibility: hidden;"></wz-checkbox></div>'
+'<wz-checkbox name="optionDBF8" checked="false" id="optionDBF8" value="on">Afficher uniquement les n° de rue<input type="checkbox" name="optionDBF8" value="on" style="display: none; visibility: hidden;"></wz-checkbox></div>'
+'<wz-label html-for="" style="margin-top:15px;">Rue sélectionnée</wz-label>'
+'<wz-body2 class="alert-settings-period-label" id="selectedRoad"></wz-body2>'
+'<div class="region-switcher" style="margin-top:15px;"><wz-select id="DBFselectRoad" name="selectRue" label="Rues disponibles" value=""><wz-option value="">---</wz-option><input name="selectRue" style="display: none; visibility: hidden;"></wz-select></div>';
var DBFaddon=document.createElement('section');
DBFaddon.id="sidepanel-DrawBordersFR";
DBFaddon.innerHTML=DBFcontent;
DBFaddon.className='tab-pane';
DBFhandleClass2.appendChild(DBFaddon);
var settings = JSON.parse(localStorage.DBFsettings);
(settings.optionDBF0 === true ? getId('optionDBF0').checked='checked' : getId('optionDBF0').checked='false');
(settings.optionDBF1 === true ? getId('optionDBF1').checked='checked' : getId('optionDBF1').checked='false');
(settings.optionDBF2 === true ? getId('optionDBF2').checked='checked' : getId('optionDBF2').checked='false');
(settings.optionDBF3 === true ? getId('optionDBF3').checked='checked' : getId('optionDBF3').checked='false');
(settings.optionDBF4 === true ? getId('optionDBF4').checked='checked' : getId('optionDBF4').checked='false');
(settings.optionDBF5 === true ? getId('optionDBF5').checked='checked' : getId('optionDBF5').checked='false');
(settings.optionDBF6 === true ? getId('optionDBF6').checked='checked' : getId('optionDBF6').checked='false');
(settings.optionDBF7 === true ? getId('optionDBF7').checked='checked' : getId('optionDBF7').checked='false');
(settings.optionDBF8 === true ? getId('optionDBF8').checked='checked' : getId('optionDBF8').checked='false');
getId('optionDBF0').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
(getId('optionDBF0').checked ? a.optionDBF0=true : a.optionDBF0=false)
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('optionDBF1').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
(getId('optionDBF1').checked ? a.optionDBF1=true : a.optionDBF1=false)
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('optionDBF2').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
(getId('optionDBF2').checked ? a.optionDBF2=true : a.optionDBF2=false)
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('optionDBF3').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
(getId('optionDBF3').checked ? a.optionDBF3=true : a.optionDBF3=false)
localStorage.setItem('DBFsettings', JSON.stringify(a));
});
getId('optionDBF4').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
(getId('optionDBF4').checked ? a.optionDBF4=true : a.optionDBF4=false)
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('optionDBF5').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
(getId('optionDBF5').checked ? a.optionDBF5=true : a.optionDBF5=false)
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('optionDBF6').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
(getId('optionDBF6').checked ? a.optionDBF6=true : a.optionDBF6=false)
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('optionDBF7').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
if (getId('optionDBF7').checked) { a.optionDBF7=true; a.optionDBF8=false; getId('optionDBF8').checked="false"; } else { a.optionDBF7=false; }
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('optionDBF8').addEventListener('click', function(e) {
var a=JSON.parse(localStorage.DBFsettings);
if (getId('optionDBF8').checked) { a.optionDBF8=true; a.optionDBF7=false; getId('optionDBF7').checked="false"; } else { a.optionDBF8=false; }
localStorage.setItem('DBFsettings', JSON.stringify(a));
load_ban();
});
getId('layerBanVisib').addEventListener('click', function(e) {
getId('layer-switcher-item_infos_ban_').click();
if (Ban_Layer.visibility === true) { getId('layerBanVisib').style.backgroundColor='#bbffcc'; }
else { getId('layerBanVisib').style.backgroundColor='#fac3c3'; }
load_ban();
});
getId('layerHNVisib').addEventListener('click', function(e) {
getId('layer-switcher-item_house_numbers').click();
if ($('#layer-switcher-item_house_numbers').prop('checked') === true) { getId('layerHNVisib').style.backgroundColor='#bbffcc'; }
else { getId('layerHNVisib').style.backgroundColor='#fac3c3'; }
load_ban();
});
getId('zoomBanValue').addEventListener('click', function(e) {
W.map.getOLMap().zoomTo("19");
if (W.map.getZoom() < 19) { getId('zoomBanValue').style.backgroundColor='#fac3c3'; }
else { getId('zoomBanValue').style.backgroundColor='#bbffcc'; }
load_ban();
});
getId('DBFselectRoad').addEventListener('change', function(e) { load_ban(); });
getId('zoomBanValue').innerHTML="Zoom: " + W.map.getZoom();
if (W.map.getZoom() < 19) { getId('zoomBanValue').style.backgroundColor='#fac3c3'; }
else { getId('zoomBanValue').style.backgroundColor='#bbffcc'; }
getId('zoomMiscValue').innerHTML="Zoom: " + W.map.getZoom();
if (W.map.getZoom() < 13) { getId('zoomMiscValue').style.backgroundColor='#fac3c3'; }
else { getId('zoomMiscValue').style.backgroundColor='#bbffcc'; }
if (Ban_Layer.visibility === true) { getId('layerBanVisib').style.backgroundColor='#bbffcc'; }
else { getId('layerBanVisib').style.backgroundColor='#fac3c3'; }
if ($('#layer-switcher-item_house_numbers').prop('checked') === true) { getId('layerHNVisib').style.backgroundColor='#bbffcc'; }
else { getId('layerHNVisib').style.backgroundColor='#fac3c3'; }
}
function DBFstep1() {
if (typeof (W.map) == 'undefined') { window.setTimeout(DBFstep1, 500); return; }
if (typeof (W.model) === 'undefined') { window.setTimeout(DBFstep1, 500); return; }
if (typeof (OpenLayers) === 'undefined') { window.setTimeout(DBFstep1, 500); return; }
if (document.querySelector('.togglers') === null) { window.setTimeout(DBFstep1, 500); return; }
DBFhandle=getId("user-info"); if(typeof(DBFhandle) == 'undefined'){ window.setTimeout(DBFstep1, 500); return; }
DBFhandleClass=getElementsByClassName("nav-tabs", DBFhandle)[0]; if(typeof(DBFhandleClass) === 'undefined'){ window.setTimeout(DBFstep1, 500); return; }
DBFhandleClass2=getElementsByClassName("tab-content", DBFhandle)[0]; if(typeof(DBFhandleClass2) === 'undefined'){ window.setTimeout(DBFstep1, 500); return; }
window.setTimeout(DBFstep2, 500);
}
function DBFstep2() {
if ('undefined' === typeof localStorage.speedCamList || !isJsonString(localStorage.speedCamList)) { localStorage.setItem('speedCamList', '[]'); }
if ('undefined' === typeof localStorage.DBFsettings || !isJsonString(localStorage.DBFsettings)) { localStorage.setItem('DBFsettings', '{"optionDBF0":false,"optionDBF1":true,"optionDBF2":false,"optionDBF3":false,"optionDBF4":true,"optionDBF5":false,"optionDBF6":false}'); }
// WME Layers check
addScriptsMenu();
WazeWrap.Interface.AddLayerCheckbox("_scripts", "Limites Villes", false, LayerVilToggled);
checklayer("__WME_Draw_Border_Cty");
WazeWrap.Interface.AddLayerCheckbox("_scripts", "Limites Départements", false, LayerDepToggled);
checklayer("__WME_Draw_Border_Dpt");
WazeWrap.Interface.AddLayerCheckbox("_scripts", "Points Routiers", false, LayerPRToggled);
checklayer("__WME_Draw_Border_PR");
WazeWrap.Interface.AddLayerCheckbox("_scripts", "Radars", false, LayerCamToggled);
checklayer("__WME_Draw_Border_Cam");
WazeWrap.Interface.AddLayerCheckbox("_scripts", "Infos BAN ", false, LayerBanToggled);
checklayer("__WME_Draw_Border_Ban");
addTooltipToCheckbox("layer-switcher-item_infos_ban", "Affiche les adresses tirées de la BAN à partir du zoom 19.");
W.map.events.register("moveend", null, show_border);
W.map.events.register('zoomend', null, show_border);
W.map.events.register('moveend', null, show_border);
W.map.events.register('mergeend', null, show_border);
W.map.events.register("moveend", null, load_ban);
W.map.events.register('zoomend', null, load_ban);
W.map.events.register('moveend', null, load_ban);
W.map.events.register('mergeend', null, load_ban);
W.selectionManager.events.register('selectionchanged', null, load_ban);
W.model.actionManager.events.register("afterclearactions", null, load_ban);
W.model.actionManager.events.register("afterundoaction", null, load_ban);
getId('layer-switcher-item_infos_ban_').addEventListener('click', function(e) {
if ($('#layer-switcher-item_infos_ban_').prop('checked')===true && $('#layer-switcher-item_house_numbers').prop('checked')===false) { $('#layer-switcher-item_house_numbers').click(); }
});
insertScriptHTML();
load_radar(); // Just one time on launch
}
function LayerVilToggled(checked) { Cty_Layer.setVisibility(checked); }
function LayerDepToggled(checked) { Dpt_Layer.setVisibility(checked); }
function LayerPRToggled(checked) { PR_Layer.setVisibility(checked); }
function LayerCamToggled(checked) { Cam_Layer.setVisibility(checked); }
function LayerBanToggled(checked) { Ban_Layer.setVisibility(checked); }
function checklayer(layer) {
var layers = W.map.getLayersBy("uniqueName", layer);
if (layers.length === 0) {
var DBF_style = new OpenLayers.Style({
pointRadius: 2,
fontWeight: "normal",
label: "${labelText}",
fontFamily: "Tahoma, Courier New",
labelOutlineColor: "#FFFFFF",
labelOutlineWidth: 2,
fontColor: '#000000',
fontSize: "10px"
});
if (layer == "__WME_Draw_Border_Cty") {
Cty_Layer = new OpenLayers.Layer.Vector("Limites Villes", {
displayInLayerSwitcher: true,
uniqueName: layer,
styleMap: new OpenLayers.StyleMap(DBF_style)
});
Cty_Layer.setVisibility(false);
W.map.addLayer(Cty_Layer);
I18n.translations[I18n.locale].layers.name[layer] = "Villes";
}
if (layer == "__WME_Draw_Border_Dpt") {
Dpt_Layer = new OpenLayers.Layer.Vector("Limites Departements", {
displayInLayerSwitcher: true,
uniqueName: layer,
styleMap: new OpenLayers.StyleMap(DBF_style)
});
Dpt_Layer.setVisibility(false);
W.map.addLayer(Dpt_Layer);
I18n.translations[I18n.locale].layers.name[layer] = "Departements";
}
if (layer == "__WME_Draw_Border_PR") {
PR_Layer = new OpenLayers.Layer.Vector("Points Routiers", {
displayInLayerSwitcher: true,
uniqueName: layer,
styleMap: new OpenLayers.StyleMap(DBF_style)
});
PR_Layer.setVisibility(false);
W.map.addLayer(PR_Layer);
I18n.translations[I18n.locale].layers.name[layer] = "PR";
}
if (layer == "__WME_Draw_Border_Cam") {
Cam_Layer = new OpenLayers.Layer.Vector("Radars", {
displayInLayerSwitcher: true,
uniqueName: layer,
styleMap: new OpenLayers.StyleMap(DBF_style)
});
Cam_Layer.setVisibility(false);
W.map.addLayer(Cam_Layer);
I18n.translations[I18n.locale].layers.name[layer] = "Radars";
}
if (layer == "__WME_Draw_Border_Ban") {
Ban_Layer = new OpenLayers.Layer.Vector("Infos BAN", {
displayInLayerSwitcher: true,
uniqueName: layer,
styleMap: new OpenLayers.StyleMap(DBF_style)
});
Ban_Layer.setVisibility(false);
W.map.addLayer(Ban_Layer);
I18n.translations[I18n.locale].layers.name[layer] = "BAN";
}
}
}
function load_radar() {
getId('zoomMiscValue').innerHTML="Zoom: " + W.map.getZoom();
if (W.map.getZoom() < 13) { getId('zoomMiscValue').style.backgroundColor='#fac3c3'; return; }
else { getId('zoomMiscValue').style.backgroundColor='#bbffcc'; }
var listCam = localStorage.speedCamList;
//Get Data
try {
getId('loadMiscData').style.backgroundColor='#bbffcc';
var url = "https://radars.securite-routiere.gouv.fr/radars/all?_format=json";
var datas = null;
var method = "GET";
DBDLHelper.add(url, method, datas, function (data) {
if (data.status == 'success') {
if (_.isEqual(JSON.parse(listCam), JSON.parse(data.data)) !== true && data.data) {
console.log("WME Draw Borders France: Mise à jour de la liste des radars");
localStorage.setItem('speedCamList', data.data);
}
getId('loadMiscData').style.backgroundColor='#ffffff';
} else {
getId('loadMiscData').style.backgroundColor='#fac3c3';
}
});
}
catch (e) { console.error("Error @ upload data:", e); }
}
function load_ban() {
if (Ban_Layer.visibility === true) { getId('layerBanVisib').style.backgroundColor='#bbffcc'; }
else { getId('layerBanVisib').style.backgroundColor='#fac3c3'; }
if ($('#layer-switcher-item_house_numbers').prop('checked') === true) { getId('layerHNVisib').style.backgroundColor='#bbffcc'; }
else { getId('layerHNVisib').style.backgroundColor='#fac3c3'; }
getId('zoomBanValue').innerHTML="Zoom: " + W.map.getZoom();
if (W.map.getZoom() < 19) { getId('zoomBanValue').style.backgroundColor='#fac3c3'; return; }
else { getId('zoomBanValue').style.backgroundColor='#bbffcc'; }
if (Ban_Layer.visibility === true) {
if (getId('optionDBF4').checked) { Ban_Layer.destroyFeatures(); checklayer("__WME_Draw_Border_Ban"); }
else { Ban_Layer.redraw(); }
try {
getId('loadBanData').style.backgroundColor='#bbffcc';
//Liste les noms de rue à l'écran
var streetList = [];
for (var i in W.model.streets.objects) {
var streetName = W.model.streets.objects[i].attributes.name
if (streetName != "") {
if (streetList.indexOf(streetName) == - 1) {
streetList.push(streetName);
}
}
}
streetList.sort();
//Création du menu déroulant après l'avoir vidé (actualisation), mis l'option par défaut et, éventuellement, la rue sélectionnée
var tmp=getId('DBFselectRoad').value;
getId('DBFselectRoad').innerHTML = "";
getId('selectedRoad').innerHTML = "";
var cList = document.createElement('wz-option');
cList.value = "";
cList.innerHTML = "---";
getId('DBFselectRoad').appendChild(cList);
if (tmp != "") {
cList = document.createElement('wz-option');
cList.value = tmp;
cList.innerHTML = tmp;
getId('DBFselectRoad').appendChild(cList);
}
//On complète avec les autres rues
for (var k = 0; streetList[k]; k++) {
if (tmp != streetList[k]) {
cList = document.createElement('wz-option');
cList.value = streetList[k];
cList.innerHTML = streetList[k];
getId('DBFselectRoad').appendChild(cList);
}
}
//Segment sélectionné à l'écran
if (typeof W.selectionManager.getSelectedFeatures()[0] != 'undefined') {
getId('selectedRoad').innerHTML = W.model.streets.objects[W.model.segments.objects[W.selectionManager.getSelectedFeatures()[0].id].attributes.primaryStreetID].attributes.name;
} else {
getId('selectedRoad').innerHTML="";
}
//Liste des n° de rue déjà existants sur la carte
var HNdone = [];
for (var i in W.model.segmentHouseNumbers.objects) {
if (typeof W.model.segmentHouseNumbers.objects[i].attributes.segID != "null"
&& typeof W.model.segments.objects[W.model.segmentHouseNumbers.objects[i].attributes.segID] != "undefined") {
// Mise en mémoire des noms de rue et ville
let segId = W.model.segmentHouseNumbers.objects[i].attributes.segID;
let streetName = W.model.streets.objects[W.model.segments.objects[segId].attributes.primaryStreetID].attributes.name;
streetName = streetName.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
let cityName = W.model.cities.objects[W.model.streets.objects[W.model.segments.objects[segId].attributes.primaryStreetID].attributes.cityID].attributes.name
cityName = cityName.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
if(cityName.indexOf("(") > 0) { cityName = cityName.substring(cityName.indexOf("(")+1).replace(")",""); } // On garde le nom de la commune principale si sous-commune
HNdone.push(W.model.segmentHouseNumbers.objects[i].attributes.number + " " + streetName + " " + cityName);
// Mise en mémoire des noms de rue et ville alt
if (typeof W.model.segments.objects[segId].attributes.streetIDs[0] != "undefined") {
for (var j = 0; j < W.model.segments.objects[segId].attributes.streetIDs.length; j++) {
let streetAltName = W.model.streets.objects[W.model.segments.objects[segId].attributes.streetIDs[j]].attributes.name;
streetAltName = streetAltName.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
let cityName = W.model.cities.objects[W.model.streets.objects[W.model.segments.objects[segId].attributes.streetIDs[j]].attributes.cityID].attributes.name
cityName = cityName.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
if(cityName.indexOf("(") > 0) { cityName = cityName.substring(cityName.indexOf("(")+1).replace(")",""); } // On garde le nom de la commune principale si sous-commune
HNdone.push(W.model.segmentHouseNumbers.objects[i].attributes.number + " " + streetAltName + " " + cityName);
}
}
}
}
//Liste des POI résidentiels déjà existants sur la carte
for (var i in W.model.venues.objects) {
if (typeof W.model.venues.objects[i].attributes.residential != "null"
&& typeof W.model.venues.objects[i].attributes.streetID != "undefined"
&& typeof W.model.streets.objects[W.model.venues.objects[i].attributes.streetID] != "undefined") {
let streetName = W.model.streets.objects[W.model.venues.objects[i].attributes.streetID].attributes.name;
streetName = streetName.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
let cityName = W.model.cities.objects[W.model.streets.objects[W.model.venues.objects[i].attributes.streetID].attributes.cityID].attributes.name
cityName = cityName.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase();
if(cityName.indexOf("(") > 0) { cityName = cityName.substring(cityName.indexOf("(")+1).replace(")",""); } // On garde le nom de la commune principale si sous-commune
HNdone.push(W.model.venues.objects[i].attributes.houseNumber + " " + streetName + " " + cityName);
}
}
//On récupère les infos de la carte et vérification de la présence de toutes les données nécessaires
let lonlat = new OpenLayers.LonLat(W.map.getProjectedCenter().lon, W.map.getProjectedCenter().lat);
lonlat.transform(W.Config.map.projection.local, W.Config.map.projection.remote);
let pt = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
var clat = pt.y;
var clon = pt.x;
var zoomLevel = W.map.getZoom();
if (!clat || !clon || !zoomLevel) {
console.error("Latitude, longitude ou zoomLevel manquant dans l'URL");
return;
}
// Construction de l'URL pour l'API Flask
var url = "http://api.wazefrance.com/combined_data?lat=" + clat + "&lon=" + clon + "&zoom=" + zoomLevel;
// Requête à l'API Flask
var datas = null;
var method = "GET";
DBDLHelper.add(url, method, datas, function (data) {
if (data.status == 'success') {
const correction = {
"Mal ": "Maréchal ",
"Av ": "Avenue ",
"Oe": "Œ", "Œ": "Oe", "oe": "œ", "œ": "oe",
"Ae": "Æ", "Æ": "Ae", "ae": "æ", "æ": "ae",
"jean ": "Jean-",
"marie ": "Marie-",
"st ": "Saint-",
"saint ": "Saint-"
};
var adresses = JSON.parse(data.data);
//Numéros de rue
if (debug) { console.log("N° BAN",adresses.info_ban); }
var a = adresses.info_ban;
for (var i = 0; i < a.length; i++) {
var adresse = a[i], nomComplet2;
var nomComplet = adresse.numero + (adresse.rep != null ? adresse.rep : "") + " " + adresse.nom_voie;
Object.keys(correction).forEach((key) => {
nomComplet = nomComplet.replaceAll(key, correction[key]);
});
nomComplet2 = nomComplet.normalize('NFD').replace(/\p{Diacritic}/gu, '').replace("’", "'").toLowerCase();
if (getId('optionDBF6').checked == true) { var Ville = ""; } else { var Ville="\n" + adresse.nom_commune; }
// Appel à Ban_Borders_DrawBorder avec le format attendu après avoir testé si le n° existe déjà sur WME
var state;
((HNdone.indexOf(nomComplet2 +" "+adresse.nom_commune.normalize('NFD').replace(/\p{Diacritic}/gu, '').toLowerCase()) == "-1") ? state = 'no' : state = 'yes')
if (getId('optionDBF0').checked == true && state == 'yes') { continue; } // On bloque l'affichage des n° renseignés sur WME
if (getId('optionDBF1').checked == true && adresse.certification_commune == 0) { continue; } // On bloque l'affichage des n° non certifiés
if (getId('optionDBF2').checked == true && adresse.nom_ancienne_commune != null) { Ville = "\n" + adresse.nom_ancienne_commune + ' (' + adresse.nom_commune + ')'; } // On affiche l'ancien nom de commune
if (getId('optionDBF3').checked == true && adresse.date_ajout_modif != null) { Ville = Ville + '\n' + deltaDate(adresse.date_ajout_modif); } // On affiche l'age de l'info
if (getId('optionDBF5').checked == true && (getId('selectedRoad').innerHTML != "" || getId('DBFselectRoad').value != "")) {
if (getId('selectedRoad').innerHTML != "") { var selectedRoad = getId('selectedRoad').innerHTML; } // Rue sélectionnée
else if (getId('DBFselectRoad').value != "") { var selectedRoad = getId('DBFselectRoad').value; } // Sinon rue dans le menu déroulant
var adres = adresse.nom_voie;
adres = adres.normalize('NFD').replace(/\p{Diacritic}/gu, '').replace("’", "'").toLowerCase();
var selectRoad = selectedRoad.normalize('NFD').replace(/\p{Diacritic}/gu, '').replace("’", "'").toLowerCase();
if (selectRoad != adres) { continue; } // On bloque si ce n'est pas la rue sélectionnée
}
if (getId('optionDBF7').checked == false) { Ban_Borders_DrawBorder(nomComplet + Ville, adresse.lon, adresse.lat, state, adresse.certification_commune); }
}
//Lieux-dits
if (debug) { console.log("Lieux-dits",adresses.lieux_dits); }
var b = adresses.lieux_dits;
for (var i = 0; i < b.length; i++) {
var lieux = b[i], lieudit2;
var lieudit = lieux.nom_lieu_dit;
Object.keys(correction).forEach((key) => {
lieudit = lieudit.replaceAll(key, correction[key]);
});
lieudit2 = lieudit.normalize('NFD').replace(/\p{Diacritic}/gu, '').replace("’", "'").toLowerCase();
if (getId('optionDBF6').checked == true) { var Ville = ""; } else { var Ville="\n" + adresse.nom_commune; }
// Appel à Ban_Borders_DrawBorder avec le format attendu après avoir testé si le n° existe déjà sur WME
var state;
((HNdone.indexOf(lieudit2) == "-1") ? state = 'no' : state = 'yes')
if (getId('optionDBF0').checked == true && state == 'yes') { continue; } // On bloque l'affichage des lieux-dits renseignés sur WME
if (getId('optionDBF8').checked == false) { Ban_Borders_DrawBorder(lieudit + Ville, lieux.lon, lieux.lat,"",""); }
}
getId('loadBanData').style.backgroundColor='#ffffff';
} else {
getId('loadBanData').style.backgroundColor='#fac3c3';
}
});
} catch (e) {
console.error("Erreur lors du chargement des données:", e);
}
}
}
function show_border() {
getId('zoomMiscValue').innerHTML="Zoom: " + W.map.getZoom();
if (W.map.getZoom() < 13) { getId('zoomMiscValue').style.backgroundColor='#fac3c3'; return; }
else { getId('zoomMiscValue').style.backgroundColor='#bbffcc'; }
var Cty_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Cty"; });
var Dpt_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Dpt"; });
var PR_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_PR"; });
var Cam_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Cam"; });
var Ban_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Ban"; });
//Draw cities
if (Cty_Layer.visibility === true) {
if (W.model.cities.objects.length === 0) return;
// collect list if unique cities from the segments
var Cities = [], temp_city = "";
for (var cid in W.model.cities.objects) {
var city = W.model.cities.getObjectById(cid).attributes.name;
var state = W.model.states.getObjectById(W.model.cities.getObjectById(cid).attributes.stateID).attributes.name;
if (city && state) {
city = city.toLowerCase(); state = state.toLowerCase();
city = city.replace(/[èéêë]/g, "e").replace(/ç/g, 'c').replace(/[àâ]/g, 'a').replace(/[îï]/g, 'i').replace(/[ôö]/g, 'o').replace(/œ/g, 'oe').replace(/\'/g, '_');
state = state.replace(/[èé]/g, "e").replace(/ô/g, 'o').replace(/\'/g, '_');
if (city.indexOf("(") != "-1") { city = city.substring(city.indexOf(" ("), city.substr(city.length - 1)); } // Commune de...
if (city) {
Cities.push({ name: city, state: state });
if (debug) { console.log(city, state); temp_city = temp_city + city + ", "; }
}
}
}
if (debug) { console.log("Villes demandées : ", temp_city); }
//Get Data
if (JSON.stringify(CitiesOld) != JSON.stringify(Cities)) {
try {
getId('loadMiscData').style.backgroundColor = '#bbffcc';
if (debug) { console.log(JSON.stringify(Cities)); }
var url = "https://api.wazefrance.com/communes"; // Utiliser HTTPS ici
var datas = JSON.stringify(Cities);
var method = "POST";
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
var temp_city = "", c = 0;
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
Cty_Borders_DrawBorder(data[i].name, data[i].coord); c++;
if (debug) { temp_city = temp_city + data[i].name + ", "; }
}
}
if (debug) { console.log("WME Draw Borders France: " + c + " villes reçues ", temp_city); }
getId('loadMiscData').style.backgroundColor = '#ffffff';
} else {
getId('loadMiscData').style.backgroundColor = '#fac3c3';
}
}
};
xhr.send(datas); // Envoyer les données JSON dans le corps de la requête
} catch (e) { console.error("Error @ upload data:", e); }
CitiesOld = Cities;
} else {
if (debug) { console.log("WME Draw Borders France: Pas de nouvelles Villes détectées"); }
}
}
//Dpt_Layer.visibility
if (Dpt_Layer.visibility === true) {
if (W.model.states.objects.length === 0) return;
// Collect list if unique states from the segments
var States = [], temp_state = "";
for (var sid in W.model.states.objects) {
var state = W.model.states.getObjectById(sid).attributes;
if (state.countryID == "73") {
state = state.name.replace(/[èé]/g, "e").replace(/[ô]/g, 'o').replace(/\'/g, '_').replace(/ /g, '_');
States.push({ name: state });
if (debug) { temp_state = temp_state + state + ", "; }
}
}
if (debug) { console.log("Départements demandés : ", temp_state); }
// Get Data
if (JSON.stringify(StatesOld) != JSON.stringify(States)) {
try {
getId('loadMiscData').style.backgroundColor = '#bbffcc';
var url = "https://api.wazefrance.com/dep"; // Utiliser HTTPS ici
var datas = JSON.stringify(States);
var method = "POST";
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
var temp_state = "", c = 0;
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
Dpt_Borders_DrawBorder(data[i].name, data[i].coord); c++;
if (debug) { temp_state = temp_state + data[i].name + ", "; }
}
}
if (debug) { console.log("WME Draw Borders France: " + c + " départements reçus ", temp_state); }
getId('loadMiscData').style.backgroundColor = '#ffffff';
} else {
getId('loadMiscData').style.backgroundColor = '#fac3c3';
}
}
};
xhr.send(datas); // Envoyer les données JSON dans le corps de la requête
} catch (e) { console.error("Error @ upload data:", e); }
StatesOld = States;
} else {
if (debug) { console.log("WME Draw Borders France: Pas de nouveaux Départements détectés"); }
}
}
//PR_Layer.visibility
if (PR_Layer.visibility === true) {
if (W.model.states.objects.length === 0) return;
// collect list if unique states from the segments
var StatesPR = [], temp_statePR = "";
for (var sid in W.model.states.objects) {
var statePR = W.model.states.getObjectById(sid).attributes;
if (statePR.countryID == "73") {
statePR = statePR.id;
StatesPR.push({ id: statePR });
if (debug) { temp_statePR = temp_statePR + statePR + ", "; }
}
}
if (debug) { console.log("ID départements demandées", temp_statePR); }
//Get Data
if (JSON.stringify(StatesPROld) != JSON.stringify(StatesPR)) {
if (debug) { console.log(JSON.stringify(StatesPR)); }
try {
getId('loadMiscData').style.backgroundColor='#bbffcc';
var url = "http://wmebookmarks.free.fr/pr.php";
var datas = "data=" + JSON.stringify(StatesPR);
var method = "POST";
DBDLHelper.add(url, method, datas, function (data) {
if (data.status == 'success') {
var r = JSON.parse(data.data), c = 0;
if (r.length > 0) {
for (var i = 0; r[i]; i++) {
PR_Borders_DrawBorder(r[i].pk, r[i].lon, r[i].lat); c++;
}
}
if (debug) { console.log("WME Draw Borders France: " + c + " PR pour les départements"); }
getId('loadMiscData').style.backgroundColor='#ffffff';
} else {
getId('loadMiscData').style.backgroundColor='#fac3c3';
}
});
}
catch (e) { console.error("Error @ upload data:", e); }
StatesPROld = StatesPR;
}
else { if (debug) { console.log("WME Draw Borders France: Pas de nouveaux Départements détectés pour PR"); } }
}
//Cam_Layer.visibility
if (Cam_Layer.visibility === true) {
var listCam = localStorage.speedCamList;
if (listCam) {
var a = JSON.parse(listCam);
if (debug) { console.log(a); }
for (var i = 0; i < a.length; i++) { Cam_Borders_DrawBorder(a[i].typeLabel, a[i].lng, a[i].lat); }
}
}
}
function Cty_Borders_DrawBorder(Name, coordinateString) {
var poly = new OpenLayers.Feature.Vector(Geometrize(Name, coordinateString), null, new Cty_Borders_Style(Name));
var Cty_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Cty"; });
Cty_Layer.addFeatures(poly);
}
function Dpt_Borders_DrawBorder(Name, coordinateString) {
var poly = new OpenLayers.Feature.Vector(Geometrize(Name, coordinateString), null, new Dpt_Borders_Style(Name));
var Dpt_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Dpt"; });
Dpt_Layer.addFeatures(poly);
}
function PR_Borders_DrawBorder(Name, lon, lat) {
var poly = new OpenLayers.Feature.Vector(Geometrize(Name, lon + ";" + lat), null, new PR_Borders_Style(Name));
var PR_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_PR"; });
PR_Layer.addFeatures(poly);
}
function Cam_Borders_DrawBorder(Name, lon, lat) {
var poly = new OpenLayers.Feature.Vector(Geometrize(Name, lon + ";" + lat), null, new Cam_Borders_Style(Name));
var Cam_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Cam"; });
Cam_Layer.addFeatures(poly);
}
function Ban_Borders_DrawBorder(Name, lon, lat, status, verif) {
var cStat1, cStat2, cVerif;
if (status == "yes") { cStat1 = "#99ffff"; cStat2 = "#002222"; }
else { cStat1 = "#ff0000"; cStat2 = "#ffff00"; }
(verif == "1" ? cVerif = "#00dd00" : cVerif = "#ff8000")
var poly = new OpenLayers.Feature.Vector(Geometrize(Name, lon + ";" + lat), null, new Ban_Borders_Style(Name, cStat1, cStat2, cVerif));
var Ban_Layer = W.map.layers.find(function (l) { return l.uniqueName == "__WME_Draw_Border_Ban"; });
Ban_Layer.addFeatures(poly);
}
function Cty_Borders_Style(Name) {
this.fill = false;
this.stroke = true;
this.strokeColor = "#ce00ce";
this.strokeWidth = 2;
this.strokeDashstyle = "solid";
}
function Dpt_Borders_Style(Name) {
this.fill = false;
this.stroke = true;
this.strokeColor = "#b20000";
this.strokeWidth = 5;
this.strokeDashstyle = "solid";
this.label = Name.replace(/_/g, "'");
this.fontSize = 24;
this.fontColor = "#b20000";
this.fontWeight = "bold";
}
function PR_Borders_Style(Name) {
this.fill = false;
this.stroke = true;
this.strokeColor = "#ff0000";
this.strokeWidth = 10;
this.strokeDashstyle = "solid";
this.label = "PR" + Name;
this.labelYOffset = 13;
this.fontSize = 12;
this.fontColor = "#ffff00";
this.labelOutlineColor = "#ff0000";
this.labelOutlineWidth = 3;
}
function Cam_Borders_Style(Name) {
this.stroke = true;
this.strokeColor = "#ff0000";
this.strokeWidth = 10;
this.strokeDashstyle = "solid";
this.label = Name;
this.labelYOffset = 13;
this.fontSize = 12;
this.fontColor = "#ffff00";
this.labelOutlineColor = "#ff0000";
this.labelOutlineWidth = 3;
}
function Ban_Borders_Style(Name, cStat1, cStat2, cVerif) {
this.fill = false;
this.stroke = true;
this.strokeColor = cVerif;
this.strokeWidth = 10;
this.strokeDashstyle = "solid";
this.label = Name;
this.labelYOffset = 22;
this.fontSize = 12;
this.fontColor = cStat2;
this.labelOutlineColor = cStat1;
this.labelOutlineWidth = 4;
}
function Geometrize(Name, coordinateString) {
var tempVector = coordinateString.split(" ");
var polyPoints = new Array(tempVector.length);
for (var i = 0; i < tempVector.length; i++) {
var coordinateVector = tempVector[i].split(";");
polyPoints[i] = new OpenLayers.Geometry.Point(coordinateVector[0], coordinateVector[1]).transform(new OpenLayers.Projection("EPSG:4326"), W.map.getProjectionObject());
}
var polygon = new OpenLayers.Geometry.Polygon(new OpenLayers.Geometry.LinearRing(polyPoints));
return polygon;
}
DBF_bootstrap();
}
let BKMscript = GM_addElement('script', {
textContent: "" + run_DBF.toString() + " \n" + "run_DBF();"
});