mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-15 09:11:49 +02:00
Add argument for redrawing tiles.
This commit is contained in:
parent
c03b0ad488
commit
791bf3be75
1 changed files with 11 additions and 5 deletions
|
@ -305,6 +305,7 @@ class Tiles:
|
|||
cache_path: Path,
|
||||
configuration: MapConfiguration,
|
||||
osm_data: OSMData,
|
||||
redraw: bool = False,
|
||||
) -> None:
|
||||
"""
|
||||
Draw one PNG image with all tiles and split it into a set of separate
|
||||
|
@ -314,13 +315,16 @@ class Tiles:
|
|||
:param cache_path: directory for temporary OSM files
|
||||
:param configuration: drawing configuration
|
||||
:param osm_data: OpenStreetMap data
|
||||
:param redraw: update cache
|
||||
"""
|
||||
if self.tiles_exist(directory):
|
||||
if self.tiles_exist(directory) and not redraw:
|
||||
return
|
||||
|
||||
self.draw_image_from_osm_data(cache_path, configuration, osm_data)
|
||||
|
||||
self.draw_image_from_osm_data(
|
||||
cache_path, configuration, osm_data, redraw
|
||||
)
|
||||
input_path: Path = self.get_file_path(cache_path).with_suffix(".png")
|
||||
|
||||
with input_path.open("rb") as input_file:
|
||||
image: Image = Image.open(input_file)
|
||||
|
||||
|
@ -365,11 +369,12 @@ class Tiles:
|
|||
cache_path: Path,
|
||||
configuration: MapConfiguration,
|
||||
osm_data: OSMData,
|
||||
redraw: bool = False,
|
||||
) -> None:
|
||||
"""Draw all tiles using OSM data."""
|
||||
output_path: Path = self.get_file_path(cache_path)
|
||||
|
||||
if not output_path.exists():
|
||||
if not output_path.exists() or redraw:
|
||||
top, left = self.tile_1.get_coordinates()
|
||||
bottom, right = Tile(
|
||||
self.tile_2.x + 1,
|
||||
|
@ -404,7 +409,8 @@ class Tiles:
|
|||
logging.debug(f"File {output_path} already exists.")
|
||||
|
||||
png_path: Path = self.get_file_path(cache_path).with_suffix(".png")
|
||||
if not png_path.exists():
|
||||
|
||||
if not png_path.exists() or redraw:
|
||||
with output_path.open(encoding="utf-8") as input_file:
|
||||
cairosvg.svg2png(file_obj=input_file, write_to=str(png_path))
|
||||
logging.info(f"SVG file is rasterized to {png_path}.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue