mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 09:56:17 -05:00
The map draws its own icons on an overlay (#967)
An overlay drawn with a style of its own names icons, which needed the sprite sheet that style was made for. The map now ships icons for overlays, the Maki and Temaki sets (both CC0), and always draws those, in both viewers. The sprite sheet is the translation: its index lists every icon under its own name, under each other name it answers to (modules/map/icons/aliases.json), and in both spellings of each. A name with no icon is drawn as a plain dot. The icons are signed distance fields, so a style's icon color and halo apply. A pattern is not an icon: what it filled (a fill, a line or an extrusion) is drawn in a translucent color, where removing a pattern used to leave MapLibre's opaque black. A sprite sheet beside a map file is no longer used, served or reported. wrolpi/scripts/build_map_icons.py builds the sheet from the SVGs; the sheet is committed.
This commit is contained in:
parent
177d0dba4b
commit
b2b8e2075c
794 changed files with 4193 additions and 252 deletions
|
|
@ -263,13 +263,6 @@ def test_delete_pmtiles_file_forgets_ignored(async_client, test_directory, make_
|
|||
assert file['visible'] is True
|
||||
|
||||
|
||||
def _make_sprite(base, resolutions=('',)):
|
||||
"""Create sprite sheets (`<base>.json`, `<base>.png`); each says which it is."""
|
||||
for resolution in resolutions:
|
||||
base.with_name(f'{base.name}{resolution}.json').write_text(f'{{"sheet": "{base.name}{resolution}"}}')
|
||||
base.with_name(f'{base.name}{resolution}.png').write_bytes(f'{base.name}{resolution}'.encode())
|
||||
|
||||
|
||||
def test_sidecar_style(test_directory, make_pmtiles):
|
||||
"""A style beside a map file says how it is drawn: its own, else the one its directory shares."""
|
||||
own = make_pmtiles('map/extras/own.pmtiles', vector_metadata('towers'))
|
||||
|
|
@ -292,46 +285,6 @@ def test_sidecar_style(test_directory, make_pmtiles):
|
|||
assert files['elsewhere.pmtiles']['style_map_path'] is None
|
||||
assert files['extras/shared.pmtiles']['style_path'] == 'map/extras/style.json'
|
||||
assert files['elsewhere.pmtiles']['style_path'] is None
|
||||
assert {i['has_sprite'] for i in files.values()} == {False}
|
||||
|
||||
|
||||
def test_sidecar_sprite(test_directory, make_pmtiles):
|
||||
"""A sprite sheet is a .json and a .png; a file's own is used before the one its directory shares."""
|
||||
own = make_pmtiles('map/extras/own.pmtiles', vector_metadata('towers'))
|
||||
shared = make_pmtiles('map/extras/shared.pmtiles', vector_metadata('towers'))
|
||||
extras = test_directory / 'map/extras'
|
||||
|
||||
# Half of a sheet is not a sheet.
|
||||
(extras / 'sprite.json').write_text('{}')
|
||||
assert lib.find_sidecar_sprite(shared) is None
|
||||
|
||||
_make_sprite(extras / 'sprite')
|
||||
_make_sprite(extras / 'own.sprite')
|
||||
assert lib.find_sidecar_sprite(shared, 'json') == extras / 'sprite.json'
|
||||
assert lib.find_sidecar_sprite(shared, 'png') == extras / 'sprite.png'
|
||||
assert lib.find_sidecar_sprite(own, 'png') == extras / 'own.sprite.png'
|
||||
|
||||
files = {i['map_path']: i['has_sprite'] for i in lib.get_pmtiles_files()}
|
||||
assert files == {'extras/own.pmtiles': True, 'extras/shared.pmtiles': True}
|
||||
|
||||
|
||||
def test_sidecar_sprite_resolution(test_directory, make_pmtiles):
|
||||
"""The sheet of the other resolution is used when the one asked for does not exist."""
|
||||
path = make_pmtiles('map/extras/features.pmtiles', vector_metadata('towers'))
|
||||
extras = test_directory / 'map/extras'
|
||||
|
||||
_make_sprite(extras / 'sprite')
|
||||
assert lib.find_sidecar_sprite(path, 'png', high_resolution=True) == extras / 'sprite.png'
|
||||
|
||||
_make_sprite(extras / 'sprite', ('@2x',))
|
||||
assert lib.find_sidecar_sprite(path, 'png', high_resolution=True) == extras / 'sprite@2x.png'
|
||||
assert lib.find_sidecar_sprite(path, 'json', high_resolution=True) == extras / 'sprite@2x.json'
|
||||
assert lib.find_sidecar_sprite(path, 'png') == extras / 'sprite.png'
|
||||
|
||||
# Only the double resolution sheet exists.
|
||||
(extras / 'sprite.json').unlink()
|
||||
assert lib.find_sidecar_sprite(path, 'png') == extras / 'sprite@2x.png'
|
||||
assert lib.find_sidecar_sprite(path, 'json') == extras / 'sprite@2x.json'
|
||||
|
||||
|
||||
def test_sidecar_style_custom_map_directory(test_directory, make_pmtiles, test_wrolpi_config):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue