Skip to content

Commit

Permalink
add getter and setter for renderWorldCopies (#5944)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewharvey authored Feb 13, 2018
1 parent a950ff7 commit cd4a19b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,15 @@ class Transform {
this.zoom = Math.min(this.zoom, zoom);
}

get renderWorldCopies(): boolean {
return this._renderWorldCopies;
get renderWorldCopies(): boolean { return this._renderWorldCopies; }
set renderWorldCopies(renderWorldCopies?: ?boolean) {
if (renderWorldCopies === undefined) {
renderWorldCopies = true;
} else if (renderWorldCopies === null) {
renderWorldCopies = false;
}

this._renderWorldCopies = renderWorldCopies;
}

get worldSize(): number {
Expand Down
21 changes: 21 additions & 0 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,27 @@ class Map extends Camera {
} else throw new Error(`maxZoom must be greater than the current minZoom`);
}

/**
* Returns the state of renderWorldCopies.
*
* @returns {boolean} renderWorldCopies
*/
getRenderWorldCopies() { return this.transform.renderWorldCopies; }

/**
* Sets the state of renderWorldCopies.
*
* @param {boolean} renderWorldCopies If `true`, multiple copies of the world will be rendered, when zoomed out. `undefined` is treated as `true`, `null` is treated as `false`.
* @returns {Map} `this`
*/
setRenderWorldCopies(renderWorldCopies?: ?boolean) {

this.transform.renderWorldCopies = renderWorldCopies;
this._update();

return this;
}

/**
* Returns the map's maximum allowable zoom level.
*
Expand Down
48 changes: 48 additions & 0 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,54 @@ test('Map', (t) => {
t.end();
});

t.test('#getRenderWorldCopies', (t) => {
t.test('initially false', (t) => {
const map = createMap({renderWorldCopies: false});
t.equal(map.getRenderWorldCopies(), false);
t.end();
});

t.test('initially true', (t) => {
const map = createMap({renderWorldCopies: true});
t.equal(map.getRenderWorldCopies(), true);
t.end();
});

t.end();
});

t.test('#setRenderWorldCopies', (t) => {
t.test('initially false', (t) => {
const map = createMap({renderWorldCopies: false});
map.setRenderWorldCopies(true);
t.equal(map.getRenderWorldCopies(), true);
t.end();
});

t.test('initially true', (t) => {
const map = createMap({renderWorldCopies: true});
map.setRenderWorldCopies(false);
t.equal(map.getRenderWorldCopies(), false);
t.end();
});

t.test('undefined', (t) => {
const map = createMap({renderWorldCopies: false});
map.setRenderWorldCopies(undefined);
t.equal(map.getRenderWorldCopies(), true);
t.end();
});

t.test('null', (t) => {
const map = createMap({renderWorldCopies: true});
map.setRenderWorldCopies(null);
t.equal(map.getRenderWorldCopies(), false);
t.end();
});

t.end();
});

t.test('#setMinZoom', (t) => {
const map = createMap({zoom:5});
map.setMinZoom(3.5);
Expand Down

0 comments on commit cd4a19b

Please sign in to comment.