$("[data-changeset]").each(function () {
var changeset = $(this).data('changeset');
if (changeset.bbox) {
- var latModifier = 0;
- var lonModifier = 0;
+ var minProjection = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
+ maxProjection = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
+ xGap = maxProjection.x - minProjection.x,
+ yGap = minProjection.y - maxProjection.y,
+ minXGap = 40, // Min width/height of changeset in pixels
+ minYGap = 40;
+
+ if (xGap < minXGap) {
+ minProjection.x -= ((minXGap - xGap) / 2);
+ maxProjection.x += ((minXGap - xGap) / 2);
+ }
- if (changeset.bbox.minlat === changeset.bbox.maxlat || changeset.bbox.minlon === changeset.bbox.maxlon) {
- latModifier = 0.0001;
- lonModifier = 0.0002;
+ if (yGap < minYGap) {
+ minProjection.y += ((minYGap - yGap) / 2);
+ maxProjection.y -= ((minYGap - yGap) / 2);
}
- changeset.bounds = L.latLngBounds(
- [changeset.bbox.minlat - latModifier, changeset.bbox.minlon - lonModifier],
- [changeset.bbox.maxlat + latModifier, changeset.bbox.maxlon + lonModifier]);
+ var minUnProjection = map.unproject(minProjection),
+ maxUnProjection = map.unproject(maxProjection),
+ bounds = [minUnProjection,
+ maxUnProjection];
+
+ changeset.bounds = L.latLngBounds(bounds);
changesets.push(changeset);
}
});