Kibana: [Maps][Maki] add build scripts to build sprite sheet with SDF

Created on 26 Jun 2019  路  7Comments  路  Source: elastic/kibana

https://github.com/elastic/maki needs some build scripts to convert SVGs into sprite sheet with SDF enabled

cc @nyurik

Geo maki

Most helpful comment

Apologies @nyurik. I meant to link this file. https://github.com/mapbox/maki/blob/v0.5.0/sdf-render.js

All 7 comments

Pinging @elastic/kibana-gis

The relevant article is (in Russian) - https://habr.com/ru/post/215905/ describes a process of converting a PNG into an SDF PNG using ImageMagick:

convert in.png -filter Jinc -resize 400% -threshold 30% \( +clone -negate -morphology Distance Euclidean -level 50%,-50% \) -morphology Distance Euclidean -compose Plus -composite -level 45%,55% -resize 25% out.png

I can take a look at this.

Also, an older version of Maki included a script to generate SDF icons.

I am not sure that script generates sdfs. It seems it just converts SVGs -> PNGs... Also, I suspect convert (imagemagic) could take svgs directly, but i'm no expert.

Apologies @nyurik. I meant to link this file. https://github.com/mapbox/maki/blob/v0.5.0/sdf-render.js

imagemagick

The example in the link Yuri posted above did not work well for the Maki icons. I assume this is because the Maki icons are much more intricate and have holes rather than a complete fill as seen in the jaguar example.

This is the script I wrote based on the Russian article.

convert -resize 1024x icons/bicycle-15.svg -threshold 50% -alpha off \
    \( +clone -negate -morphology Distance Euclidean -level 50%,-50% \) \
    -morphology Distance Euclidean -compose Plus -composite -level 50%,50% \
    -filter Jinc -transparent white -resize 15x \
    png/bicycle.png

Here's the result PNG for the bicycle icon.
bicycle_Jinc

And here is what it looks like in Mapbox-gl
Screenshot_2019-07-01 Add an icon to the map(1)

fontnik

I had much better luck with directly rendering SDF images from SVGs in the browser using a fork of Mapbox's fontnik library (I had to fix a bug, hence the fork). Here is a demo that shows this in action.

Here is a screenshot from the demo.
Screenshot_2019-07-01 Display a map

spritezero

I also have been working on a POC for rendering an SDF sprite sheet using Spritezero. Currently spritezero only creates regular PNGs from SVG icons. My changes to Spritezero uses the Fontnik example above, but it creates a sprite sheet of SDF PNG images and a JSON file. These could be used in the sprite parameter of the Mapbox Style Spec.

sdf

Was this page helpful?
0 / 5 - 0 ratings

Related issues

treussart picture treussart  路  3Comments

timroes picture timroes  路  3Comments

MaartenUreel picture MaartenUreel  路  3Comments

spalger picture spalger  路  3Comments

socialmineruser1 picture socialmineruser1  路  3Comments