Greasy Fork is available in English.

WME Color Errors

Adds colours to show errors

Від 12.03.2017. Дивіться остання версія.

// ==UserScript==
// @name             WME Color Errors
// @name:fr          WME Color Errors
// @version          0.32
// @icon             data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAALuSURBVHja7Jots6swEIb7x6qiUFVVUVEoVBSqKioqU8EfqKpCRaE6FShMo5gjUCiOYebOzTXnvaKlhR44LbS9vcyQmVWdbt5nd7P5GGbr/eFjvT98jtQ+Zuv9oVzvDxiplbMTyVgBPieACWACmADeD/Bn7ABfE8D77PfYAfBUgFCt4DEKZz7H/Js5oMzDSoXPBPh6GCBSHAvSJviGkQW4it4HECmvI9IncygYY2ALcgPGgTccpD9AkQRwf4g4cQPEWYnzsDHkXRlxESTFawFixUDOkxIwIeEvLiKojFFclKPIDOJwhWWX6AWHWF35VPFrAEJeKwXHw9aUsIm8TO6GyE7S80iA3bUuCGRiUZotPKeWRR4+F0DXxBMeIrNHoUaRhhAAKCJei+htI8ocnZUGG7c+j34OQF08FTvk5xLJELJKiEICAEixWfbsRuySOSDHTtA+ED8D5Jo3nF3EA4CBqkR4p98KDd63nc4VTMNv3gga1/lwALeahCoYi6tRA5hzhFmJPFr1Kp92AADWQNHqd3cYQORX7Y1D52gZObQ3YAO7Nu86s5X7Wjb9qD/AOboihkX7SDfLhwGWm7TDu0UsLlnqDbATVR1SKGO7CEAfAqDo0m+NOvsmYjdsDXByq4wsYkkGAxDZkd1cN+YevIgbPb11IV8vuB52lz8CHhWP7QNG1foyC5CULZMWMWQfCCoRFy1+ygQBq+07yjxnJ65vLnMqELWVk82gBbvRRh24MuroOhFELQi0u+6HnYViSRuLT+gUbclAmSEOFVYeOx6nGQPzJbY6Qdb+B6RaNJoBlfFrTqNZ6DfuAIQJ6LTE0FGmGoKRRob8MHv9haY56RxkwaG0QV7am6JtkSHRCvzqokOY+Lc3slR3HJkdCuatoIIAwdmOJUWdtosMg9Dp++7EpiWad+0Bp6z9V68S6/0BgfTBvr1MOKCMwZfBs59Vfs3G/CZUvczZ6XV6ApgAJoAJYAIYM8DoP/YY9ec2fwcAaebQXj6i79wAAAAASUVORK5CYII=
// @description      Adds colours to show errors
// @description:fr   Colorisation pour afficher les erreurs
// @include          https://www.waze.com/editor/*
// @include          https://www.waze.com/*/editor/*
// @include          https://beta.waze.com/*
// @exclude          https://www.waze.com/user/*
// @exclude          https://www.waze.com/*/user/*
// @namespace        https://greasyfork.org/fr/scripts/21186-wme-color-errors
// @author	         Sebiseba
// @copyright        Sebiseba 2014-2016
// @grant            none
// ==/UserScript==

var WMECErrors={}, ColorErrors_mapLayer=[], CErrLeg, CErrSeg, CErrPoi, debug;
var CErrWaze, CErrorsMap, CErrorsModel, CErrorsI18n, CErrorsOpenLayers, CErrorshandle, CErrorshandleClass, CErrorshandleClass2;

// *********************
// ** HELPER FUNCTION **
// *********************

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;
}

// *************
// **  INIT   **
// *************
function CErrors_bootstrap() {
    if (typeof unsafeWindow === "undefined") {
        unsafeWindow   =( function () {
            var dummyElem=document.createElement('p');
            dummyElem.setAttribute('onclick', 'return window;');
            return dummyElem.onclick();
        }) ();
    }
    console.log("starting WME Color Errors", GM_info.script.version);
    CErrors_init();
}
function CErrors_init(){
    // Waze object needed
    CErrWaze=unsafeWindow.Waze;    if(typeof(CErrWaze) === 'undefined'){ if (debug) { console.error("WME ColorErrors - CErrWaze : NOK"); } window.setTimeout(CErrors_init, 500); return; }
    CErrorsMap=CErrWaze.map;       if(typeof(CErrorsMap) == 'undefined'){ if (debug) { console.error("WME ColorErrors - CErrorsmap : NOK"); } window.setTimeout(CErrors_init, 500); return; }
    CErrorsModel=CErrWaze.model;   if(typeof(CErrorsModel) == 'undefined'){ if (debug) { console.error("WME ColorErrors - CErrorsmodel : NOK"); } window.setTimeout(CErrors_init, 500); return; }
    CErrorsI18n=unsafeWindow.I18n; if(typeof (CErrorsI18n) == 'undefined') { if (debug) { console.error('WME ColorErrors - CErrorsI18n : NOK'); } setTimeout(CErrors_init, 500); return; }
    // OpenLayers
    CErrorsOpenLayers=unsafeWindow.OpenLayers; if(typeof(CErrorsOpenLayers) === 'undefined'){ if (debug) { console.error("WME ColorErrors - OpenLayers : NOK"); } window.setTimeout(CErrors_init, 500); return; }
    // Waze GUI needed
    CErrorshandle=getId("user-info"); if(typeof(CErrorshandle) == 'undefined'){ window.setTimeout(CErrors_init, 500); return; }
    CErrorshandleClass=getElementsByClassName("nav-tabs", CErrorshandle)[0]; if(typeof(CErrorshandleClass) === 'undefined'){ window.setTimeout(CErrors_init, 500); return; }
    CErrorshandleClass2=getElementsByClassName("tab-content", CErrorshandle)[0]; if(typeof(CErrorshandleClass2) === 'undefined'){ window.setTimeout(CErrors_init, 500); return; }

    // Verify localStorage. Init if empty or not correct
    if (typeof(localStorage.WMEColorErrors) === "undefined" || localStorage.WMEColorErrors.lenght===null || !IsJsonString(localStorage.WMEColorErrors)) {
        WMECErrors.seg_Bad=false; // Bad Segments (group)
        WMECErrors.seg_Priv=true; // Private with bad name
        WMECErrors.seg_Park=true; // Parking with name (but Place / Square)
        WMECErrors.seg_Rail=true; // Railroad with bad name
        WMECErrors.seg_HW_name=true; //Highways with bad name
        WMECErrors.seg_Dir_name=true; // Directions but not Ramp/Freeway
        WMECErrors.seg_Toll=true; // Toll (but Ramp/Freeway)
        WMECErrors.seg_Ramp_name=true; // Ramp with 3 directions or more
        WMECErrors.seg_Ramp_city=true; // Ramp with city name
        WMECErrors.seg_RShield=true; // Wrong prefix
        WMECErrors.seg_RSAlt=true; //Roadshield must be in alt
        WMECErrors.seg_SNameAlt=true; //Road name must be in alt
        WMECErrors.seg_DleSpace=true; // Double space in name
        WMECErrors.seg_SegBadRS=true; // RoadShield but bad type
        // POI
        WMECErrors.poi_Bad=false; // Bad POI (group)
        WMECErrors.poi_Park_name=true; // Parking with [P]
        WMECErrors.poi_Address=true; // Dxxx/Nxxx in or no address
        WMECErrors.poi_Entry=true; // Entry Point not defined
        WMECErrors.poi_LandM=true; // Landmark with address (street |& city)
        WMECErrors.poi_DleSpace=true; // Double space in name
        // Low errors
        WMECErrors.poi_Resid=true; // Maybe a residential
        WMECErrors.poi_Google=true; // No link with Google
        WMECErrors.poi_WFeed=true; // Place created by WazeFeed
        WMECErrors.poi_WPark=true; // Place created by WazeParking1
        WMECErrors.poi_Other=true; // Place "Other"
        localStorage.setItem('WMEColorErrors', JSON.stringify(WMECErrors));
    }

    // WME Layers check
    var layersColor=CErrorsMap.getLayersBy("uniqueName","__WME_Color_Errors"), layersIcons=CErrorsMap.getLayersBy("uniqueName","__WME_Color_Errors_Icons");
    var ColorErrors_style=new CErrorsOpenLayers.Style({
        pointRadius: 2,
        fontWeight: "normal",
        label : "${labelText}",
        fontFamily: "Tahoma, Courier New",
        labelOutlineColor: "#FFFFFF",
        labelOutlineWidth: 2,
        fontColor: '#000000',
        fontSize: "10px"
    });
    if (layersColor.length === 0) {
        ColorErrors_mapLayer=new CErrorsOpenLayers.Layer.Vector("Color Errors", {
            displayInLayerSwitcher: false,
            uniqueName: "__WME_Color_Errors",
            styleMap: new CErrorsOpenLayers.StyleMap(ColorErrors_style)
        });
        CErrorsI18n.translations[CErrorsI18n.locale].layers.name["__WME_Color_Errors"]="Color Errors";
        CErrorsMap.addLayer(ColorErrors_mapLayer);
        ColorErrors_mapLayer.setVisibility(true);
    }
    if (layersIcons.length === 0) {
        ColorErrors_mapLayerIcons=new CErrorsOpenLayers.Layer.Vector("Color Errors Icons", {
            displayInLayerSwitcher: false,
            uniqueName: "__WME_Color_Errors_Icons",
            styleMap: new CErrorsOpenLayers.StyleMap(ColorErrors_style)
        });
        CErrorsI18n.translations[CErrorsI18n.locale].layers.name["__WME_Color_Errors_Icons"]="Color Errors Icons";
        CErrorsMap.addLayer(ColorErrors_mapLayerIcons);
        ColorErrors_mapLayerIcons.setVisibility(true);
    }
    CErrors_Mainhtml();
}

// *************
// **  HTML   **
// *************

