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:
lrnselfreliance 2026-11-13 17:59:03 -07:00 • committed by Roland
parent 177d0dba4b
commit b2b8e2075c
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
794 changed files with 4193 additions and 252 deletions

View file

@ -290,53 +290,13 @@ def test_maps_config_is_shared(async_client):
@pytest.mark.asyncio
async def test_get_file_sprite(async_client, test_directory, make_pmtiles):
"""MapLibre asks for the sprite of a map file as `<map file>.json` and `.png`, and as `@2x` on a dense screen;
it gets the single resolution sheet when that is all there is."""
async def test_map_file_has_no_sprite_of_its_own(async_client, test_directory, make_pmtiles):
"""The map draws its own icons on an overlay: a sprite sheet beside a map file is not served or reported."""
make_pmtiles('map/extras/features.pmtiles', vector_metadata('towers'))
extras = test_directory / 'map/extras'
(extras / 'sprite.json').write_text('{"tower": {"x": 0, "y": 0, "width": 8, "height": 8, "pixelRatio": 1}}')
(extras / 'sprite.png').write_bytes(b'single')
(test_directory / 'map/extras/sprite.json').write_text('{}')
(test_directory / 'map/extras/sprite.png').write_bytes(b'png')
request, response = await async_client.get('/api/map/files')
assert 'has_sprite' not in response.json['files'][0]
request, response = await async_client.get('/api/map/files/sprite/extras/features.pmtiles.json')
assert response.status_code == HTTPStatus.OK
assert response.json['tower']['pixelRatio'] == 1
request, response = await async_client.get('/api/map/files/sprite/extras/features.pmtiles.png')
assert response.status_code == HTTPStatus.OK
assert response.body == b'single'
# There is no double resolution sheet.
request, response = await async_client.get('/api/map/files/sprite/extras/features.pmtiles@2x.png')
assert response.status_code == HTTPStatus.OK
assert response.body == b'single'
(extras / 'sprite@2x.json').write_text('{"tower": {"x": 0, "y": 0, "width": 16, "height": 16, "pixelRatio": 2}}')
(extras / 'sprite@2x.png').write_bytes(b'double')
request, response = await async_client.get('/api/map/files/sprite/extras/features.pmtiles@2x.png')
assert response.body == b'double'
request, response = await async_client.get('/api/map/files/sprite/extras/features.pmtiles@2x.json')
assert response.json['tower']['pixelRatio'] == 2
request, response = await async_client.get('/api/map/files/sprite/extras/features.pmtiles.png')
assert response.body == b'single'
@pytest.mark.asyncio
async def test_get_file_sprite_missing(async_client, test_directory, make_pmtiles):
"""Only the sprite of a map file is served."""
make_pmtiles('map/features.pmtiles', vector_metadata('towers'))
(test_directory / 'secret.json').write_text('{"secret": true}')
(test_directory / 'map/notes.json').write_text('{"notes": true}')
# The file has no sprite.
request, response = await async_client.get('/api/map/files/sprite/features.pmtiles.json')
assert response.status_code == HTTPStatus.NOT_FOUND
# There is no such map file.
request, response = await async_client.get('/api/map/files/sprite/missing.pmtiles.json')
assert response.status_code == HTTPStatus.NOT_FOUND
# Not the name of a sprite.
for name in ('notes.json', 'features.pmtiles', 'features.pmtiles.txt', 'features.pmtiles@3x.png'):
request, response = await async_client.get(f'/api/map/files/sprite/{name}')
assert response.status_code == HTTPStatus.BAD_REQUEST, name
# Outside of the map directory.
request, response = await async_client.get('/api/map/files/sprite/..%2Fsecret.pmtiles.json')
assert response.status_code in (HTTPStatus.BAD_REQUEST, HTTPStatus.NOT_FOUND)
assert b'secret' not in response.body or response.status_code == HTTPStatus.BAD_REQUEST
assert response.status_code in (HTTPStatus.NOT_FOUND, HTTPStatus.METHOD_NOT_ALLOWED)