WME OH Scripts

Recommended scripts for editing in Ohio

Stan na 11-01-2017. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         WME OH Scripts
// @namespace    https://greasyfork.org/users/30701-justins83-waze
// @version      0.5.3
// @description  Recommended scripts for editing in Ohio
// @include      https://www.waze.com/editor/*
// @include      https://www.waze.com/*/editor/*
// @include      https://beta.waze.com/*
// @exclude      https://www.waze.com/user/editor*
// @author       JustinS83
// @grant        none
// @require      https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @license      GPLv3
// ==/UserScript==

/* global W */
/* global WazeWrap */

(function() {
    'use strict';

    // Your code here...
    function bootstrap(tries) {
        tries = tries || 1;

        if (window.W &&
            window.W.map &&
            window.W.model &&
            $) {
            init();
        } else if (tries < 1000) {
            setTimeout(function () {bootstrap(tries++);}, 200);
        }
    }

    bootstrap();
    
    function isChecked(id) {
        return $('#' + id).is(':checked');
    }

    function setChecked(id, checked) {
        $('#' + id).prop('checked', checked);
    }

    function init(){
        var $section = $("<div>", {style:"padding:8px 16px", id:"OHScriptsSettings"});
        $section.html([
            '<div>Toggling options requires a hard refresh.</div>',
            '<p><div title="OH Validator Localization, Author: Xanderb" id="divOHValidatorLocalization" class="controls-container"><input type="checkbox" id="_cbOHValidatorLocalizationEnable" /><label for="_cbOHValidatorLocalizationEnable">OH Validator Localization <a href="https://greasyfork.org/en/scripts/8746-wme-validator-localization-for-ohio" target="_blank">...</a></label></div>',
            '<div title="OH Counties 2014, Author: rickzable" class="controls-container"><input type="checkbox" id="_cbOHCounties2014Enable" /><label for ="_cbOHCounties2014Enable"> OH Counties 2014 <a href="https://greasyfork.org/scripts/11240-wme-counties-ohio-census-2014" target="_blank">...</a></label></div>',
            '<div title="OH Cities 2014-1, Author: JustinS83" class="controls-container"><input type="checkbox" id="_cbOHCities20141Enable" /><label for ="_cbOHCities20141Enable"> OH Cities 2014-1 <a href="https://greasyfork.org/scripts/17391-wme-ohio-cities-census-2014-1" target="_blank">...</a></label></div>',
            '<div title="OH Cities 2014-2, Author: JustinS83" class="controls-container"><input type="checkbox" id="_cbOHCities20142Enable" /><label for ="_cbOHCities20142Enable"> OH Cities 2014-2 <a href="https://greasyfork.org/scripts/17392-wme-ohio-cities-census-2014-2" target="_blank">...</a></label></div>',
            '<hr>',
            '<div class="controls-container"><button type="button" id="_btnLoadTIMS">Open in TIMS</button><input type="radio" style="display:block" name="TIMSOptions" id="FCDisplay" /><label for="FCDisplay" title="Function Classification Display">FC Display</label><input type="radio" style="display:block" name="TIMSOptions" id="CRDisplay"/><label for="CRDisplay" title="County Road Display">CR Display</label></div>',
            '<div class="controls-container"><button type="button" id="_btnOpenGMM">Open in GMM</button></div>',
            '</p>'
        ].join(' '));
        new WazeWrap.Interface.Tab('OH Scripts', $section.html(), initializeSettings);
    }

    function GMMButtonClick(){
        var center_lonlat = WazeWrap.Geometry.ConvertTo4326(Waze.map.center.lon, Waze.map.center.lat);
        var topleft = WazeWrap.Geometry.ConvertTo4326(Waze.map.getExtent().left, Waze.map.getExtent().top);
        var bottomright = WazeWrap.Geometry.ConvertTo4326(Waze.map.getExtent().right, Waze.map.getExtent().bottom);
        var lat = Math.round(center_lonlat.lat * 1000000) / 1000000;
        var lon = Math.round(center_lonlat.lon * 1000000) / 1000000;
        var spn = Math.abs(topleft.lat - bottomright.lat) + ',' + Math.abs(topleft.lon - bottomright.lon);
        window.open('https://www.google.com/mapmaker?ll=' + lat + ',' + lon + '&spn=' + spn + '&lyt=large_map_v3', 'Google Map Maker');
    }

    function TIMSButtonClick(){
        var center_lonlat = WazeWrap.Geometry.ConvertTo4326(Waze.map.center.lon, Waze.map.center.lat);
        var topleft = WazeWrap.Geometry.ConvertTo4326(Waze.map.getExtent().left, Waze.map.getExtent().top);
        var bottomright = WazeWrap.Geometry.ConvertTo4326(Waze.map.getExtent().right, Waze.map.getExtent().bottom);
        var lat = Math.round(center_lonlat.lat * 1000000) / 1000000;
        var lon = Math.round(center_lonlat.lon * 1000000) / 1000000;
        var spn = Math.abs(topleft.lat - bottomright.lat) + ',' + Math.abs(topleft.lon - bottomright.lon);
        var newZoom = (Waze.map.zoom + 12);
        if($('#FCDisplay').is(':checked')) //FC display
            window.open('https://gis.dot.state.oh.us/tims/map?center=' + lon + ',' + lat + '&level=' + newZoom + '&visiblelayers=odot-osip-1:0,1%7Codot-osip-2:0,3%7CAssets:-1%7CBoundaries:2%7CEnvironmental:-1%7CProjects:-1%7CRoadway%20Information:9%7CStrategic%20Transportation%20System:-1%7CSafety:-1', 'ODOT TIMS');
        else //CR display
            window.open('https://gis.dot.state.oh.us/tims/map?center=' + lon + ',' + lat + '&level=' + newZoom + '&visiblelayers=Assets:-1|Environmental:-1|Projects:-1|Roadway%20Information:8|Strategic%20Transportation%20System:-1','ODOT TIMS');
    }

    function initializeSettings(){
        var storedOptionsStr = localStorage.GLR_OHScripts;

        if(!localStorage.GLR_OHScripts)
            storedOptionsStr = localStorage.OHScripts;

        var options =  storedOptionsStr ? JSON.parse(storedOptionsStr) : [0, true, true, false, false, true];
        setChecked('_cbOHValidatorLocalizationEnable', options[1]);
        setChecked('_cbOHCounties2014Enable', options[2]);
        setChecked('_cbOHCities20141Enable', options[3]);
        setChecked('_cbOHCities20142Enable', options[4]);

        if(!localStorage.GLR_OHScripts){
            SaveSettings();
            localStorage.removeItem("OHScripts");
        }

        if(options[5])
            setChecked('FCDisplay', true);
        else
            setChecked('CRDisplay', true);

        $('input[id^="_cbOH"]').change(function() { SaveSettings(); });

        $('#FCDisplay').change(function() { SaveSettings(); });
        $('#CRDisplay').change(function() { SaveSettings(); });
        $('#_btnLoadTIMS').click(TIMSButtonClick);
        $('#_btnOpenGMM').click(GMMButtonClick);

        if(options[1])
            $.getScript("https://greasyfork.org/scripts/8746-wme-validator-localization-for-ohio/code/WME%20Validator%20Localization%20for%20Ohio.user.js");

        if(options[2])
            $.getScript("https://greasyfork.org/scripts/26450-wme-counties-ohio-census-2014-justins83-fork/code/WME%20Counties%20Ohio%20Census%202014%20(JustinS83%20fork).user.js");

        if(options[3])
            $.getScript("https://greasyfork.org/scripts/17391-wme-ohio-cities-census-2014-1/code/WME%20Ohio%20Cities%20Census%202014%20-%201.user.js");

        if(options[4])
            $.getScript("https://greasyfork.org/scripts/17392-wme-ohio-cities-census-2014-2/code/WME%20Ohio%20Cities%20Census%202014%20-%202.user.js");
    }

    function SaveSettings(){
        if (localStorage) {
            var options = [];
            // preserve previous options which may get lost after logout
            if (localStorage.GLR_OHScripts) { options = JSON.parse(localStorage.GLR_OHScripts); }
            options[1] = isChecked('_cbOHValidatorLocalizationEnable');
            options[2] = isChecked('_cbOHCounties2014Enable');
            options[3] = isChecked('_cbOHCities20141Enable');
            options[4] = isChecked('_cbOHCities20142Enable');
            options[5] = isChecked('FCDisplay');
            localStorage.GLR_OHScripts = JSON.stringify(options);
		}
    }
})();