show the world map behind each rotator scale
Fall back to the IP-rotator firmware's default xplanet grayline map (remoteqth.com/xplanet/OK.png) when the rotator has no map URL, draw it beneath the scale instead of over the spokes, refresh it every 30 min with a cache-buster, and skip it for elevation rotators. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+42
-9
@@ -141,6 +141,11 @@
|
||||
<div class="rotators" id="rotators"></div>
|
||||
|
||||
<script>
|
||||
// Same default as the IP-rotator firmware: a live xplanet grayline map centred on OK.
|
||||
const DEFAULT_MAP_URL = 'https://remoteqth.com/xplanet/OK.png';
|
||||
const MAP_REFRESH_MS = 30 * 60 * 1000;
|
||||
const MAP_RETRY_MS = 10 * 1000;
|
||||
|
||||
class RotatorState {
|
||||
constructor() {
|
||||
this.boxSize = 400;
|
||||
@@ -172,8 +177,11 @@
|
||||
this.bgCanvas.height = state.boxSize;
|
||||
this.bgCtx = this.bgCanvas.getContext('2d');
|
||||
|
||||
this.mapImage = new Image();
|
||||
this.mapImage.onload = () => this.drawBackgroundCache();
|
||||
this.mapImage = null;
|
||||
this.mapUrl = null;
|
||||
this.mapLoadGeneration = 0;
|
||||
this.mapRetryTimer = null;
|
||||
setInterval(() => this.loadMap(), MAP_REFRESH_MS);
|
||||
}
|
||||
|
||||
getPoint(angle, radius) {
|
||||
@@ -184,12 +192,34 @@
|
||||
};
|
||||
}
|
||||
|
||||
/** Sets the background map; elevation rotators get none, like in the firmware UI. */
|
||||
updateMap(url) {
|
||||
if (url && this.mapImage.src !== new URL(url, document.baseURI).href) {
|
||||
this.mapImage.src = url;
|
||||
} else {
|
||||
const nextUrl = this.state.elevation !== 0 ? null
|
||||
: (url && url !== '0') ? url : DEFAULT_MAP_URL;
|
||||
if (nextUrl !== this.mapUrl) {
|
||||
this.mapUrl = nextUrl;
|
||||
this.mapImage = null;
|
||||
this.loadMap();
|
||||
}
|
||||
this.drawBackgroundCache();
|
||||
}
|
||||
|
||||
/** (Re)loads the map with a cache-buster so the grayline stays current. */
|
||||
loadMap() {
|
||||
clearTimeout(this.mapRetryTimer);
|
||||
if (!this.mapUrl) return;
|
||||
const generation = ++this.mapLoadGeneration;
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
if (generation !== this.mapLoadGeneration) return;
|
||||
this.mapImage = img;
|
||||
this.drawBackgroundCache();
|
||||
};
|
||||
img.onerror = () => {
|
||||
if (generation !== this.mapLoadGeneration) return;
|
||||
this.mapRetryTimer = setTimeout(() => this.loadMap(), MAP_RETRY_MS);
|
||||
};
|
||||
img.src = this.mapUrl + (this.mapUrl.includes('?') ? '&' : '?') + 't=' + Date.now();
|
||||
}
|
||||
|
||||
drawBackgroundCache() {
|
||||
@@ -200,6 +230,11 @@
|
||||
|
||||
ctx.clearRect(0, 0, sz, sz);
|
||||
|
||||
// The map's globe has the same 0.9 radius as the scale, so it is drawn at full size.
|
||||
if (this.mapImage) {
|
||||
ctx.drawImage(this.mapImage, 0, 0, sz, sz);
|
||||
}
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.lineWidth = 1;
|
||||
ctx.strokeStyle = '#606060';
|
||||
@@ -212,10 +247,6 @@
|
||||
}
|
||||
ctx.stroke();
|
||||
|
||||
if (this.mapImage.complete && this.mapImage.naturalHeight !== 0) {
|
||||
ctx.drawImage(this.mapImage, 0, 0, sz, sz);
|
||||
}
|
||||
|
||||
ctx.lineWidth = 8;
|
||||
ctx.strokeStyle = 'orange';
|
||||
if (this.state.azRange > 360) {
|
||||
@@ -475,6 +506,8 @@
|
||||
body: `ROT=${angle}`
|
||||
}).catch(() => {});
|
||||
});
|
||||
|
||||
this.updateStatic();
|
||||
}
|
||||
|
||||
updateStatic() {
|
||||
|
||||
Reference in New Issue
Block a user