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>
|
<div class="rotators" id="rotators"></div>
|
||||||
|
|
||||||
<script>
|
<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 {
|
class RotatorState {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.boxSize = 400;
|
this.boxSize = 400;
|
||||||
@@ -172,8 +177,11 @@
|
|||||||
this.bgCanvas.height = state.boxSize;
|
this.bgCanvas.height = state.boxSize;
|
||||||
this.bgCtx = this.bgCanvas.getContext('2d');
|
this.bgCtx = this.bgCanvas.getContext('2d');
|
||||||
|
|
||||||
this.mapImage = new Image();
|
this.mapImage = null;
|
||||||
this.mapImage.onload = () => this.drawBackgroundCache();
|
this.mapUrl = null;
|
||||||
|
this.mapLoadGeneration = 0;
|
||||||
|
this.mapRetryTimer = null;
|
||||||
|
setInterval(() => this.loadMap(), MAP_REFRESH_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPoint(angle, radius) {
|
getPoint(angle, radius) {
|
||||||
@@ -184,12 +192,34 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the background map; elevation rotators get none, like in the firmware UI. */
|
||||||
updateMap(url) {
|
updateMap(url) {
|
||||||
if (url && this.mapImage.src !== new URL(url, document.baseURI).href) {
|
const nextUrl = this.state.elevation !== 0 ? null
|
||||||
this.mapImage.src = url;
|
: (url && url !== '0') ? url : DEFAULT_MAP_URL;
|
||||||
} else {
|
if (nextUrl !== this.mapUrl) {
|
||||||
|
this.mapUrl = nextUrl;
|
||||||
|
this.mapImage = null;
|
||||||
|
this.loadMap();
|
||||||
|
}
|
||||||
this.drawBackgroundCache();
|
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() {
|
drawBackgroundCache() {
|
||||||
@@ -200,6 +230,11 @@
|
|||||||
|
|
||||||
ctx.clearRect(0, 0, sz, sz);
|
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.beginPath();
|
||||||
ctx.lineWidth = 1;
|
ctx.lineWidth = 1;
|
||||||
ctx.strokeStyle = '#606060';
|
ctx.strokeStyle = '#606060';
|
||||||
@@ -212,10 +247,6 @@
|
|||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
|
|
||||||
if (this.mapImage.complete && this.mapImage.naturalHeight !== 0) {
|
|
||||||
ctx.drawImage(this.mapImage, 0, 0, sz, sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.lineWidth = 8;
|
ctx.lineWidth = 8;
|
||||||
ctx.strokeStyle = 'orange';
|
ctx.strokeStyle = 'orange';
|
||||||
if (this.state.azRange > 360) {
|
if (this.state.azRange > 360) {
|
||||||
@@ -475,6 +506,8 @@
|
|||||||
body: `ROT=${angle}`
|
body: `ROT=${angle}`
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.updateStatic();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStatic() {
|
updateStatic() {
|
||||||
|
|||||||
Reference in New Issue
Block a user