ipyleaflet icon indicating copy to clipboard operation
ipyleaflet copied to clipboard

Mouse events do not correctly report their location when they are over a marker which contains a DivIcon.

Open charliedaly opened this issue 1 year ago • 1 comments

The following code shows the problem:

from ipyleaflet import Map, Marker, DivIcon

m = ipyleaflet.Map(center = (52, -8))

def handler(**kwargs):
    if kwargs['type'] == 'mousemove':
         print(kwargs)

icon = DivIcon(icon_size = [100, 100])

marker = Marker(location = (52, -8), icon = icon)

m.add(marker)
    
m.on_interaction(handler)
m

When the mouse is over the marker, it shows the coordinates of the marker rather than the mouse.

charliedaly avatar Jul 15 '24 18:07 charliedaly

This happens even when the DivIcon is covered by another marker. In the following case, it's covered by a CircleMarker:

from ipyleaflet import Map, Marker, DivIcon, CircleMarker

m = Map(center = (52, -8))

def get_handler(m):
    m.coords = None
    def handler(**kwargs):
        if kwargs['type'] == 'mousemove':
            if m.coords == kwargs['coordinates']:
                print('.', end='')
            else:
                m.coords = kwargs['coordinates']
                print(kwargs)

    return handler

icon = DivIcon(icon_size = [100, 100])

marker = Marker(location = (52, -8), icon = icon)

cm = CircleMarker(location = (52, -8), radius = 80)

m.add(marker)
m.add(cm)
    
m.on_interaction(get_handler(m))
m

The mouse coordinates are correctly reported everywhere except where the DivIcon is.

charliedaly avatar Jul 17 '24 14:07 charliedaly