WME Color Errors

Adds colours to show errors

目前為 2017-02-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name             WME Color Errors
// @name:fr          WME Color Errors
// @version          0.27
// @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
        // 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 layers=CErrorsMap.getLayersBy("uniqueName","__WME_Color_Errors");
    if(layers.length === 0) {
        var ColorErrors_style=new CErrorsOpenLayers.Style({
            pointRadius: 2,
            fontWeight: "normal",
            label : "${labelText}",
            fontFamily: "Tahoma, Courier New",
            labelOutlineColor: "#FFFFFF",
            labelOutlineWidth: 2,
            fontColor: '#000000',
            fontSize: "10px"
        });

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

    }
    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',
                          'Parking avec un nom (sauf Place & Square)',
                          'Voie ferrée avec nom 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'
                         );
        CErrPoi=new Array('Contrôle des places',
                          'Mauvaise places',
                          'Parking nommé [P] 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'
                         );
        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 (But Place / Square)',
                          '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'
                         );
        CErrPoi=new Array('Places Checking',
                          'Bad Places',
                          'Parking named [P] 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 red='<div style="width:8px;height:8px;border-radius:4px;background-color:#ff0000;margin-right:2px;"></div>';
    var ora='<div style="width:8px;height:8px;border-radius:4px;background-color:#ff7700;margin-right:2px;"></div>';
    var yel='<div style="width:8px;height:8px;border-radius:4px;background-color:#ffcc00;margin-right:2px;"></div>';
    CEaddon.innerHTML="<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>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_Priv"     '+(WMECErrors.seg_Priv      ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+ora+'</td><td>'+CErrSeg[2]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_Park"     '+(WMECErrors.seg_Park      ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[3]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_Rail"     '+(WMECErrors.seg_Rail      ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[4]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_HW_name"  '+(WMECErrors.seg_HW_name   ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[5]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_Dir_name" '+(WMECErrors.seg_Dir_name  ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[6]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_Toll"     '+(WMECErrors.seg_Toll      ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[10]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_Ramp_name"'+(WMECErrors.seg_Ramp_name ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+ora+'</td><td>'+CErrSeg[7]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_Ramp_city"'+(WMECErrors.seg_Ramp_city ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[11]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_RShield"  '+(WMECErrors.seg_RShield   ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[8]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_RSAlt"    '+(WMECErrors.seg_RSAlt     ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[12]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_SNameAlt" '+(WMECErrors.seg_SNameAlt  ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[13]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_seg" id="_seg_DleSpace" '+(WMECErrors.seg_DleSpace  ? ' checked' : '')+(WMECErrors.seg_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrSeg[9]+'</td></tr></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>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_Address"  '+(WMECErrors.poi_Address   ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrPoi[3]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_LandM"    '+(WMECErrors.poi_LandM     ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrPoi[5]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_DleSpace" '+(WMECErrors.poi_DleSpace  ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+red+'</td><td>'+CErrPoi[6]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_Park_name"'+(WMECErrors.poi_Park_name ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+red+ora+'</td><td>'+CErrPoi[2]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_Entry"    '+(WMECErrors.poi_Entry     ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+ora+'</td><td>'+CErrPoi[4]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_Resid"    '+(WMECErrors.poi_Resid     ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+ora+'</td><td>'+CErrPoi[7]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_Google"   '+(WMECErrors.poi_Google    ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+ora+'</td><td>'+CErrPoi[8]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_Other"    '+(WMECErrors.poi_Other     ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+ora+'</td><td>'+CErrPoi[10]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_WFeed"    '+(WMECErrors.poi_WFeed     ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+yel+'</td><td>'+CErrPoi[9]+'</td></tr>'
        + '<tr><td><input type="checkbox" class="_poi" id="_poi_WPark"    '+(WMECErrors.poi_WPark     ? ' checked' : '')+(WMECErrors.poi_Bad ? '' : ' disabled')+'/></td><td>'+yel+'</td><td>'+CErrPoi[11]+'</td></tr></table></div></div>'
        + '<br><h4 style="float:left;">'+CErrLeg[0]+'</h4><div style="clear:both;">'
        + '<table><tr><td><div style="margin:5px;width:30px;height:2px;background-color:#ff0000;"></div></td><td>'+CErrLeg[1]+'</td></tr>'
        + '<tr><td><div style="margin:5px;width:30px;height:2px;background-color:#ff7700;"></div></td><td>'+CErrLeg[2]+'</td></tr>'
        + '<tr><td><div style="margin:5px;width:30px;height:2px;background-color:#ffcc00;"></div></td><td>'+CErrLeg[3]+'</td></tr></table></div>'
    ;
    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('_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_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 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 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 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();
                }
            }
            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 |Villa |Voie )/.test(street.name)===false) {
                        newColor="#ff7700"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices();
                    }
                }
                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();
                    }
                }
                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();
                    }
                }
                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();
                    }
                }
                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();
                    }
                    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();
                    }
                }
                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();
                    }
                }
                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();
                    }
                }
                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();
                    }
                }
                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 -)
                        && streetCity // City ok
                       ) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices();
                    }
                }
                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/.test(street.name)===false // Exception
                        && / - /.test(street.name)===true // Roadshield & street name (separator -)
                        && !streetCity // No city
                       ) {
                        newColor="#ff0000"; newWidth=3; newOpacity=0.95; gline=segment.attributes.geometry.getVertices();
                    }
                }
                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();
                    }
                }
            }
            // 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 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) {
                    newColor="#ff7700"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                    if (venue.isPoint()) newWidth=26;
                }
            }
            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;
                }
            }
            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;
                }
            }
            if (ls.poi_Entry) { // POI with default entryExitPoints
                if (/(BRIDGE|CANAL|FOREST_GROVE|ISLAND|JUNCTION_INTERCHANGE|PARK|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();
                }
            }
            if (ls.poi_WFeed || ls.poi_WPark) { //Place updated by WazeFeed
                var pUpd=pattributes.updatedBy;
                if (pUpd) { var updName = CErrorsModel.users.get(pUpd).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; }
                }
            }
            if (ls.poi_Park_name && categories.indexOf("PARKING_LOT") > -1  && pattributes.residential===false) { // Parking named [P] or null
                if (pname.indexOf("[P]") > -1) {
                    newColor="#ff0000"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                }
                else if (pname==="") {
                    newColor="#ff7700"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                }
                if (venue.isPoint()) newWidth=26;
            }
            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) || typeof (venueStreet.name)==='undefined')) {
                    newColor="#ff0000"; newWidth=15; newOpacity=0.5; gpoly=pattributes.geometry.getVertices();
                }
                if (venue.isPoint()) newWidth=26;
            }
            if (ls.poi_LandM) { // Landmark with road name or city name
                if (/(RIVER_STREAM|CANAL|SEA_LAKE_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 (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();
                }
                if (venue.isPoint()) newWidth=26;
            }
            // 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();