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

Custom Icon #19

Open
jimbok8 opened this issue Jul 2, 2020 · 2 comments
Open

Custom Icon #19

jimbok8 opened this issue Jul 2, 2020 · 2 comments

Comments

@jimbok8
Copy link

jimbok8 commented Jul 2, 2020

Sorry not sure if this is a bug or feature request!
Firstly thanks for your program!
I am trying to use my own .png images (e.g colored triangles) for marker icons.

I can see a marker if I use the default icon (marker-icon.png).

I have tried creating an image called tri.png and I put it in the folder called "images". This is where the confusion arises as it took me a while to appreciate that there are two "images" locations:
"src\webapp\images"
and of course "node_modules\leaflet\dist\images"
Unfortunately, I cannot load images from either of these two locations.
Ideally, I think the best location would be "src\main\resources\images".

Now I am just very confused, and I don't know if it is possible to load my own .png file or where to put it.
Please could you advise?
Thanks.
Jim

P.S. Just noticed that localhost:8080/images contains marker-icon.png, marker-icon-demo.png, layers-2x.png but I don't what creates this folder and copies the files there.

@jimbok8
Copy link
Author

jimbok8 commented Jul 2, 2020

I have finally answered my own question.
You need to read this excellent article:
"Where should I place my Vaadin 10+ static files?"

https://stackoverflow.com/questions/57553973/where-should-i-place-my-vaadin-10-static-files/57553974#57553974

Its says for Vaadin 14, and I can verify Vaadin 15, for SPRING-BOOT applications, you should put images here:
src\main\resources\META-INF\resources\images
Then you can refer to them like this new Icon("images/leaf-green.png").
Hope this helps.
Jim

@Gubancs
Copy link
Owner

Gubancs commented Jul 2, 2020

Hi Jim,
Thank you for your issue request and also your quick response. It is good to know.
I'm very happy to know it works for you.
Alternatively, you can use DivIcon instead of Icon and then you can style it with CSS.

Eg. new DivIcon("my-custom-class");

and in your CSS file:
.my-custom-class: {
background: url("images/leaf-green.png");
}

Of course, you need to put your images to the correct location.

Best regards,
Gabor

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