Skip to content

Conversation

@batuakan
Copy link

Added support to cache online tile maps,
Added custom http headers to pass to the remote tile server to pass around CORS limitations

src/index.ts Outdated
})
if (!response.ok) {
console.error(`Error fetching tile ${provider.name}/${z}/${x}/${y}:`)
res.sendStatus(500)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we pass on whatever status code we got from upstream?

Copy link
Member

@tkurki tkurki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly worked, except when I entered a non working chart source the result was this:
image

This feature is a bit dangerous, as it can fill up your disk and effectively lock people out of their system if the system won't start properly with disk full.

I propose at least the following safeguards:

  • minimum free disk space - so that seeding stops if there is not enough free space
  • some threshold for seeding region size, maybe with just an alert to confirm that the region is large

This kind of long running operations easily error out for one reason or another, and you don't want to start over from the very beginning. The jobs are not persisted over restarts, so it would be useful if the UI could present a list of cached providers and their seeding statuses: what regions are seeded and their status, for example in terms of number of files on disk and a [Continue seeding] button, that would create the tiles list, check for their existence and fetch only missing tiles.

<label for="chart">Chart:</label>
<select id="chart" name="chart" required>
<option value="">-- Select chart --</option>
<option value="eniro">Eniro</option>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these defaults used in some cases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove them

<option value="24">24</option>
</select>
<button id="seedChartsButton">Seed Chart</button>
<button id="clearCacheButton">Clear Cache</button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is all right like this to get started, but I think it would make sense to have a separate list of cached chart providers with associated [Clear Cache] functionality and a separate panel/control for starting seeding jobs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some how tried to fix it

const bbox = this.getBBox(feature.geometry as Polygon);
for (let z = zoomMin; z <= zoomMax; z++) {
const [minX, minY] = this.lonLatToTileXY(bbox[0], bbox[3], z); // top-left
const [maxX, maxY] = this.lonLatToTileXY(bbox[2], bbox[1], z); // bottom-right
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work over antimeridian?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, I hope


async getRegion(regionGUID: string): Promise<Record<string, any>> {
let regionData: any
const resp = await fetch(`${this.urlBase}/signalk/v2/api/resources/regions/${regionGUID}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@panaaj do we have a way to call the resources api from a plugin, to skip the http call?

src/index.ts Outdated
const { jobId, downloader } = ChartDownloader.createAndRegister(urlBase, defaultChartsPath, provider)
// Long going process, create an endpoint to monitor progress
;(async () => {
await downloader.deleteTiles(regionGUID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a weird construction. Can't deleteTiles start deleting the files in the background and return a Promise, and here we just don't await it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to tidy this up a little

@batuakan
Copy link
Author

batuakan commented Oct 28, 2025

This mostly worked, except when I entered a non working chart source the result was this: image

This feature is a bit dangerous, as it can fill up your disk and effectively lock people out of their system if the system won't start properly with disk full.

I propose at least the following safeguards:

* minimum free disk space - so that seeding stops if there is not enough free space

* some threshold for seeding region size, maybe with just an alert to confirm that the region is large

This kind of long running operations easily error out for one reason or another, and you don't want to start over from the very beginning. The jobs are not persisted over restarts, so it would be useful if the UI could present a list of cached providers and their seeding statuses: what regions are seeded and their status, for example in terms of number of files on disk and a [Continue seeding] button, that would create the tiles list, check for their existence and fetch only missing tiles.

I have added a safeguard for diskspace, for the moment if disk space runs lower than 1GB you cannot seed anymore

For the second safeguard, I am thinking of changing the code a little bit, After selecting chart provider and region and click create, it will just create the job instance, calculate the total number tiles, cached tiles and number of tiles to download and show them on webapp, then the user can start actual seeding or deleting process, We can here also add if the number of tiles is greater than lets say 1 million, we can show another confirmation box, saying that is a lot of tiles, consider seeding smaller regions.

Since nobody likes regions, i am also considering /cache/:identifier endpoint to accept several types of inputs, e.g. regionGUID, tile [z,x,y] and all of its subtiles until maxzoom, and bbox. I guess that provides more flexible api and more suitable for different use cases

Trying to fix the anti-meridian thingy now

- antimeridian check
- Added support to seed regions, bboz or tile and subtiles
- Updated webui
- Added safeguards for low diskspace and huge downloads
- Code restructuring
- Changed signalk typo to SignalK
@batuakan batuakan force-pushed the caching_online_map_sources branch from 37dba5a to f16dd19 Compare November 1, 2025 04:55
@tkurki tkurki added the feature label Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants