CliffCloud / Leaflet.EasyButton

leaflet control buttons with icons and callbacks
http://cliffcloud.github.io/Leaflet.EasyButton/v1/
MIT License
524 stars 123 forks source link

Custom icon #83

Closed ghost closed 6 years ago

ghost commented 6 years ago

How can I add custom png icon to the button? I put a full path in the icon field as below but it doesn't seem to work. e.g.

 L.easyButton({
 position: 'bottomleft',
 id: 'map-switcher-button',
 states: [{ stateName: 'show-minimap',
 icon:  '../images/marker-icon.png', // this doesn't seem to work
 title: 'test',...
ghost commented 6 years ago

I think I found solution something along the lines of:


import test from '../images/marker-icon.png'

 L.easyButton({
 position: 'bottomleft',
 id: 'map-switcher-button',
 states: [{ stateName: 'show-minimap',
 icon:  `<img src=${test} />`,
 title: 'test',...

if you have better options, feel free to suggest.

atstp commented 6 years ago

you've got the right idea; that's the expected approach.