SVG as symbol source #175
Replies: 4 comments 23 replies
-
Thanks for this suggestion. I think it would be best to open an issue in MapLibre GL JS and Native if there is not already one for this issue. |
Beta Was this translation helpful? Give feedback.
-
I built this capability for a couple of map controls in the past. This eventually made it into Azure Maps which uses MapLibre under the hood. Happy to make a pull request for this, but want to outline how I think this should work and see if that aligns with your expectations: The map control has the With this in mind there are two methods we could use to add SVGs to the map: Method 1: Add an SVG that already has style defined (colors): With this method we could add the SVG to the image sprite and the user could use it as a static image. There would be a couple of constraints on the image that we would document, such as the SVG must have a Method 2: Add an SVG Template framework This would be more of an extension of method 1 and would provide an easy way to load an SVG template into a class that can set a primary and secondary color, and scale the SVG. Setting color and scale would be optional. For example, an SVG template might look like this:
Notice the placeholders for scale and colors. The text placeholder is there to allow the template to also be reusable with HTML Markers. With this framework, you could load a single template into framework, then loop through all the color combinations you want and generate and add the images to the maps image sprite quickly. You can also make use of the maps In Azure Maps the methods for loading templates is in the root namespace and includes methods to add, get a single template, and get all templates. The map control then has a method to create and add an image from a template as documented here: https://learn.microsoft.com/en-us/javascript/api/azure-maps-control/atlas.imagespritemanager?view=azure-maps-typescript-latest#azure-maps-control-atlas-imagespritemanager-createfromtemplate In Azure Maps we also preloaded a couple dozen templates to save developers time. Here are some samples:
With the methods I mentioned above there are some key constraints to know:
Does the above approach align with the functionality you are looking to achieve? |
Beta Was this translation helpful? Give feedback.
-
I've created an initial proof of concept plugin that provides a manager or adding SVG images to the map sprite, and also provides a framework for templated SVG images. You can check it out here: https://github.com/rbrundritt/maplibre-gl-svg Have a look and see if this meets your needs. I haven't published an NPM package yet as I want to get feedback first and lock in the initial version. |
Beta Was this translation helpful? Give feedback.
-
The @nationalparkservice / @jmcandrew-nps (/ others?) recently released an SVG plugin for Maplibre GL JS: https://github.com/nationalparkservice/npmap5-plugins/tree/main/svg-icons It looks pretty promising, and supports CSS styling. |
Beta Was this translation helpful? Give feedback.
-
I would love to be able to use SVG images as a symbol source. Moreover, if we had the possibility to colorize via the class names of objects, that would be perfect!
Beta Was this translation helpful? Give feedback.
All reactions