Accept renderers as sources for the raster source

This commit is contained in:
ahocevar
2018-05-25 11:59:44 +02:00
parent c7207c5a07
commit f53a1e7507
2 changed files with 26 additions and 9 deletions

View File

@@ -13,6 +13,7 @@ import {equals, getCenter, getHeight, getWidth} from '../extent.js';
import ImageLayer from '../layer/Image.js'; import ImageLayer from '../layer/Image.js';
import TileLayer from '../layer/Tile.js'; import TileLayer from '../layer/Tile.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import CanvasLayerRenderer from '../renderer/canvas/Layer.js';
import CanvasImageLayerRenderer from '../renderer/canvas/ImageLayer.js'; import CanvasImageLayerRenderer from '../renderer/canvas/ImageLayer.js';
import CanvasTileLayerRenderer from '../renderer/canvas/TileLayer.js'; import CanvasTileLayerRenderer from '../renderer/canvas/TileLayer.js';
import ImageSource from '../source/Image.js'; import ImageSource from '../source/Image.js';
@@ -111,7 +112,7 @@ inherits(RasterSourceEvent, Event);
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {Array.<module:ol/source/Source>} sources Input sources. * @property {Array.<module:ol/source/Source|module:ol/renderer/canvas/Layer>} sources Input sources.
* @property {module:ol/source/Raster~Operation} [operation] Raster operation. * @property {module:ol/source/Raster~Operation} [operation] Raster operation.
* The operation will be called with data from input sources * The operation will be called with data from input sources
* and the output will be assigned to the raster source. * and the output will be assigned to the raster source.
@@ -487,6 +488,10 @@ function createRenderer(source) {
renderer = createTileRenderer(source); renderer = createTileRenderer(source);
} else if (source instanceof ImageSource) { } else if (source instanceof ImageSource) {
renderer = createImageRenderer(source); renderer = createImageRenderer(source);
} else if (source instanceof TileLayer) {
renderer = new CanvasTileLayerRenderer(source);
} else if (source instanceof CanvasLayerRenderer) {
renderer = source;
} }
return renderer; return renderer;
} }

View File

@@ -1,12 +1,19 @@
import Map from '../../../../src/ol/Map.js'; import Map from '../../../../src/ol/Map.js';
import TileState from '../../../../src/ol/TileState.js'; import TileState from '../../../../src/ol/TileState.js';
import View from '../../../../src/ol/View.js'; import View from '../../../../src/ol/View.js';
import ImageLayerRenderer from '../../../../src/ol/renderer/canvas/ImageLayer.js';
import ImageLayer from '../../../../src/ol/layer/Image.js'; import ImageLayer from '../../../../src/ol/layer/Image.js';
import VectorLayerRenderer from '../../../../src/ol/renderer/canvas/VectorLayer.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js';
import Projection from '../../../../src/ol/proj/Projection.js'; import Projection from '../../../../src/ol/proj/Projection.js';
import Static from '../../../../src/ol/source/ImageStatic.js'; import Static from '../../../../src/ol/source/ImageStatic.js';
import RasterSource from '../../../../src/ol/source/Raster.js'; import RasterSource from '../../../../src/ol/source/Raster.js';
import Source from '../../../../src/ol/source/Source.js'; import Source from '../../../../src/ol/source/Source.js';
import TileSource from '../../../../src/ol/source/Tile.js'; import TileSource from '../../../../src/ol/source/Tile.js';
import VectorSource from '../../../../src/ol/source/Vector.js';
import Feature from '../../../../src/ol/Feature.js';
import Point from '../../../../src/ol/geom/Point.js';
import {Style, Circle, Fill} from '../../../../src/ol/style.js';
import XYZ from '../../../../src/ol/source/XYZ.js'; import XYZ from '../../../../src/ol/source/XYZ.js';
const red = 'data:image/gif;base64,R0lGODlhAQABAPAAAP8AAP///yH5BAAAAAAALAAAAAA' + const red = 'data:image/gif;base64,R0lGODlhAQABAPAAAP8AAP///yH5BAAAAAAALAAAAAA' +
@@ -15,9 +22,6 @@ const red = 'data:image/gif;base64,R0lGODlhAQABAPAAAP8AAP///yH5BAAAAAAALAAAAAA'
const green = 'data:image/gif;base64,R0lGODlhAQABAPAAAAD/AP///yH5BAAAAAAALAAAA' + const green = 'data:image/gif;base64,R0lGODlhAQABAPAAAAD/AP///yH5BAAAAAAALAAAA' +
'AABAAEAAAICRAEAOw=='; 'AABAAEAAAICRAEAOw==';
const blue = 'data:image/gif;base64,R0lGODlhAQABAPAAAAAA/////yH5BAAAAAAALAAAAA' +
'ABAAEAAAICRAEAOw==';
where('Uint8ClampedArray').describe('ol.source.Raster', function() { where('Uint8ClampedArray').describe('ol.source.Raster', function() {
let map, target, redSource, greenSource, blueSource, raster; let map, target, redSource, greenSource, blueSource, raster;
@@ -45,10 +49,18 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
imageExtent: extent imageExtent: extent
}); });
blueSource = new Static({ blueSource = new ImageLayerRenderer(new VectorLayer({
url: blue, source: new VectorSource({
imageExtent: extent features: [new Feature(new Point([0, 0]))]
}); }),
style: new Style({
image: new Circle({
radius: 3,
fill: new Fill({color: 'blue'})
})
})
}));
blueSource.setVectorRenderer(new VectorLayerRenderer(blueSource.getLayer()));
raster = new RasterSource({ raster = new RasterSource({
threads: 0, threads: 0,
@@ -89,7 +101,7 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
describe('constructor', function() { describe('constructor', function() {
it('returns a tile source', function() { it('returns a raster source', function() {
const source = new RasterSource({ const source = new RasterSource({
threads: 0, threads: 0,
sources: [new TileSource({})] sources: [new TileSource({})]