WME TX FC Map

Open a TX FC 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 TX FC Map
  3. // @namespace https://greatest.deepsurf.us/users/45389
  4. // @version 0.1
  5. // @description Open a TX FC 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:\/\/www\.arcgis\.com\/home\/webmap\/viewer\.html.*/
  9. // @license GNU GPLv3
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var debugLevel = 0;
  16. var mapWindow;
  17.  
  18. function log(message, level) {
  19. if (message && level <= debugLevel) {
  20. console.log('TxDOT-FC:', message);
  21. }
  22. }
  23.  
  24. function onButtonClick() {
  25. var wazeExt = W.map.getExtent();
  26. var url = 'https://www.arcgis.com/home/webmap/viewer.html?useExisting=1&layers=b553554a0a0842928936cf41e0721bc5';
  27. url += '&extent=' + wazeExt.left + '%2C' + wazeExt.bottom + '%2C' + wazeExt.right + '%2C' + wazeExt.top + '%2C102113';
  28. if (!mapWindow || mapWindow.closed) {
  29. setTimeout(function(){mapWindow = window.open(url, '_blank'); syncGISMapExtent();}, 5);
  30. } else {
  31. mapWindow.focus();
  32. syncGISMapExtent();
  33. }
  34. }
  35.  
  36. function syncGISMapExtent() {
  37. if (mapWindow && !mapWindow.closed) {
  38. var wazeExt = W.map.getExtent();
  39. mapWindow.postMessage({xmin:wazeExt.left, xmax:wazeExt.right, ymin:wazeExt.bottom, ymax:wazeExt.top}, 'https://www.arcgis.com');
  40. }
  41. }
  42.  
  43. function init() {
  44. console.log('OK!!!!!!!!!!!!!');
  45. $('.WazeControlPermalink').prepend(
  46. $('<div>').css({float:'left',display:'inline-block', padding:'0px 5px 0px 3px'}).append(
  47. $('<a>',{id:'gis-button',title:'Open the external map in a new window'})
  48. .text('TxDOT-FC').attr('href','javascript:void(0)')
  49. .css({float:'left',textDecoration:'none', color:'#000000', fontWeight:'bold'})
  50. .click(onButtonClick)
  51. )
  52. );
  53.  
  54. setInterval(function() {
  55. var $btn = $('#gis-button');
  56. if ($btn.length > 0) {
  57. $btn.css('color', (mapWindow && !mapWindow.closed) ? '#1e9d12' : '#000000');
  58. }
  59. }, 500);
  60.  
  61. /* Event listeners */
  62. W.map.events.register('moveend',null, syncGISMapExtent);
  63.  
  64. log('Initialized.', 1);
  65. }
  66.  
  67. function receiveMessage(event) {
  68. var extentData = event.data;
  69. var Extent = unsafeWindow.require('esri/geometry/Extent');
  70. var SpatialReference = unsafeWindow.require('esri/SpatialReference');
  71. var map = unsafeWindow.arcgisonline.map.main.map;
  72. var ext = new Extent({xmin:extentData.xmin, xmax:extentData.xmax, ymin:extentData.ymin, ymax:extentData.ymax, spatialReference:new SpatialReference({wkid:102113})});
  73. unsafeWindow.arcgisonline.map.main.map.setExtent(ext);
  74. }
  75.  
  76. function bootstrap() {
  77. if (window.location.host.toLowerCase() === "www.arcgis.com") {
  78. window.addEventListener("message", receiveMessage, false);
  79. } else if (W && W.loginManager &&
  80. W.loginManager.events.register &&
  81. W.map) {
  82. log('Initializing...', 1);
  83. init();
  84. } else {
  85. log('Bootstrap failed. Trying again...', 1);
  86. window.setTimeout(function () {
  87. bootstrap();
  88. }, 200);
  89. }
  90. }
  91.  
  92. log('Bootstrap...', 1);
  93. bootstrap();
  94. })();