-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWME-StreetViewAvailability.user.js
126 lines (118 loc) · 10.4 KB
/
WME-StreetViewAvailability.user.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
// ==UserScript==
// @name WME Street View Availability
// @namespace http://www.tomputtemans.com/
// @description Shows a layer displaying the available street view roads and locations
// @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADcAAAA3CAYAAACo29JGAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4AQDBy0e4s/JBQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAPtUlEQVRo3s2aeXRV9bXHP79zzh1yk9zMhIQMzHMQBIImEDAEDSqDBsHW2qp1RNBaV/vqs7bawVdfS9XWPvWhhapVaQEFFUGRACEDk0lIIGGUkIEkZL65Q+49Q/8IgjHTTaSr/tY6ayXrnt9e+3v23t89/H5i7969Bl9bBYVFfByYgDx0GElledwycwpIMt/WVVVVx5Txf+fY8QBi41eh6xoAUk8vXzNtKqvtHXSUfs7Rq9L5zeaPMXT9WwlM1w08zr8hJI3W9psuAQMQPVnu4k/UNzbwqjkezemE00d5YtoILLbAK6ZYRUUF77//IadPnUEIwYiRiSxZcjMjRozwa78kSeTl7uGBe0rYsHkEkybfjKb5AU4W8OTbWzBmpWMvzsWxYDmcKeP75jbGTZrcRchAl9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uvQ6pXSNtyFTuGbeER5OnMLf0M2TVy9khI3nmT/9HXUMDXp8PVVUH7SVfH0F2i7nW5hY2OHOhxctDU5ah6Vq/dC0JiU2bNlJQdpiIhKGED4+m7lQVOFUyUzOYOH4Clq/NWoQQNDY08Nu167GPHIPP0cbC0cOYc938KwJu1969XcFpmsZfst9CxAWS7Exg1vTkXnNfQ0MDBQUFHK88jduiEjKs08Jao5upCRMZPWIk8XHxaJrWq7JCCAxDZ+OOnewtLsWaOIbhvnbuX5E16AsIAsjLz2N7QvJlcLIsU1B4kLIRbXTsqeKRZffi9ni6EIO3w0tZ2TEOHy3mTGMlEQnRBEeF0lLZgN2wkjb1WiZNmoTX5x2QYiaTiWPHjvH2wRLUDg8dF85z39JFTJw0CZ9vYKc/qqrybIUT1WK7DK6lsZn1tZ9gjw5nsT6VyCGdecjn8+H2etjy/hayc/eQ+p0F+NxeAgJtXDhSSdYNi4iJiUVIArPZ/M0qSV3nhXVvoo4YR3NlBUkRdm7LXDCgRtjd4eX3ziBiygo6wZlMJt7asxl1Zhix+zXmp11HU2Mj723bimeCjYAOmYYvzmO123CdbebWm5aQMCwei8VyZa94XEz+xSUlrN2ezZj0TFqK9vPY8qXY7Xa/yrWc/Qf4bHIGGec+51/VubELnJH3/AAAAABJRU5ErkJggg==
// @version 2.0.0
// @grant none
// ==/UserScript==
var wmeSDK;
window.SDK_INITIALIZED.then(() => {
wmeSDK = getWmeSdk({ scriptId: "street-view-availability", scriptName: "Street View Availability"});
wmeSDK.Events.once({ eventName: "wme-ready" }).then(init);
});
function init() {
var enteringStreetView = false, // Set to true when the marker is being dragged to the map
ignoreStreetViewExit = false, // Set to true to indicate that the street view availability was set to visible manually and should not be reverted
pinWasHidden = true; // Contains previous pin display state, used to detected changes
const streetViewControl = document.querySelector('.street-view-control');
const buttons = document.getElementById('overlay-buttons-region');
// Layer object to encapsulate layer logic
const layer = function() {
const layerName = 'Street View';
wmeSDK.Map.addTileLayer({
layerName: layerName,
layerOptions: {
tileHeight: 256,
tileWidth: 256,
url: {
fileName: 'mapslt?lyrs=svv&x=${x}&y=${y}&z=${z}&w=256&h=256&style=40',
servers: ['https://mts0.google.com', 'https://mts1.google.com', 'https://mts2.google.com', 'https://mts3.google.com' ]
}
}
});
wmeSDK.Events.trackLayerEvents({ layerName: layerName });
wmeSDK.Events.on({
eventName: 'wme-layer-visibility-changed',
eventHandler: () => {
if (!enteringStreetView && layer.isLayerVisible()) {
ignoreStreetViewExit = true;
}
if (!layer.isLayerVisible()) {
ignoreStreetViewExit = false;
}
}
});
return {
setVisibility: (visibility) => wmeSDK.Map.setLayerVisibility({
layerName: layerName,
visibility: visibility
}),
isLayerVisible: () => wmeSDK.Map.isLayerVisible({ layerName: layerName })
};
}();
layer.setVisibility(false);
// Add layer entry in the new layer drawer
var displayGroupToggle = document.getElementById('layer-switcher-group_display');
if (displayGroupToggle != null) {
var displayGroup = displayGroupToggle.parentNode;
while (displayGroup != null && displayGroup.className != 'group') {
displayGroup = displayGroup.parentNode;
}
var togglesList = displayGroup.querySelector('.collapsible-GROUP_DISPLAY');
var toggler = document.createElement('li');
var checkbox = document.createElement('wz-checkbox');
checkbox.id = 'layer-switcher-item_street_view';
checkbox.type = 'checkbox';
checkbox.className = 'hydrated';
checkbox.textContent = 'Street View';
checkbox.addEventListener('click', e => layer.setVisibility(e.target.checked));
toggler.appendChild(checkbox);
togglesList.appendChild(toggler);
displayGroupToggle.addEventListener('click', function() {
checkbox.disabled = !displayGroupToggle.checked;
layer.setVisibility(displayGroupToggle.checked && checkbox.checked);
});
}
// Create keyboard shortcut to toggle the imagery layer (Shift+T)
wmeSDK.Shortcuts.createShortcut({
callback: () => {
layer.setVisibility(!layer.isLayerVisible());
checkbox.checked = layer.isLayerVisible();
},
description: 'Toggle street view availability',
shortcutId: 'toggleStreetViewAvailability',
shortcutKeys: 'S+t'
});
// Add an observer to activate the script whenever the street view marker gets dragged around
// TODO: maybe simplify by both observering the pin and the class street-view-mode in #map?
var controlObserver = new MutationObserver(function(mutationRecords) {
try {
var activeButton = mutationRecords.find(record => record.target.classList.contains('overlay-button-active'));
if ((activeButton == null) != pinWasHidden) {
if (pinWasHidden == true && displayGroupToggle.checked) {
pinWasHidden = activeButton == null;
enteringStreetView = true;
layer.setVisibility(true);
enteringStreetView = false;
} else if (pinWasHidden == false && !ignoreStreetViewExit) {
pinWasHidden = activeButton == null;
layer.setVisibility(false);
}
}
} catch (error) {
console.error('Error caught while observing pin mutation', error);
}
});
controlObserver.observe(streetViewControl, { attributes: true, attributeFilter: ['class'] });
var buttonsObserver = new MutationObserver(function(mutationRecords) {
mutationRecords.forEach(record => {
var streetViewControl = record.target.querySelector('.street-view-control');
if (streetViewControl) {
controlObserver.observe(streetViewControl, { attributes: true, attributeFilter: ['class'] });
}
});
});
buttonsObserver.observe(buttons, { childList: true });
}