Fire events before and after running ops
This commit is contained in:
@@ -266,6 +266,18 @@ oli.source.ImageEvent = function() {};
|
||||
oli.source.ImageEvent.prototype.image;
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
oli.source.RasterEvent = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
oli.source.RasterEvent.prototype.resolution;
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
goog.provide('ol.source.Raster');
|
||||
goog.provide('ol.source.RasterEvent');
|
||||
goog.provide('ol.source.RasterEventType');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.vec.Mat4');
|
||||
goog.require('ol.ImageCanvas');
|
||||
@@ -182,6 +185,11 @@ ol.source.Raster.prototype.composeFrame_ = function(frameState) {
|
||||
var targetImageData = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
var target = targetImageData.data;
|
||||
|
||||
|
||||
var resolution = frameState.viewState.resolution / frameState.pixelRatio;
|
||||
this.dispatchEvent(new ol.source.RasterEvent(
|
||||
ol.source.RasterEventType.BEFOREOPERATIONS, resolution));
|
||||
|
||||
var source, pixel;
|
||||
for (var j = 0, jj = target.length; j < jj; j += 4) {
|
||||
for (var k = 0; k < len; ++k) {
|
||||
@@ -192,13 +200,17 @@ ol.source.Raster.prototype.composeFrame_ = function(frameState) {
|
||||
pixel[2] = source[j + 2];
|
||||
pixel[3] = source[j + 3];
|
||||
}
|
||||
this.transformPixels_(pixels);
|
||||
this.runOperations_(pixels);
|
||||
pixel = pixels[0];
|
||||
target[j] = pixel[0];
|
||||
target[j + 1] = pixel[1];
|
||||
target[j + 2] = pixel[2];
|
||||
target[j + 3] = pixel[3];
|
||||
}
|
||||
|
||||
this.dispatchEvent(new ol.source.RasterEvent(
|
||||
ol.source.RasterEventType.AFTEROPERATIONS, resolution));
|
||||
|
||||
context.putImageData(targetImageData, 0, 0);
|
||||
|
||||
frameState.tileQueue.loadMoreTiles(16, 16);
|
||||
@@ -211,7 +223,7 @@ ol.source.Raster.prototype.composeFrame_ = function(frameState) {
|
||||
* @return {Array.<ol.raster.Pixel>} The modified pixels.
|
||||
* @private
|
||||
*/
|
||||
ol.source.Raster.prototype.transformPixels_ = function(pixels) {
|
||||
ol.source.Raster.prototype.runOperations_ = function(pixels) {
|
||||
for (var i = 0, ii = this.operations_.length; i < ii; ++i) {
|
||||
pixels = this.operations_[i](pixels);
|
||||
}
|
||||
@@ -314,3 +326,49 @@ ol.source.Raster.createTileRenderer_ = function(source) {
|
||||
var layer = new ol.layer.Tile({source: source});
|
||||
return new ol.renderer.canvas.TileLayer(layer);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Events emitted by {@link ol.source.Raster} instances are instances of this
|
||||
* type.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {goog.events.Event}
|
||||
* @implements {oli.source.RasterEvent}
|
||||
* @param {string} type Type.
|
||||
* @param {number} resolution Map units per pixel.
|
||||
*/
|
||||
ol.source.RasterEvent = function(type, resolution) {
|
||||
goog.base(this, type);
|
||||
|
||||
/**
|
||||
* Map units per pixel.
|
||||
* @type {number}
|
||||
* @api
|
||||
*/
|
||||
this.resolution = resolution;
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.RasterEvent, goog.events.Event);
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.source.RasterEventType = {
|
||||
/**
|
||||
* Triggered before operations are run.
|
||||
* @event ol.source.RasterEvent#beforeoperations
|
||||
* @api
|
||||
*/
|
||||
BEFOREOPERATIONS: 'beforeoperations',
|
||||
|
||||
/**
|
||||
* Triggered after operations are run.
|
||||
* @event ol.source.RasterEvent#afteroperations
|
||||
* @api
|
||||
*/
|
||||
AFTEROPERATIONS: 'afteroperations'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user