maplibre / martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.
https://martin.maplibre.org
Apache License 2.0
2.17k stars 205 forks source link

Support SDF sprites #1075

Open nyurik opened 9 months ago

nyurik commented 9 months ago

In some cases, images should be encoded using SDF first. The @flother's spreet crate already supports it with https://github.com/flother/spreet/issues/58, so it should be fairly easy (?) to use that.

Overview

Similar to the regular spritesheets, given a directory with png/svg/... images, converts all images in that directory and subdirectories to SDF images before packaging them in a spritesheet. If needed SDF and non-SDF spritesheets can be combined by the client, e.g. GET /sprites/icons,sdf_icons.png (or .json|@2x.png|@2x.json. No new API endpoints are introduced.

CLI Configuration

martin --sdf-sprites <directory_or_image>

YAML Configuration

# Sprite configuration
sprites:
  # This controls how all all images will be processed. false by default
  # This can be overridden only by setting   sources.<sprite_id>.sdf
  default_sdf: false | true | pretransformed
  paths:
    # all SVG files in this dir will be published as a "my_images" sprite source
    - /path/to/my_images
  sources:
    # SVG images in this directory will be published as a "my_sprites" sprite source
    my_sprites: /path/to/some_dir
    # SDF SVG images in this directory will be published as a "my_sprites" sprite source
    my_sprites:
      path: /path/to/some_sdf_dir
      # This tells Martin to handle images in some_sdf_dir as SDFs
      sdf: false | true | pretransformed
jleedev commented 9 months ago
      # This tells Martin to handle images in some_sdf_dir as SDFs

As worded, this could be read as though the images will be interpreted as SDFs and served as-is. That's presumably not a desired use case, but it's a possible one, so this should imply that the images will be transformed to SDFs.

nyurik commented 9 months ago

Thx @jleedev , good point. We seem to have 3 cases:

I could change the above use_sdf to sdf: no | convert | assume -- I am not a big fan of these names though... suggestions?

jleedev commented 9 months ago

Perhaps sdf: false | true | pretransformed. It's my assumption that it's slightly weird to have existing SDF images that you want to serve, but it's trivial to support this so it would be weirder not to. The plain value of sdf: true can mean "apply the SDF transformation to these images".

nyurik commented 9 months ago

Agree, thx, updated the proposal above

CommanderStorm commented 2 weeks ago

So, I looked into this:

Will provide the PR tomorrow after further testing that it works ^^

CommanderStorm commented 2 weeks ago

Scratch that, since spreet just converts the entirety of the stylesheet, it either makes sense to just reduce this to one setting make_sdf: bool which affects all sprites.