Leaflet.label icon indicating copy to clipboard operation
Leaflet.label copied to clipboard

Allow center-position of Labels

Open crrobinson14 opened this issue 11 years ago • 4 comments

This pull request adds a 'center' option for 'position' that shifts the Label half its width rather than all or none of it. This can be used to horizontally center a Label, e.g. by:

var mapCenter = map.getCenter();
var label = new L.Label({
    classname: 'heading',
    direction: 'center',
    offset: [0, 0]
});
label.setContent('My Heading');
label.setLatLng([51.6, mapCenter.lng]);
map.showLabel(label);

The vertical position is still up to the caller - Label only calculates its width, not its height.

crrobinson14 avatar Dec 16 '13 18:12 crrobinson14

Have you checked out https://github.com/Leaflet/Leaflet.label/pull/55? I have to find some time to review that pull, but I think it will provide this functionality.

jacobtoye avatar Dec 17 '13 04:12 jacobtoye

I didn't read it thoroughly yet but at first glance they seem similar. In the comment trail there seems to be some confusion about why this is required. autoVertical isn't a complete answer. My use case is for things like legends and headings where you want to put something in a fixed lat/lng rather than having the system guess whether to bump it up or down...

crrobinson14 avatar Dec 17 '13 04:12 crrobinson14

Will this be merged?

Arxi avatar Sep 07 '14 08:09 Arxi

Is this going to be merged?

ceesvanegmond avatar Nov 11 '14 08:11 ceesvanegmond