Set time and handle frame animation in raster source
This commit is contained in:
@@ -181,6 +181,8 @@ ol.source.Raster.prototype.updateFrameState_ = function(extent, resolution, proj
|
|||||||
frameState.focus = center;
|
frameState.focus = center;
|
||||||
frameState.size[0] = Math.round(ol.extent.getWidth(extent) / resolution);
|
frameState.size[0] = Math.round(ol.extent.getWidth(extent) / resolution);
|
||||||
frameState.size[1] = Math.round(ol.extent.getHeight(extent) / resolution);
|
frameState.size[1] = Math.round(ol.extent.getHeight(extent) / resolution);
|
||||||
|
frameState.time = Date.now();
|
||||||
|
frameState.animate = false;
|
||||||
|
|
||||||
var viewState = frameState.viewState;
|
var viewState = frameState.viewState;
|
||||||
viewState.center = center;
|
viewState.center = center;
|
||||||
@@ -234,6 +236,11 @@ ol.source.Raster.prototype.getImage = function(extent, resolution, pixelRatio, p
|
|||||||
}
|
}
|
||||||
|
|
||||||
frameState.tileQueue.loadMoreTiles(16, 16);
|
frameState.tileQueue.loadMoreTiles(16, 16);
|
||||||
|
|
||||||
|
if (frameState.animate) {
|
||||||
|
requestAnimationFrame(this.changed.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
return this.renderedImageCanvas_;
|
return this.renderedImageCanvas_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
BIN
test/rendering/ol/source/expected/raster-1.png
Normal file
BIN
test/rendering/ol/source/expected/raster-1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
84
test/rendering/ol/source/raster.test.js
Normal file
84
test/rendering/ol/source/raster.test.js
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
goog.require('ol.Map');
|
||||||
|
goog.require('ol.View');
|
||||||
|
goog.require('ol.layer.Image');
|
||||||
|
goog.require('ol.source.Raster');
|
||||||
|
goog.require('ol.source.XYZ');
|
||||||
|
|
||||||
|
where('Uint8ClampedArray').describe('ol.rendering.source.Raster', function() {
|
||||||
|
|
||||||
|
function afterRender(source, raster, callback) {
|
||||||
|
var loading = 0;
|
||||||
|
|
||||||
|
source.on('tileloadstart', function(event) {
|
||||||
|
loading++;
|
||||||
|
});
|
||||||
|
source.on('tileloadend', function(event) {
|
||||||
|
loading--;
|
||||||
|
if (loading == 0) {
|
||||||
|
raster.once('afteroperations', function() {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
source.on('tileloaderror', function(event) {
|
||||||
|
callback(new Error('Tile failed to load'));
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var map;
|
||||||
|
function createMap(renderer, pixelRatio) {
|
||||||
|
map = new ol.Map({
|
||||||
|
target: createMapDiv(200, 200),
|
||||||
|
pixelRatio: pixelRatio,
|
||||||
|
renderer: renderer,
|
||||||
|
view: new ol.View({
|
||||||
|
center: [0, 0],
|
||||||
|
zoom: 0
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
if (map) {
|
||||||
|
disposeMap(map);
|
||||||
|
}
|
||||||
|
map = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('raster source rendering', function() {
|
||||||
|
it('renders the result of an operation', function(done) {
|
||||||
|
createMap('canvas', 1);
|
||||||
|
|
||||||
|
var source = new ol.source.XYZ({
|
||||||
|
url: 'rendering/ol/data/tiles/osm/{z}/{x}/{y}.png',
|
||||||
|
transition: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
var raster = new ol.source.Raster({
|
||||||
|
sources: [source],
|
||||||
|
operation: function(pixels) {
|
||||||
|
var pixel = pixels[0];
|
||||||
|
// swap blue and red
|
||||||
|
var red = pixel[0];
|
||||||
|
pixel[0] = pixel[2];
|
||||||
|
pixel[2] = red;
|
||||||
|
return pixel;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
afterRender(source, raster, function(err) {
|
||||||
|
if (err) {
|
||||||
|
done(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
expectResemble(map, 'rendering/ol/source/expected/raster-1.png', IMAGE_TOLERANCE, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
var layer = new ol.layer.Image({source: raster});
|
||||||
|
|
||||||
|
map.addLayer(layer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user