Merge pull request #5670 from Benjaki2/master
Added image data value to 'forEachLayerAtPixel' method callback
This commit is contained in:
+5
-4
@@ -619,10 +619,11 @@ ol.Map.prototype.forEachFeatureAtPixel = function(pixel, callback, opt_this, opt
|
|||||||
* execute a callback with each matching layer. Layers included in the
|
* execute a callback with each matching layer. Layers included in the
|
||||||
* detection can be configured through `opt_layerFilter`.
|
* detection can be configured through `opt_layerFilter`.
|
||||||
* @param {ol.Pixel} pixel Pixel.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
* @param {function(this: S, ol.layer.Layer): T} callback Layer
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer
|
||||||
* callback. Will receive one argument, the {@link ol.layer.Layer layer}
|
* callback. This callback will recieve two arguments: first is the
|
||||||
* that contains the color pixel. To stop detection, callback functions can
|
* {@link ol.layer.Layer layer}, second argument is {@link ol.Color}
|
||||||
* return a truthy value.
|
* and will be null for layer types that do not currently support this
|
||||||
|
* argument. To stop detection callback functions can return a truthy value.
|
||||||
* @param {S=} opt_this Value to use as `this` when executing `callback`.
|
* @param {S=} opt_this Value to use as `this` when executing `callback`.
|
||||||
* @param {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
|
* @param {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
|
||||||
* filter function. The filter function will receive one argument, the
|
* filter function. The filter function will receive one argument, the
|
||||||
|
|||||||
@@ -69,7 +69,13 @@ ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtCoordinate = function(co
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer
|
||||||
|
* callback.
|
||||||
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
|
* @return {T|undefined} Callback result.
|
||||||
|
* @template S,T,U
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
||||||
if (!this.getImage()) {
|
if (!this.getImage()) {
|
||||||
@@ -85,7 +91,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fr
|
|||||||
coordinate, frameState, ol.functions.TRUE, this);
|
coordinate, frameState, ol.functions.TRUE, this);
|
||||||
|
|
||||||
if (hasFeature) {
|
if (hasFeature) {
|
||||||
return callback.call(thisArg, this.getLayer());
|
return callback.call(thisArg, this.getLayer(), null);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -108,7 +114,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fr
|
|||||||
|
|
||||||
var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
|
var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
|
||||||
if (imageData[3] > 0) {
|
if (imageData[3] > 0) {
|
||||||
return callback.call(thisArg, this.getLayer());
|
return callback.call(thisArg, this.getLayer(), imageData);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,13 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame = function(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer
|
||||||
|
* callback.
|
||||||
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
|
* @return {T|undefined} Callback result.
|
||||||
|
* @template S,T,U
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel = function(
|
ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel = function(
|
||||||
pixel, frameState, callback, thisArg) {
|
pixel, frameState, callback, thisArg) {
|
||||||
@@ -200,7 +206,7 @@ ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel = function(
|
|||||||
pixel[0], pixel[1], 1, 1).data;
|
pixel[0], pixel[1], 1, 1).data;
|
||||||
|
|
||||||
if (imageData[3] > 0) {
|
if (imageData[3] > 0) {
|
||||||
return callback.call(thisArg, this.getLayer());
|
return callback.call(thisArg, this.getLayer(), imageData);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ ol.renderer.Layer.prototype.forEachFeatureAtCoordinate = ol.nullFunction;
|
|||||||
/**
|
/**
|
||||||
* @param {ol.Pixel} pixel Pixel.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
* @param {olx.FrameState} frameState Frame state.
|
* @param {olx.FrameState} frameState Frame state.
|
||||||
* @param {function(this: S, ol.layer.Layer): T} callback Layer callback.
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer callback.
|
||||||
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
* @return {T|undefined} Callback result.
|
* @return {T|undefined} Callback result.
|
||||||
* @template S,T
|
* @template S,T
|
||||||
@@ -60,7 +60,7 @@ ol.renderer.Layer.prototype.forEachLayerAtPixel = function(pixel, frameState, ca
|
|||||||
coordinate, frameState, ol.functions.TRUE, this);
|
coordinate, frameState, ol.functions.TRUE, this);
|
||||||
|
|
||||||
if (hasFeature) {
|
if (hasFeature) {
|
||||||
return callback.call(thisArg, this.layer_);
|
return callback.call(thisArg, this.layer_, null);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ ol.renderer.Map.prototype.forEachFeatureAtCoordinate = function(coordinate, fram
|
|||||||
/**
|
/**
|
||||||
* @param {ol.Pixel} pixel Pixel.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
* @param {olx.FrameState} frameState FrameState.
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
* @param {function(this: S, ol.layer.Layer): T} callback Layer
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer
|
||||||
* callback.
|
* callback.
|
||||||
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
* @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
|
* @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
|
||||||
|
|||||||
@@ -218,7 +218,13 @@ ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtCoordinate = function(coordin
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer
|
||||||
|
* callback.
|
||||||
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
|
* @return {T|undefined} Callback result.
|
||||||
|
* @template S,T,U
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
||||||
if (!this.image_ || !this.image_.getImage()) {
|
if (!this.image_ || !this.image_.getImage()) {
|
||||||
@@ -234,7 +240,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
|
|||||||
coordinate, frameState, ol.functions.TRUE, this);
|
coordinate, frameState, ol.functions.TRUE, this);
|
||||||
|
|
||||||
if (hasFeature) {
|
if (hasFeature) {
|
||||||
return callback.call(thisArg, this.getLayer());
|
return callback.call(thisArg, this.getLayer(), null);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -266,7 +272,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel = function(pixel, fra
|
|||||||
|
|
||||||
var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
|
var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
|
||||||
if (imageData[3] > 0) {
|
if (imageData[3] > 0) {
|
||||||
return callback.call(thisArg, this.getLayer());
|
return callback.call(thisArg, this.getLayer(), imageData);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,7 +364,13 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame = function(frameState, layerS
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer
|
||||||
|
* callback.
|
||||||
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
|
* @return {T|undefined} Callback result.
|
||||||
|
* @template S,T,U
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
||||||
if (!this.framebuffer) {
|
if (!this.framebuffer) {
|
||||||
@@ -388,7 +394,7 @@ ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel = function(pixel, fram
|
|||||||
gl.RGBA, gl.UNSIGNED_BYTE, imageData);
|
gl.RGBA, gl.UNSIGNED_BYTE, imageData);
|
||||||
|
|
||||||
if (imageData[3] > 0) {
|
if (imageData[3] > 0) {
|
||||||
return callback.call(thisArg, this.getLayer());
|
return callback.call(thisArg, this.getLayer(), imageData);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,7 +147,13 @@ ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtCoordinate = function(coordi
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
|
* @param {function(this: S, ol.layer.Layer, ol.Color): T} callback Layer
|
||||||
|
* callback.
|
||||||
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
|
* @return {T|undefined} Callback result.
|
||||||
|
* @template S,T,U
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, frameState, callback, thisArg) {
|
||||||
var coordinate = ol.transform.apply(
|
var coordinate = ol.transform.apply(
|
||||||
@@ -155,7 +161,7 @@ ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel = function(pixel, fr
|
|||||||
var hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState);
|
var hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState);
|
||||||
|
|
||||||
if (hasFeature) {
|
if (hasFeature) {
|
||||||
return callback.call(thisArg, this.getLayer());
|
return callback.call(thisArg, this.getLayer(), null);
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -104,7 +104,7 @@ ol.CircleRenderOptions;
|
|||||||
* red, green, and blue should be integers in the range 0..255 inclusive.
|
* red, green, and blue should be integers in the range 0..255 inclusive.
|
||||||
* alpha should be a float in the range 0..1 inclusive. If no alpha value is
|
* alpha should be a float in the range 0..1 inclusive. If no alpha value is
|
||||||
* given then `1` will be used.
|
* given then `1` will be used.
|
||||||
* @typedef {Array.<number>}
|
* @typedef {Array.<number>|Uint8Array|Uint8ClampedArray}
|
||||||
*/
|
*/
|
||||||
ol.Color;
|
ol.Color;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user