I have been working with both Folium and Dash Leaflet and one thing that I wish is that they were more consistent on how to do the same thing. As the title of the question suggests, I am looking to achieve changing the marker icons in Dash Leaflet. I have been able to change the marker to an image (example below)
import dash_leaflet as dl
import dash_leaflet.express as dlx
from dash import html, Dash
from dash_extensions.javascript import assign
import json
locations = '''{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-74.00570869445801,
40.713175131022695
]
}
}
]
}'''
use_icon = assign("""function(feature, latlng){
const i = L.icon({iconUrl: `https://cdn4.iconfinder.com/data/icons/standard-free-icons/139/Checkin01-512.png`, iconSize: [40, 40]});
return L.marker(latlng, {icon: i});
}""")
app = Dash()
app.layout = html.Div(children=[
dl.Map(center=[39, -98], zoom=4, children=[
dl.TileLayer(),
dl.GeoJSON(data=dlx.geojson_to_geobuf(json.loads(locations)),
format='geobuf',
options=dict(pointToLayer=use_icon))],
style={'width': '100%', 'height': '100vh'})])
if __name__ == "__main__":
app.run_server(debug=False)
And here is what it looks like
This is great and all, but one of the things that is not desirable is that the coordinate for the maker is in the middle of the image. So as you zoom out the center of the image is where the coordinate is. What I want is the functionality of the regular marker where the base is always where the coordinate is.
In addition, what I would like is to do the same thing that you can do in Folium. Folium allows you to change the color of the regular marker as well as the marker icon from a selection given by Font-Awesome 4.0, Bootstrap 3, and (I believe) Ionicons 1.5.2.. Below is an example of what I am talking about
import folium
m = folium.Map()
folium.Marker((40.713175131022695, -74.00570869445801),
icon=folium.Icon(color='black', icon='fire', prefix='fa')).add_to(m)
m
And here is the result from the code
The behavior of this marker is what I would like to do in Dash Leaflet. Now, before I finish this question, I do want to add one thing. I am looking to use these markers for filtering data (hence why I am using Dash Leaflet), so I am not looking for a solution where you simply use an iframe tag to have the Folium map with the desired marker in the dashboard.
If someone out there is familiar with implementing this, I would appreciate it.
Thanks