function CErrors_Mainhtml() {
    if (CErrorsI18n.locale == 'fr') {
        CErrSeg=new Array('Contrôle des segments',
                          'Mauvais segments',
                          'Voie privée avec mauvais nom',
                          'Voie de Parking nommée',
                          'Voie ferrée nommée ou alt',
                          'Types Routes avec mauvais nom',
                          'Bretelle avec plusieurs directions',
                          'Direction (sauf bretelle et Autoroute)',
                          'Mauvais préfixe (RoadShield)',
                          'Double espace dans le nom',
                          'Péage (sauf bretelle et Autoroute)',
                          'Bretelle/Autoroute avec nom de ville',
                          'Le RoadShield doit être en alt',
                          'Le nom de route doit être en alt',
                          'RoadShield sur mauvais type de voie'
                         );
        CErrPoi=new Array('Contrôle des places',
                          'Mauvaises places',
                          'Parking mal nommé ou rien',
                          'Pas d\'adresse ou contenant Dxxx/Nxxx',
                          'Point d\'entré non défini',
                          'Site naturel avec adresse',
                          'Double espace dans le nom',
                          'Peut-être une place résidentielle',
                          'Pas de lien avec Google',
                          'Lieu édité par WazeFeed',
                          'Lieu de type "Autres"',
                          'Lieu édité par WazeParking1',
                          'Parking : type non défini'
                         );
        CErrLeg=new Array('Légende',
                          'A corriger',
                          'A vérifier',
                          'Pour information'
                         );
    }
    else {
        CErrSeg=new Array('Segments Checking',
                          'Bad Segments',
                          'Private with bad name',
                          'Parking with name',
                          'Railroad with name or altname',
                          'Highways with bad name',
                          'Ramp with several directions',
                          'Direction (but Ramp/Freeway)',
                          'Wrong prefix (RoadShield)',
                          'Double spacing in name',
                          'Toll (but Ramp/Freeway)',
                          'Ramp/Freeway with city name',
                          'RoadShield must be in alt',
                          'Road name must be in alt',
                          'RoadShield but bad type',
                          'Parking : type undefined'
                         );
        CErrPoi=new Array('Places Checking',
                          'Bad Places',
                          'Parking with bad name or null',
                          'No address or Dxxx/Nxxx within',
                          'Entry Point not defined',
                          'Natural features with address',
                          'Double spacing in name',
                          'Maybe a residential place',
                          'No link with Google',
                          'Place created by WazeFeed',
                          'Place type is "Other"',
                          'Place created by WazeParking1'
                         );
        CErrLeg=new Array('Legend',
                          'To correct',
                          'To check',
                          'For information'
                         );
    }
    //Create content in CErrors's tab
    var CEnewtab=document.createElement('li');
    CEnewtab.innerHTML="<a href='#sidepanel-ColorErrors' data-toggle='tab'><span class='fa fa-eye' title='Color Errors'></span></a>";
    CErrorshandleClass.appendChild(CEnewtab);

    var WMECErrors=JSON.parse(localStorage.getItem('WMEColorErrors'));
    var CEaddon=document.createElement('section');
    CEaddon.id="sidepanel-ColorErrors";
    var CEcontent="<div style='float:left; margin-left:5px;'><b><a href='https://greasyfork.org/scripts/xxx-wme-color-errors' target='_blank'><u>WME Color Errors</u></a></b> v"+ GM_info.script.version +"</div>"
    + '<br><br><h4 style="float:left;">'+CErrSeg[0]+'</h4><div style="clear:both;">'
    + '<input type="checkbox" id="_seg_Bad"'+(WMECErrors.seg_Bad ? ' checked' : '')+'/> '+CErrSeg[1]+'<br><div id="BadSeg" style="margin-left:5px;"><table>';
    CEcontent += fillHtml("seg_Priv",     "seg_Bad","#ff7700","\uf256",CErrSeg[2]);
    CEcontent += fillHtml("seg_Park",     "seg_Bad","#ff0000","\uf288",CErrSeg[3]);
    CEcontent += fillHtml("seg_Rail",     "seg_Bad","#ff0000","\uf238",CErrSeg[4]);
    CEcontent += fillHtml("seg_Dir_name", "seg_Bad","#ff0000","\uf0a9",CErrSeg[6]);
    CEcontent += fillHtml("seg_Toll",     "seg_Bad","#ff0000","\uf155",CErrSeg[10]);
    CEcontent += fillHtml("seg_Ramp_name","seg_Bad","#ff7700","\uf25a",CErrSeg[7]);
    CEcontent += fillHtml("seg_Ramp_city","seg_Bad","#ff0000","\uf015",CErrSeg[11]);
    CEcontent += fillHtml("seg_SNameAlt", "seg_Bad","#ff0000","\uf079",CErrSeg[13]);
    CEcontent += fillHtml("seg_DleSpace", "seg_Bad","#ff0000","\uf101",CErrSeg[9]);
    CEcontent += fillHtml("seg_HW_name",  "seg_Bad","#ff0000","\uf018",CErrSeg[5]);
    CEcontent += fillHtml("seg_RSAlt",    "seg_Bad","#ff0000","\uf074",CErrSeg[12]);
    CEcontent += fillHtml("seg_RShield",  "seg_Bad","#ff0000","\uf152",CErrSeg[8]);
    CEcontent += fillHtml("seg_SegBadRS", "seg_Bad","#ff0000","\uf044",CErrSeg[14]);
    CEcontent += '</table></div></div><br><h4 style="float:left;">'+CErrPoi[0]+'</h4><div style="clear:both;"><tr><td><input type="checkbox" id="_poi_Bad"'+(WMECErrors.poi_Bad ? ' checked' : '')+'/> '+CErrPoi[1]+'<br><div id="BadPoi" style="margin-left:5px;"><table>';
    CEcontent += fillHtml("poi_Address",  "poi_Bad","#ff0000","\uf2bc",CErrPoi[3]);
    CEcontent += fillHtml("poi_LandM",    "poi_Bad","#ff0000","\uf1bb",CErrPoi[5]);
    CEcontent += fillHtml("poi_DleSpace", "poi_Bad","#ff0000","\uf101",CErrPoi[6]);
    CEcontent += fillHtml("poi_Park_name","poi_Bad","#ff0000","\uf288",CErrPoi[2]);
    CEcontent += fillHtml("poi_Park_type","poi_Bad","#ff0000","\uf11d",CErrPoi[12]);
    CEcontent += fillHtml("poi_Entry",    "poi_Bad","#ff7700","\uf18e",CErrPoi[4]);
    CEcontent += fillHtml("poi_Resid",    "poi_Bad","#ff7700","\uf015",CErrPoi[7]);
    CEcontent += fillHtml("poi_Google",   "poi_Bad","#ff7700","\uf1a0",CErrPoi[8]);
    CEcontent += fillHtml("poi_Other",    "poi_Bad","#ff7700","\uf29c",CErrPoi[10]);
    CEcontent += fillHtml("poi_WFeed",    "poi_Bad","#ffcc00","\uf263",CErrPoi[9]);
    CEcontent += fillHtml("poi_WPark",    "poi_Bad","#ffcc00","\uf263",CErrPoi[11]);
    CEcontent += '</table></div></div><br><h4 style="float:left;">'+CErrLeg[0]+'</h4><div style="clear:both;">';
    CEcontent += '<table><tr><td><div style="margin:5px;width:30px;height:2px;background-color:#ff0000;"></div></td><td>'+CErrLeg[1]+'</td></tr>';
    CEcontent += '<tr><td><div style="margin:5px;width:30px;height:2px;background-color:#ff7700;"></div></td><td>'+CErrLeg[2]+'</td></tr>';
    CEcontent += '<tr><td><div style="margin:5px;width:30px;height:2px;background-color:#ffcc00;"></div></td><td>'+CErrLeg[3]+'</td></tr></table></div>';
    CEaddon.innerHTML=CEcontent;
    CEaddon.className='tab-pane';
    CErrorshandleClass2.appendChild(CEaddon);

    getId('_seg_Bad').onclick=(function(){
        var ls=JSON.parse(localStorage.WMEColorErrors);
        if (getId('_seg_Bad').checked === true) {
            for (var i=0; getElementsByClassName('_seg', BadSeg) [i]; i++) getElementsByClassName('_seg', BadSeg) [i].disabled=false;
            ls.seg_Bad=true;
        }
        else {
            for (var i=0; getElementsByClassName('_seg', BadSeg) [i]; i++) getElementsByClassName('_seg', BadSeg) [i].disabled=true;
            ls.seg_Bad=false;
        }
        localStorage.setItem('WMEColorErrors', JSON.stringify(ls));
        CErrColor();
    });
    getId('_poi_Bad').onclick=(function(){
        var ls=JSON.parse(localStorage.WMEColorErrors);
        if (getId('_poi_Bad').checked === true) {
            for (var i=0; getElementsByClassName('_poi', BadPoi) [i]; i++) getElementsByClassName('_poi', BadPoi) [i].disabled=false;
            ls.poi_Bad=true;
        }
        else {
            for (var i=0; getElementsByClassName('_poi', BadPoi) [i]; i++) getElementsByClassName('_poi', BadPoi) [i].disabled=true;
            ls.poi_Bad=false;
        }
        localStorage.setItem('WMEColorErrors', JSON.stringify(ls));
        CErrColor();
    });
    getId('_seg_Priv').onclick=(function(){      var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_Priv').checked === true) ? ls.seg_Priv=true : ls.seg_Priv=false;                localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_Park').onclick=(function(){      var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_Park').checked === true) ? ls.seg_Park=true : ls.seg_Park=false;                localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_Rail').onclick=(function(){      var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_Rail').checked === true) ? ls.seg_Rail=true : ls.seg_Rail=false;                localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_HW_name').onclick=(function(){   var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_HW_name').checked === true) ? ls.seg_HW_name=true : ls.seg_HW_name=false;       localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_Dir_name').onclick=(function(){  var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_Dir_name').checked === true) ? ls.seg_Dir_name=true : ls.seg_Dir_name=false;    localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_Toll').onclick=(function(){      var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_Toll').checked === true) ? ls.seg_Toll=true : ls.seg_Toll=false;                localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_Ramp_name').onclick=(function(){ var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_Ramp_name').checked === true) ? ls.seg_Ramp_name=true : ls.seg_Ramp_name=false; localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_Ramp_city').onclick=(function(){ var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_Ramp_city').checked === true) ? ls.seg_Ramp_city=true : ls.seg_Ramp_city=false; localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_RShield').onclick=(function(){   var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_RShield').checked === true) ? ls.seg_RShield=true : ls.seg_RShield=false;       localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_RSAlt').onclick=(function(){     var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_RSAlt').checked === true) ? ls.seg_RSAlt=true : ls.seg_RSAlt=false;             localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_SNameAlt').onclick=(function(){  var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_SNameAlt').checked === true) ? ls.seg_SNameAlt=true : ls.seg_SNameAlt=false;    localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_DleSpace').onclick=(function(){  var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_DleSpace').checked === true) ? ls.seg_DleSpace=true : ls.seg_DleSpace=false;    localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_seg_SegBadRS').onclick=(function(){  var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_seg_SegBadRS').checked === true) ? ls.seg_SegBadRS=true : ls.seg_SegBadRS=false;    localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_Park_name').onclick=(function(){ var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_Park_name').checked === true) ? ls.poi_Park_name=true : ls.poi_Park_name=false; localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_Park_type').onclick=(function(){ var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_Park_type').checked === true) ? ls.poi_Park_type=true : ls.poi_Park_type=false; localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_Address').onclick=(function(){   var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_Address').checked === true) ? ls.poi_Address=true : ls.poi_Address=false;       localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_Entry').onclick=(function(){     var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_Entry').checked === true) ? ls.poi_Entry=true : ls.poi_Entry=false;             localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_LandM').onclick=(function(){     var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_LandM').checked === true) ? ls.poi_LandM=true : ls.poi_LandM=false;             localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_DleSpace').onclick=(function(){  var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_DleSpace').checked === true) ? ls.poi_DleSpace=true : ls.poi_DleSpace=false;    localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_Resid').onclick=(function(){     var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_Resid').checked === true) ? ls.poi_Resid=true : ls.poi_Resid=false;             localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_Google').onclick=(function(){    var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_Google').checked === true) ? ls.poi_Google=true : ls.poi_Google=false;          localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_WFeed').onclick=(function(){     var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_WFeed').checked === true) ? ls.poi_WFeed=true : ls.poi_WFeed=false;             localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_WPark').onclick=(function(){     var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_WPark').checked === true) ? ls.poi_WPark=true : ls.poi_WPark=false;             localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });
    getId('_poi_Other').onclick=(function(){     var ls=JSON.parse(localStorage.WMEColorErrors); (getId('_poi_Other').checked === true) ? ls.poi_Other=true : ls.poi_Other=false;             localStorage.setItem('WMEColorErrors', JSON.stringify(ls)); CErrColor(); });

    //window.setInterval(checkClicLayer, 500);
    CErrWaze.selectionManager.events.register("selectionchanged", null, CErrColor);
    CErrorsModel.actionManager.events.register("afterclearactions", null, CErrColor);
    CErrorsModel.actionManager.events.register("afterundoaction", null, CErrColor);
    CErrorsMap.events.register("zoomend", null, CErrColor);
    CErrorsMap.events.register("moveend", null, CErrColor);
    window.setTimeout(CErrColor, 500);
}
function fillHtml(id,type,color,icon,text) {
    var WMECErrors=JSON.parse(localStorage.getItem('WMEColorErrors'));
    return '<tr style="line-height:14px;"><td style="width:20px;"><input type="checkbox" class="'+(type==="seg_Bad" ? '_seg' : '_poi')+'" id="_'+id+'"'+(WMECErrors[id] ? ' checked' : '')+(WMECErrors[type] ? '' : ' disabled')+'/></td><td style="width:20px;"><font style="color:'+color+';font-family:FontAwesome;">'+icon+'</font></td><td><label for="_'+id+'" style="font-weight:normal;">'+text+'</label></td></tr>';
}
function checkClicLayer(){
    var lieu=CErrorsI18n.translations[CErrorsI18n.locale].layers.name.landmarks;
    getId('layer-switcher-'+CErrorsMap.getLayersByName(lieu)[0].id).onclick=(function(){
        window.setTimeout((function() {
            CErrColor();
        }),10);
    });
}
function addIcon(icon,color,geometry,type) {
    var style = {
        fill: false,
        stroke: false,
        label: icon,
        labelAlign: "cb",
        labelXOffset: -4,
        labelYOffset: 8,
        fontColor: color,
        fontSize:"20px",
        fontOpacity: 0.85,
        fontFamily: "FontAwesome",
        labelOutlineWidth: 2,
        zIndex: 99999
    };
    if (type==="segment") {
        if(geometry.length==2){
            var midX = (((geometry[0].x + geometry[1].x) / 2) + geometry[0].x) / 2;
            var midY = (((geometry[0].y + geometry[1].y) / 2) + geometry[0].y) / 2;
            var labelPoint = new CErrorsOpenLayers.Geometry.Point(midX,midY);
            var imageFeature = new CErrorsOpenLayers.Feature.Vector(labelPoint, null, style);
            ColorErrors_mapLayer.addFeatures([imageFeature]);
        }
        else {
            for(i=0;i<geometry.length-1;i++){
                if(i%3==1){
                    var midX = (((geometry[i].x + geometry[i+1].x) / 2) + geometry[i].x) / 2;
                    var midY = (((geometry[i].y + geometry[i+1].y) / 2) + geometry[i].y) / 2;
                    var labelPoint = new CErrorsOpenLayers.Geometry.Point(midX,midY);
                    var imageFeature = new CErrorsOpenLayers.Feature.Vector(labelPoint, null, style);
                    ColorErrors_mapLayer.addFeatures([imageFeature]);
                }
            }
        }
    }
    else {
        var midX = (((geometry.left + geometry.right) / 2) + geometry.right) / 2;
        var midY = (((geometry.bottom + geometry.top) / 2) + geometry.bottom) / 2;
        var labelPoint = new CErrorsOpenLayers.Geometry.Point(midX,midY);
        var imageFeature = new CErrorsOpenLayers.Feature.Vector(labelPoint, null, style);
        ColorErrors_mapLayer.addFeatures([imageFeature]);
    }
}
function CErrColor(){
    var lineFeature=[], ls=JSON.parse(localStorage.WMEColorErrors);
    var lieu=CErrorsI18n.translations[CErrorsI18n.locale].layers.name.landmarks;

    // Initialize layer
    try { ColorErrors_mapLayer.destroyFeatures(); }
    catch(err){ log('err destroyFeatures: ',err); }

    //Segments Checking
    if (ls.seg_Bad) {
        for (var seg in CErrorsModel.segments.objects) {
            // Get values
            var segment=CErrorsModel.segments.get(seg);
            var attributes=segment.attributes;
            var geometry=attributes.geometry.components;
            var line=getId(segment.geometry.id);
            if (typeof (segment)==='undefined' || line === null || segment.state == "Update" || segment.selected == true) continue;
            //Name
            var sid=attributes.primaryStreetID;
            var street=CErrorsModel.streets.get(sid);
            if (typeof (street)==='undefined') continue;
            //Alt Name
            var salt=attributes.streetIDs[0];
            var streetalt=CErrorsModel.streets.get(salt);
            if (streetalt) { var altname=streetalt.name; } else { var altname=""; }
            //City
            var streetCity = CErrorsModel.cities.get(street.cityID);
            if (typeof (streetCity)==='undefined') continue;
            streetCity = streetCity.attributes.name;

            var roadType=attributes.roadType;
            if (attributes.primaryStreetID === null || attributes.primaryStreetID === undefined) continue;
            if (CErrorsModel.streets.get(attributes.primaryStreetID) === null || CErrorsModel.streets.get(attributes.primaryStreetID) === undefined) continue;
            var newWidth="", newColor="", newOpacity="0", gline="";

            if (ls.seg_Ramp_city) { // Ramp/Freeway with city name
                if (streetCity && /^(3|4)$/.test(attributes.roadType)) {
                    newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf015",newColor,geometry,"segment");
                }
            }
            if (street.name || altname) {
                if (/( - )/.test(street.name)) { var trs=street.name.split(" - "); }
                // Segments with bad name
                /*if (/^(3|4|5|6|8|10|16|17|19)$/.test(attributes.roadType)===false && /^[A|C|D|N|M|R][0-9]+[a-z]?[0-9]?/.test(trs[0].replace(".",""))===false && /(^Le |^La |^Les |Allée |[ ]?Avenue[]?|Boulevard |Chemin |Cité |Clos |Côte |Cour[s]? |Domaine |Faubourg |Hameau |Impasse |Levée |Lotissement |Mail |Montée |Parc |Passage |Place |Pont |Porte |Promenade |Quai |Résidence[s]? |Route |[ ]?Rue[ ]?|Ruelle |Sente |Sentier |Square |Traverse |Villa |Voie )/.test(street.name)===false) {
                    newColor="#ff7700"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices();
                }*/
                if (ls.seg_Priv) { // Private with bad name
                    if (attributes.roadType===17 && /^(^Le |^La |^Les |Grande |Allée |[ ]?Avenue[]?|Boulevard |Chemin |Cité |Clos |Côte |Cour[s]? |Domaine |Hameau |Impasse |Levée |Lotissement |Mail |Montée |Parc |Passage |Place |Pont |Promenade |Quai |Résidence[s]? |Route |[ ]?Rue[ ]?|Ruelle |Sente |Sentier |Square |Traverse |Venelle |Villa |Voie )/.test(street.name)===false) {
                        newColor="#ff7700"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf256",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_Park && street.name) { // Parking with name (But Place / Square)
                    if (attributes.roadType===20 && /^(Place |Square )/.test(street.name)===false) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf288",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_Rail && street.name) { // Railroad with bad name
                    if (attributes.roadType===18 && (altname || street.name)) { //Railroad with name
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf238",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_Ramp_name && street.name) {
                    if (/^(3|4)$/.test(attributes.roadType) && /\/.*\//.test(street.name)) { // Ramp with 3 directions or more
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf25b",newColor,geometry,"segment");
                    }
                    else if (/^(3|4)$/.test(attributes.roadType) && /\//.test(street.name)) {  // Ramp with 2 directions
                        newColor="#ff7700"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf25a",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_Dir_name && street.name) { // Directions but not Ramp/Freeway/Major
                    if (/^[^3|4|6]$/.test(attributes.roadType) && /[:|>]/.test(street.name)) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf0a9",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_Toll) { // Toll but not Ramp/Freeway
                    if (/^[^3|4]$/.test(attributes.roadType) && (attributes.fwdToll || attributes.revToll)) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf155",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_RSAlt && street.name) { // RoadShield must be in alt
                    if (attributes.roadType!=19 && trs
                        && /^[A|C|D|N|M|R][0-9]+[a-z]?[0-9]?/.test(trs[0].replace(".",""))===true // Roadshield (1st part)
                        &&  / - /.test(street.name)===true // Roadshield & street name (separator -)
                        && /Intérieure|Extérieure/.test(trs[1])===false
                        && streetCity // City ok
                       ) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf074",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_HW_name && street.name) { // Highways with bad name
                    if (/^(3|4|6)$/.test(attributes.roadType) && (/:/.test(street.name)===true && /^[A|C|D|N|M|R][0-9]+[a-z]?[0-9]?/.test(street.name)===false) && /^>/.test(street.name)===false && /^[Sortie ]+[0-9]+/.test(street.name)===false && /^(Rocade|Périphérique)/.test(street.name)===false) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf018",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_SegBadRS && street.name) { // RoadShield but bad type
                    if (/^(1|8|17|20|999)$/.test(attributes.roadType) && (/^[A|C|D|N|M|R][0-9]+/.test(street.name) || /^[A|C|D|N|M|R]$/.test(street.name))) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf044",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_RShield && street.name) { // Wrong prefix (RoadShield)
                    if (trs && attributes.roadType!=19 && /^[A|C|D|N|M|R][0-9]+[a-z]?[0-9]?/.test(trs[0].replace(".",""))===false &&  / - /.test(street.name)===true) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf152",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_SNameAlt && street.name) { // Street Name must be in alt
                    if (attributes.roadType!=19 && trs
                        && /^[A|C|D|N|M|R][0-9]+[a-z]?[0-9]?/.test(trs[0].replace(".",""))===true // Roadshield (1st part)
                        && /^[E][0-9]/.test(trs[1])===false // European Roadshield (2nd part)
                        && /Périphérique|Rocade|Duplex/.test(street.name)===false // Exception
                        && / - /.test(street.name)===true // Roadshield & street name (separator -)
                        && /Intérieure|Extérieure/.test(trs[1])===false
                        && !streetCity // No city
                       ) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf079",newColor,geometry,"segment");
                    }
                }
                if (ls.seg_DleSpace && street.name) { // Double spacing in name
                    if (/  /.test(street.name)===true) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices(); addIcon("\uf101",newColor,geometry,"segment");
                    }
                }
            }
            // Highlight if error
            if (gline !== "") {
                var style={
                    strokeWidth: newWidth,
                    strokeColor: newColor,
                    strokeOpacity: newOpacity
                };
                var points=[];
                for (var i=0; i<gline.length; i++) { points.push(new CErrorsOpenLayers.Geometry.Point(gline[i].x, gline[i].y)); }
                var newline=new CErrorsOpenLayers.Geometry.LineString(points);
                lineFeature.push(new CErrorsOpenLayers.Feature.Vector(newline, null, style));
            }
        }
    }

    //Places Checking
    if (ls.poi_Bad && getId(CErrorsMap.getLayersByName(lieu)[0].id).style.display==="block") {
        for (var poi in CErrorsModel.venues.objects) {
            // Get values
            var venue=CErrorsModel.venues.get(poi);
            var pattributes=venue.attributes;
            var geometry=pattributes.geometry.bounds;
            var poly=pattributes.id;
            if (typeof (venue)==='undefined' || poly === null || poi.state=="Update" || poi.selected) continue;
            var categories=pattributes.categories;
            var pname=pattributes.name;
            var venueStreet=CErrorsModel.streets.get(pattributes.streetID);
            if (venueStreet) { var venueCity = CErrorsModel.cities.get(venueStreet.cityID); }
            var newWidth="", newColor="", newOpacity="0", gpoly="";

            if (ls.poi_Resid) { // maybe a residential POI
                if ((/^[0-9][ ]?[a-zA-Z]/.test(pname)===true || /^(Allée |Avenue |Boulevard |Chemin |Clos |Côte |Cours |Faubourg |Hameau |Impasse |Lotissement |Mail |Passage |Porte |Promenade |Quai |Route |Rue |Ruelle |Sente |Sentier |Voie )/.test(pname)===true) && pattributes.residential===false && pattributes.categories.indexOf("PARKING_LOT")===-1) {
                    newColor="#ff7700"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    if (venue.isPoint()) { newWidth=26; }
                    addIcon("\uf015",newColor,geometry,"venue");
                }
            }
            if (ls.poi_Google) { //POI without Google link
                if (pattributes.externalProviderIDs.length===0 && pattributes.residential===false && /(RIVER_STREAM|CANAL|SEA_LAKE_POOL|SWAMP_MARSH|ISLAND|FOREST_GROVE|BRIDGE|SWAMP_MARSH|PARK|JUNCTION_INTERCHANGE|CEMETERY)/.test(categories)===false) {
                    newColor="#ff7700"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    if (venue.isPoint()) { newWidth=26; }
                    addIcon("\uf1a0",newColor,geometry,"venue");
                }
            }
            if (ls.poi_Other) { // Place type is "Other"
                if (categories.indexOf("OTHER") > -1) {
                    newColor="#ff7700"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    if (venue.isPoint()) { newWidth=26; }
                    addIcon("\uf29c",newColor,geometry,"venue");
                }
            }
            if (ls.poi_Entry) { // POI with default entryExitPoints
                if (/(BRIDGE|CANAL|FOREST_GROVE|ISLAND|JUNCTION_INTERCHANGE|PARK|POOL|RIVER_STREAM|SEA_LAKE_POOL|SWAMP_MARSH|TUNNEL)/.test(categories)===false && pattributes.entryExitPoints.length===0 && venue.isPoint()===false) {
                    newColor="#ff7700"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    addIcon("\uf18e",newColor,geometry,"venue");
                }
            }
            if (ls.poi_Park_name && categories.indexOf("PARKING_LOT") > -1) { // Parking with bad name
                if (/(Allée |Avenue |Boulevard |Chemin |Clos |Côte |Cours |Faubourg |Hameau |Impasse |Lotissement |Mail |Passage |Place | Porte |Promenade |Quai |Route |Rue |Ruelle |Sente |Sentier |Voie )/.test(pname)===true && /^(?️ |Parking )/.test(pname)===true) { continue; } //If parking name is a road
                if (/^(?️|Parking[s]?)$/.test(pname)===true || // Only ?️ or Parkings
                    /^(?️ |Parking )/.test(pname)===false || // Don't start by ?️ or Parking
                    /^(?️|Parking[s]?)( de[s]? | du | le[s]? | la | pour )/.test(pname)===true // Contain bad words
                   ) {
                    newColor="#ff0000"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    addIcon("\uf288",newColor,geometry,"venue");
                }
                else if (pname==="") {
                    newColor="#ff7700"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    addIcon("\uf288",newColor,geometry,"venue");
                }
                if (venue.isPoint()) newWidth=26;
            }
            if (ls.poi_Park_type && categories.indexOf("PARKING_LOT") > -1) { // Parking with type undefined
                if (/PUBLIC|RESTRICTED|PRIVATE/.test(pattributes.categoryAttributes.PARKING_LOT.parkingType)===false) {
                    newColor="#ff0000"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    addIcon("\uf11d",newColor,geometry,"venue");
                }
            }
            if (ls.poi_Address) { // POI with bad address (Nxxx/Dxxx) or without address
                if (typeof (venueStreet)!='undefined' && ((/^[A|D|N|M|R][0-9]+/.test(venueStreet.name) && /[ - ]/.test(venueStreet.name)) || typeof (venueStreet.name)==='undefined')) {
                    newColor="#ff0000"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    if (venue.isPoint()) { newWidth=26; }
                    addIcon("\uf2bc",newColor,geometry,"venue");
                }
            }
            if (ls.poi_LandM) { // Landmark with road name or city name
                if (/(RIVER_STREAM|CANAL|SEA_LAKE_POOL|POOL|SWAMP_MARSH|ISLAND|FOREST_GROVE|BRIDGE)/.test(categories) && pname==="" && ((venueStreet && venueStreet.name) || (venueCity && venueCity.attributes.name))) {
                    newColor="#ff0000"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    if (venue.isPoint()) { newWidth=26; }
                    addIcon("\uf1bb",newColor,geometry,"venue");
                }
            }
            if (ls.poi_DleSpace) { // Double spacing in name
                if (venueStreet && (/  /.test(venueStreet.name)===true || /  /.test(pname)===true)) {
                    newColor="#ff0000"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    addIcon("\uf101",newColor,geometry,"venue");
                    if (venue.isPoint()) { newWidth=26; }
                }
            }
            if (ls.poi_WFeed || ls.poi_WPark) { //Place updated by WazeFeed
                if (pattributes.updatedBy && CErrorsModel.users.get(pattributes.updatedBy)) {
                    var updName = CErrorsModel.users.get(pattributes.updatedBy).userName;
                    if (((ls.poi_WFeed && updName=="WazeFeed") || (ls.poi_WPark && updName=="WazeParking1")) && pattributes.residential===false) {
                        newColor="#ffcc00"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                        if (venue.isPoint()) { newWidth=26; newOpacity=0.75; }
                        addIcon("\uf263",newColor,geometry,"venue");
                    }
                }
            }
            // Highlight if error
            if (gpoly!=="") {
                var style={
                    strokeWidth: newWidth,
                    strokeColor: newColor,
                    strokeOpacity: newOpacity,
                    fillOpacity: 0
                };
                var points=[];
                for (var i=0; i<gpoly.length; i++) { points.push(new CErrorsOpenLayers.Geometry.Point(gpoly[i].x, gpoly[i].y)); }
                var newpoly=new CErrorsOpenLayers.Geometry.LinearRing(points);
                lineFeature.push(new CErrorsOpenLayers.Feature.Vector(newpoly, null, style));
            }
        }
    }

    // Display highlighted features
    try{ ColorErrors_mapLayer.addFeatures(lineFeature); }
    catch(err){ log('err addFeatures: ',err); }
}
CErrors_bootstrap();