-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWME-TN-Parcel-GIS-Map.js
143 lines (127 loc) · 4.84 KB
/
WME-TN-Parcel-GIS-Map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// ==UserScript==
// @name WME TN Parcel GIS Map
// @namespace https://greasyfork.org/users/45389
// @version 2024.12.08.000
// @description Open the TN Parcel GIS map in another window, at the same location as the WME map. Keeps the location of the GIS map synced to WME.
// @author MapOMatic
// @match *://*.waze.com/*editor*
// @exclude *://*.waze.com/user/editor*
// @match https://tnmap.tn.gov/assessment/beta/*
// @match https://tnmap.tn.gov/assessment/*
// @license GNU GPLv3
// ==/UserScript==
/* global W */
/* global OpenLayers */
const URL_PROTOCOL = 'https://';
const URL_DOMAIN = 'tnmap.tn.gov';
const URL_PATH = '/assessment/';
const WINDOW_NAME = 'tn_gis_map';
const BUTTON_ID = 'tn-gis-button';
const BUTTON_TITLE = 'Open the TN GIS map in a new window';
const LOG_SCRIPT_NAME = 'TN Parcel GIS';
let _mapWindow;
(function main() {
'use strict';
function log(message) {
console.log(LOG_SCRIPT_NAME, message);
}
function logDebug(message) {
console.debug(LOG_SCRIPT_NAME, message);
}
function onButtonClick() {
const url = URL_PROTOCOL + URL_DOMAIN + URL_PATH;
if (!_mapWindow || _mapWindow.closed) {
_mapWindow = window.open(null, WINDOW_NAME);
try {
if (_mapWindow.location && _mapWindow.location.href) {
_mapWindow.location.assign(url);
setTimeout(() => syncGISMapExtent(_mapWindow), 2000);
}
} catch (ex) {
if (ex.code === 18) {
// Ignore if accessing location.href is blocked by cross-domain.
} else {
throw ex;
}
}
}
_mapWindow.focus();
setTimeout(() => syncGISMapExtent(_mapWindow), 2000);
}
function syncGISMapExtent(myMapWindow) {
if (myMapWindow && !myMapWindow.closed) {
const olCenterLonLat = W.map.getCenter();
const olPoint = new OpenLayers.Geometry.Point(olCenterLonLat.lon, olCenterLonLat.lat);
const wgs84Point = W.userscripts.toGeoJSONGeometry(olPoint);
const zoom = W.map.getZoom() - 1;
W.userscripts.toGeoJSONGeometry(olPoint);
try {
myMapWindow.postMessage({
lon: wgs84Point.coordinates[0],
lat: wgs84Point.coordinates[1],
zoom
}, URL_PROTOCOL + URL_DOMAIN);
} catch (ex) {
log(ex);
}
}
}
function init() {
logDebug('Initializing...');
$('.WazeControlPermalink').prepend(
$('<div>').css({ float: 'left', display: 'inline-block', padding: '0px 5px 0px 3px' }).append(
$('<a>', { id: BUTTON_ID, title: BUTTON_TITLE })
.text('TN-GIS')
.css({
float: 'left',
textDecoration: 'none',
color: '#000000',
fontWeight: 'bold'
})
.click(onButtonClick)
)
);
setInterval(() => {
const $btn = $(`#${BUTTON_ID}`);
if ($btn.length > 0) {
$btn.css('color', (_mapWindow && !_mapWindow.closed) ? '#1e9d12' : '#000000');
}
}, 1000);
/* Event listeners */
W.map.events.register('moveend', null, () => syncGISMapExtent(_mapWindow));
logDebug('Initialized.');
}
let waitingForDetailsToClose = false;
let lastData = null;
function receiveMessageGIS(event) {
logDebug(event);
const { data } = event;
lastData = data;
if (!window.location.href.includes('parcel')) {
window.location.assign(`https://tnmap.tn.gov/assessment/#/location/${data.lat}/${data.lon}/${data.zoom}`);
} else if (!waitingForDetailsToClose) {
waitingForDetailsToClose = true;
updateLocationWhenDetailsClosed();
}
}
function updateLocationWhenDetailsClosed() {
if (window.location.href.includes('parcel')) {
setTimeout(updateLocationWhenDetailsClosed, 100);
} else {
window.location.assign(`https://tnmap.tn.gov/assessment/#/location/${lastData.lat}/${lastData.lon}/${lastData.zoom}`);
waitingForDetailsToClose = false;
}
}
function bootstrap() {
if (window.location.host.toLowerCase() === URL_DOMAIN) {
window.addEventListener('message', receiveMessageGIS, false);
} else if (W && W.loginManager && W.loginManager.events.register && W.map) {
init();
} else {
logDebug('Bootstrap failed. Trying again...');
window.setTimeout(bootstrap, 500);
}
}
logDebug('Bootstrap...');
bootstrap();
})();