WME Larimer GIS Map

Open a Larimer County 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 Larimer GIS Map
  3. // @namespace https://greasyfork.org/users/45389
  4. // @version 0.3.2
  5. // @description Open a Larimer County 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 jcloudm for localization, MapOMatic original
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
  8. // @include /^http:\/\/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. var Extent;
  18. var SpatialReference;
  19. var receiverAdded = false;
  20.  
  21. function log(message, level) {
  22. if (message && level <= debugLevel) {
  23. console.log('LC GIS:', message);
  24. }
  25. }
  26.  
  27. function onButtonClick() {
  28. var wazeExt = W.map.getExtent();
  29. var url = 'http://www.arcgis.com/home/webmap/viewer.html?urls=http%3A%2F%2Fmaps1.larimer.org%2Farcgis%2Frest%2Fservices%2FBasemaps%2Fbasemap%2FMapServer%2Chttp%3A%2F%2Fmaps1.larimer.org%2Farcgis%2Frest%2Fservices%2FMapServices%2FParcels%2FMapServer&source=sd&extent=';
  30. url += wazeExt.left + '%2C' + wazeExt.bottom + '%2C' + wazeExt.right + '%2C' + wazeExt.top + '%2C102113';
  31. if (!mapWindow || mapWindow.closed) {
  32. mapWindow = window.open(null, 'lc_gis_map');
  33. try {
  34. if (mapWindow.location && mapWindow.location.href) {
  35. mapWindow.location.assign(url);
  36. }
  37. } catch (ex) {
  38. if (ex.code === 18) {
  39. // Ignore if accessing location.href is blocked by cross-domain.
  40. } else {
  41. throw ex;
  42. }
  43. }
  44. }
  45. mapWindow.focus();
  46. syncGISMapExtent();
  47. }
  48.  
  49. function syncGISMapExtent() {
  50. if (mapWindow && !mapWindow.closed) {
  51. var wazeExt = W.map.getExtent();
  52. mapWindow.postMessage({type:'setExtent', xmin:wazeExt.left, xmax:wazeExt.right, ymin:wazeExt.bottom, ymax:wazeExt.top, spatialReference: 102113}, 'http://www.arcgis.com');
  53. }
  54. }
  55.  
  56. function init() {
  57. $('.WazeControlPermalink').prepend(
  58. $('<div>').css({float:'left',display:'inline-block', padding:'0px 5px 0px 3px'}).append(
  59. $('<a>',{id:'lc-gis-button',title:'Open the LC GIS map in a new window', href:'javascript:void(0)'})
  60. .text('LCGIS')
  61. .css({float:'left',textDecoration:'none', color:'#000000', fontWeight:'bold'})
  62. .click(onButtonClick)
  63. )
  64. );
  65.  
  66. setInterval(function() {
  67. var $btn = $('#lc-gis-button');
  68. if ($btn.length > 0) {
  69. $btn.css('color', (mapWindow && !mapWindow.closed) ? '#1e9d12' : '#000000');
  70. }
  71. }, 500);
  72.  
  73. /* Event listeners */
  74. W.map.events.register('moveend',null, syncGISMapExtent);
  75.  
  76. log('Initialized.', 1);
  77. }
  78.  
  79. function receiveMessageGIS(event) {
  80. var data = event.data;
  81. if (!Extent) {
  82. Extent = unsafeWindow.require('esri/geometry/Extent');
  83. SpatialReference = unsafeWindow.require('esri/SpatialReference');
  84. }
  85. switch (data.type) {
  86. case 'setExtent':
  87. }
  88. var map = unsafeWindow.arcgisonline.map.main.map;
  89. var ext = new Extent({xmin:data.xmin, xmax:data.xmax, ymin:data.ymin, ymax:data.ymax, spatialReference:new SpatialReference({wkid:data.spatialReference})});
  90. unsafeWindow.arcgisonline.map.main.map.setExtent(ext);
  91. }
  92.  
  93. function receiveMessageWME(event) {
  94. // TBD
  95. }
  96.  
  97. function bootstrap() {
  98. if (window.location.host.toLowerCase() === "www.arcgis.com") {
  99. window.addEventListener("message", receiveMessageGIS, false);
  100. } else {
  101. if (!receiverAdded) {
  102. window.addEventListener("message", receiveMessageWME, false);
  103. receiverAdded = true;
  104. }
  105. if (W && W.loginManager &&
  106. W.loginManager.events.register &&
  107. W.map) {
  108. log('Initializing...', 1);
  109. init();
  110. } else {
  111. log('Bootstrap failed. Trying again...', 1);
  112. window.setTimeout(function () {
  113. bootstrap();
  114. }, 200);
  115. }
  116. }
  117. }
  118.  
  119. log('Bootstrap...', 1);
  120. bootstrap();
  121. })();