Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Allow center-position of Labels #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,24 @@ L.Label = L.Class.extend({
labelWidth = this._labelWidth,
offset = L.point(this.options.offset);

// position to the right (right or auto & needs to)
if (direction === 'right' || direction === 'auto' && labelPoint.x < centerPoint.x) {
// Left, Center, Right positioning. 'Auto' chooses left or right as
// necessary to fit the label on the map.
if (direction === 'center') {
L.DomUtil.addClass(container, 'leaflet-label-center');
L.DomUtil.removeClass(container, 'leaflet-label-left');
L.DomUtil.removeClass(container, 'leaflet-label-right');

pos = pos.add(L.point(-offset.x - (labelWidth / 2), offset.y));
} else if (direction === 'right' || direction === 'auto' && labelPoint.x < centerPoint.x) {
L.DomUtil.addClass(container, 'leaflet-label-right');
L.DomUtil.removeClass(container, 'leaflet-label-left');
L.DomUtil.removeClass(container, 'leaflet-label-center');

pos = pos.add(offset);
} else { // position to the left
L.DomUtil.addClass(container, 'leaflet-label-left');
L.DomUtil.removeClass(container, 'leaflet-label-right');
L.DomUtil.removeClass(container, 'leaflet-label-center');

pos = pos.add(L.point(-offset.x - labelWidth, offset.y));
}
Expand Down