Skip to content

Commit

Permalink
Auto basemap generation if tms url is input during project creation (#…
Browse files Browse the repository at this point in the history
…2027)

* feat: add background task for basemap generation during project file generation

* feat: add 'tms' option to tile_source for basemap generation

* feat: update basemap generation to support custom tile source
  • Loading branch information
Anuj-Gupta4 authored Dec 31, 2024
1 parent 1d6bf1d commit 6d7aa55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ async def add_additional_entity_list(
async def generate_files(
db: Annotated[Connection, Depends(db_conn)],
project_user_dict: Annotated[ProjectUserDict, Depends(project_manager)],
background_tasks: BackgroundTasks,
xlsform_upload: Annotated[
Optional[BytesIO], Depends(central_deps.read_optional_xlsform)
],
Expand All @@ -905,6 +906,7 @@ async def generate_files(
created (i.e. the project form references multiple geometries).
db (Connection): The database connection.
project_user_dict (ProjectUserDict): Project admin role.
background_tasks (BackgroundTasks): FastAPI background tasks.
Returns:
json (JSONResponse): A success message containing the project ID.
Expand Down Expand Up @@ -980,6 +982,13 @@ async def generate_files(
},
)

if project.custom_tms_url:
basemap_in = project_schemas.BasemapGenerate(
tile_source="custom", file_format="pmtiles", tms_url=project.custom_tms_url
)
org_id = project.organisation_id
await generate_basemap(project_id, org_id, basemap_in, db, background_tasks)

return JSONResponse(
status_code=HTTPStatus.OK,
content={"message": "success"},
Expand All @@ -999,7 +1008,19 @@ async def generate_project_basemap(
project_id = project_user.get("project").id
org_id = project_user.get("project").organisation_id

await generate_basemap(project_id, org_id, basemap_in, db, background_tasks)
# Create task in db and return uuid
return {"Message": "Tile generation started"}


async def generate_basemap(
project_id: int,
org_id: int,
basemap_in: project_schemas.BasemapGenerate,
db: Connection,
background_tasks: BackgroundTasks,
):
"""Generate basemap tiles for a project."""
log.debug(
"Creating generate_project_basemap background task "
f"for project ID: {project_id}"
Expand All @@ -1023,8 +1044,6 @@ async def generate_project_basemap(
basemap_in.tms_url,
)

return {"Message": "Tile generation started"}


@router.patch("/{project_id}", response_model=project_schemas.ProjectOut)
async def update_project(
Expand Down
4 changes: 3 additions & 1 deletion src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ class ProjectUserContributions(BaseModel):
class BasemapGenerate(BaseModel):
"""Params to generate a new basemap."""

tile_source: Annotated[Literal["esri", "bing", "google"], Field(default="esri")]
tile_source: Annotated[
Literal["esri", "bing", "google", "custom"], Field(default="esri")
]
file_format: Annotated[
Literal["mbtiles", "sqlitedb", "pmtiles"],
Field(default="mbtiles"),
Expand Down

0 comments on commit 6d7aa55

Please sign in to comment.