WME DOT Advisories

Overlay DOT Advisories on the WME Map Object

// ==UserScript==
// @name         WME DOT Advisories
// @namespace    https://greasyfork.org/en/users/668704-phuz
// @require      https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @version      1.93
// @description  Overlay DOT Advisories on the WME Map Object
// @author       phuz
// @include      /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
// @require      http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/tablesort.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/sorts/tablesort.number.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/tablesort/5.2.1/sorts/tablesort.date.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js
// @grant        GM_xmlhttpRequest
// @grant        GM_info
// @grant        GM_fetch
// @grant        GM_addStyle
// @connect      511nj.org
// @connect      511ny.org
// @connect      511pa.com
// @connect      511wi.gov
// @connect      arcgis.com
// @connect      deldot.gov
// @connect      essentialintegrations.com
// @connect      fl511.com
// @connect      md.gov
// @connect      mi.us
// @connect      ohgo.com
// @connect      rehostjson.phuz.repl.co
// @connect      tripcheck.com
// @connect      iteris-atis.com
// @connect      carsprogram.org
// @connect      phoenix.gov
// @connect      511virginia.org
// @connect      72.167.49.86
// @connect      72.167.49.86
// @connect      ncdot.gov
/* global OpenLayers */
/* global W */
/* global WazeWrap */
/* global $ */
/* global I18n */
/* global _ */
/* global MutationObserver */
/* global localStorage */

// ==/UserScript==

let promises = {};
let advisories = {};
let feeds = {};
let endpointsLayer;
let settings, settingID;
var loadedSettings = {}, localsettings = {};
let mapBounds;
let state, stateLength;
const updateMessage = "► Fixed stuff that the last release broke.";
const DEIconC = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAGXRFWHRTb2Z0d2Fy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FyhqY6W7C4wvdzm4zmH5nMevXP1/p7vHwcXs1K8t24KqqFZeOtwjgahenrZUBCC14wT88uc5p2TBMTsy4aVtBPSvAiwEwDcI7BSxtpd9OhCr0/l0Oxdtwbq2sz2F9TErgEUXQgRQiSyf4VErgzaEZm0JZ56FH8X2liQbEEiTfE3dljJt+A51ITtXwAqZV0a8tROnJZTzwWwWtMvzY20dHX5MgZgvxa9ZfKmbhK334YQPYJhJJTrWDoWpUYrRssh6dWIDAZFgx8LEfmkPT8BCudwSmOeolnfG6rov1gQT535+/OIoJgVcctZkRMakUgMA36ZVO4PUpl7JNQjfF3B5gBUR3hGE1dReEgX1xwSTpZkFnODMIk+cTLQ9ADANqzqegBynrj75U8VunJtFZHodOSiJArLsa1ZWBMiRJpr+KoOIiIsTarfI5l3MKygWxA/MONRjpeDpbCulQP6uhJQTrL73DacHBvrg/h80emLQ9u6JSkX6iPDlB6RVL3l/akVmzBpmOnV6HSOA62sk1PtDn5O/xaE1wHmHNrwl2faEIZu+w6fuV/R87d+jAaNBodGmTWqkZ6PabXbw3ltLab3iNd85pRpTO+O5F99Kb7BrbuNLX8KMABsAtMAoTJBEwAAAABJRU5ErkJggg==';
const endpointMarker = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIZSURBVEhLtZZNSwJRGIVflf6AkGFEHwgJugjbtHDRol/QxpAE921qE0X76GcEQfS1bNXGiKDog6RFbWsRFJjI1K6auZ1zxxGrO5bDdOARHZ1z7tz73vcakc7qBwUwBbKgF1DP4AZUwC54AEb5BdB4FcyCnnhcZGxMJJnkVyJPTyLX1yL1uv74AbbACvANatc0aESjogoFUUdHomxblFJf4bXjY1HFoij+FvdYgE/bUXPATqVEnZz8NPXj7EzU6KgOccA8jUziyO2JCVF4dKNRJxoNUfl8K2SGhu3inDc48iDmHgxJp3XICxiksad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DRuXw2IhAg+CSLkp1wCG31fB6A0jilLrva6g7r3EaDU7MVEGi72yX1mNwJj8CAgpiOFV/+FhIRADs=';
const NJURLDetail = 'https://511nj.org/API/client/Map/getEventPopupData?EventId=';
const NotNY = ['Pennsylvania Statewide', 'New Jersey Statewide', 'Connecticut Statewide'];
const NJConstruction = ['Construction', 'ScheduledConstruction'];

