Skip to content

Commit

Permalink
Merge pull request #794 from OpenGeoscience/map-maxbounds-gcs
Browse files Browse the repository at this point in the history
Allow specifying the map's initial maxBounds in a different gcs.
  • Loading branch information
manthey authored Mar 21, 2018
2 parents 673b2bd + 8d39981 commit 213a0c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var sceneObject = require('./sceneObject');
* @param {number} [arg.maxBounds.right=20037508] The right bound.
* @param {number} [arg.maxBounds.bottom=-20037508] The bottom bound.
* @param {number} [arg.maxBounds.top=20037508] The top bound.
* @param {number} [arg.maxBounds.gcs=arg.ingcs] The coordinate system for the
* bounds.
*
* @param {number} [arg.zoom=4] Initial zoom.
* @param {object?} [arg.center] Initial map center.
Expand Down Expand Up @@ -128,17 +130,17 @@ var map = function (arg) {
* [0, width] and [0, height] instead. */
var mcx = ((m_maxBounds.left || 0) + (m_maxBounds.right || 0)) / 2,
mcy = ((m_maxBounds.bottom || 0) + (m_maxBounds.top || 0)) / 2;
m_maxBounds.left = transform.transformCoordinates(m_ingcs, m_gcs, {
m_maxBounds.left = transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: m_maxBounds.left !== undefined ? m_maxBounds.left : -180, y: mcy
}).x;
m_maxBounds.right = transform.transformCoordinates(m_ingcs, m_gcs, {
m_maxBounds.right = transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: m_maxBounds.right !== undefined ? m_maxBounds.right : 180, y: mcy
}).x;
m_maxBounds.top = (m_maxBounds.top !== undefined ?
transform.transformCoordinates(m_ingcs, m_gcs, {
transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: mcx, y: m_maxBounds.top}).y : m_maxBounds.right);
m_maxBounds.bottom = (m_maxBounds.bottom !== undefined ?
transform.transformCoordinates(m_ingcs, m_gcs, {
transform.transformCoordinates(m_maxBounds.gcs || m_ingcs, m_gcs, {
x: mcx, y: m_maxBounds.bottom}).y : m_maxBounds.left);
m_unitsPerPixel = (arg.unitsPerPixel || (
m_maxBounds.right - m_maxBounds.left) / 256);
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ describe('geo.core.map', function () {
expect(map.rotation()).toBe(1);
expect(map.maxBounds().left).toBe(0);
expect(map.maxBounds().right).toBe(50000);
expect(map.maxBounds().top).toBe(0);
expect(map.maxBounds().bottom).toBe(40000);
expect(map.size().width).toBe(640);
expect(map.zoomRange().max).toEqual(9);
expect(map.zoomRange().origMin).toEqual(3);
Expand All @@ -76,6 +78,14 @@ describe('geo.core.map', function () {
expect(map.clampBoundsX()).toBe(true);
expect(map.clampBoundsY()).toBe(false);
expect(map.clampZoom()).toBe(false);
// with gcs specified for maxBounds
map = createMap({
ingcs: '+proj=longlat +axis=esu',
gcs: '+proj=longlat +axis=enu',
maxBounds: {left: 0, top: 0, right: 50000, bottom: -40000, gcs: '+proj=longlat +axis=enu'}
});
expect(map.maxBounds().top).toBe(0);
expect(map.maxBounds().bottom).toBe(40000);
});
});

Expand Down

0 comments on commit 213a0c3

Please sign in to comment.