Don't store private functions and variables into RasterSource
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import Map from '../src/ol/Map.js';
|
||||
import _ol_View_ from '../src/ol/View.js';
|
||||
import _ol_layer_Image_ from '../src/ol/layer/Image.js';
|
||||
import _ol_source_Raster_ from '../src/ol/source/Raster.js';
|
||||
import RasterSource from '../src/ol/source/Raster.js';
|
||||
import _ol_source_Stamen_ from '../src/ol/source/Stamen.js';
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ function xyz2rgb(x) {
|
||||
12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
|
||||
}
|
||||
|
||||
var raster = new _ol_source_Raster_({
|
||||
var raster = new RasterSource({
|
||||
sources: [new _ol_source_Stamen_({
|
||||
layer: 'watercolor',
|
||||
transition: 0
|
||||
|
||||
@@ -5,7 +5,7 @@ import _ol_View_ from '../src/ol/View.js';
|
||||
import _ol_layer_Image_ from '../src/ol/layer/Image.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import _ol_source_BingMaps_ from '../src/ol/source/BingMaps.js';
|
||||
import _ol_source_Raster_ from '../src/ol/source/Raster.js';
|
||||
import RasterSource from '../src/ol/source/Raster.js';
|
||||
|
||||
var minVgi = 0;
|
||||
var maxVgi = 0.25;
|
||||
@@ -59,7 +59,7 @@ var bing = new _ol_source_BingMaps_({
|
||||
* Create a raster source where pixels with VGI values above a threshold will
|
||||
* be colored green.
|
||||
*/
|
||||
var raster = new _ol_source_Raster_({
|
||||
var raster = new RasterSource({
|
||||
sources: [bing],
|
||||
/**
|
||||
* Run calculations on pixel data.
|
||||
|
||||
@@ -5,7 +5,7 @@ import _ol_layer_Image_ from '../src/ol/layer/Image.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import {fromLonLat} from '../src/ol/proj.js';
|
||||
import _ol_source_BingMaps_ from '../src/ol/source/BingMaps.js';
|
||||
import _ol_source_Raster_ from '../src/ol/source/Raster.js';
|
||||
import RasterSource from '../src/ol/source/Raster.js';
|
||||
|
||||
function growRegion(inputs, data) {
|
||||
var image = inputs[0];
|
||||
@@ -78,7 +78,7 @@ var imagery = new TileLayer({
|
||||
source: new _ol_source_BingMaps_({key: key, imagerySet: 'Aerial'})
|
||||
});
|
||||
|
||||
var raster = new _ol_source_Raster_({
|
||||
var raster = new RasterSource({
|
||||
sources: [imagery.getSource()],
|
||||
operationType: 'image',
|
||||
operation: growRegion,
|
||||
|
||||
@@ -4,7 +4,7 @@ import _ol_View_ from '../src/ol/View.js';
|
||||
import _ol_layer_Image_ from '../src/ol/layer/Image.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import {fromLonLat} from '../src/ol/proj.js';
|
||||
import _ol_source_Raster_ from '../src/ol/source/Raster.js';
|
||||
import RasterSource from '../src/ol/source/Raster.js';
|
||||
import _ol_source_XYZ_ from '../src/ol/source/XYZ.js';
|
||||
|
||||
function flood(pixels, data) {
|
||||
@@ -30,7 +30,7 @@ var elevation = new _ol_source_XYZ_({
|
||||
transition: 0
|
||||
});
|
||||
|
||||
var raster = new _ol_source_Raster_({
|
||||
var raster = new RasterSource({
|
||||
sources: [elevation],
|
||||
operation: flood
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import _ol_View_ from '../src/ol/View.js';
|
||||
import _ol_layer_Image_ from '../src/ol/layer/Image.js';
|
||||
import TileLayer from '../src/ol/layer/Tile.js';
|
||||
import _ol_source_OSM_ from '../src/ol/source/OSM.js';
|
||||
import _ol_source_Raster_ from '../src/ol/source/Raster.js';
|
||||
import RasterSource from '../src/ol/source/Raster.js';
|
||||
import _ol_source_XYZ_ from '../src/ol/source/XYZ.js';
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ var elevation = new _ol_source_XYZ_({
|
||||
transition: 0
|
||||
});
|
||||
|
||||
var raster = new _ol_source_Raster_({
|
||||
var raster = new RasterSource({
|
||||
sources: [elevation],
|
||||
operationType: 'image',
|
||||
operation: shade
|
||||
|
||||
@@ -21,6 +21,27 @@ import SourceState from '../source/State.js';
|
||||
import _ol_source_Tile_ from '../source/Tile.js';
|
||||
import _ol_transform_ from '../transform.js';
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
var RasterEventType = {
|
||||
/**
|
||||
* Triggered before operations are run.
|
||||
* @event ol.source.Raster.Event#beforeoperations
|
||||
* @api
|
||||
*/
|
||||
BEFOREOPERATIONS: 'beforeoperations',
|
||||
|
||||
/**
|
||||
* Triggered after operations are run.
|
||||
* @event ol.source.Raster.Event#afteroperations
|
||||
* @api
|
||||
*/
|
||||
AFTEROPERATIONS: 'afteroperations'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A source that transforms data from any number of input sources using an
|
||||
@@ -33,7 +54,7 @@ import _ol_transform_ from '../transform.js';
|
||||
* @param {olx.source.RasterOptions} options Options.
|
||||
* @api
|
||||
*/
|
||||
var _ol_source_Raster_ = function(options) {
|
||||
var RasterSource = function(options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -58,7 +79,7 @@ var _ol_source_Raster_ = function(options) {
|
||||
* @private
|
||||
* @type {Array.<ol.renderer.canvas.Layer>}
|
||||
*/
|
||||
this.renderers_ = _ol_source_Raster_.createRenderers_(options.sources);
|
||||
this.renderers_ = createRenderers(options.sources);
|
||||
|
||||
for (var r = 0, rr = this.renderers_.length; r < rr; ++r) {
|
||||
_ol_events_.listen(this.renderers_[r], EventType.CHANGE,
|
||||
@@ -75,7 +96,7 @@ var _ol_source_Raster_ = function(options) {
|
||||
},
|
||||
this.changed.bind(this));
|
||||
|
||||
var layerStatesArray = _ol_source_Raster_.getLayerStatesArray_(this.renderers_);
|
||||
var layerStatesArray = getLayerStatesArray(this.renderers_);
|
||||
var layerStates = {};
|
||||
for (var i = 0, ii = layerStatesArray.length; i < ii; ++i) {
|
||||
layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i];
|
||||
@@ -136,7 +157,7 @@ var _ol_source_Raster_ = function(options) {
|
||||
|
||||
};
|
||||
|
||||
inherits(_ol_source_Raster_, _ol_source_Image_);
|
||||
inherits(RasterSource, _ol_source_Image_);
|
||||
|
||||
|
||||
/**
|
||||
@@ -146,7 +167,7 @@ inherits(_ol_source_Raster_, _ol_source_Image_);
|
||||
* in a worker.
|
||||
* @api
|
||||
*/
|
||||
_ol_source_Raster_.prototype.setOperation = function(operation, opt_lib) {
|
||||
RasterSource.prototype.setOperation = function(operation, opt_lib) {
|
||||
this.worker_ = new Processor({
|
||||
operation: operation,
|
||||
imageOps: this.operationType_ === RasterOperationType.IMAGE,
|
||||
@@ -166,7 +187,7 @@ _ol_source_Raster_.prototype.setOperation = function(operation, opt_lib) {
|
||||
* @return {olx.FrameState} The updated frame state.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.prototype.updateFrameState_ = function(extent, resolution, projection) {
|
||||
RasterSource.prototype.updateFrameState_ = function(extent, resolution, projection) {
|
||||
|
||||
var frameState = /** @type {olx.FrameState} */ (
|
||||
_ol_obj_.assign({}, this.frameState_));
|
||||
@@ -196,7 +217,7 @@ _ol_source_Raster_.prototype.updateFrameState_ = function(extent, resolution, pr
|
||||
* @return {boolean} All sources are ready.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.prototype.allSourcesReady_ = function() {
|
||||
RasterSource.prototype.allSourcesReady_ = function() {
|
||||
var ready = true;
|
||||
var source;
|
||||
for (var i = 0, ii = this.renderers_.length; i < ii; ++i) {
|
||||
@@ -213,7 +234,7 @@ _ol_source_Raster_.prototype.allSourcesReady_ = function() {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
_ol_source_Raster_.prototype.getImage = function(extent, resolution, pixelRatio, projection) {
|
||||
RasterSource.prototype.getImage = function(extent, resolution, pixelRatio, projection) {
|
||||
if (!this.allSourcesReady_()) {
|
||||
return null;
|
||||
}
|
||||
@@ -248,12 +269,12 @@ _ol_source_Raster_.prototype.getImage = function(extent, resolution, pixelRatio,
|
||||
* Start processing source data.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.prototype.processSources_ = function() {
|
||||
RasterSource.prototype.processSources_ = function() {
|
||||
var frameState = this.requestedFrameState_;
|
||||
var len = this.renderers_.length;
|
||||
var imageDatas = new Array(len);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
var imageData = _ol_source_Raster_.getImageData_(
|
||||
var imageData = getImageData(
|
||||
this.renderers_[i], frameState, frameState.layerStatesArray[i]);
|
||||
if (imageData) {
|
||||
imageDatas[i] = imageData;
|
||||
@@ -263,10 +284,8 @@ _ol_source_Raster_.prototype.processSources_ = function() {
|
||||
}
|
||||
|
||||
var data = {};
|
||||
this.dispatchEvent(new _ol_source_Raster_.Event(
|
||||
_ol_source_Raster_.EventType_.BEFOREOPERATIONS, frameState, data));
|
||||
this.worker_.process(imageDatas, data,
|
||||
this.onWorkerComplete_.bind(this, frameState));
|
||||
this.dispatchEvent(new RasterSource.Event(RasterEventType.BEFOREOPERATIONS, frameState, data));
|
||||
this.worker_.process(imageDatas, data, this.onWorkerComplete_.bind(this, frameState));
|
||||
};
|
||||
|
||||
|
||||
@@ -278,7 +297,7 @@ _ol_source_Raster_.prototype.processSources_ = function() {
|
||||
* @param {Object} data The user data.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.prototype.onWorkerComplete_ = function(frameState, err, output, data) {
|
||||
RasterSource.prototype.onWorkerComplete_ = function(frameState, err, output, data) {
|
||||
if (err || !output) {
|
||||
return;
|
||||
}
|
||||
@@ -305,8 +324,7 @@ _ol_source_Raster_.prototype.onWorkerComplete_ = function(frameState, err, outpu
|
||||
this.changed();
|
||||
this.renderedRevision_ = this.getRevision();
|
||||
|
||||
this.dispatchEvent(new _ol_source_Raster_.Event(
|
||||
_ol_source_Raster_.EventType_.AFTEROPERATIONS, frameState, data));
|
||||
this.dispatchEvent(new RasterSource.Event(RasterEventType.AFTEROPERATIONS, frameState, data));
|
||||
};
|
||||
|
||||
|
||||
@@ -316,27 +334,26 @@ _ol_source_Raster_.prototype.onWorkerComplete_ = function(frameState, err, outpu
|
||||
* @param {olx.FrameState} frameState The frame state.
|
||||
* @param {ol.LayerState} layerState The layer state.
|
||||
* @return {ImageData} The image data.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.getImageData_ = function(renderer, frameState, layerState) {
|
||||
function getImageData(renderer, frameState, layerState) {
|
||||
if (!renderer.prepareFrame(frameState, layerState)) {
|
||||
return null;
|
||||
}
|
||||
var width = frameState.size[0];
|
||||
var height = frameState.size[1];
|
||||
if (!_ol_source_Raster_.context_) {
|
||||
_ol_source_Raster_.context_ = createCanvasContext2D(width, height);
|
||||
if (!RasterSource.context_) {
|
||||
RasterSource.context_ = createCanvasContext2D(width, height);
|
||||
} else {
|
||||
var canvas = _ol_source_Raster_.context_.canvas;
|
||||
var canvas = RasterSource.context_.canvas;
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
_ol_source_Raster_.context_ = createCanvasContext2D(width, height);
|
||||
RasterSource.context_ = createCanvasContext2D(width, height);
|
||||
} else {
|
||||
_ol_source_Raster_.context_.clearRect(0, 0, width, height);
|
||||
RasterSource.context_.clearRect(0, 0, width, height);
|
||||
}
|
||||
}
|
||||
renderer.composeFrame(frameState, layerState, _ol_source_Raster_.context_);
|
||||
return _ol_source_Raster_.context_.getImageData(0, 0, width, height);
|
||||
};
|
||||
renderer.composeFrame(frameState, layerState, RasterSource.context_);
|
||||
return RasterSource.context_.getImageData(0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -344,77 +361,72 @@ _ol_source_Raster_.getImageData_ = function(renderer, frameState, layerState) {
|
||||
* @type {CanvasRenderingContext2D}
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.context_ = null;
|
||||
RasterSource.context_ = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of layer states from a list of renderers.
|
||||
* @param {Array.<ol.renderer.canvas.Layer>} renderers Layer renderers.
|
||||
* @return {Array.<ol.LayerState>} The layer states.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.getLayerStatesArray_ = function(renderers) {
|
||||
function getLayerStatesArray(renderers) {
|
||||
return renderers.map(function(renderer) {
|
||||
return renderer.getLayer().getLayerState();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create renderers for all sources.
|
||||
* @param {Array.<ol.source.Source>} sources The sources.
|
||||
* @return {Array.<ol.renderer.canvas.Layer>} Array of layer renderers.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.createRenderers_ = function(sources) {
|
||||
function createRenderers(sources) {
|
||||
var len = sources.length;
|
||||
var renderers = new Array(len);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
renderers[i] = _ol_source_Raster_.createRenderer_(sources[i]);
|
||||
renderers[i] = createRenderer(sources[i]);
|
||||
}
|
||||
return renderers;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a renderer for the provided source.
|
||||
* @param {ol.source.Source} source The source.
|
||||
* @return {ol.renderer.canvas.Layer} The renderer.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.createRenderer_ = function(source) {
|
||||
function createRenderer(source) {
|
||||
var renderer = null;
|
||||
if (source instanceof _ol_source_Tile_) {
|
||||
renderer = _ol_source_Raster_.createTileRenderer_(source);
|
||||
renderer = createTileRenderer(source);
|
||||
} else if (source instanceof _ol_source_Image_) {
|
||||
renderer = _ol_source_Raster_.createImageRenderer_(source);
|
||||
renderer = createImageRenderer(source);
|
||||
}
|
||||
return renderer;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an image renderer for the provided source.
|
||||
* @param {ol.source.Image} source The source.
|
||||
* @return {ol.renderer.canvas.Layer} The renderer.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.createImageRenderer_ = function(source) {
|
||||
function createImageRenderer(source) {
|
||||
var layer = new _ol_layer_Image_({source: source});
|
||||
return new _ol_renderer_canvas_ImageLayer_(layer);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a tile renderer for the provided source.
|
||||
* @param {ol.source.Tile} source The source.
|
||||
* @return {ol.renderer.canvas.Layer} The renderer.
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.createTileRenderer_ = function(source) {
|
||||
function createTileRenderer(source) {
|
||||
var layer = new TileLayer({source: source});
|
||||
return new _ol_renderer_canvas_TileLayer_(layer);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -429,7 +441,7 @@ _ol_source_Raster_.createTileRenderer_ = function(source) {
|
||||
* @param {olx.FrameState} frameState The frame state.
|
||||
* @param {Object} data An object made available to operations.
|
||||
*/
|
||||
_ol_source_Raster_.Event = function(type, frameState, data) {
|
||||
RasterSource.Event = function(type, frameState, data) {
|
||||
Event.call(this, type);
|
||||
|
||||
/**
|
||||
@@ -455,34 +467,15 @@ _ol_source_Raster_.Event = function(type, frameState, data) {
|
||||
this.data = data;
|
||||
|
||||
};
|
||||
inherits(_ol_source_Raster_.Event, Event);
|
||||
inherits(RasterSource.Event, Event);
|
||||
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_ol_source_Raster_.prototype.getImageInternal = function() {
|
||||
RasterSource.prototype.getImageInternal = function() {
|
||||
return null; // not implemented
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
* @private
|
||||
*/
|
||||
_ol_source_Raster_.EventType_ = {
|
||||
/**
|
||||
* Triggered before operations are run.
|
||||
* @event ol.source.Raster.Event#beforeoperations
|
||||
* @api
|
||||
*/
|
||||
BEFOREOPERATIONS: 'beforeoperations',
|
||||
|
||||
/**
|
||||
* Triggered after operations are run.
|
||||
* @event ol.source.Raster.Event#afteroperations
|
||||
* @api
|
||||
*/
|
||||
AFTEROPERATIONS: 'afteroperations'
|
||||
};
|
||||
export default _ol_source_Raster_;
|
||||
export default RasterSource;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Map from '../../../../src/ol/Map.js';
|
||||
import _ol_View_ from '../../../../src/ol/View.js';
|
||||
import _ol_layer_Image_ from '../../../../src/ol/layer/Image.js';
|
||||
import _ol_source_Raster_ from '../../../../src/ol/source/Raster.js';
|
||||
import RasterSource from '../../../../src/ol/source/Raster.js';
|
||||
import _ol_source_XYZ_ from '../../../../src/ol/source/XYZ.js';
|
||||
|
||||
where('Uint8ClampedArray').describe('ol.rendering.source.Raster', function() {
|
||||
@@ -55,7 +55,7 @@ where('Uint8ClampedArray').describe('ol.rendering.source.Raster', function() {
|
||||
transition: 0
|
||||
});
|
||||
|
||||
var raster = new _ol_source_Raster_({
|
||||
var raster = new RasterSource({
|
||||
sources: [source],
|
||||
operation: function(pixels) {
|
||||
var pixel = pixels[0];
|
||||
|
||||
@@ -4,7 +4,7 @@ import _ol_View_ from '../../../../src/ol/View.js';
|
||||
import _ol_layer_Image_ from '../../../../src/ol/layer/Image.js';
|
||||
import _ol_proj_Projection_ from '../../../../src/ol/proj/Projection.js';
|
||||
import _ol_source_ImageStatic_ from '../../../../src/ol/source/ImageStatic.js';
|
||||
import _ol_source_Raster_ from '../../../../src/ol/source/Raster.js';
|
||||
import RasterSource from '../../../../src/ol/source/Raster.js';
|
||||
import Source from '../../../../src/ol/source/Source.js';
|
||||
import _ol_source_Tile_ from '../../../../src/ol/source/Tile.js';
|
||||
import _ol_source_XYZ_ from '../../../../src/ol/source/XYZ.js';
|
||||
@@ -50,7 +50,7 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
imageExtent: extent
|
||||
});
|
||||
|
||||
raster = new _ol_source_Raster_({
|
||||
raster = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [redSource, greenSource, blueSource],
|
||||
operation: function(inputs) {
|
||||
@@ -90,19 +90,19 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
describe('constructor', function() {
|
||||
|
||||
it('returns a tile source', function() {
|
||||
var source = new _ol_source_Raster_({
|
||||
var source = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [new _ol_source_Tile_({})]
|
||||
});
|
||||
expect(source).to.be.a(Source);
|
||||
expect(source).to.be.a(_ol_source_Raster_);
|
||||
expect(source).to.be.a(RasterSource);
|
||||
});
|
||||
|
||||
it('defaults to "pixel" operation', function(done) {
|
||||
|
||||
var log = [];
|
||||
|
||||
var source = new _ol_source_Raster_({
|
||||
var source = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [redSource, greenSource, blueSource],
|
||||
operation: function(inputs) {
|
||||
@@ -129,7 +129,7 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
it('allows operation type to be set to "image"', function(done) {
|
||||
var log = [];
|
||||
|
||||
var source = new _ol_source_Raster_({
|
||||
var source = new RasterSource({
|
||||
operationType: 'image',
|
||||
threads: 0,
|
||||
sources: [redSource, greenSource, blueSource],
|
||||
@@ -315,7 +315,7 @@ where('Uint8ClampedArray').describe('ol.source.Raster', function() {
|
||||
url: 'spec/ol/data/osm-{z}-{x}-{y}.png'
|
||||
});
|
||||
|
||||
raster = new _ol_source_Raster_({
|
||||
raster = new RasterSource({
|
||||
threads: 0,
|
||||
sources: [source],
|
||||
operation: function(inputs) {
|
||||
|
||||
Reference in New Issue
Block a user