Importing icons from icondata
Hey The library icondata has become a fairly standard component for Icons in several frameworks. Its therefore often an autoinclude in many projects. Would it be possible to create a feature flag that makes it possible to use the icons defined there?
I tried to look at it myself, but i can't read macros that well yet. I would also be haopy if you just pointed me to a way of doing it that already exists
@TheToddmeister I'm not quite sure what you mean exactly. Can you give me an example in JS?
I'm not that knowledgeable on JS, but ill explain a bit more. According to this documentation: lealet docsf An icon looks like this in JS:
var greenIcon = L.icon({
iconUrl: 'leaf-green.png',
shadowUrl: 'leaf-shadow.png',
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
Icondata Icondata is a popular library for Icons on crates.io. It offers SVG icons using this format: It provides icons using this format:
#[allow(non_upper_case_globals)]
#[doc(hidden)]
pub static AiAccountBookFilled: &icondata_core::IconData = &icondata_core::IconData {
style: None,
x: None,
y: None,
width: None,
height: None,
view_box: Some("0 0 1024 1024"),
stroke_linecap: None,
stroke_linejoin: None,
stroke_width: None,
stroke: None,
fill: None,
data: r###"<path d="M880 184H712v........................................};
Without any personal knowledge on how or if this could be done: I'm wondering if an icondata::Icon could be provided as an argument to output a custom icon in leaflet? Alternativly a macro could transform it at complie time with something like this:
const MOUNTAIN_ICON: &'static LeafletIconUrl = leaflet_icon!(icondata::BsMountainIcon);
struct LeafletIcon{
icon: LeafletIconUrl,
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76]
}
This is a little above my knowledge about rust, but this is my step by step thinking while shooting from the hip;
- At compile time leaflet compiles the svg and and converts it to png
- That compiled png is made available at "mountain_icon.png"
- At runtime MOUNTAIN_ICON is a const url to that png icon
- You can now build a LeafletIcon with args equivalent to those shown above from leaflet documentation