Greasy Fork is available in English.

WME

Helper class for Greasy Fork plugins for Waze Map Editor

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/452563/1619574/WME.js

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

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

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
// @version      0.0.3
// @description  Helper class for Greasy Fork plugins for Waze Map Editor
// @license      MIT License
// @author       Anton Shevchuk
// @namespace    https://greasyfork.org/users/227648-anton-shevchuk
// @supportURL   https://github.com/AntonShevchuk/wme-base/issues
// @match        https://*.waze.com/editor*
// @match        https://*.waze.com/*/editor*
// @exclude      https://*.waze.com/user/editor*
// @icon         https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://anton.shevchuk.name&size=64
// @grant        none
// ==/UserScript==

/* jshint esversion: 8 */

/* global W */

class WME {
  /**
   * Get all available POI except selected categories
   * @param {Array} except
   * @return {Array}
   */
  static getVenues (except = []) {
    let selected = W.model.venues.getObjectArray()
    selected = selected.filter(x => x.isGeometryEditable())
    // filter by main category
    if (except.length) {
      selected = selected.filter(model => except.indexOf(model.getMainCategory()) === -1)
    }
    return selected
  }

  /**
   * Get all available segments except selected road types
   * @param {Array} except
   * @return {Array}
   */
  static getSegments (except = []) {
    let selected = W.model.segments.getObjectArray()
    selected = selected.filter(x => x.isGeometryEditable())
    // filter by road type
    if (except.length) {
      selected = selected.filter(segment => except.indexOf(segment.getRoadType()) === -1)
    }
    return selected
  }

  /**
   * Get selected features which you can(!) edit
   * @returns {Array}
   */
  static getSelected () {
    if (!W.selectionManager.hasSelectedFeatures()) {
      return []
    }
    return W.selectionManager.getSelectedDataModelObjects()
      .filter(x => x.isGeometryEditable())
  }

  /**
   * Get selected Area POI(s)
   * @return {Array}
   */
  static getSelectedVenues () {
    return WME.getSelected().filter(x => x.type === 'venue')
  }

  /**
   * Get selected Area POI
   * @return {Object|null}
   */
  static getSelectedVenue () {
    if (WME.getSelectedVenues().length) {
      return WME.getSelectedVenues()[0]
    }
    return null
  }

  /**
   * Get selected Segments
   * @return {Array}
   */
  static getSelectedSegments () {
    return WME.getSelected().filter(x => x.type === 'segment')
  }

  /**
   * Get selected Segment
   * @return {Object|null}
   */
  static getSelectedSegment () {
    if (WME.getSelectedSegments().length) {
      return WME.getSelectedSegments()[0]
    }
    return null
  }

  /**
   * Get selected Nodes
   * @return {Object}
   */
  static getSelectedNodes () {
    return WME.getSelected().filter(x => x.type === 'node')
  }

  /**
   * Get selected Node
   * @return {Object|null}
   */
  static getSelectedNode () {
    if (WME.getSelectedNodes().length) {
      return WME.getSelectedNodes()[0]
    }
    return null
  }
}