Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Change first candidates in case corners have no offset
Browse files Browse the repository at this point in the history
  • Loading branch information
fab-girard committed Aug 21, 2015
1 parent fc473a1 commit 5686d7b
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/Leaflet.ControlledBounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@
// This assumes that all corner controls are placed vertically to one another.
// Oh $deity, what a mess of spaghetti code and casuistics.
var size = this.getSize();
var candidates = {
var corners = (this._controlCorners.topright.offsetLeft && this._controlCorners.bottomleft.offsetTop && this._controlCorners.bottomright.offsetLeft && this._controlCorners.bottomright.offsetTop) ? {
topleft: [L.point(this._controlCorners.topleft.offsetLeft, this._controlCorners.topleft.offsetTop)],
topright: [L.point(this._controlCorners.topright.offsetLeft + this._controlCorners.topright.offsetWidth, this._controlCorners.topright.offsetTop)],
bottomleft: [L.point(this._controlCorners.bottomleft.offsetLeft, this._controlCorners.bottomleft.offsetTop + this._controlCorners.bottomleft.offsetHeight)],
bottomright: [L.point(this._controlCorners.bottomright.offsetLeft + this._controlCorners.bottomright.offsetWidth, this._controlCorners.bottomright.offsetTop + this._controlCorners.bottomright.offsetHeight)]
} : {
topleft: [L.point(0, 0)],
topright: [L.point(size.x, 0)],
bottomleft: [L.point(0, size.y)],
bottomright: [L.point(size.x, size.y)]
};
var candidates = {
topleft: [L.point(corners.topleft[0].x, corners.topleft[0].y)],
topright: [L.point(corners.topright[0].x, corners.topright[0].y)],
bottomleft: [L.point(corners.bottomleft[0].x, corners.bottomleft[0].y)],
bottomright: [L.point(corners.bottomright[0].x, corners.bottomright[0].y)]
};
var previousBottom = this._controlCorners.topleft.offsetTop;
var previousBottom = corners.topleft[0].y;
for (var i=0; i<this._controlCorners.topleft.children.length; i++) {
var child = this._controlCorners.topleft.children[i];
if (child.offsetTop + child.offsetLeft + child.offsetWidth + child.offsetHeight > 0) {
Expand All @@ -43,13 +54,13 @@
}
}
candidates.topleft.push(L.point(childRight, previousBottom));
candidates.topleft.push(L.point(this._controlCorners.topleft.offsetLeft, childBottom));
candidates.topleft.push(L.point(corners.topleft[0].x, childBottom));

previousBottom = childBottom;
}
}

previousBottom = this._controlCorners.topright.offsetTop;
previousBottom = corners.topright[0].y;
for (var i=0; i<this._controlCorners.topright.children.length; i++) {
var child = this._controlCorners.topright.children[i];
if (child.offsetTop + child.offsetLeft + child.offsetWidth + child.offsetHeight > 0) {
Expand All @@ -65,13 +76,13 @@
}
}
candidates.topright.push(L.point(childLeft, previousBottom));
candidates.topright.push(L.point(this._controlCorners.topright.offsetLeft + this._controlCorners.topright.offsetWidth, childBottom));
candidates.topright.push(L.point(corners.topright[0].x, childBottom));

previousBottom = childBottom;
}
}

var previousTop = this._controlCorners.bottomleft.offsetTop;
var previousTop = corners.bottomleft[0].y;
for (var i=this._controlCorners.bottomleft.children.length - 1; i>=0; i--) {
var child = this._controlCorners.bottomleft.children[i];
if (child.offsetTop + child.offsetLeft + child.offsetWidth + child.offsetHeight > 0) {
Expand All @@ -87,13 +98,13 @@
}
}
candidates.bottomleft.push(L.point(childRight, previousTop));
candidates.bottomleft.push(L.point(this._controlCorners.bottomleft.offsetLeft, childTop));
candidates.bottomleft.push(L.point(corners.bottomleft[0].x, childTop));

previousTop = childTop;
}
}

previousTop = this._controlCorners.bottomright.offsetTop;
previousTop = corners.bottomright[0].y;
for (var i=this._controlCorners.bottomright.children.length - 1; i>=0; i--) {
var child = this._controlCorners.bottomright.children[i];
if (child.offsetTop + child.offsetLeft + child.offsetWidth + child.offsetHeight > 0) {
Expand All @@ -109,7 +120,7 @@
}
}
candidates.bottomright.push(L.point(childLeft, previousTop));
candidates.bottomright.push(L.point(this._controlCorners.bottomright.offsetLeft + this._controlCorners.bottomright.offsetWidth, childTop));
candidates.bottomright.push(L.point(corners.bottomright[0].x, childTop));

previousTop = childTop;
}
Expand Down

0 comments on commit 5686d7b

Please sign in to comment.