X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/9bf489a0b90f80a9be2dab78896950a4da7d0fc2..31c44617660dd6a483f1dbe9d407c6ae9915692a:/app/assets/javascripts/index/history.js diff --git a/app/assets/javascripts/index/history.js b/app/assets/javascripts/index/history.js index 71a94aef0..3fcc2f790 100644 --- a/app/assets/javascripts/index/history.js +++ b/app/assets/javascripts/index/history.js @@ -97,17 +97,29 @@ OSM.History = function(map) { $("[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); } });