WME Clear Geometry

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

2017-01-23 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         WME Clear Geometry
// @namespace    https://greasyfork.org/users/30701-justins83-waze
// @version      0.6
// @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) {
        tries = tries || 1;

        if (window.W &&
            window.W.map &&
            window.W.model &&
            window.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 (Waze.selectionManager.selectedItems.length !== 0) {
            for (i = 0; i < Waze.selectionManager.selectedItems.length; i++) {
                var seg = Waze.selectionManager.selectedItems[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();
                    Waze.model.actionManager.add(new UpdateSegmentGeometry(seg, seg.geometry, newGeo));
                }
            }
        }
    }
})();