Custom symbols: creating vector icons from svg files (sprites) #3243
daniel-j-h
started this conversation in
Show and tell
Replies: 2 comments
-
We just recently updated the sprite docs to be a bit more clear, it is in the style-spec repo, feel free to add more info there. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for the write-up, @daniel-j-h. Note to others trying this out: spritezero currently contains a bug in its retina scaling when the svg files have a viewport attribute (which they most probably have). The retina-version will be cut off. Remove the viewport attributes from your svg files or install the fork with the fix: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey folks, I started playing around with maplibre and protomaps and after learning about font glyphs my next step is sprites!
I'll document below what I have found out because it was not obvious to me.
Here's what we want to achieve: being able to put icons from iconsax (or any svg icon library) on the map as vector symbols (sdf). Vector symbols means we can style its properties like the color at runtime based on data or zoom level.
The icons I'm going for as an example for no particular reason; it's a zip file of svg files
Here's a direct download link for the zip file with iconsax svg files in it
https://codeload.github.com/rendinjast/iconsax-react/zip/refs/heads/master
Let's create a single directory with symbolic links to all svg files in the "bold" variant
We can then use spritezero from https://www.npmjs.com/package/@elastic/spritezero - the retina flag creates
@2
files for high-density screens. Maplibre will request either the regular sprite or the high-density one automatically later on.Put the four files (2x .png and 2x .json) on a static host, e.g. I'm using an S3 bucket here
In the frontend map code we add the sprite url to the map initialization
Add a source and style it with a symbol from the sprite
https://maplibre.org/maplibre-style-spec/layers/#symbol
And there it is! 😍
Hope that helps!
Existing documentation
Beta Was this translation helpful? Give feedback.
All reactions