ipyleaflet icon indicating copy to clipboard operation
ipyleaflet copied to clipboard

Label layers

Open jacogasp opened this issue 7 years ago • 8 comments

Hello, It would be great to have a label over Circle and Rectangle markers, or just having a new Label marker/layer to stick a bare text on the map.

I'm aware of the Label ipywidget, but I'm not able to use it. Any solution? Thanks

jacogasp avatar Jul 31 '18 15:07 jacogasp

Hi, you can bind a popup to the marker/circle if you want. See this example of the documentation.

martinRenou avatar Jul 31 '18 15:07 martinRenou

Hey @martinRenou, thanks for the reply.

Yes, I saw the example and I'm currently using popups for makers. But they are very limited because I cannot remove the background and at the same time I'm forced to click on the marker to read the text. For my purposes, I would like to have the text inside the circle/rectangle to be able to identify in a glance all my POIs without having to click them one by one.

jacogasp avatar Aug 01 '18 07:08 jacogasp

Ok, I'll see what I can do 😊 it would be a nice feature

martinRenou avatar Aug 01 '18 07:08 martinRenou

And of course if you want to do it go on, I think it should be implemented like the popup, but using L.Tooltip of Leafletjs

martinRenou avatar Aug 01 '18 07:08 martinRenou

Great! I have been looking for a way to subclass a Layer o UILayer object within the python module, but it seems that the real graphics layout is managed by Leafletjs, isn't?

jacogasp avatar Aug 03 '18 07:08 jacogasp

Exactly. I actually tried the L.Tooltip of Leafletjs I mentioned, but it may still not be what you're looking for. It looks a lot like what you can do with the popup, just a bit smaller: tooltip

You cannot remove the background. You can center the tooltip if you want but you can't have it "inside" the circle like you asked.

I guess the only way to implement the exact behavior you want is to use the DivIcon of Leafletjs.

As you wish, we can go for the tooltip solution if you like it, it would be simple to implement. Or we can go for a new custom marker containing text using the DivIcon, but it would be more difficult to implement. Anyway, if you want to implement it I can help you through it.

As a workaround for your use case for now, you can use the popup example, and you don't have to click on it in order to show it if you use the following attributes:

popup = Popup(
    close_button=False,
    auto_close=False,
    close_on_escape_key=False
)

exactly like I did in the example of the documentation I gave you (for the popup on the map, but you also can do it for the Marker)

martinRenou avatar Aug 03 '18 08:08 martinRenou

Actually, your result is not too bad for me. It would be great to hide the tooltip and the circle. A plain rectangular object with a small text, than placing on top of it an interactive popup, its a nice solution.

For sure it would be cool to have such kind of marker! I could give a look after vacation.

jacogasp avatar Aug 03 '18 16:08 jacogasp

And of course if you want to do it go on, I think it should be implemented like the popup, but using L.Tooltip of Leafletjs

@martinRenou

I would love to have the leaflet tooltip feature available, could you point me in a general direction on how to implement it?

tomried avatar Mar 04 '24 21:03 tomried