Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing icons from icondata #35

Open
TheToddmeister opened this issue Oct 17, 2024 · 2 comments
Open

Importing icons from icondata #35

TheToddmeister opened this issue Oct 17, 2024 · 2 comments

Comments

@TheToddmeister
Copy link

TheToddmeister commented Oct 17, 2024

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

@flosse
Copy link
Member

flosse commented Oct 18, 2024

@TheToddmeister I'm not quite sure what you mean exactly. Can you give me an example in JS?

@TheToddmeister
Copy link
Author

TheToddmeister commented Oct 23, 2024

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;

  1. At compile time leaflet compiles the svg and and converts it to png
  2. That compiled png is made available at "mountain_icon.png"
  3. At runtime MOUNTAIN_ICON is a const url to that png icon
  4. You can now build a LeafletIcon with args equivalent to those shown above from leaflet documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants