I need to make popups dragable

2,088 views
Skip to first unread message

beams...@gmail.com

unread,
Dec 14, 2012, 10:28:52 AM12/14/12
to leafl...@googlegroups.com
looking for a way to drag the labels for a marker. If I have multiple makers near each other I would like to be able to arrange the labels without moving the marker so I can read them all, and they do not overlap. Any ideas on how this might be done?

Thanks, Joe

Paulo Vieira

unread,
Dec 14, 2012, 10:51:22 AM12/14/12
to leafl...@googlegroups.com
On Fri, Dec 14, 2012 at 3:28 PM, <beams...@gmail.com> wrote:
looking for a way to drag the labels for a marker. If I have multiple makers near each other I would like to be able to arrange the labels without moving the marker so I can read them all, and they do not overlap. Any ideas on how this might be done?

This plugin might give you some ideas:

http://erictheise.github.com/rrose/

beams...@gmail.com

unread,
Dec 14, 2012, 1:31:24 PM12/14/12
to leafl...@googlegroups.com
I found the L.Draggable, http://leafletjs.com/reference.html#draggable 

Not sure how to use it, google does not turn up much, any examples out there?

Paulo Vieira

unread,
Dec 14, 2012, 2:39:47 PM12/14/12
to leafl...@googlegroups.com
On Fri, Dec 14, 2012 at 6:31 PM, <beams...@gmail.com> wrote:
I found the L.Draggable, http://leafletjs.com/reference.html#draggable 

Not sure how to use it, google does not turn up much, any examples out there?

See the example in leaflet.draw (0.2 branch). After you add a marker to the map, you can change its position.
https://github.com/jacobtoye/Leaflet.draw

However I'm not sure if the popup attached to a marker will drag too. You probably have to close the pop, drag the marker, and open again.

Michał Drzał

unread,
Sep 8, 2014, 11:52:58 AM9/8/14
to leafl...@googlegroups.com
Sorry for digging this out, but in case someone would need it:

var popup = L.popup({closeOnClick:false}) .setLatLng(e.latlng)   .setContent('<h3>Hello world!<br />This is a nice popup.</h3>');

 map.addLayer(popup);

var pos = map.latLngToLayerPoint(popup._latlng);
L.DomUtil.setPosition(popup._wrapper.parentNode, pos);
var draggable = new L.Draggable(popup._container, popup._wrapper);
draggable.enable();

I know using _properties is risky, but I don't know how to access them other way.
Reply all
Reply to author
Forward
0 new messages