Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take into account global offsets of corners #3 #5

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
34 changes: 22 additions & 12 deletions src/Leaflet.ControlledBounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@
// 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 previousBottom = 0;
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 = 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) {
var childTop = child.offsetTop;
var childLeft = child.offsetLeft;
var childLeft = child.offsetLeft + this._controlCorners.topleft.offsetLeft;
var childBottom = childTop + child.offsetHeight;
var childRight = childLeft + child.offsetWidth;

Expand All @@ -43,13 +54,13 @@
}
}
candidates.topleft.push(L.point(childRight, previousBottom));
candidates.topleft.push(L.point(0, childBottom));
candidates.topleft.push(L.point(corners.topleft[0].x, childBottom));

previousBottom = childBottom;
}
}

previousBottom = 0;
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,18 +76,18 @@
}
}
candidates.topright.push(L.point(childLeft, previousBottom));
candidates.topright.push(L.point(size.x, childBottom));
candidates.topright.push(L.point(corners.topright[0].x, childBottom));

previousBottom = childBottom;
}
}

var previousTop = size.y;
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) {
var childTop = child.offsetTop + this._controlCorners.bottomleft.offsetTop;
var childLeft = child.offsetLeft;
var childLeft = child.offsetLeft + this._controlCorners.bottomleft.offsetLeft;
var childBottom = childTop + child.offsetHeight;
var childRight = childLeft + child.offsetWidth;

Expand All @@ -87,13 +98,13 @@
}
}
candidates.bottomleft.push(L.point(childRight, previousTop));
candidates.bottomleft.push(L.point(0, childTop));
candidates.bottomleft.push(L.point(corners.bottomleft[0].x, childTop));

previousTop = childTop;
}
}

previousTop = size.y;
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(size.x, childTop));
candidates.bottomright.push(L.point(corners.bottomright[0].x, childTop));

previousTop = childTop;
}
Expand All @@ -122,7 +133,6 @@

// console.log(candidates);


// Try out all combinations of the candidate corners, stick with the one that gives
// out the biggest area.
var maxArea = -Infinity;
Expand Down