From 16c9303a8690f868206dcd3d9dd9f2d5e436e00d Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Thu, 4 Jul 2024 20:49:01 +0100 Subject: [PATCH] fix(hotfix): download of basemaps in ui, max zoom level 22 used for tms --- src/backend/app/projects/project_crud.py | 17 ++++++++++++----- src/backend/app/projects/project_routes.py | 2 +- src/frontend/src/api/Project.js | 5 +++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index d333f23dde..df7f9c3b22 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -1368,7 +1368,7 @@ def get_project_tiles( background_task_id: uuid.UUID, source: str, output_format: str = "mbtiles", - tms: str = None, + tms: Optional[str] = None, ): """Get the tiles for a project. @@ -1381,7 +1381,12 @@ def get_project_tiles( Other options: "pmtiles", "sqlite3". tms (str, optional): Default None. Custom TMS provider URL. """ - zooms = "12-19" + # TODO update this for user input or automatic + # maxzoom can be determined from OAM: https://tiles.openaerialmap.org/663 + # c76196049ef00013b8494/0/663c76196049ef00013b8495 + # TODO xy should also be user configurable + # NOTE mbtile max supported zoom level is 22 (in GDAL at least) + zooms = "12-22" if tms else "12-19" tiles_dir = f"{TILESDIR}/{project_id}" outfile = f"{tiles_dir}/{project_id}_{source}tiles.{output_format}" @@ -1415,7 +1420,9 @@ def get_project_tiles( if project_bbox: min_lon, min_lat, max_lon, max_lat = project_bbox else: - log.error(f"Failed to get bbox from project: {project_id}") + msg = f"Failed to get bbox from project: {project_id}" + log.error(msg) + raise HTTPException(status_code=HTTPStatus.UNPROCESSABLE_ENTITY, detail=msg) log.debug( "Creating basemap with params: " @@ -1424,7 +1431,7 @@ def get_project_tiles( f"zooms={zooms} | " f"outdir={tiles_dir} | " f"source={source} | " - f"xy={False} | " + f"xy={True if tms else False} | " f"tms={tms}" ) @@ -1434,7 +1441,7 @@ def get_project_tiles( zooms=zooms, outdir=tiles_dir, source=source, - xy=False, + xy=True if tms else False, tms=tms, ) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index 8b1669aa18..e11daa3f9a 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -370,7 +370,7 @@ async def download_tiles( return FileResponse( dbtile_obj.path, headers={ - "Content-Disposition": f'attachment; filename="{filename}"', + "Content-Disposition": f"attachment; filename={filename}", "Content-Type": tiles_mime_type, }, ) diff --git a/src/frontend/src/api/Project.js b/src/frontend/src/api/Project.js index 2bc985e789..7285cac28f 100755 --- a/src/frontend/src/api/Project.js +++ b/src/frontend/src/api/Project.js @@ -182,9 +182,10 @@ export const DownloadTile = (url, payload, toOpfs = false) => { return; } - const filename = response.headers['Content-Disposition'].split('filename=')[1]; + const filename = response.headers['content-disposition'].split('filename=')[1]; + console.log(filename) // Create Blob from ArrayBuffer - const blob = new Blob([tileData], { type: response.headers['Content-Type'] }); + const blob = new Blob([tileData], { type: response.headers['content-type'] }); const downloadUrl = URL.createObjectURL(blob); const a = document.createElement('a');