WME WI GIS Map

Open a WI GIS map in another window, at the same location as the WME map. Keeps the location of the GIS map synced to WME.

  1. // ==UserScript==
  2. // @name WME WI GIS Map
  3. // @namespace https://greatest.deepsurf.us/users/45389
  4. // @version 2018.06.19.001
  5. // @description Open a WI GIS map in another window, at the same location as the WME map. Keeps the location of the GIS map synced to WME.
  6. // @author MapOMatic
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @include /^https?:\/\/maps\.sco\.wisc\.edu\/Parcels.*/
  9. // @license GNU GPLv3
  10. // ==/UserScript==
  11.  
  12. // NOTE: As of July 2023, the WI parcel viewer was changed so that it no longer works with this code.
  13. // There is not "map" object to manipulate. So this script is broken, probably for good...
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. var debugLevel = 0;
  19. var mapWindow;
  20. var Extent;
  21. var SpatialReference;
  22. var receiverAdded = false;
  23.  
  24. function log(message, level) {
  25. if (message && level <= debugLevel) {
  26. console.log('WI GIS:', message);
  27. }
  28. }
  29.  
  30. function onButtonClick() {
  31. var wazeExt = W.map.getExtent();
  32. var url = 'http://maps.sco.wisc.edu/Parcels/';
  33. if (!mapWindow || mapWindow.closed) {
  34. mapWindow = window.open(null, 'wi_gis_map');
  35. try {
  36. if (mapWindow.location && mapWindow.location.href) {
  37. mapWindow.location.assign(url);
  38. setTimeout(function() {syncGISMapExtent(mapWindow); }, 1000);
  39. }
  40. } catch (ex) {
  41. if (ex.code === 18) {
  42. // Ignore if accessing location.href is blocked by cross-domain.
  43. } else {
  44. throw ex;
  45. }
  46. }
  47. }
  48. mapWindow.focus();
  49. syncGISMapExtent(mapWindow);
  50. }
  51.  
  52. function syncGISMapExtent(myMapWindow) {
  53. console.log('sync message sent');
  54. if (myMapWindow && !myMapWindow.closed) {
  55. var wazeExt = W.map.getExtent();
  56. try {
  57. myMapWindow.postMessage({type:'setExtent', xmin:wazeExt.left, xmax:wazeExt.right, ymin:wazeExt.bottom, ymax:wazeExt.top, spatialReference: 102113}, 'http://maps.sco.wisc.edu');
  58. } catch (ex) {
  59. log(ex, 0);
  60. }
  61. try {
  62. myMapWindow.postMessage({type:'setExtent', xmin:wazeExt.left, xmax:wazeExt.right, ymin:wazeExt.bottom, ymax:wazeExt.top, spatialReference: 102113}, 'https://maps.sco.wisc.edu');
  63. } catch (ex) {
  64. log(ex, 0);
  65. }
  66. }
  67. }
  68.  
  69. function init() {
  70. $('.WazeControlPermalink').prepend(
  71. $('<div>').css({float:'left',display:'inline-block', padding:'0px 5px 0px 3px'}).append(
  72. $('<a>',{id:'wi-gis-button',title:'Open the WI GIS map in a new window', href:'javascript:void(0)'})
  73. .text('WI-GIS')
  74. .css({float:'left',textDecoration:'none', color:'#000000', fontWeight:'bold'})
  75. .click(onButtonClick)
  76. )
  77. );
  78.  
  79. setInterval(function() {
  80. var $btn = $('#wi-gis-button');
  81. if ($btn.length > 0) {
  82. $btn.css('color', (mapWindow && !mapWindow.closed) ? '#1e9d12' : '#000000');
  83. }
  84. }, 500);
  85.  
  86. /* Event listeners */
  87. W.map.events.register('moveend',null, function(){syncGISMapExtent(mapWindow);});
  88.  
  89. log('Initialized.', 1);
  90. }
  91.  
  92. function receiveMessageGIS(event) {
  93. if (unsafeWindow._viewerMap) {
  94. log(event, 1);
  95. var data = event.data;
  96. if (!Extent) {
  97. Extent = unsafeWindow.require('esri/geometry/Extent');
  98. SpatialReference = unsafeWindow.require('esri/SpatialReference');
  99. }
  100. switch (data.type) {
  101. case 'setExtent':
  102. }
  103. //var map = unsafeWindow.arcgisonline.map.main.map;
  104. var ext = new Extent({xmin:data.xmin, xmax:data.xmax, ymin:data.ymin, ymax:data.ymax, spatialReference:new SpatialReference({wkid:data.spatialReference})});
  105. unsafeWindow._viewerMap.setExtent(ext);
  106. } else {
  107. setTimeout(function() {receiveMessageGIS(event);}, 1000);
  108. }
  109. }
  110.  
  111. function receiveMessageWME(event) {
  112. // TBD
  113. }
  114.  
  115. function bootstrap() {
  116. if (window.location.host.toLowerCase() === "maps.sco.wisc.edu") {
  117. window.addEventListener("message", receiveMessageGIS, false);
  118. } else {
  119. if (!receiverAdded) {
  120. window.addEventListener("message", receiveMessageWME, false);
  121. receiverAdded = true;
  122. }
  123. if (W && W.loginManager &&
  124. W.loginManager.events.register &&
  125. W.map) {
  126. log('Initializing...', 1);
  127. init();
  128. } else {
  129. log('Bootstrap failed. Trying again...', 1);
  130. window.setTimeout(function () {
  131. bootstrap();
  132. }, 200);
  133. }
  134. }
  135. }
  136.  
  137. log('Bootstrap...', 1);
  138. bootstrap();
  139. })();