WME

Helper class for Greasy Fork镜像 plugins for Waze Map Editor

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/452563/1218878/WME.js

  1. // ==UserScript==
  2. // @name WME
  3. // @version 0.0.3
  4. // @description Helper class for Greasy Fork镜像 plugins for Waze Map Editor
  5. // @license MIT License
  6. // @author Anton Shevchuk
  7. // @namespace https://gf.qytechs.cn/users/227648-anton-shevchuk
  8. // @supportURL https://github.com/AntonShevchuk/wme-base/issues
  9. // @match https://*.waze.com/editor*
  10. // @match https://*.waze.com/*/editor*
  11. // @exclude https://*.waze.com/user/editor*
  12. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://anton.shevchuk.name&size=64
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. /* jshint esversion: 8 */
  17.  
  18. /* global W */
  19.  
  20. class WME {
  21. /**
  22. * Get all available POI except selected categories
  23. * @param {Array} except
  24. * @return {Array}
  25. */
  26. static getVenues (except = []) {
  27. let selected = W.model.venues.getObjectArray()
  28. selected = selected.filter(x => x.isGeometryEditable())
  29. // filter by main category
  30. if (except.length) {
  31. selected = selected.filter(model => except.indexOf(model.getMainCategory()) === -1)
  32. }
  33. return selected
  34. }
  35.  
  36. /**
  37. * Get all available segments except selected road types
  38. * @param {Array} except
  39. * @return {Array}
  40. */
  41. static getSegments (except = []) {
  42. let selected = W.model.segments.getObjectArray()
  43. selected = selected.filter(x => x.isGeometryEditable())
  44. // filter by road type
  45. if (except.length) {
  46. selected = selected.filter(segment => except.indexOf(segment.getRoadType()) === -1)
  47. }
  48. return selected
  49. }
  50.  
  51. /**
  52. * Get selected features which you can(!) edit
  53. * @returns {Array}
  54. */
  55. static getSelected () {
  56. if (!W.selectionManager.hasSelectedFeatures()) {
  57. return []
  58. }
  59. return W.selectionManager.getSelectedDataModelObjects()
  60. .filter(x => x.isGeometryEditable())
  61. }
  62.  
  63. /**
  64. * Get selected Area POI(s)
  65. * @return {Array}
  66. */
  67. static getSelectedVenues () {
  68. return WME.getSelected().filter(x => x.type === 'venue')
  69. }
  70.  
  71. /**
  72. * Get selected Area POI
  73. * @return {Object|null}
  74. */
  75. static getSelectedVenue () {
  76. if (WME.getSelectedVenues().length) {
  77. return WME.getSelectedVenues()[0]
  78. }
  79. return null
  80. }
  81.  
  82. /**
  83. * Get selected Segments
  84. * @return {Array}
  85. */
  86. static getSelectedSegments () {
  87. return WME.getSelected().filter(x => x.type === 'segment')
  88. }
  89.  
  90. /**
  91. * Get selected Segment
  92. * @return {Object|null}
  93. */
  94. static getSelectedSegment () {
  95. if (WME.getSelectedSegments().length) {
  96. return WME.getSelectedSegments()[0]
  97. }
  98. return null
  99. }
  100.  
  101. /**
  102. * Get selected Nodes
  103. * @return {Object}
  104. */
  105. static getSelectedNodes () {
  106. return WME.getSelected().filter(x => x.type === 'node')
  107. }
  108.  
  109. /**
  110. * Get selected Node
  111. * @return {Object|null}
  112. */
  113. static getSelectedNode () {
  114. if (WME.getSelectedNodes().length) {
  115. return WME.getSelectedNodes()[0]
  116. }
  117. return null
  118. }
  119. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址