signalk-livedepth-plugin 0.3.11 → 0.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -897,13 +897,30 @@ var PLUGIN_ID = "signalk-livedepth-plugin";
897
897
  var ASSET_BASE = `/plotterext/${PLUGIN_ID}`;
898
898
  var BATHY_BASE = `${ASSET_BASE}/bathymetry`;
899
899
  var DEBOUNCE_MS = 400;
900
+ var TILE_PAD = 0.25;
901
+ var MAX_LAT = 85;
902
+ var fetchedBounds = null;
903
+ function padBounds(bounds, pad) {
904
+ const [west, south, east, north] = bounds;
905
+ const dx = (east - west) * pad;
906
+ const dy = (north - south) * pad;
907
+ return [
908
+ west - dx,
909
+ Math.max(-MAX_LAT, south - dy),
910
+ east + dx,
911
+ Math.min(MAX_LAT, north + dy)
912
+ ];
913
+ }
914
+ function boundsContain(outer, inner) {
915
+ return inner[0] >= outer[0] && inner[1] >= outer[1] && inner[2] <= outer[2] && inner[3] <= outer[3];
916
+ }
900
917
  var POLL_MS = 15e3;
901
918
  var MAX_TILE_FETCHES = 24;
902
919
  var LIVE_FLUSH_MS = 300;
903
920
  var DEFAULT_DEPTH_PATH = "environment.depth.belowTransducer";
904
921
  var client = await connectExtension();
905
922
  var worker = new Worker(
906
- new URL(`./render-worker.js?v=${"0.3.11"}`, import.meta.url),
923
+ new URL(`./render-worker.js?v=${"0.3.13"}`, import.meta.url),
907
924
  { type: "module" }
908
925
  );
909
926
  var settings = { ...DEFAULT_SETTINGS };
@@ -992,14 +1009,18 @@ async function fetchHistory() {
992
1009
  publishBase();
993
1010
  }
994
1011
  async function fetchTiles(req) {
1012
+ if (fetchedBounds && boundsContain(fetchedBounds, req.bounds)) {
1013
+ return;
1014
+ }
1015
+ const fetchBounds = padBounds(req.bounds, TILE_PAD);
995
1016
  const cellMetres = Math.max(req.resolution, 0.01);
996
1017
  let zoom = zoomForCellSize(cellMetres, MIN_ZOOM, BASE_ZOOM);
997
1018
  while (zoom > MIN_ZOOM) {
998
- const { xs: xs2, ys: ys2 } = tileRangeForBbox(req.bounds, zoom);
1019
+ const { xs: xs2, ys: ys2 } = tileRangeForBbox(fetchBounds, zoom);
999
1020
  if (xs2.length * ys2.length <= MAX_TILE_FETCHES) break;
1000
1021
  zoom--;
1001
1022
  }
1002
- const { xs, ys } = tileRangeForBbox(req.bounds, zoom);
1023
+ const { xs, ys } = tileRangeForBbox(fetchBounds, zoom);
1003
1024
  const out = [];
1004
1025
  await Promise.all(
1005
1026
  xs.flatMap(
@@ -1017,6 +1038,7 @@ async function fetchTiles(req) {
1017
1038
  )
1018
1039
  );
1019
1040
  baseSamples = out;
1041
+ fetchedBounds = fetchBounds;
1020
1042
  publishBase();
1021
1043
  }
1022
1044
  function schedule() {
@@ -1154,6 +1176,7 @@ await client.subscribe(["overlay.state"], (_name, payload) => {
1154
1176
  const state = payload;
1155
1177
  if (!state.visible || state.suspended) {
1156
1178
  worker.postMessage({ type: "release" });
1179
+ fetchedBounds = null;
1157
1180
  stopLive();
1158
1181
  } else {
1159
1182
  startLive();