WME OH Scripts

Recommended scripts for editing in Ohio

当前为 2016-11-16 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         WME OH Scripts
// @namespace    https://greasyfork.org/users/30701-justins83-waze
// @version      0.5.2
// @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?version=158078
// @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/11240-wme-counties-ohio-census-2014/code/WME%20Counties%20Ohio%20Census%202014.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);
		}
    }
})();