WME_Assist_Scanner

Waze Map Editor Assist Scanner

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

  1. // ==UserScript==
  2. // @name WME_Assist_Scanner
  3. // @author borman84 (Boris Molodenkov)
  4. // @description Waze Map Editor Assist Scanner
  5. // @match https://world.waze.com/editor/*
  6. // @match https://*.waze.com/editor/*
  7. // @match https://*.waze.com/*/editor/*
  8. // @match https://world.waze.com/map-editor/*
  9. // @match https://world.waze.com/beta_editor/*
  10. // @match https://www.waze.com/map-editor/*
  11. // @grant none
  12. // @include https://editor-beta.waze.com/*
  13. // @include https://*.waze.com/editor/editor/*
  14. // @include https://*.waze.com/*/editor/*
  15. // @version 0.5.22
  16. // @namespace WazeRus
  17. // ==/UserScript==
  18.  
  19. var WME_Assist = WME_Assist || {}
  20.  
  21. WME_Assist.Scaner = function (wazeapi) {
  22. var model = wazeapi.model;
  23. var map = wazeapi.map;
  24. var controller = wazeapi.controller;
  25.  
  26. var getData = function (e, cb) {
  27. console.log(e);
  28. $.get(wazeapi.Config.paths.features, e).done(cb);
  29. }
  30.  
  31. var splitExtent = function (extent, zoom) {
  32. var result = [];
  33.  
  34. var ratio = map.getResolution() / map.getResolutionForZoom(zoom);
  35. var dx = extent.getWidth() / ratio;
  36. var dy = extent.getHeight() / ratio;
  37.  
  38. var x, y;
  39. for (x = extent.left; x < extent.right; x += dx) {
  40. for (y = extent.bottom; y < extent.top; y += dy) {
  41. var bounds = new OpenLayers.Bounds();
  42. bounds.extend(new OpenLayers.LonLat(x, y));
  43. bounds.extend(new OpenLayers.LonLat(x + dx, y + dy));
  44.  
  45. result.push(bounds);
  46. }
  47. }
  48.  
  49. return result;
  50. }
  51.  
  52. var zoomToRoadType = function (zoom) {
  53. var s = wazeapi.Config.segments.zoomToRoadType[zoom] || [];
  54. if (-1 === s) {
  55. s = W.Config.segments.allTypes;
  56. }
  57.  
  58. var r = [];
  59. Object.keys(wazeapi.Config.segments.zoomToRoadType).forEach(function (t) {
  60. t = parseInt(t, 10);
  61. var i = s.contains(t);
  62. if (i) {
  63. r.push(t);
  64. }
  65. })
  66.  
  67. return (r.length == 0) ? null : { roadTypes: s.toString() }
  68. }
  69.  
  70. this.scan = function (bounds, zoom, analyze, progress) {
  71. var boundsArray = splitExtent(bounds, zoom);
  72. var completed = 0;
  73.  
  74. if (boundsArray.length > 20 && !confirm('Script will scan ' + boundsArray.length + ' peaces. Are you OK?')) {
  75. return;
  76. }
  77.  
  78. progress = progress || function () {}
  79.  
  80. WME_Assist.series(boundsArray, 0, function (bounds, next) {
  81. var peace = bounds.transform(map.getProjectionObject(), map.displayProjection);
  82.  
  83. var e = {
  84. bbox: peace.toBBOX(),
  85. language: I18n.locale,
  86. venueFilter: '1',
  87. venueLevel: wazeapi.Config.venues.zoomToSize[zoom],
  88. };
  89.  
  90. OL.Util.extend(e, zoomToRoadType(zoom));
  91.  
  92. getData(e, function (data) {
  93. analyze(peace, zoom, data);
  94. progress(++completed*100/boundsArray.length);
  95. next();
  96. });
  97. });
  98. }
  99. }