I noticed two further optimizations possible in spritezero, and this PR implements them.
Compute
Currently if a calling application wants both a sprite.png and sprite.json it needs to call generateLayout twice with different options. This incurs the mapnik SVG rasterization twice, which is expensive.
So this PR adds a backwards compatible extra argument to the options.format path to generateLayout so that a calling application can get all the data needed to pass to generateImage in one call.
Size
The PNGs being generated by generateImage are not optimized. With a few options passed to mapnik they can easily be cut in half the size without any noticeable visual quality drop.
Because it is impossible for spritezero to know the right defaults for color quantization for all downstream applications, this exposes a new function called generateOptimizedImage. This accepts an options argument to control the color optimization level.
I noticed two further optimizations possible in spritezero, and this PR implements them.
Compute
Currently if a calling application wants both a
sprite.png
andsprite.json
it needs to callgenerateLayout
twice with different options. This incurs the mapnik SVG rasterization twice, which is expensive.So this PR adds a backwards compatible extra argument to the
options.format
path togenerateLayout
so that a calling application can get all the data needed to pass togenerateImage
in one call.Size
The PNGs being generated by
generateImage
are not optimized. With a few options passed to mapnik they can easily be cut in half the size without any noticeable visual quality drop.Because it is impossible for spritezero to know the right defaults for color quantization for all downstream applications, this exposes a new function called
generateOptimizedImage
. This accepts anoptions
argument to control the color optimization level./cc @mapbox/map-design-api @mapbox/static-apis