WME Clear Geometry

Temporary script to hook "1" for clearing geometry until Toolbox is fixed

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         WME Clear Geometry
// @namespace    https://greasyfork.org/users/30701-justins83-waze
// @version      0.8
// @description  Temporary script to hook "1" for clearing geometry until Toolbox is fixed
// @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() {

var UpdateSegmentGeometry;

    function bootstrap(tries = 1) {

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

    bootstrap();

    function init(){
        UpdateSegmentGeometry = require('Waze/Action/UpdateSegmentGeometry');

        new WazeWrap.Interface.Shortcut('clearGeomShortcut', 'Clears road geometry', 'editing', 'Editing', '1', ClearGeometry, this).add();

    }

    function ClearGeometry(){
        if (W.selectionManager.getSelectedFeatures().length !== 0) {
            for (i = 0; i < W.selectionManager.getSelectedFeatures().length; i++) {
                var seg = W.selectionManager.getSelectedFeatures()[i].model;
                if (seg.type == "segment") {
                    var newGeo = seg.geometry.clone();
                    newGeo.components.splice(1, newGeo.components.length - 2);
                    newGeo.components[0].calculateBounds();
                    newGeo.components[1].calculateBounds();
                    W.model.actionManager.add(new UpdateSegmentGeometry(seg, seg.geometry, newGeo));
                }
            }
        }
    }
})();