//Begin script function
(function () {
    'use strict';
    //Bootstrap
    function bootstrap(tries = 1) {
        if (W && W.loginManager && W.map && W.loginManager.user && W.model && W.model.states && W.model.states.getObjectArray().length && WazeWrap && WazeWrap.Ready) {
            console.log("WME DOT Advisories Loaded!");
            init();
            addListeners();
            if (!OpenLayers.Icon) {
                installIcon();
            }
        } else if (tries < 1000) {
            setTimeout(function () { bootstrap(++tries); }, 200);
        }
    }
    // Function.prototype.bind = function (thisObject) {
    //     var method = this;
    //     var oldargs = [].slice.call(arguments, 1);
    //     return function () {
    //         var newargs = [].slice.call(arguments);
    //         return method.apply(thisObject, oldargs.concat(newargs));
    //     };
    // }
    //Build the Tab and Settings Division
    function init() {
        var $section = $('<div id="WMEDOTAdvisoriesPanel">');
        $section.html([
            '<div id="chkAdvisoryEnables">',
            '<a href="https://www.waze.com/forum/viewtopic.php?f=819&t=308141" target="_blank">WME DOT Advisories</a> v' + GM_info.script.version + '<br>',
            '* The WME Refresh Button will update reports.',
            '<div id="chkSettings">',
            '<table border=1 style="text-align:center;width:90%;padding:10px;">',
            '<tr><td width=20% style="text-align:center"><b>Enable</b></td><td style="text-align:center"><b>Setting</b></td></tr>',
            '<tr><td align=center><input type="checkbox" id="chkDOTHideZoomOut" class="wmeDOTSettings"></td><td align=center>',
            'Hide at zoom: <select class="wmeDOTSettings" id="valueHideZoomLevel">',
            '<option value=12>12</option>',
            '<option value=13>13</option>',
            '<option value=14>14</option>',
            '<option value=15>15</option>',
            '<option value=16>16</option>',
            '<option value=17>17</option>',
            '<option value=18>18</option>',
            '</select>or lower',
            '</td></tr>',
            '</table>',
            '</div><br>',
            '<table border=1 style="text-align:center;width:90%;padding:10px;">',
            '<tr><td width=20% style="text-align:center"><b>Enable</b></td><td style="text-align"><b>State</b></td><td width=15%><b>Rpt</b></td></tr>',
            '<tr><td><input type="checkbox" id="chkAKDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>AK</td><td><div class=DOTreport data-report="report" data-state="Alaska" id="AK"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkAZDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>AZ</td><td><div class=DOTreport data-report="report" data-state="Arizona" id="AZ"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkCTDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>CT</td><td><div class=DOTreport data-report="report" data-state="Connecticut" id="CT"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkDEDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>DE</td><td><div class=DOTreport data-report="report" data-state="Delaware" id="DE"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkFLDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>FL</td><td><div class=DOTreport data-report="report" data-state="Florida" id="FL"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkGADOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>GA</td><td><div class=DOTreport data-report="report" data-state="Georgia" id="GA"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkIADOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>IA</td><td><div class=DOTreport data-report="report" data-state="Iowa" id="IA"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkILDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>IL</td><td><div class=DOTreport data-report="report" data-state="Illinois" id="IL"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkINDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>IN</td><td><div class=DOTreport data-report="report" data-state="Indiana" id="IN"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkLADOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>LA</td><td><div class=DOTreport data-report="report" data-state="Louisiana" id="LA"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkMDDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>MD</td><td><div class=DOTreport data-report="report" data-state="Maryland" id="MD"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkMIDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>MI</td><td><div class=DOTreport data-report="report" data-state="Michigan" id="MI"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkMNDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>MN</td><td><div class=DOTreport data-report="report" data-state="Minnesota" id="MN"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkNCDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>NC</td><td><div class=DOTreport data-report="report" data-state="North Carolina" id="NC"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkNJDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>NJ</td><td><div class=DOTreport data-report="report" data-state="New Jersey" id="NJ"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkNVDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>NV</td><td><div class=DOTreport data-report="report" data-state="Nevada" id="NV"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkNYDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>NY</td><td><div class=DOTreport data-report="report" data-state="New York" id="NY"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkOHDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>OH</td><td><div class=DOTreport data-report="report" data-state="Ohio" id="OH"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkORDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>OR</td><td><div class=DOTreport data-report="report" data-state="Oregon" id="OR"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkPADOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>PA</td><td><div class=DOTreport data-report="report" data-state="Pennsylvania" id="PA"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkTXDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>TX (Houston)</td><td><div class=DOTreport data-report="report" data-state="Texas" id="TX"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkVADOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>VA</td><td><div class=DOTreport data-report="report" data-state="Virginia" id="VA"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkWADOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>WA</td><td><div class=DOTreport data-report="report" data-state="Washington" id="WA"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkWIDOTEnabled" class="WMEDOTAdvSettingsCheckbox"></td><td>WI</td><td><div class=DOTreport data-report="report" data-state="Wisconsin" id="WI"><img src=' + reportIcon + '></div></td></tr>',
            '<tr><td><input type="checkbox" id="chkWVDOTEnabled" class="WMEDOTAdvSettingsCheckbox" disabled></td><td>WV</td><td><div class=DOTreport data-report="report" data-state="West Virginia" id="WV"><img src=' + reportIcon + '></div></td></tr>',
            '</table>',
            '</div></div>'
        ].join(' '));
        WazeWrap.Interface.Tab('DOT Advisories', $section.html(), initializeSettings, '<span title="DOT Advisories">DOT Advisories</span>');
        //WazeWrap.Interface.ShowScriptUpdate("WME DOT Advisories", GM_info.script.version, updateMessage, "https://greasyfork.org/en/scripts/412976-wme-dot-advisories", "https://www.waze.com/forum/viewtopic.php?f=819&t=308141");
        getBounds();
        W.map.events.register("moveend", W.map, function () {
            if (localsettings.enabled) {
                getBounds();
                redrawAdvs();
            }
        });
        $('#chkDOTHideZoomOut').change(function () {
            redrawAdvs();
        })
        $('#valueHideZoomLevel').change(function () {
            redrawAdvs();
        })
    }
    function setEnabled(value) {
        localsettings.enabled = value;
        saveSettings();
        const color = value ? '#00bd00' : '#ccc';
        $('span#dot-advisories-power-btn').css({ color });
        for (var i = 0; i < stateLength; i++) {
            state = document.getElementsByClassName("WMEDOTAdvSettingsCheckbox")[i].id.replace("chk", "").replace("DOTEnabled", "");
            W.map.getLayersByName(state + 'DOTLayer')[0]?.setVisibility(value);
        }
    }
    function getBounds() {
        mapBounds = new OpenLayers.Bounds(W.map.getExtent());
        mapBounds = mapBounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:3857"));
        return mapBounds;
    }

    //Load the CSS
    GM_xmlhttpRequest({
        method: "GET",
        url: 'http://72.167.49.86:8080/CSS',
        onload: function (response) {
            var result = response.responseText;
            GM_addStyle(result);
        }
    });

    //Build the State Layers
    function buildDOTAdvLayers(state) {
        const layer = new OpenLayers.Layer.Markers(state.substring(0, 2) + 'DOTLayer');
        W.map.addLayer(layer);
        //W.map.getOLMap().setLayerIndex(eval(state.substring(0, 2) + 'DOTLayer'), 10);
    }
    function redrawAdvs() {
        for (const property in settings) {
            let state = property.replace("chk", "").replace("DOTEnabled", "");
            if (state.length == 2) {
                const layer = W.map.getLayersByName(state + 'DOTLayer')[0];
                if (document.getElementById('chk' + state + 'DOTEnabled').checked && layer) {
                    W.map.removeLayer(layer);
                    buildDOTAdvLayers(state);
                    testAdv(feeds[state], config[state]);
                    if (W.map.getZoom() >= 12) {
                        if (document.getElementById('chkDOTHideZoomOut').checked) {
                            if (W.map.getZoom() > document.getElementById('valueHideZoomLevel').value) {
                                layer.setVisibility(true);
                            } else {
                                layer.setVisibility(false);
                            }
                        } else {
                            layer.setVisibility(true);
                        }
                    } else {
                        layer.setVisibility(false);
                    }
                }
            }
        }
    }
    function testAdv(resultObj, state) {
        let i = 0;
        while (i < resultObj?.length) {
            if ((resultObj[i].lon > mapBounds.left) && (resultObj[i].lon < mapBounds.right)) {
                if ((resultObj[i].lat > mapBounds.bottom) && (resultObj[i].lat < mapBounds.top)) {
                    drawMarkers(resultObj[i]);
                }
            }
            i++;
        }
    }
    function getFeed(url, callback) {
        GM_xmlhttpRequest({
            method: "GET",
            url: url,
            onload: callback_function1.bind({}, callback)
            //onload: function (response) {
            //    var result = response;
            //    callback(result);
            //}
        });
    }
    function callback_function1(callback, response) {
        var result = response;
        setTimeout(function () { callback(result) }, 150);
    }
    const timer = ms => new Promise(res => setTimeout(res, ms))
    function getAdvisories(state, stateAbv, type) {
        promises[stateAbv] = [];
        advisories[stateAbv] = [];
        let thesepromises = [];
        for (let j = 0; j < state.URL.length; j++) {
            let thispromise = new Promise((resolve, reject) => {
                getFeed(state.URL[j], function (result) {
                    let resultObj = [];
                    resultObj = state.data(JSON.parse(result.responseText), j);
                    async function innerLoop() {
                        for (let i = 0; i < resultObj.length; i++) {
                            const filter = state.filters[j];
                            if (!filter || filter(resultObj[i])) {
                                state.scheme(resultObj[i], j);
                            }
                            if (i == (resultObj.length - 1)) {
                                resolve();
                            }
                            await timer(1);
                        }
                        if (resultObj.length == 0) {
                            resolve();
                        }
                    }
                    innerLoop();
                });
            })
            thesepromises.push(thispromise);
        }
        Promise.all(thesepromises).then(function () {
            setTimeout(function () { promiseWorker(stateAbv, type) }, 1000);
        })
    }
    function promiseWorker(stateAbv, type) {
        let thisadvisory = advisories[stateAbv];
        Promise.all(promises[stateAbv])
            .then(function () {
                for (let i = 0; i < thisadvisory.length; i++) {
                    if (type == "report") {
                        let parms = thisadvisory[i];
                        let table = document.getElementById("reportTable").getElementsByTagName('tbody')[0];
                        var row = table.insertRow(-1);
                        var cell1 = row.insertCell(0);
                        var cell2 = row.insertCell(1);
                        var cell3 = row.insertCell(2);
                        var cell4 = row.insertCell(3);
                        cell1.innerHTML = '<div class="gotoPL" data-lat="' + parms.lat + '" data-lon="' + parms.lon + '"><img src=' + PLIcon + '></div>'; //PL
                        cell2.innerHTML = parms.desc;  //Description
                        cell3.innerHTML = parms.title; //Location
                        cell4.innerHTML = parms.time;  //Time
                    } else {
                        //drawMarkers(thisadvisory[i]);
                        feeds[thisadvisory[i].state[0]] = thisadvisory;
                        testAdv(thisadvisory, state);
                    }
                }
                if ((type == "report")) { //Wait until we loop through all the advisory URLs before sorting the table
                    reportWorker();
                }
            });
    }
    function reportWorker() {
        var elements = document.getElementsByClassName("gotoPL");
        for (var i = 0; i < elements.length; i++) {
            elements[i].addEventListener('click', moveMap, false);
        }
        refreshReportTable();
    }
    function refreshReportTable() {
        var sort = new Tablesort(document.getElementById('reportTable'), { descending: true });
        sort.refresh();
        document.getElementById("spinner").style.visibility = "hidden";
    }
    function getReportData(stateAbv, stateName) {
        popupdetails(stateName);
        //if (stateAbv != "NJ") {
        getAdvisories(config[stateAbv], stateAbv, "report");
        //} else { getNJDOT("report"); }
    }

    //Generate the Advisory markers
    function drawMarkers(parms) {
        var icontype;
        var size = new OpenLayers.Size(20, 20);
        var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
        for (let i = 0; i < parms.keyword.length; i++) { //Check each of the keywords for roadwork/construction
            if (parms.type == parms.keyword[i]) {
                icontype = Roadwork;
                break;
            } else {
                icontype = Incident;
            }
        }
        var icon = new OpenLayers.Icon(icontype, size);
        var epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection
        var projectTo = W.map.getProjectionObject(); //The map projection (Spherical Mercator)
        var lonLat = new OpenLayers.LonLat(parms.lon, parms.lat).transform(epsg4326, projectTo);
        var newMarker = new OpenLayers.Marker(lonLat, icon);
        newMarker.eventId = parms.id;
        newMarker.title = parms.title;
        newMarker.desc = parms.desc;
        newMarker.popupType = parms.popupType;
        newMarker.state = parms.state;
        newMarker.timestamp = parms.time;
        newMarker.startTime = parms.startTime;
        newMarker.plannedEndTime = parms.plannedEndTime;
        newMarker.events.register('click', newMarker, popup);
        newMarker.location = lonLat;
        newMarker.recurrence = parms.recurrence;
        if (parms.hasEndpoints) {
            newMarker.fromLon = parms.fromLon;
            newMarker.toLon = parms.toLon;
            newMarker.fromLat = parms.fromLat;
            newMarker.toLat = parms.toLat;
        }
        if (parms.link != '') {
            newMarker.link = '<a href="' + parms.link + '" target="_blank">Publication Link</a>';
        } else {
            newMarker.link = '';
        }
        W.map.getLayersByName(parms.state[0] + "DOTLayer")[0].addMarker(newMarker);
    }

    //Draw the endpoint markers
    function drawEndpoints(lon, lat) {
        var size = new OpenLayers.Size(24, 24);
        var icon = new OpenLayers.Icon(endpointMarker, size);
        var epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection
        var projectTo = W.map.getProjectionObject(); //The map projection (Spherical Mercator)
        var lonLat = new OpenLayers.LonLat(lon, lat).transform(epsg4326, projectTo);
        var endpoint = new OpenLayers.Marker(lonLat, icon);
        endpointsLayer.addMarker(endpoint);
        endpointsLayer.setOpacity(0.75);
    }

    //Generate the Popup
    function popup(evt) {
        $("#gmPopupContainer").remove();
        $("#gmPopupContainer").hide();
        if (W.map.getLayersByName("endpointsLayer").length > 0) {
            W.map.removeLayer(endpointsLayer);
        }
        endpointsLayer = new OpenLayers.Layer.Markers("endpointsLayer");
        W.map.addLayer(endpointsLayer);
        if ((this.fromLon != this.toLon) || (this.fromLat != this.toLat)) {
            drawEndpoints(this.fromLon, this.fromLat);
            drawEndpoints(this.toLon, this.toLat);
        }
        var popupHTML;
        W.map.moveTo(this.location);
        let htmlString = '<div id="gmPopupContainer" style="max-width:500px;margin: 1;text-align: center;padding: 5px;z-index: 1100">' +
            '<a href="#close" id="gmCloseDlgBtn" title="Close" class="modalclose" style="color:#FF0000;">X</a>' +
            '<table border=0><tr><td><div id="mydivheader" style="min-height: 20px;">' + this.title + '</div></div>' +
            '<hr class="myhrline"/>Updated: ' + this.timestamp.toLocaleString();
        if (this.startTime != null) {
            htmlString += '<br/>Start: ' + this.startTime.toLocaleString();
        }
        if (this.plannedEndTime != null) {
            htmlString += '<br/>Planned End: ' + this.plannedEndTime.toLocaleString();
        }
        if (this.recurrence != null) {
            htmlString += '<br/>Recurrence: ' + this.recurrence;
        }
        htmlString += '<hr class="myhrline"/></td></tr><tr><td>' + this.desc + '</td></tr>' +
            '<tr><td>' + this.link + '</td></tr>' +
            '</table>' +
            '</div>';
        popupHTML = ([htmlString]);
        $("body").append(popupHTML);
        //Position the modal based on the position of the click event
        $("#gmPopupContainer").css({ left: document.getElementById("user-tabs").offsetWidth + W.map.getPixelFromLonLat(W.map.getUnprojectedCenter()).x - document.getElementById("gmPopupContainer").clientWidth - 10 });
        $("#gmPopupContainer").css({ top: document.getElementById("left-app-head").offsetHeight + W.map.getPixelFromLonLat(W.map.getUnprojectedCenter()).y - (document.getElementById("gmPopupContainer").clientHeight / 2) });
        $("#gmPopupContainer").show();
        //Add listener for popup's "Close" button
        $("#gmCloseDlgBtn").click(function () {
            $("#gmPopupContainer").remove();
            $("#gmPopupContainer").hide();
            W.map.removeLayer(endpointsLayer);
        });
        dragElement(document.getElementById("gmPopupContainer"));
    }
    function popupdetails(stateName) {
        $("#gmPopupContainer").remove();
        $("#gmPopupContainer").hide();
        var popupHTML;
        popupHTML = (['<div id="gmPopupContainer" style="max-width:750px;max-height:500px;margin:1;text-align:center;padding: 5px;z-index: 1100">' +
            '<a href="#close" id="popupdetailsclose" title="Close" class="modalclose" style="color:#FF0000;">X</a>' +
            '<table border=0><tr><td><div id="mydivheader" style="float:center">' + stateName + ' Reports <div id="spinner" class="spinner" style="float:left;position:relative;left:70%">' +
            '<div class="bounce1" style="float:left;position:relative;left:40%"></div><div class="bounce2" style="float:left;position:relative;left:50%"></div><div class="bounce3" style="float:left;position:relative;left:60%"></div></div></td></tr>' +
            '<tr><td>' +
            '<div style="width:720px; height:450px; overflow:auto;"><table id="reportTable" border=1>' +
            '<thead><tr><td data-sort-method="none" width=30><b>PL</b></td><th width=394>Description</th><th width=100>Misc.</th><th data-sort-default width=210>Time</th></tr></thead>' +
            '<tbody></tbody></table></div>' +
            '</td></tr></table>' +
            '</div>'
        ]);
        $("body").append(popupHTML);
        //Position the modal based on the position of the click event
        $("#gmPopupContainer").css({ left: 350 });
        $("#gmPopupContainer").css({ top: 100 });
        $("#gmPopupContainer").show();
        //Add listener for popup's "Close" button
        $("#popupdetailsclose").click(function () {
            $("#gmPopupContainer").remove();
            $("#gmPopupContainer").hide();
        });
        dragElement(document.getElementById("gmPopupContainer"));
    }
    // Make the DIV element draggable
    function dragElement(elmnt) {
        var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
        if (document.getElementById("mydivheader")) {
            // if present, the header is where you move the DIV from:
            document.getElementById("mydivheader").onmousedown = dragMouseDown;
        } else {
            // otherwise, move the DIV from anywhere inside the DIV:
            elmnt.onmousedown = dragMouseDown;
        }
        function dragMouseDown(e) {
            e = e || window.event;
            e.preventDefault();
            // get the mouse cursor position at startup:
            pos3 = e.clientX;
            pos4 = e.clientY;
            document.onmouseup = closeDragElement;
            // call a function whenever the cursor moves:
            document.onmousemove = elementDrag;
        }

        function elementDrag(e) {
            e = e || window.event;
            e.preventDefault();
            // calculate the new cursor position:
            pos1 = pos3 - e.clientX;
            pos2 = pos4 - e.clientY;
            pos3 = e.clientX;
            pos4 = e.clientY;
            // set the element's new position:
            elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
            elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
        }
        function closeDragElement() {
            // stop moving when mouse button is released:
            document.onmouseup = null;
            document.onmousemove = null;
        }
    }
    //Move map to coordinates specified
    function moveMap() {
        var epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection
        var projectTo = W.map.getProjectionObject(); //The map projection (Spherical Mercator)
        var lat = this.getAttribute("data-lat");
        var lon = this.getAttribute("data-lon");
        W.map.moveTo(new OpenLayers.LonLat(lon, lat).transform(epsg4326, projectTo), 16);
    }
    //Initialize Settings
    function initializeSettings() {
        stateLength = document.getElementsByClassName("WMEDOTAdvSettingsCheckbox").length;
        loadSettings();
        //Set the state checkboxes according to saved settings
        for (var i = 0; i < stateLength; i++) {
            state = document.getElementsByClassName("WMEDOTAdvSettingsCheckbox")[i].id.replace("chk", "").replace("DOTEnabled", "");
            setChecked('chk' + state + 'DOTEnabled', settings[state + 'DOTEnabled']);
        }
        for (var i = 0; i < document.getElementsByClassName("wmeDOTSettings").length; i++) {
            settingID = document.getElementsByClassName("wmeDOTSettings")[i].id;
            if (document.getElementsByClassName("wmeDOTSettings")[i].type == "checkbox") {
                setChecked(settingID, settings[settingID]);
            } else if (document.getElementsByClassName("wmeDOTSettings")[i].type == "select-one") {
                $("#valueHideZoomLevel").val(settings[settingID]).change();
            }
        }
        //Build the layers for the selected states
        for (var i = 0; i < stateLength; i++) {
            state = document.getElementsByClassName("WMEDOTAdvSettingsCheckbox")[i].id.replace("chk", "").replace("DOTEnabled", "");
            if (document.getElementById('chk' + state + 'DOTEnabled').checked) {
                buildDOTAdvLayers(state);
                getAdvisories(config[state], state);
                console.log("enabling" + state);
            }
        }
        $('.wmeDOTSettings').change(function () {
            var settingName = $(this)[0].id;
            settings[settingName] = this.checked;
            saveSettings();
        });
        setEnabled(localsettings.enabled);
    }
    function addListeners() {
        //Add event listener to report icon
        for (var i = 0; i < document.getElementsByClassName("DOTreport").length; i++) {
            document.getElementsByClassName("DOTreport")[i].addEventListener('click', function (e) { getReportData(this.getAttribute("id"), this.getAttribute("data-state")); }, false);
        }
        //Refresh selected states when WME's refresh button is clicked
        document.getElementsByClassName("reload-button")[0].addEventListener('click', function (e) {
            for (var i = 0; i < stateLength; i++) {
                state = document.getElementsByClassName("WMEDOTAdvSettingsCheckbox")[i].id.replace("chk", "").replace("DOTEnabled", "");
                if (document.getElementsByClassName("WMEDOTAdvSettingsCheckbox")[i].checked) {
                    W.map.removeLayer(W.map.getLayersByName(state + 'DOTLayer')[0]);
                }
            }
            initializeSettings();
        });
        //Add Handler for Checkbox Setting Changes
        $('.WMEDOTAdvSettingsCheckbox').change(function () {
            var settingName = $(this)[0].id.substr(3);
            settings[settingName] = this.checked;
            saveSettings();
            if (this.checked) {
                buildDOTAdvLayers(settingName.substring(0, 2));
                getAdvisories(config[settingName.substring(0, 2)], settingName.substring(0, 2));
            }
            else {
                W.map.removeLayer(W.map.getLayersByName(settingName.substring(0, 2) + 'DOTLayer')[0]);
            }
        });
    }
    //Set Checkbox from Settings
    function setChecked(checkboxId, checked) {
        $('#' + checkboxId).prop('checked', checked);
    }
    //Load Saved Settings
    function loadSettings() {
        if (!localStorage.WMEDOT_Settings) {
            localsettings.enabled = true;
            localStorage.setItem("WMEDOT_Settings", JSON.stringify(localsettings));
        }
        localsettings = $.parseJSON(localStorage.getItem("WMEDOT_Settings"));
        var defaultSettings = {
            Enabled: false,
        };
        settings = localsettings ? localsettings : defaultSettings;
        for (var prop in defaultSettings) {
            if (!settings.hasOwnProperty(prop)) {
                settings[prop] = defaultSettings[prop];
            }
        }
        const color = localsettings.enabled ? '#00bd00' : '#ccc';
        if (!document.getElementById('dot-advisories-power-btn')) {
            $('span[title="DOT Advisories"]').prepend(
                $('<span>', {
                    class: 'fa fa-power-off',
                    id: 'dot-advisories-power-btn',
                    style: `margin-right: 5px;cursor: pointer;color: ${color};font-size: 13px;`,
                    title: 'Toggle DOT Advisories'
                }).click(evt => {
                    evt.stopPropagation();
                    setEnabled(!localsettings.enabled);
                })
            );
        }
    }
    //Save Tab Settings
    function saveSettings() {
        if (localStorage) {
            //var localsettings = {};
            for (var i = 0; i < stateLength; i++) {
                state = document.getElementsByClassName("WMEDOTAdvSettingsCheckbox")[i].id.replace("chk", "").replace("DOTEnabled", "");
                localsettings[state + 'DOTEnabled'] = document.getElementsByClassName("WMEDOTAdvSettingsCheckbox")[i].checked;
            }
        }
        for (var i = 0; i < document.getElementsByClassName("wmeDOTSettings").length; i++) {
            if (document.getElementsByClassName("wmeDOTSettings")[i].type == "checkbox") {
                settingID = document.getElementsByClassName("wmeDOTSettings")[i].id;
                localsettings[settingID] = document.getElementsByClassName("wmeDOTSettings")[i].checked;
            } else if (document.getElementsByClassName("wmeDOTSettings")[i].type == "select-one") {
                settingID = document.getElementsByClassName("wmeDOTSettings")[i].id;
                localsettings[settingID] = document.getElementsByClassName("wmeDOTSettings")[i].value;
            }
        }
        localStorage.setItem("WMEDOT_Settings", JSON.stringify(localsettings));
    }
    //Add the Icon Class to OpenLayers
    function installIcon() {
        console.log('Installing OpenLayers.Icon');
        OpenLayers.Icon = OpenLayers.Class({
            url: null,
            size: null,
            offset: null,
            calculateOffset: null,
            imageDiv: null,
            px: null,
            initialize: function (a, b, c, d) {
                this.url = a;
                this.size = b || { w: 20, h: 20 };
                this.offset = c || { x: -(this.size.w / 2), y: -(this.size.h / 2) };
                this.calculateOffset = d;
                a = OpenLayers.Util.createUniqueID("OL_Icon_");
                let div = this.imageDiv = OpenLayers.Util.createAlphaImageDiv(a);
                $(div.firstChild).removeClass('olAlphaImg'); // LEAVE THIS LINE TO PREVENT WME-HARDHATS SCRIPT FROM TURNING ALL ICONS INTO HARDHAT WAZERS --MAPOMATIC
            },
            destroy: function () { this.erase(); OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); this.imageDiv.innerHTML = ""; this.imageDiv = null; },
            clone: function () { return new OpenLayers.Icon(this.url, this.size, this.offset, this.calculateOffset); },
            setSize: function (a) { null !== a && (this.size = a); this.draw(); },
            setUrl: function (a) { null !== a && (this.url = a); this.draw(); },
            draw: function (a) {
                OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, this.size, this.url, "absolute");
                this.moveTo(a);
                return this.imageDiv;
            },
            erase: function () { null !== this.imageDiv && null !== this.imageDiv.parentNode && OpenLayers.Element.remove(this.imageDiv); },
            setOpacity: function (a) { OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, null, null, null, null, a); },
            moveTo: function (a) {
                null !== a && (this.px = a);
                null !== this.imageDiv && (null === this.px ? this.display(!1) : (
                    this.calculateOffset && (this.offset = this.calculateOffset(this.size)),
                    OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, { x: this.px.x + this.offset.x, y: this.px.y + this.offset.y })
                ));
            },
            display: function (a) { this.imageDiv.style.display = a ? "" : "none"; },
            isDrawn: function () { return this.imageDiv && this.imageDiv.parentNode && 11 != this.imageDiv.parentNode.nodeType; },
            CLASS_NAME: "OpenLayers.Icon"
        });
    }
    bootstrap();

    const config = { //Configuration data for each state
        AK: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [], //['(resultObj[i].LanesAffected).replace(/ +(?= )/g, "") == ("All Lanes Closed")'];
            scheme(obj, index) {
                promises.AK.push(new Promise((resolve, reject) => {
                    advisories.AK.push({
                        state: ['AK', 'Alaska'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.RoadwayName,
                        lon: obj.Longitude,
                        lat: obj.Latitude,
                        type: obj.EventType,
                        keyword: ['roadwork'], //keywords for roadwork/construction
                        desc: obj.Description,
                        time: moment(new Date(obj.LastUpdated * 1000)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/AK']
        },
        AZ: {
            data(res, index) {
                let resultText = [res, res.features, res.features, res.features];
                return (resultText[index]);
            },
            filters: [
                obj => ((obj.LanesAffected).replace(/ +(?= )/g, "") == ("All Lanes Closed")) || (obj.RoadwayName).includes("Road Closed")
            ],
            scheme(obj, index) {

                promises.AZ.push(new Promise((resolve, reject) => {
                    advisories.AZ.push({
                        state: ['AZ', 'Arizona'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.RoadwayName,
                        lon: obj.Longitude,
                        lat: obj.Latitude,
                        type: obj.EventType,
                        keyword: ['roadwork'], //keywords for roadwork/construction
                        desc: obj.Description,
                        time: moment(new Date(obj.LastUpdated * 1000)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/AZ', 'https://maps.phoenix.gov/pub/rest/services/Public/STR_PubTraffRes/MapServer/0/query?where=Closure_Type+LIKE+%27FULL%27&text=&objectIds=&time=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Foot&relationParam=&outFields=*&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=4326&havingClause=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=0&resultRecordCount=300&returnExtentOnly=false&datumTransformation=&parameterValues=&rangeValues=&quantizationParameters=&featureEncoding=esriDefault&f=pjson', 'https://maps.phoenix.gov/pub/rest/services/Public/STR_PubTraffRes/MapServer/1/query?where=Closure_Type+LIKE+%27FULL%27&text=&objectIds=&time=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Foot&relationParam=&outFields=*&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=4326&havingClause=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=0&resultRecordCount=200&returnExtentOnly=false&datumTransformation=&parameterValues=&rangeValues=&quantizationParameters=&featureEncoding=esriDefault&f=pjson', 'https://maps.phoenix.gov/pub/rest/services/Public/STR_PubTraffRes/MapServer/2/query?f=json&where=1%3D1&returnGeometry=true&outSR=4326&spatialRel=esriSpatialRelIntersects&outFields=*&resultOffset=0&resultRecordCount=25']
        },
        CT: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [obj => obj.eventSubType == "closures"],
            scheme(obj, index) {
                promises.CT.push(new Promise((resolve, reject) => {
                    advisories.CT.push({
                        state: ['CT', 'Connecticut'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.Location,
                        lon: obj.Longitude,
                        lat: obj.Latitude,
                        type: obj.eventType,
                        keyword: ['roadwork'], //keywords for roadwork/construction
                        desc: obj.Description,
                        startTime: obj.StartDate,
                        plannedEndTime: obj.PlannedEndDate,
                        time: obj.LastUpdated,
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/CT']
        },
        DE: {
            data(res, index) {
                let resultText = [res.advisories, res.restrictions, res.features];
                return (resultText[index]);
            },
            filters: [
                null,
                obj => (obj.impactType == "Closure") || ((obj.impactType == "Restriction") && ((obj.construction.toUpperCase().includes("AMP CLOS") || (obj.construction.toUpperCase().includes("ROAD CLOS"))))),
                null
            ],
            scheme(obj, index) {
                switch (index) {
                    case 0:
                        promises.DE.push(new Promise((resolve, reject) => {
                            advisories.DE.push({
                                state: ['DE', 'Delaware'],
                                id: obj.id,
                                popupType: 0,
                                title: obj.where.county.name,
                                lon: obj.where.lon,
                                lat: obj.where.lat,
                                type: obj.type.name,
                                keyword: ['Construction'], //keyword for roadwork/construction
                                desc: obj.where.location,
                                time: moment(new Date(obj.timestamp)).format('LLL'),
                                link: obj.published.linkbackUrl
                            });
                            resolve();
                        }))
                        break;
                    case 1:
                        var pubLink;
                        if (obj.releaseId) {
                            if (obj.releaseId.toString() == "-1") {
                                pubLink = '';
                            } else {
                                pubLink = 'https://deldot.gov/About/news/index.shtml?dc=release&id=' + obj.releaseId;
                            }
                        }
                        promises.DE.push(new Promise((resolve, reject) => {
                            advisories.DE.push({
                                state: ['DE', 'Delaware'],
                                id: obj.restrictionId,
                                popupType: 0,
                                title: obj.where.county.name,
                                lon: obj.where.lon,
                                lat: obj.where.lat,
                                type: obj.impactType,
                                keyword: ['Closure'], //keywords for roadwork/construction
                                desc: obj.title + " - " + obj.construction,
                                time: moment(new Date(obj.startDate)).format('LLL'),
                                link: pubLink
                            });
                            resolve();
                        }))
                        break;
                    case 2:
                        var direction, WorkType;
                        switch (obj.attributes.direction) {
                            case 'ONE_DIRECTION':
                                direction = "One Way from ";
                                break;
                            case 'BOTH_DIRECTIONS':
                                direction = "Both Ways between ";
                        }
                        switch (obj.attributes.WorkType) {
                            case "1":
                                WorkType = "Gas Work";
                                break;
                            case "2":
                                WorkType = "Street Work (city)";
                                break;
                            case "3":
                                WorkType = "Street Work (DelDOT)";
                                break;
                            case "4":
                                WorkType = "Water Work";
                                break;
                            case "5":
                                WorkType = "Work (other)";
                                break;
                            case "6":
                                WorkType = "Sewer Work";
                        }
                        if (obj.attributes.street != null) {
                            var originShift = 2.0 * Math.PI * 6378137.0 / 2.0;
                            var lon = (obj.geometry.paths[0][0][0] / originShift) * 180.0;
                            var lat = (obj.geometry.paths[0][0][1] / originShift) * 180.0;
                            lat = 180.0 / Math.PI * (2.0 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);
                            promises.DE.push(new Promise((resolve, reject) => {
                                advisories.DE.push({
                                    state: ['DE', 'Delaware'],
                                    id: obj.attributes.OBJECTID,
                                    popupType: 0,
                                    title: 'Wilmington Road Closures',
                                    lon: lon,
                                    lat: lat,
                                    type: 'Closure',
                                    keyword: ['Closure'], //keywords for roadwork/construction
                                    desc: WorkType + ' - ' + direction + obj.attributes.StartingFrom + ' to ' + obj.attributes.EndingAt + '<br> from ' + moment(new Date(obj.attributes.starttime)).format('LLL') + ' to ' + moment(new Date(obj.attributes.endtime)).format('LLL'),
                                    time: moment(new Date(obj.attributes.EditDate)).format('LLL'),
                                    link: ''
                                });
                                resolve();
                            }))
                        }
                }
            },
            URL: ['https://tmc.deldot.gov/json/advisory.json', 'https://tmc.deldot.gov/json/restriction.json?id=ACVN', 'https://services.arcgis.com/hQ3wdpbjO3fPf612/ArcGIS/rest/services/RoadClosures_5b3e88c5556242dfa6e058198be7eb52_public/FeatureServer/1/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=standard&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=']
        },
        FL: {
            data(res, index) {
                let resultText = [res.item2, res.item2, res.item2];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                switch (index) {
                    case 0:
                        promises.FL.push(new Promise((resolve, reject) => {
                            //setTimeout(function () { resolve() }, 4000);
                            getFeed(config.FL.detailURL[0] + obj.itemId.replace("/ /g", "%20"), async function (result) {
                                var eventObj = JSON.parse(result.responseText);
                                if (eventObj.details.detailLang1.eventTypeName == "Closures") {
                                    advisories.FL.push({
                                        state: ['FL', 'Florida'],
                                        id: eventObj.id.id,
                                        popupType: 0,
                                        title: eventObj.areas.area5.areaLang1,
                                        lon: eventObj.coordinates.locationLongitude / 1000000,
                                        lat: eventObj.coordinates.locationLatitude / 1000000,
                                        type: eventObj.details.detailLang1.eventTypeName,
                                        keyword: ['Construction'], //keywords for roadwork/construction
                                        desc: eventObj.details.detailLang1.eventDescription,
                                        time: moment(new Date(eventObj.dates.lastUpdated)).format('LLL'),
                                        link: ''
                                    });
                                }
                                resolve();
                            });
                        }));
                        break;
                    case 1:
                        promises.FL.push(new Promise((resolve, reject) => {
                            //setTimeout(function () { resolve() }, 4000);
                            getFeed(config.FL.detailURL[1] + obj.itemId.replace("/ /g", "%20"), async function (result) {
                                var eventObj = JSON.parse(result.responseText);
                                if (eventObj.details.detailLang1.eventTypeName == "Closures") {
                                    advisories.FL.push({
                                        state: ['FL', 'Florida'],
                                        id: eventObj.id.id,
                                        popupType: 0,
                                        title: eventObj.areas.area5.areaLang1,
                                        lon: eventObj.coordinates.locationLongitude / 1000000,
                                        lat: eventObj.coordinates.locationLatitude / 1000000,
                                        type: eventObj.details.detailLang1.eventTypeName,
                                        keyword: ['Closures'], //keywords for roadwork/construction
                                        desc: eventObj.details.detailLang1.eventDescription,
                                        time: moment(new Date(eventObj.dates.lastUpdated)).format('LLL'),
                                        link: ''
                                    });
                                }
                                resolve();
                            });
                        }));
                        break;
                    case 2:
                        promises.FL.push(new Promise((resolve, reject) => {
                            //setTimeout(function () { resolve() }, 4000);
                            getFeed(config.FL.detailURL[1] + obj.itemId.replace("/ /g", "%20"), async function (result) {
                                var eventObj = JSON.parse(result.responseText);
                                if (eventObj.details.detailLang1.eventTypeName == "Closures") {
                                    advisories.FL.push({
                                        state: ['FL', 'Florida'],
                                        id: eventObj.id.id,
                                        popupType: 0,
                                        title: eventObj.areas.area5.areaLang1,
                                        lon: eventObj.coordinates.locationLongitude / 1000000,
                                        lat: eventObj.coordinates.locationLatitude / 1000000,
                                        type: eventObj.details.detailLang1.eventTypeName,
                                        keyword: ['Constructions'], //keywords for roadwork/construction
                                        desc: eventObj.details.detailLang1.eventDescription,
                                        time: moment(new Date(eventObj.dates.lastUpdated)).format('LLL'),
                                        link: ''
                                    });
                                }
                                resolve();
                            });
                        }));
                }
            },
            URL: ['https://fl511.com/map/mapIcons/Incidents?_=1604955914474', 'https://fl511.com/map/mapIcons/Construction?_=1604965926997', 'https://fl511.com/map/mapIcons/Closures?_=1604965926997'],
            detailURL: ['https://fl511.com/map/data/Incidents/', 'https://fl511.com/map/data/Construction/', 'https://fl511.com/map/data/Closures/']
        },
        GA: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [obj => (obj.IsFullClosure == true)],
            scheme(obj, index) {
                let secondLon, secondLat;
                if ((obj.LongitudeSecondary != 0) && (obj.LatitudeSecondary != 0)) {
                    secondLon = obj.LongitudeSecondary;
                    secondLat = obj.LatitudeSecondary;
                }
                promises.GA.push(new Promise((resolve, reject) => {
                    advisories.GA.push({
                        state: ['GA', 'Georgia'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.RoadwayName,
                        lon: obj.Longitude,
                        lat: obj.Latitude,
                        type: obj.Subtype,
                        hasEndpoints: true,
                        fromLon: obj.Longitude,
                        fromLat: obj.Latitude,
                        toLon: secondLon,
                        toLat: secondLat,
                        toLon: obj.LongitudeSecondary,
                        toLat: obj.LatitudeSecondary,
                        keyword: ['roadwork', 'road construction', 'road maintenance'], //keyword for roadwork/construction
                        desc: obj.Description + "<br>" + moment(new Date(obj.StartDate * 1000)).format('LLL') + " to " + moment(new Date(obj.PlannedEndDate * 1000)).format('LLL'),
                        time: moment(new Date(obj.LastUpdated * 1000)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/GA']
        },
        IA: {
            data(res, index) {
                let resultText = [res[0].data.mapFeaturesQuery.mapFeatures];
                return (resultText[index]);
            },
            filters: [
                obj => obj.features[0].properties.icon.url == "/images/tg_closure_critical.svg"
                    || obj.features[0].properties.icon.url == "/images/tg_closure_routine.svg"
                    || obj.features[0].properties.icon.url == "/images/tg_crash_routine.svg"
                    || obj.features[0].properties.icon.url == "/images/tg_warning_urgent.svg"
                    || (obj.features[0].properties.icon.url == "/images/tg_warning_routine.svg" && obj.tooltip.toUpperCase().includes("RAMP CLOSE"))
            ],
            scheme(obj, index) {
                let advType = "";
                if (obj.tooltip.toUpperCase().includes("CONSTRUCTION")) {
                    advType = "Construction";
                } else { advType = "Incident"; }
                promises.IA.push(new Promise((resolve, reject) => {
                    advisories.IA.push({
                        state: ['IA', 'Iowa'],
                        id: obj.features[0].id,
                        popupType: 0,
                        title: "N/A",
                        lon: obj.features[0].geometry.coordinates[0],
                        lat: obj.features[0].geometry.coordinates[1],
                        type: advType,
                        keyword: ['Construction'], //keywords for roadwork/construction
                        desc: obj.tooltip,
                        time: "N/A",
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/IA']
        },
        IL: {
            data(res, index) {
                let resultText = [res.features, res.features, res.features];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                switch (index) {
                    case 0:
                        promises.IL.push(new Promise((resolve, reject) => {
                            advisories.IL.push({
                                state: ['IL', 'Illinois'],
                                id: obj.attributes.OBJECTID,
                                popupType: 0,
                                title: obj.attributes.NearTown,
                                lon: obj.geometry.x,
                                lat: obj.geometry.y,
                                type: "Construction",
                                keyword: ['Construction'], //keywords for roadwork/construction
                                desc: 'Closed from ' + obj.attributes.Location + '<br> from ' + moment(new Date(obj.attributes.StartDate)).format('LLL') + ' to ' + moment(new Date(obj.attributes.EndDate)).format('LLL'),
                                time: moment(new Date(obj.attributes.StartDate)).format('LLL'),
                                link: obj.attributes.WebAddress
                            });
                            resolve();
                        }))
                        break;
                    case 1:
                        var DateUpdate;
                        if (obj.attributes.DateUpdate == null) {
                            DateUpdate = moment(new Date(obj.attributes.DateEntered)).format('LLL');
                        } else {
                            DateUpdate = moment(new Date(obj.attributes.DateUpdate)).format('LLL');
                        }
                        var originShift = 2.0 * Math.PI * 6378137.0 / 2.0;
                        var lon = (obj.geometry.paths[0][0][0] / originShift) * 180.0;
                        var lat = (obj.geometry.paths[0][0][1] / originShift) * 180.0;
                        lat = 180.0 / Math.PI * (2.0 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0);
                        if (obj.attributes.SuggestionToMotorist.includes("Closed")) {
                            promises.IL.push(new Promise((resolve, reject) => {
                                advisories.IL.push({
                                    state: ['IL', 'Illinois'],
                                    id: obj.attributes.OBJECTID,
                                    popupType: 0,
                                    title: obj.attributes.County,
                                    lon: lon,
                                    lat: lat,
                                    type: "Construction",
                                    keyword: ['Construction'], //keywords for roadwork/construction
                                    desc: 'Closed from ' + obj.attributes.Location + '<br> from ' + moment(new Date(obj.attributes.StartDate)).format('LLL') + ' to ' + moment(new Date(obj.attributes.EndDate)).format('LLL'),
                                    time: DateUpdate,
                                    link: obj.attributes.WebAddress
                                });
                                resolve();
                            }))
                        }
                        break;
                    case 2:
                        promises.IL.push(new Promise((resolve, reject) => {
                            advisories.IL.push({
                                state: ['IL', 'Illinois'],
                                id: obj.attributes.OBJECTID,
                                popupType: 0,
                                title: obj.attributes.NearTown,
                                lon: obj.geometry.paths[0][0][0],
                                lat: obj.geometry.paths[0][0][1],
                                type: "",
                                keyword: ['Flooding'], //keywords for roadwork/construction
                                desc: 'Closed from ' + obj.attributes.Location + '<br> from ' + moment(new Date(obj.attributes.StartDate)).format('LLL') + ' to ' + moment(new Date(obj.attributes.EndDate)).format('LLL'),
                                time: moment(new Date(obj.attributes.StartDate)).format('LLL'),
                                link: ''
                            });
                            resolve();
                        }))
                }
            },

            URL: ['https://services2.arcgis.com/aIrBD8yn1TDTEXoz/ArcGIS/rest/services/ClosureIncidents/FeatureServer/0/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=', 'https://services2.arcgis.com/aIrBD8yn1TDTEXoz/ArcGIS/rest/services/RoadConstruction_View/FeatureServer/0/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=', 'https://services2.arcgis.com/aIrBD8yn1TDTEXoz/ArcGIS/rest/services/Flooding_Road_Closures/FeatureServer/0/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=']
        },
        IN: {
            data(res, index) {
                let resultText = [res[0].data.mapFeaturesQuery.mapFeatures];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                let advType = "";
                if (obj.tooltip.toUpperCase().includes("CONSTRUCTION")) {
                    advType = "Construction";
                } else { advType = "Incident"; }
                if (obj.features[0].properties.icon.url == "/images/tg_closure_urgent.svg" || obj.features[0].properties.icon.url == "/images/tg_closure_critical.svg" || obj.features[0].properties.icon.url == "/images/tg_closure_routine.svg" || obj.features[0].properties.icon.url == "/images/tg_crash_routine.svg" || (obj.features[0].properties.icon.url == "/images/tg_warning_routine.svg" && obj.tooltip.toUpperCase().includes("RAMP CLOSE"))) {
                    promises.IN.push(new Promise((resolve, reject) => {
                        advisories.IN.push({
                            state: ['IN', 'Indiana'],
                            id: obj.features[0].id,
                            popupType: 0,
                            title: "N/A",
                            lon: obj.features[0].geometry.coordinates[0],
                            lat: obj.features[0].geometry.coordinates[1],
                            type: advType,
                            keyword: ['Construction'], //keywords for roadwork/construction
                            desc: obj.tooltip,
                            time: "N/A",
                            link: ''
                        });
                        resolve();
                    }))
                }
            },
            URL: ['http://72.167.49.86:8080/IN']
        },
        LA: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [obj => obj.LanesAffected.replace(/ +(?= )/g, "") == ("All Lanes Closed")],
            scheme(obj, index) {
                promises.LA.push(new Promise((resolve, reject) => {
                    advisories.LA.push({
                        state: ['LA', 'Louisiana'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.RoadwayName,
                        lon: obj.Longitude,
                        lat: obj.Latitude,
                        type: obj.EventType,
                        keyword: ['roadwork'], //keywords for roadwork/construction
                        desc: obj.Description,
                        time: moment(new Date(obj.LastUpdated * 1000)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/LA']
        },
        MD: {
            data(res, index) {
                let resultText = [res.features];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                promises.MD.push(new Promise((resolve, reject) => {
                    advisories.MD.push({
                        state: ['MD', 'Maryland'],
                        id: obj.attributes.OBJECTID,
                        popupType: 0,
                        title: obj.attributes.Jurisdiction,
                        lon: obj.attributes.Longitude,
                        lat: obj.attributes.Latitude,
                        type: obj.attributes.typeSummary,
                        keyword: ['Construction'], //keywords for roadwork/construction
                        desc: obj.attributes.ClosureSummary,
                        time: moment(new Date(obj.attributes.EditDate)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['https://geodata.md.gov/appdata/rest/services/SHA_RoadClosure/RoadClosureActive/MapServer//0/query?where=1%3D1&outFields=*&outSR=4326&f=json']
        },
        MI: {
            data(res, index) {
                let resultText = [res, res];
                return (resultText[index]);
            },
            filters: [obj => (obj.type == "Total")],
            scheme(obj, index) {
                switch (index) {
                    case 0:
                        promises.MI.push(new Promise((resolve, reject) => {
                            advisories.MI.push({
                                state: ['MI', 'Michigan'],
                                id: "00",
                                popupType: 0,
                                title: obj.county,
                                lon: obj.description.match(/(?<=lon=)[\s\S]*(?=&zoom)/)[0],
                                lat: obj.description.match(/(?<=lat=)[\s\S]*(?=&lon)/)[0],
                                type: "Construction",
                                keyword: ['Construction'], //keyword for roadwork/construction
                                desc: obj.description.match(/(?:(?!<).)*/),
                                time: moment(new Date(obj.startDate)).format('LL'),
                                link: ''
                            });
                            resolve();
                        }))
                        break;
                    case 1:
                        promises.MI.push(new Promise((resolve, reject) => {
                            advisories.MI.push({
                                state: ['MI', 'Michigan'],
                                id: "",
                                popupType: 0,
                                title: obj.county,
                                lon: obj.location.match(/(?<=lon=)[\s\S]*(?=&zoom)/)[0],
                                lat: obj.location.match(/(?<=lat=)[\s\S]*(?=&lon)/)[0],
                                type: "Incident",
                                keyword: ['Construction'], //keyword for roadwork/construction
                                desc: obj.location.match(/(?:(?!<).)*/),
                                time: moment(new Date(obj.reported)).format('LLL'),
                                link: ''
                            });
                            resolve();
                        }))
                }
            },
            URL: ['https://mdotjboss.state.mi.us/MiDrive//construction/list/loadConstruction', 'https://mdotjboss.state.mi.us/MiDrive//incident/list/loadIncidents']
        },
        MN: {
            data(res, index) {
                let resultText = [res[0].data.mapFeaturesQuery.mapFeatures];
                return (resultText[index]);
            },
            filters: [
                obj => obj.features[0].properties.icon.url == "/images/tg_closure_critical.svg"
                    || obj.features[0].properties.icon.url == "/images/tg_closure_routine.svg"
                    || obj.features[0].properties.icon.url == "/images/tg_crash_routine.svg"
                    || (obj.features[0].properties.icon.url == "/images/tg_warning_routine.svg" && obj.tooltip.toUpperCase().includes("RAMP CLOSE"))
            ],
            scheme(obj, index) {
                let advType = "";
                if (obj.tooltip.toUpperCase().includes("CONSTRUCTION")) {
                    advType = "Construction";
                } else { advType = "Incident"; }
                promises.MN.push(new Promise((resolve, reject) => {
                    advisories.MN.push({
                        state: ['MN', 'Minnesota'],
                        id: obj.features[0].id,
                        popupType: 0,
                        title: "N/A",
                        lon: obj.features[0].geometry.coordinates[0],
                        lat: obj.features[0].geometry.coordinates[1],
                        type: advType,
                        keyword: ['Construction'], //keywords for roadwork/construction
                        desc: obj.tooltip,
                        time: "N/A",
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/MN']
        },
        NC: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                promises.NC.push(new Promise((resolve, reject) => {
                    advisories.NC.push({
                        state: ['NC', 'North Carolina'],
                        id: obj.id,
                        popupType: 0,
                        title: obj.city + " (" + obj.countyName + ")",
                        lon: obj.longitude,
                        lat: obj.latitude,
                        type: obj.incidentType,
                        keyword: ['Construction', 'Emergency Road Work', 'Night Time Construction', 'Weekend Construction'], //keywords for roadwork/construction
                        desc: obj.reason,
                        time: moment(new Date(obj.lastUpdate)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['https://eapps.ncdot.gov/services/traffic-prod/v1/incidents']
        },
        NJ: {
            data(res, index) {
                let resultText = [res.Data.features];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                promises.NJ.push(new Promise((resolve, reject) => {
                    //setTimeout(function () { resolve() }, 4000);
                    getFeed(config.NJ.detailURL[0] + obj.properties.EventID, function (result) {
                        var eventObj = JSON.parse(result.responseText).Data;
                        console.log(result.status);
                        if (((eventObj[0].FullText.toUpperCase()).includes("ALL LANES CLOSE") || (eventObj[0].FullText.toUpperCase()).includes("RAMP CLOSE")) && ((eventObj[0].FullText).includes("NYSDOT") != true)) {
                            advisories.NJ.push({
                                state: ['NJ', 'New Jersey'],
                                id: eventObj[0].markerId,
                                popupType: 0,
                                title: eventObj[0].County,
                                lon: eventObj[0].Longitude,
                                lat: eventObj[0].Latitude,
                                type: eventObj[0].CategoryName,
                                keyword: ['Construction', 'ScheduledConstruction'], //keywords for roadwork/construction
                                desc: eventObj[0].FullText,
                                time: moment(new Date(eventObj[0].LastUpdateDate_String)).format('LLL'),
                                link: ''
                            });
                        }
                        resolve(true);
                    });
                }));
            },
            URL: ['https://publicmap1.511nj.org/API/client/Map/getEventData'],
            detailURL: ['https://publicmap1.511nj.org/API/client/Map/getEventPopupData?EventId=']
        },
        NV: {
            data(res, index) {
                let resultText = [res.d];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                promises.NV.push(new Promise((resolve, reject) => {
                    let unix = obj.LastUpdate.replace(/\\\//g, "").replace("/Date(", "").replace(")/", "");
                    advisories.NV.push({
                        state: ['NV', 'Nevada'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.Facility,
                        lon: obj.Lon,
                        lat: obj.Lat,
                        type: obj.CategoryName,
                        keyword: ['Construction'], //keywords for roadwork/construction
                        desc: obj.Description,
                        time: moment(new Date(parseInt(unix))).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/NV']
        },
        NY: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [
                obj => (
                    (NotNY.includes(obj.RegionName) == false && obj.EventType != "transitMode" && obj.EventSubType != "Capacity related")
                    && (obj.EventType == "closures" || (
                        obj.EventType != "closures" && obj.LanesAffected == "all lanes" && (obj.LanesStatus == "closed" || obj.LanesStatus == "blocked")
                    ))
                )
            ],
            scheme(obj, index) {
                promises.NY.push(new Promise((resolve, reject) => {
                    advisories.NY.push({
                        state: ['NY', 'New York'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.CountyName,
                        lon: obj.Longitude,
                        lat: obj.Latitude,
                        type: obj.EventType,
                        keyword: ['roadwork', 'transitMode', 'closures'], //keywords for roadwork/construction
                        desc: obj.Description,
                        time: moment(moment(obj.LastUpdated, "DD/MM/YYYY HH:mm:ss")).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/NY']
        },
        OH: {
            data(res, index) {
                let resultText = [res.ConstructionMarkers];
                return (resultText[index]);
            },
            filters: [obj => obj.Status == "Closed"],
            scheme(obj, index) {
                promises.OH.push(new Promise((resolve, reject) => {
                    advisories.OH.push({
                        state: ['OH', 'Ohio'],
                        id: obj.ID,
                        popupType: 0,
                        title: obj.District,
                        lon: obj.Longitude,
                        lat: obj.Latitude,
                        type: obj.Category,
                        keyword: ['Roadwork - Planned', 'Roadwork - Unplanned'], //keywords for roadwork/construction
                        desc: obj.Description,
                        time: moment(new Date(obj.StartDate)).format('LL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['https://api.ohgo.com/roadmarkers/TrafficSpeedAndAlertMarkers']
        },
        OR: {
            data(res, index) {
                let resultText = [res.features, res.features, res.features];
                return (resultText[index]);
            },
            filters: [
                null,
                obj => obj.attributes.comments.includes("clos"),
                obj => obj.attributes.tmddOther.includes("clos")
            ],
            scheme(obj, index) {
                switch (index) {
                    case 0:
                        let x, y;
                        var lonlat = obj.geometry.paths[0][0];
                        promises.OR.push(new Promise((resolve, reject) => {
                            x = obj.geometry.paths[0][0].toString().split(",")[0];
                            y = obj.geometry.paths[0][0].toString().split(",")[1];
                            advisories.OR.push({
                                state: ['OR', 'Oregon'],
                                id: obj.attributes.OBJECTID,
                                popupType: 0,
                                title: obj.attributes.FROM_TO,
                                lon: x,
                                lat: y,
                                type: obj.attributes.CLOSURE_EFFECT,
                                keyword: ['Street'], //keywords for roadwork/construction
                                desc: obj.attributes.FROM_TO + " - " + obj.attributes.REMARKS,
                                time: moment(new Date(obj.attributes.LAST_EDITED_DATE)).format('LLL'),
                                link: ''
                            });
                            resolve();
                        }))
                        break;
                    case 1:
                        promises.OR.push(new Promise((resolve, reject) => {
                            advisories.OR.push({
                                state: ['OR', 'Oregon'],
                                id: obj.attributes.incidentId,
                                popupType: 0,
                                title: obj.attributes.locationName,
                                lon: obj.attributes.startLongitude,
                                lat: obj.attributes.startLatitude,
                                type: obj.attributes.type,
                                keyword: ['ROADWORK'], //keywords for roadwork/construction
                                desc: obj.attributes.comments + " <br> " + obj.attributes.beginMarker + " to " + obj.attributes.endMarker,
                                time: moment(new Date(obj.attributes.lastUpdated)).format('LLL'),
                                link: ''
                            });
                            resolve();
                        }))
                        break;
                    case 2:
                        promises.OR.push(new Promise((resolve, reject) => {
                            advisories.OR.push({
                                state: ['OR', 'Oregon'],
                                id: obj.attributes.incidentId,
                                popupType: 0,
                                title: obj.attributes.locationName,
                                lon: obj.attributes.startLongitude,
                                lat: obj.attributes.startLatitude,
                                type: obj.attributes.type,
                                keyword: ['EVENT'], //keywords for roadwork/construction
                                desc: obj.attributes.tmddOther + " <br> " + obj.attributes.beginMarker + " to " + obj.attributes.endMarker,
                                time: moment(new Date(obj.attributes.lastUpdated)).format('LLL'),
                                link: ''
                            });
                            resolve();
                        }))
                }
            },
            URL: ['https://services.arcgis.com/kIA6yS9KDGqZL7U3/ArcGIS/rest/services/RoadWork/FeatureServer/1/query?where=objectid+like+%27%25%27&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=4326&datumTransformation=&applyVCSProjection=true&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=true&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=', 'https://tripcheck.com/Scripts/map/data/INCD.js?dt=1607132941398', 'https://tripcheck.com/Scripts/map/data/EVENT.js?dt=1607134261397']
        },
        PA: {
            data(res, index) {
                let resultText = [res, res.features];
                return (resultText[index]);
            },
            filters: [
                obj => (obj.LaneStatus == "closed") || (obj.LaneStatus == "ramp closure")
            ],
            scheme(obj, index) {
                switch (index) {
                    case 0:
                        let status = obj.LaneStatus;
                        let x, y, fromlat, fromlon, tolat, tolon;
                        if (typeof obj.IncidentLocLatLong != "string" && typeof obj.FromLocLatLong != "string") {
                            return;
                        }
                        if (typeof obj.IncidentLocLatLong == "string") {
                            x = obj.IncidentLocLatLong.split(",")[1];
                            y = obj.IncidentLocLatLong.split(",")[0];
                        } else {
                            x = obj.FromLocLatLong.split(",")[1];
                            y = obj.FromLocLatLong.split(",")[0];
                        }
                        if (typeof obj.FromLocLatLong == "string") {
                            fromlon = obj.FromLocLatLong.split(",")[1];
                            fromlat = obj.FromLocLatLong.split(",")[0];
                            tolon = obj.ToLocLatLong.split(",")[1];
                            tolat = obj.ToLocLatLong.split(",")[0];
                        } else {
                            fromlon = "";
                            fromlat = "";
                            tolon = "";
                            tolat = "";
                        }
                        promises.PA.push(new Promise((resolve, reject) => {
                            advisories.PA.push({
                                state: ['PA', 'Pennsylvania'],
                                id: obj.EventID,
                                popupType: 0,
                                title: obj.CountyName,
                                lon: x,
                                lat: y,
                                hasEndpoints: true,
                                fromLon: fromlon,
                                fromLat: fromlat,
                                toLon: tolon,
                                toLat: tolat,
                                type: obj.EventType,
                                keyword: ['roadwork', 'bridge outage'], //keywords for roadwork/construction
                                desc: obj.Description + '<br><br>Estimated Opening: ' + moment(new Date(obj.EstDateTimeToOpen)).format('LLL'),
                                time: moment(new Date(obj.LastUpdate)).format('LLL'),
                                link: ''
                            });
                            resolve();
                        }))
                        break;
                    case 1:
                        var timing;
                        if (obj.attributes.endtime == null) {
                            timing = moment(new Date(obj.attributes.starttime)).format('LLL');
                        } else {
                            timing = moment(new Date(obj.attributes.starttime)).format('LLL') + ' to ' + moment(new Date(obj.attributes.endtime)).format('LLL');
                        }
                        promises.PA.push(new Promise((resolve, reject) => {
                            if (obj.attributes.endtime > Date.now()) {
                                advisories.PA.push({
                                    state: ['PA', 'Pennsylvania'],
                                    id: obj.attributes.GlobalID,
                                    popupType: 0,
                                    title: 'HARRISBURG',
                                    lon: obj.geometry.paths[0][0][0],
                                    lat: obj.geometry.paths[0][0][1],
                                    hasEndpoints: true,
                                    fromLon: obj.geometry.paths[0][0][0],
                                    fromLat: obj.geometry.paths[0][0][1],
                                    toLon: obj.geometry.paths[0][obj.geometry.paths[0].length - 1][0],
                                    toLat: obj.geometry.paths[0][obj.geometry.paths[0].length - 1][1],
                                    type: 'Closure',
                                    keyword: ['Closure'], //keywords for roadwork/construction
                                    desc: obj.attributes.street + ': ' + obj.attributes.description + '<br>' + timing,
                                    time: moment(new Date(obj.attributes.EditDate)).format('LLL'),
                                    link: ''
                                });
                            }
                            resolve();
                        }))
                }
            },
            URL: ['http://72.167.49.86:8080/PAnew', 'https://services5.arcgis.com/9n3LUAMi3B692MBL/ArcGIS/rest/services/RoadClosures_f0c23ca29f394e03a9ea06a2ffcb317a/FeatureServer/1/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_StatuteMile&returnGeodetic=false&outFields=*&returnGeometry=true&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=4326&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=true&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=']
        },
        VA: {
            data(res, index) {
                let resultText = [res.features, res.features, res.features];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                switch (index) {
                    case 0:
                        promises.VA.push(new Promise((resolve, reject) => {
                            let lat = obj.geometry.coordinates[1];
                            let lon = obj.geometry.coordinates[0];
                            let thisID = obj.id;
                            getFeed(config.VA.detailURL + obj.id, async function (result) {
                                var eventObj = JSON.parse(result.responseText);
                                if (eventObj[thisID].display_text.toLowerCase().includes("all west lanes are closed")) {
                                    advisories.VA.push({
                                        state: ['VA', 'Virginia'],
                                        id: eventObj[thisID].fid,
                                        popupType: 0,
                                        title: "Construction",
                                        lon: lon,
                                        lat: lat,
                                        type: eventObj[thisID].type,
                                        keyword: ['Constructions'], //keywords for roadwork/construction
                                        desc: eventObj[thisID].report,
                                        time: moment(new Date(eventObj[thisID].update * 1000)).format('LLL'),
                                        link: ''
                                    });
                                }
                                resolve();
                            });
                        }));
                        break;
                    case 1:
                        promises.VA.push(new Promise((resolve, reject) => {
                            let lat = obj.geometry.coordinates[1];
                            let lon = obj.geometry.coordinates[0];
                            let thisID = obj.id;
                            getFeed(config.VA.detailURL + obj.id, async function (result) {
                                var eventObj = JSON.parse(result.responseText);
                                advisories.VA.push({
                                    state: ['VA', 'Virginia'],
                                    id: eventObj[thisID].fid,
                                    popupType: 0,
                                    title: "High Impact Incident",
                                    lon: lon,
                                    lat: lat,
                                    type: eventObj[thisID].type,
                                    keyword: ['Constructions'], //keywords for roadwork/construction
                                    desc: eventObj[thisID].report,
                                    time: moment(new Date(eventObj[thisID].update * 1000)).format('LLL'),
                                    link: ''
                                });
                                resolve();
                            });
                        }));
                        break;
                    case 2:
                        promises.VA.push(new Promise((resolve, reject) => {
                            let lat = obj.geometry.coordinates[1];
                            let lon = obj.geometry.coordinates[0];
                            let thisID = obj.id;
                            getFeed(config.VA.detailURL + obj.id, async function (result) {
                                var eventObj = JSON.parse(result.responseText);
                                advisories.VA.push({
                                    state: ['VA', 'Virginia'],
                                    id: eventObj[thisID].fid,
                                    popupType: 0,
                                    title: "Weather",
                                    lon: lon,
                                    lat: lat,
                                    type: eventObj[thisID].type,
                                    keyword: ['Constructions'], //keywords for roadwork/construction
                                    desc: eventObj[thisID].report,
                                    time: moment(new Date(eventObj[thisID].update * 1000)).format('LLL'),
                                    link: ''
                                });
                                resolve();
                            });
                        }));
                }
            },
            URL: ['https://www.511virginia.org/data/geojson/icons.construction.geojson', 'https://www.511virginia.org/data/geojson/icons.high_impact_incident.geojson', 'https://www.511virginia.org/data/geojson/icons.weather_closure.geojson'],
            detailURL: ['https://www.511virginia.org/report-json.pl?idents='],
        },
        WA: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [
                obj => (obj.EventCategory == "Closure" || obj.EventCategory == "Construction" || obj.EventCategory == "Bridge")
            ],
            scheme(obj, index) {
                let county;
                if (obj.County == null) {
                    county = obj.Region;
                } else {
                    county = obj.County;
                }
                let unixtime = parseInt(obj.LastUpdatedTime.replace("/Date(", "").replace(")/", "").split("-")[0]);
                promises.WA.push(new Promise((resolve, reject) => {
                    advisories.WA.push({
                        state: ['WA', 'Washington'],
                        id: obj.AlertID,
                        popupType: 0,
                        title: county,
                        lon: obj.StartRoadwayLocation.Longitude,
                        lat: obj.StartRoadwayLocation.Latitude,
                        type: obj.EventCategory,
                        keyword: ['Construction', 'Closures'], //keywords for roadwork/construction
                        desc: obj.HeadlineDescription,
                        time: moment(new Date(unixtime)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/WA']
        },
        WI: {
            data(res, index) {
                let resultText = [res];
                return (resultText[index]);
            },
            filters: [
                obj => (obj.EventType == "roadwork" || obj.EventType == "closures" || obj.EventType == "accidentsAndIncidents")
            ],
            scheme(obj, index) {
                let linkvar = '';
                let eText = '';

                let addObj = function () {
                    if (obj.PlannedEndDate == null || obj.PlannedEndDate > moment().unix()) {
                        promises.WI.push(new Promise((resolve, reject) => {
                            advisories.WI.push({
                                state: ['WI', 'Wisconsin'],
                                id: obj.ID,
                                popupType: 0,
                                title: obj.County,
                                lon: obj.Longitude,
                                lat: obj.Latitude,
                                type: obj.EventType,
                                keyword: ['roadwork', 'closure'], //keywords for roadwork/construction
                                desc: eText + ': ' + obj.Description,
                                startTime: moment.unix(obj.StartDate).format('LLL'),
                                plannedEndTime: moment.unix(obj.PlannedEndDate).format('LLL'),
                                time: moment.unix(obj.LastUpdated).format('LLL'),
                                link: linkvar,
                                recurrence: obj.Recurrence
                            });
                            resolve();
                        }))
                    }
                };

                if (obj.EventType == 'closures') {
                    linkvar = 'https://511wi.gov/map#ConstructionClosures-' + obj.ID.replace(' ', '%20');
                    new Promise((resolve, reject) => {
                        getFeed('https://511wi.gov/map/data/ConstructionClosures/' + obj.ID.replace(' ', '%20'), function (result) {
                            let resultObj = [];
                            resultObj = JSON.parse(result.responseText);
                            eText = resultObj.details.detailLang1.eventDescription + ' on ' + resultObj.location.linkDesignator + ' at ' + resultObj.location.crossStreetName
                            resolve();
                        });
                    }).then((result) => addObj());
                }
                else if (obj.EventType == 'accidentsAndIncidents') {
                    linkvar = 'https://511wi.gov/map#Incidents-' + obj.ID.replace(' ', '%20');
                    addObj();
                }
                else {
                    addObj();
                }
            },
            URL: ['http://72.167.49.86:8080/WI']
        },
        WV: {
            data(res, index) {
                let resultText = [res.changes["com.orci.opentms.web.public511.components.plannedevent.shared.data.PlannedEventBean"].changes];
                return (resultText[index]);
            },
            filters: [],
            scheme(obj, index) {
                promises.WV.push(new Promise((resolve, reject) => {
                    advisories.WV.push({
                        state: ['WV', 'West Virginia'],
                        id: obj.entity.dataGatewayId,
                        popupType: 0,
                        title: obj.entity.routeName,
                        lon: obj.entity.x,
                        lat: obj.entity.y,
                        type: 'Construction',
                        keyword: ['Construction'], //keywords for roadwork/construction
                        desc: obj.entity.message,
                        time: moment(new Date(obj.entity.startTime.millis)).format('LLL'),
                        link: ''
                    });
                    resolve();
                }))
            },
            URL: ['http://72.167.49.86:8080/WV']
        }
    };
})();