Skip to content

Commit

Permalink
Merge pull request #625 from OpenGeoscience/fix-get-bounds
Browse files Browse the repository at this point in the history
boundsFromZoomAndCenter returned incorrect values.
  • Loading branch information
manthey authored Oct 13, 2016
2 parents 470d78f + b78ba96 commit b6bf634
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ var map = function (arg) {
// preprocess the arguments
zoom = fix_zoom(zoom, ignoreDiscreteZoom);
units = m_this.unitsPerPixel(zoom);
center = m_this.gcsToWorld(center, gcs);
center = m_this.gcsToWorld(center, null);

// get half the width and height in world coordinates
width = m_width * units;
Expand Down
22 changes: 21 additions & 1 deletion tests/cases/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('geo.core.map', function () {
expect(m.scale()).toEqual({x: 1, y: 1, z: 1});
});
it('gcs and ingcs', function () {
var m = create_map(), units = m.unitsPerPixel();
var m = create_map(), units = m.unitsPerPixel(), bounds;
var error = console.error;
expect(m.gcs()).toBe('EPSG:3857');
expect(m.ingcs()).toBe('EPSG:4326');
Expand All @@ -162,6 +162,26 @@ describe('geo.core.map', function () {
left: -128 * units, top: 128 * units,
right: 128 * units, bottom: -128 * units,
width: 256 * units, height: 256 * units})).toBe(true);
// test with a different non-zero center
m.ingcs('EPSG:4326');
m.bounds({left: -180, top: 65, right: -45, bottom: 45});
bounds = m.bounds();
// compare left, top, right, bottom separately from width and height to
// use different precisions in the comparison
expect(closeToEqual({
left: bounds.left, top: bounds.top,
right: bounds.right, bottom: bounds.bottom
}, {
left: -180, top: 79.340, right: -45, bottom: 0.906
})).toBe(true);
expect(closeToEqual({width: bounds.width, height: bounds.height}, {
width: 96 * units, height: 96 * units}, -2)).toBe(true);
expect(closeToEqual(m.bounds(undefined, null), {
left: -128 * units, top: 96.6444 * units,
right: -32 * units, bottom: 0.6444 * units,
width: 96 * units, height: 96 * units}, -2)).toBe(true);
m.bounds({left: -180, top: 5, right: 180, bottom: -5});
// test with different projections
m.unitsPerPixel(0, 1);
m.gcs('+proj=longlat +axis=enu');
expect(m.gcs()).toBe('+proj=longlat +axis=enu');
Expand Down

0 comments on commit b6bf634

Please sign in to comment.