WME OpenMaps

Add an additional layer containing maps that are released as open data to Waze Map Editor

目前為 2015-10-28 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name WME OpenMaps
  3. // @namespace http://www.tomputtemans.com/
  4. // @description Add an additional layer containing maps that are released as open data to Waze Map Editor
  5. // @include https://www.waze.com/*/editor/*
  6. // @include https://www.waze.com/editor/*
  7. // @include https://editor-beta.waze.com/*
  8. // @version 1.3
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. function omInit() {
  14. // Check initialisation
  15. if (typeof Waze == 'undefined' || typeof Waze.map == 'undefined') {
  16. setTimeout(omInit, 660);
  17. log('Waze object unavailable, map still loading');
  18. return;
  19. }
  20. log('OM initated');
  21.  
  22. var layers = [
  23. // AGIV: Vlaanderen (Belgium)
  24. // <Fees>Het gebruiksrecht is te vinden op http://www.agiv.be/gis/diensten/?artid=1442</Fees>
  25. // <AccessConstraints>geen</AccessConstraints>
  26. new OL.Layer.WMS('AGIV GRB',
  27. 'https://grb.agiv.be/geodiensten/raadpleegdiensten/GRB/wms',
  28. { layers: "GRB_Basiskaart", format: "image/png" },
  29. { transitionEffect: "resize", tileSize: new OL.Size(512,512) }
  30. ),
  31. // Projet Informatique de Cartographie Continue: Wallonie (Belgium)
  32. // <Fees></Fees>
  33. // <AccessConstraints></AccessConstraints>
  34. new OL.Layer.WMS('PICC topographie',
  35. 'http://geoservices.wallonie.be/arcgis/services/TOPOGRAPHIE/PICC/MapServer/WMSServer',
  36. { layers: "1,2,3,5,6,8,24,25,33,48,49,50,52,53,54,55,56,58,59,60", format: "image/png" },
  37. { transitionEffect: "resize", tileSize: new OL.Size(512,512), projection: new OL.Projection("EPSG:3857") }
  38. )
  39. ];
  40. Waze.map.addLayers(layers);
  41. if (typeof localStorage.OM_opacity == 'undefined') {
  42. localStorage.OM_opacity = 100;
  43. }
  44. // set up language string
  45. var om_strings = {
  46. en: {
  47. opacity_label: "Opacity"
  48. },
  49. nl: {
  50. opacity_label: "Doorzichtigheid"
  51. },
  52. fr: {
  53. opacity_label: "Opacité"
  54. }
  55. };
  56. om_strings['en_GB'] = om_strings.en;
  57. I18n.availableLocales.map(function(locale) {
  58. if (I18n.translations[locale]) {
  59. I18n.translations[locale].openmaps = om_strings[locale];
  60. }
  61. });
  62.  
  63. var opacityDiv = document.createElement('div');
  64. opacityDiv.style.position = 'absolute';
  65. opacityDiv.style.display = 'none';
  66. opacityDiv.style.zIndex = 1020;
  67. if (document.getElementById('topbar-container')) { // new layout
  68. opacityDiv.style.top = "0";
  69. opacityDiv.style.right = "0";
  70. opacityDiv.style.backgroundColor = "#3d3d3d";
  71. opacityDiv.style.padding = "5px";
  72. opacityDiv.style.color = "#fff";
  73. opacityDiv.style.fontWeight = "bold";
  74. opacityDiv.style.borderBottomLeftRadius = "8px";
  75. } else {
  76. opacityDiv.className = 'WazeControlLocationInfo';
  77. opacityDiv.style.right = '20px';
  78. opacityDiv.style.left = 'auto';
  79. opacityDiv.style.top = '40px';
  80. }
  81. var opacitySlider = document.createElement('input');
  82. opacitySlider.type = 'range';
  83. opacitySlider.max = 100;
  84. opacitySlider.min = 5;
  85. opacitySlider.step = 5;
  86. opacitySlider.value = localStorage.OM_opacity;
  87. opacitySlider.style.verticalAlign = 'middle';
  88. opacitySlider.addEventListener('input', function() {
  89. layers.map(function(layer) {
  90. layer.setOpacity(opacitySlider.value / 100);
  91. });
  92. localStorage.OM_opacity = opacitySlider.value;
  93. });
  94. opacityDiv.appendChild(document.createTextNode(I18n.t('openmaps.opacity_label') + ': '));
  95. opacityDiv.appendChild(opacitySlider);
  96. document.getElementById('WazeMap').appendChild(opacityDiv);
  97. layers.map(function(layer) {
  98. layer.events.register('visibilitychanged', null, function(e) {
  99. opacityDiv.style.display = (layer.visibility ? 'block' : 'none');
  100. });
  101. layer.setOpacity(localStorage.OM_opacity / 100);
  102. });
  103.  
  104. // Necessary as the layer doesn't update when a zoom has occurred
  105. Waze.map.events.register('zoomend', null, function() {
  106. layers.map(function(layer) {
  107. layer.redraw();
  108. });
  109. });
  110. }
  111.  
  112.  
  113. function log(message) {
  114. if (typeof message === 'string') {
  115. console.log('OM: ' + message);
  116. } else {
  117. console.log('OM', message);
  118. }
  119. }
  120.  
  121. // attempt to bootstrap after about a second
  122. log('OM bootstrap set');
  123. setTimeout(omInit, 1020);
  124. })();