WME True Segment Length

Displays geodesic segment length in feet & meters

当前为 2016-12-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WME True Segment Length
// @namespace    https://greasyfork.org/users/30701-justins83-waze
// @version      0.4
// @description  Displays geodesic segment length in feet & meters
// @author       JustinS83
// @include      https://www.waze.com/editor/*
// @include      https://www.waze.com/*/editor/*
// @include      https://beta.waze.com/*
// @exclude      https://www.waze.com/user/editor*
// @grant        none
// @require      https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
// @license      GPLv3
// ==/UserScript==

(function() {

    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 init(){
        window.Waze.selectionManager.events.register("selectionchanged", null, updateDisplay);
        W.model.actionManager.events.register("afteraction",null, updateDisplay);
        W.model.actionManager.events.register("afterundoaction",null, updateDisplay);
        W.model.actionManager.events.register("afterclearactions",null, updateDisplay);
        W.model.actionManager.events.register("noActions",null, noActions);
    }

    function noActions(){
        setTimeout( updateDisplay, 100 ); //have to put in a delay for when the user uses undo to clear all actions - WME updates on top of my changes otherwise.
    }

    function updateDisplay(){
        var count = W.selectionManager.selectedItems.length;
        var metersLength = 0;
        var bold = false;
        if(count > 0){
            for(i=0;i<count;i++){
                if(W.selectionManager.selectedItems[i].model.type === "segment"){
                    metersLength += WazeWrap.Geometry.calculateDistance(W.selectionManager.selectedItems[i].geometry.components);
                    if(!W.selectionManager.selectedItems[0].model.isUnchanged())
                        bold = true;
                }
            }
            if(metersLength >0){
                var ftLength = Math.round(metersLength * 3.28084 *100)/100;
                $('#segment-edit-general > ul > li:nth-child(1) > span')[1].innerHTML = ftLength + " ft";
                if($('#segment-edit-general > ul > li:nth-child(1) > span').length === 2)
                    $('#segment-edit-general > ul > li:nth-child(1)').append('<br/><span class="name">Length: </span><span class="value">' + (Math.round(metersLength*100)/100) +' m</span>');
                if(bold){
                    $('#segment-edit-general > ul > li:nth-child(1) > span').css('font-weight', "bold");
                    $('#segment-edit-general > ul > li:nth-child(2) > span').css('font-weight', "bold");
                }
            }
        }
    }

})();