Render map replay group on the correct world instead of wrapping it

By using the frameState's focus, we can adjust extent and transform and
render it for the world of interest instead of wrapping it and rendering
for every visible world.
This commit is contained in:
Andreas Hocevar
2015-04-22 09:11:19 +02:00
parent 23ed120361
commit 513677fecd
7 changed files with 108 additions and 101 deletions

View File

@@ -19,6 +19,7 @@ describe('ol.renderer.canvas.Map', function() {
beforeEach(function() {
map = new ol.Map({});
map.on('postcompose', function() {});
layer = new ol.layer.Vector({
source: new ol.source.Vector({wrapX: true})
});
@@ -30,16 +31,23 @@ describe('ol.renderer.canvas.Map', function() {
renderer.layerRenderers_[goog.getUid(layer)] = layerRenderer;
});
it('calls #dispatchComposeEvent_() with a wrapX argument', function() {
var spy = sinon.spy(renderer, 'dispatchComposeEvent_');
it('uses correct extent and offset on wrapped worlds', function() {
var spy = sinon.spy(renderer, 'getTransform');
var proj = new ol.proj.Projection({
code: 'foo',
extent: [-180, -90, 180, 90],
global: true
});
var frameState = {
coordinateToPixelMatrix: map.coordinateToPixelMatrix_,
pixelToCoordinateMatrix: map.pixelToCoordinateMatrix_,
pixelRatio: 1,
size: [100, 100],
skippedFeatureUids: {},
extent: proj.getExtent(),
viewState: {
center: [0, 0],
projection: proj,
resolution: 1,
rotation: 0
},
@@ -53,11 +61,21 @@ describe('ol.renderer.canvas.Map', function() {
}],
postRenderFunctions: []
};
frameState.focus = [0, 0];
// focus is on real world
renderer.renderFrame(frameState);
// precompose without wrapX
expect(spy.getCall(0).args[2]).to.be(false);
// postcompose with wrapX
expect(spy.getCall(1).args[2]).to.be(true);
expect(spy.getCall(0).args[1]).to.be(0);
expect(renderer.replayGroup.maxExtent_).to.eql([-180, -90, 180, 90]);
frameState.focus = [-200, 0];
// focus is one world left of the real world
renderer.renderFrame(frameState);
expect(spy.getCall(1).args[1]).to.be(360);
expect(renderer.replayGroup.maxExtent_).to.eql([180, -90, 540, 90]);
frameState.focus = [200, 0];
// focus is one world right of the real world
renderer.renderFrame(frameState);
expect(spy.getCall(2).args[1]).to.be(-360);
expect(renderer.replayGroup.maxExtent_).to.eql([-540, -90, -180, 90]);
});
});
@@ -66,6 +84,7 @@ describe('ol.renderer.canvas.Map', function() {
goog.require('ol.layer.Vector');
goog.require('ol.Map');
goog.require('ol.proj.Projection');
goog.require('ol.renderer.canvas.Layer');
goog.require('ol.renderer.canvas.Map');
goog.require('ol.source.Vector');