JaWeilBaum / pyqtlet2

pyqtlet2 extends pyqtlet which initially brought Leaflet maps to PyQt5 and PySide6.
Other
37 stars 19 forks source link

Implement wrapper for L.icon() #12

Closed JaWeilBaum closed 2 years ago

JaWeilBaum commented 2 years ago

What was done

Created the functionallity to use L.icon. This allows the user to add custom icons to a marker. The icon can either be provided by a an URL or by an file-path. This closes #3

You can use all options which are provided by leaflet (see documentation)

Example usage

  1. Create an icon
    
    # Local file path
    icon_url = os.path.join(os.getcwd(), "pyqtle/web/modules/leaflet_171/images/marker-icon.png")
    # Remote url
    icon_url = "https://leafletjs.com/examples/custom-icons/leaf-red.png"

self.red_icon = L.icon(iconUrl=icon_url, options={ "iconSize": [38, 95], "iconAnchor": [22, 94], })

2. Add the icon to the marker
```lang=python
self.marker.setIcon(self.red_icon)