From 285a610c46dfa6350b40ce587027a97e73bfbc79 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 4 Nov 2018 09:34:07 -0700 Subject: [PATCH] Base for image layers, renderer-specific image layer types --- src/ol/layer/BaseImage.js | 69 ++++++++++++++++++++++++++++++++++++++ src/ol/layer/Image.js | 51 +++++++--------------------- src/ol/layer/WebGLImage.js | 44 ++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 38 deletions(-) create mode 100644 src/ol/layer/BaseImage.js create mode 100644 src/ol/layer/WebGLImage.js diff --git a/src/ol/layer/BaseImage.js b/src/ol/layer/BaseImage.js new file mode 100644 index 0000000000..1d02eeadc5 --- /dev/null +++ b/src/ol/layer/BaseImage.js @@ -0,0 +1,69 @@ +/** + * @module ol/layer/BaseImage + */ +import LayerType from '../LayerType.js'; +import Layer from './Layer.js'; + + +/** + * @typedef {Object} Options + * @property {number} [opacity=1] Opacity (0, 1). + * @property {boolean} [visible=true] Visibility. + * @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be + * rendered outside of this extent. + * @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers + * will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed + * for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()` + * method was used. + * @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be + * visible. + * @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will + * be visible. + * @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage + * this layer in its layers collection, and the layer will be rendered on top. This is useful for + * temporary layers. The standard way to add a layer to a map and have it managed by the map is to + * use {@link module:ol/Map#addLayer}. + * @property {import("../source/Image.js").default} [source] Source for this layer. + */ + + +/** + * @classdesc + * Server-rendered images that are available for arbitrary extents and + * resolutions. + * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject} + * property on the layer object; for example, setting `title: 'My Title'` in the + * options means that `title` is observable, and has get/set accessors. + * + * @fires import("../render/Event.js").RenderEvent + * @api + */ +class BaseImageLayer extends Layer { + + /** + * @param {Options=} opt_options Layer options. + */ + constructor(opt_options) { + const options = opt_options ? opt_options : {}; + super(options); + + /** + * The layer type. + * @protected + * @type {import("../LayerType.js").default} + */ + this.type = LayerType.IMAGE; + + } + +} + + +/** + * Return the associated {@link module:ol/source/Image source} of the image layer. + * @function + * @return {import("../source/Image.js").default} Source. + * @api + */ +BaseImageLayer.prototype.getSource; +export default BaseImageLayer; diff --git a/src/ol/layer/Image.js b/src/ol/layer/Image.js index 221c2d1a97..2a83a18cc9 100644 --- a/src/ol/layer/Image.js +++ b/src/ol/layer/Image.js @@ -1,29 +1,12 @@ /** * @module ol/layer/Image */ -import LayerType from '../LayerType.js'; -import Layer from './Layer.js'; +import BaseImageLayer from './BaseImage.js'; +import CanvasImageLayerRenderer from '../renderer/canvas/ImageLayer.js'; /** - * @typedef {Object} Options - * @property {number} [opacity=1] Opacity (0, 1). - * @property {boolean} [visible=true] Visibility. - * @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be - * rendered outside of this extent. - * @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers - * will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed - * for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()` - * method was used. - * @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be - * visible. - * @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will - * be visible. - * @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage - * this layer in its layers collection, and the layer will be rendered on top. This is useful for - * temporary layers. The standard way to add a layer to a map and have it managed by the map is to - * use {@link module:ol/Map#addLayer}. - * @property {import("../source/Image.js").default} [source] Source for this layer. + * @typedef {import("./BaseImage.js").Options} Options */ @@ -38,32 +21,24 @@ import Layer from './Layer.js'; * @fires import("../render/Event.js").RenderEvent * @api */ -class ImageLayer extends Layer { +class ImageLayer extends BaseImageLayer { /** * @param {Options=} opt_options Layer options. */ constructor(opt_options) { - const options = opt_options ? opt_options : {}; - super(options); - - /** - * The layer type. - * @protected - * @type {import("../LayerType.js").default} - */ - this.type = LayerType.IMAGE; + super(opt_options); + } + /** + * Create a renderer for this layer. + * @return {import("../renderer/Layer.js").default} A layer renderer. + * @protected + */ + createRenderer() { + return new CanvasImageLayerRenderer(this); } } - -/** - * Return the associated {@link module:ol/source/Image source} of the image layer. - * @function - * @return {import("../source/Image.js").default} Source. - * @api - */ -ImageLayer.prototype.getSource; export default ImageLayer; diff --git a/src/ol/layer/WebGLImage.js b/src/ol/layer/WebGLImage.js new file mode 100644 index 0000000000..cb8fa40ecb --- /dev/null +++ b/src/ol/layer/WebGLImage.js @@ -0,0 +1,44 @@ +/** + * @module ol/layer/WebGLImage + */ +import BaseImageLayer from './BaseImage.js'; + + +/** + * @typedef {import("./BaseImage.js").Options} Options + */ + + +/** + * @classdesc + * Server-rendered images that are available for arbitrary extents and + * resolutions. + * Note that any property set in the options is set as a {@link module:ol/Object~BaseObject} + * property on the layer object; for example, setting `title: 'My Title'` in the + * options means that `title` is observable, and has get/set accessors. + * + * @fires import("../render/Event.js").RenderEvent + * @api + */ +class WebGLImageLayer extends BaseImageLayer { + + /** + * @param {Options=} opt_options Layer options. + */ + constructor(opt_options) { + super(opt_options); + } + + /** + * Create a renderer for this layer. + * @return {import("../renderer/Layer.js").default} A layer renderer. + * @protected + */ + createRenderer() { + // TODO: rework WebGL renderers to share context + return null; + } + +} + +export default WebGLImageLayer;