Merge pull request #3172 from tsauerwein/forEachLayerAtPixel
Introduce forEachLayerAtPixel
This commit is contained in:
@@ -35,9 +35,11 @@
|
|||||||
<h4 id="title">GetFeatureInfo example (image layer)</h4>
|
<h4 id="title">GetFeatureInfo example (image layer)</h4>
|
||||||
<p id="shortdesc">This example shows how to trigger WMS GetFeatureInfo requests on click for a WMS image layer.</p>
|
<p id="shortdesc">This example shows how to trigger WMS GetFeatureInfo requests on click for a WMS image layer.</p>
|
||||||
<div id="docs">
|
<div id="docs">
|
||||||
|
<p>Additionally <code>map.forEachLayerAtPixel</code> is used to change the mouse
|
||||||
|
pointer when hovering a non-transparent pixel on the map.</p>
|
||||||
<p>See the <a href="getfeatureinfo-image.js" target="_blank">getfeatureinfo-image.js source</a> to see how this is done.</p>
|
<p>See the <a href="getfeatureinfo-image.js" target="_blank">getfeatureinfo-image.js source</a> to see how this is done.</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="tags">getfeatureinfo</div>
|
<div id="tags">getfeatureinfo, forEachLayerAtPixel</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="span4 offset4">
|
<div class="span4 offset4">
|
||||||
<div id="info" class="alert alert-success">
|
<div id="info" class="alert alert-success">
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ goog.require('ol.source.ImageWMS');
|
|||||||
var wmsSource = new ol.source.ImageWMS({
|
var wmsSource = new ol.source.ImageWMS({
|
||||||
url: 'http://demo.boundlessgeo.com/geoserver/wms',
|
url: 'http://demo.boundlessgeo.com/geoserver/wms',
|
||||||
params: {'LAYERS': 'ne:ne'},
|
params: {'LAYERS': 'ne:ne'},
|
||||||
serverType: 'geoserver'
|
serverType: 'geoserver',
|
||||||
|
crossOrigin: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
var wmsLayer = new ol.layer.Image({
|
var wmsLayer = new ol.layer.Image({
|
||||||
@@ -20,6 +21,7 @@ var view = new ol.View({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var map = new ol.Map({
|
var map = new ol.Map({
|
||||||
|
renderer: exampleNS.getRendererFromQueryString(),
|
||||||
layers: [wmsLayer],
|
layers: [wmsLayer],
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: view
|
view: view
|
||||||
@@ -36,3 +38,14 @@ map.on('singleclick', function(evt) {
|
|||||||
'<iframe seamless src="' + url + '"></iframe>';
|
'<iframe seamless src="' + url + '"></iframe>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
map.on('pointermove', function(evt) {
|
||||||
|
if (evt.dragging) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pixel = map.getEventPixel(evt.originalEvent);
|
||||||
|
var hit = map.forEachLayerAtPixel(pixel, function(layer) {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
map.getTargetElement().style.cursor = hit ? 'pointer' : '';
|
||||||
|
});
|
||||||
|
|||||||
@@ -35,9 +35,11 @@
|
|||||||
<h4 id="title">WMS GetFeatureInfo example (tile layer)</h4>
|
<h4 id="title">WMS GetFeatureInfo example (tile layer)</h4>
|
||||||
<p id="shortdesc">This example shows how to trigger WMS GetFeatureInfo requests on click for a WMS tile layer.</p>
|
<p id="shortdesc">This example shows how to trigger WMS GetFeatureInfo requests on click for a WMS tile layer.</p>
|
||||||
<div id="docs">
|
<div id="docs">
|
||||||
|
<p>Additionally <code>map.forEachLayerAtPixel</code> is used to change the mouse
|
||||||
|
pointer when hovering a non-transparent pixel on the map.</p>
|
||||||
<p>See the <a href="getfeatureinfo-tile.js" target="_blank">getfeatureinfo-tile.js source</a> to see how this is done.</p>
|
<p>See the <a href="getfeatureinfo-tile.js" target="_blank">getfeatureinfo-tile.js source</a> to see how this is done.</p>
|
||||||
</div>
|
</div>
|
||||||
<div id="tags">getfeatureinfo</div>
|
<div id="tags">getfeatureinfo, forEachLayerAtPixel</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="span4 offset4">
|
<div class="span4 offset4">
|
||||||
<div id="info" class="alert alert-success">
|
<div id="info" class="alert alert-success">
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ goog.require('ol.source.TileWMS');
|
|||||||
var wmsSource = new ol.source.TileWMS({
|
var wmsSource = new ol.source.TileWMS({
|
||||||
url: 'http://demo.boundlessgeo.com/geoserver/wms',
|
url: 'http://demo.boundlessgeo.com/geoserver/wms',
|
||||||
params: {'LAYERS': 'ne:ne'},
|
params: {'LAYERS': 'ne:ne'},
|
||||||
serverType: 'geoserver'
|
serverType: 'geoserver',
|
||||||
|
crossOrigin: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
var wmsLayer = new ol.layer.Tile({
|
var wmsLayer = new ol.layer.Tile({
|
||||||
@@ -20,6 +21,7 @@ var view = new ol.View({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var map = new ol.Map({
|
var map = new ol.Map({
|
||||||
|
renderer: exampleNS.getRendererFromQueryString(),
|
||||||
layers: [wmsLayer],
|
layers: [wmsLayer],
|
||||||
target: 'map',
|
target: 'map',
|
||||||
view: view
|
view: view
|
||||||
@@ -36,3 +38,14 @@ map.on('singleclick', function(evt) {
|
|||||||
'<iframe seamless src="' + url + '"></iframe>';
|
'<iframe seamless src="' + url + '"></iframe>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
map.on('pointermove', function(evt) {
|
||||||
|
if (evt.dragging) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pixel = map.getEventPixel(evt.originalEvent);
|
||||||
|
var hit = map.forEachLayerAtPixel(pixel, function(layer) {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
map.getTargetElement().style.cursor = hit ? 'pointer' : '';
|
||||||
|
});
|
||||||
|
|||||||
+39
-2
@@ -583,12 +583,49 @@ ol.Map.prototype.forEachFeatureAtPixel =
|
|||||||
var layerFilter = goog.isDef(opt_layerFilter) ?
|
var layerFilter = goog.isDef(opt_layerFilter) ?
|
||||||
opt_layerFilter : goog.functions.TRUE;
|
opt_layerFilter : goog.functions.TRUE;
|
||||||
var thisArg2 = goog.isDef(opt_this2) ? opt_this2 : null;
|
var thisArg2 = goog.isDef(opt_this2) ? opt_this2 : null;
|
||||||
return this.renderer_.forEachFeatureAtPixel(
|
return this.renderer_.forEachFeatureAtCoordinate(
|
||||||
coordinate, this.frameState_, callback, thisArg,
|
coordinate, this.frameState_, callback, thisArg,
|
||||||
layerFilter, thisArg2);
|
layerFilter, thisArg2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect layers that have a color value at a pixel on the viewport, and
|
||||||
|
* execute a callback with each matching layer. Layers included in the
|
||||||
|
* detection can be configured through `opt_layerFilter`. Feature overlays will
|
||||||
|
* always be included in the detection.
|
||||||
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {function(this: S, ol.layer.Layer): T} callback Layer
|
||||||
|
* callback. If the detected feature is not on a layer, but on a
|
||||||
|
* {@link ol.FeatureOverlay}, then the argument to this function will
|
||||||
|
* be `null`. To stop detection, callback functions can return a truthy
|
||||||
|
* value.
|
||||||
|
* @param {S=} opt_this Value to use as `this` when executing `callback`.
|
||||||
|
* @param {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
|
||||||
|
* filter function, only layers which are visible and for which this
|
||||||
|
* function returns `true` will be tested for features. By default, all
|
||||||
|
* visible layers will be tested. Feature overlays will always be tested.
|
||||||
|
* @param {U=} opt_this2 Value to use as `this` when executing `layerFilter`.
|
||||||
|
* @return {T|undefined} Callback result, i.e. the return value of last
|
||||||
|
* callback execution, or the first truthy callback return value.
|
||||||
|
* @template S,T,U
|
||||||
|
* @api stable
|
||||||
|
*/
|
||||||
|
ol.Map.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, callback, opt_this, opt_layerFilter, opt_this2) {
|
||||||
|
if (goog.isNull(this.frameState_)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var thisArg = goog.isDef(opt_this) ? opt_this : null;
|
||||||
|
var layerFilter = goog.isDef(opt_layerFilter) ?
|
||||||
|
opt_layerFilter : goog.functions.TRUE;
|
||||||
|
var thisArg2 = goog.isDef(opt_this2) ? opt_this2 : null;
|
||||||
|
return this.renderer_.forEachLayerAtPixel(
|
||||||
|
pixel, this.frameState_, callback, thisArg,
|
||||||
|
layerFilter, thisArg2);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect if features intersect a pixel on the viewport. Layers included in the
|
* Detect if features intersect a pixel on the viewport. Layers included in the
|
||||||
* detection can be configured through `opt_layerFilter`. Feature overlays will
|
* detection can be configured through `opt_layerFilter`. Feature overlays will
|
||||||
@@ -612,7 +649,7 @@ ol.Map.prototype.hasFeatureAtPixel =
|
|||||||
var layerFilter = goog.isDef(opt_layerFilter) ?
|
var layerFilter = goog.isDef(opt_layerFilter) ?
|
||||||
opt_layerFilter : goog.functions.TRUE;
|
opt_layerFilter : goog.functions.TRUE;
|
||||||
var thisArg = goog.isDef(opt_this) ? opt_this : null;
|
var thisArg = goog.isDef(opt_this) ? opt_this : null;
|
||||||
return this.renderer_.hasFeatureAtPixel(
|
return this.renderer_.hasFeatureAtCoordinate(
|
||||||
coordinate, this.frameState_, layerFilter, thisArg);
|
coordinate, this.frameState_, layerFilter, thisArg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1858,16 +1858,16 @@ ol.render.canvas.ReplayGroup.prototype.finish = function() {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @param {number} rotation Rotation.
|
* @param {number} rotation Rotation.
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
|
||||||
* @param {Object} skippedFeaturesHash Ids of features to skip
|
* @param {Object} skippedFeaturesHash Ids of features to skip
|
||||||
* @param {function(ol.Feature): T} callback Feature callback.
|
* @param {function(ol.Feature): T} callback Feature callback.
|
||||||
* @return {T|undefined} Callback result.
|
* @return {T|undefined} Callback result.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
ol.render.canvas.ReplayGroup.prototype.forEachGeometryAtPixel = function(
|
ol.render.canvas.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
|
||||||
resolution, rotation, coordinate, skippedFeaturesHash, callback) {
|
coordinate, resolution, rotation, skippedFeaturesHash, callback) {
|
||||||
|
|
||||||
var transform = this.hitDetectionTransform_;
|
var transform = this.hitDetectionTransform_;
|
||||||
ol.vec.Mat4.makeTransform2D(transform, 0.5, 0.5,
|
ol.vec.Mat4.makeTransform2D(transform, 0.5, 0.5,
|
||||||
|
|||||||
@@ -1154,6 +1154,7 @@ ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {ol.webgl.Context} context Context.
|
* @param {ol.webgl.Context} context Context.
|
||||||
* @param {ol.Coordinate} center Center.
|
* @param {ol.Coordinate} center Center.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
@@ -1166,15 +1167,14 @@ ol.render.webgl.ReplayGroup.prototype.replayHitDetection_ = function(context,
|
|||||||
* @param {number} hue Global hue.
|
* @param {number} hue Global hue.
|
||||||
* @param {number} saturation Global saturation.
|
* @param {number} saturation Global saturation.
|
||||||
* @param {Object} skippedFeaturesHash Ids of features to skip.
|
* @param {Object} skippedFeaturesHash Ids of features to skip.
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
|
||||||
* @param {function(ol.Feature): T|undefined} callback Feature callback.
|
* @param {function(ol.Feature): T|undefined} callback Feature callback.
|
||||||
* @return {T|undefined} Callback result.
|
* @return {T|undefined} Callback result.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtPixel = function(
|
ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
|
||||||
context, center, resolution, rotation, size, pixelRatio,
|
coordinate, context, center, resolution, rotation, size, pixelRatio,
|
||||||
opacity, brightness, contrast, hue, saturation, skippedFeaturesHash,
|
opacity, brightness, contrast, hue, saturation, skippedFeaturesHash,
|
||||||
coordinate, callback) {
|
callback) {
|
||||||
var gl = context.getGL();
|
var gl = context.getGL();
|
||||||
gl.bindFramebuffer(
|
gl.bindFramebuffer(
|
||||||
gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
|
gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
|
||||||
@@ -1215,6 +1215,7 @@ ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtPixel = function(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {ol.webgl.Context} context Context.
|
* @param {ol.webgl.Context} context Context.
|
||||||
* @param {ol.Coordinate} center Center.
|
* @param {ol.Coordinate} center Center.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
@@ -1227,13 +1228,11 @@ ol.render.webgl.ReplayGroup.prototype.forEachFeatureAtPixel = function(
|
|||||||
* @param {number} hue Global hue.
|
* @param {number} hue Global hue.
|
||||||
* @param {number} saturation Global saturation.
|
* @param {number} saturation Global saturation.
|
||||||
* @param {Object} skippedFeaturesHash Ids of features to skip.
|
* @param {Object} skippedFeaturesHash Ids of features to skip.
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @return {boolean} Is there a feature at the given coordinate?
|
||||||
* @return {boolean} Is there a feature at the given pixel?
|
|
||||||
*/
|
*/
|
||||||
ol.render.webgl.ReplayGroup.prototype.hasFeatureAtPixel = function(
|
ol.render.webgl.ReplayGroup.prototype.hasFeatureAtCoordinate = function(
|
||||||
context, center, resolution, rotation, size, pixelRatio,
|
coordinate, context, center, resolution, rotation, size, pixelRatio,
|
||||||
opacity, brightness, contrast, hue, saturation, skippedFeaturesHash,
|
opacity, brightness, contrast, hue, saturation, skippedFeaturesHash) {
|
||||||
coordinate) {
|
|
||||||
var gl = context.getGL();
|
var gl = context.getGL();
|
||||||
gl.bindFramebuffer(
|
gl.bindFramebuffer(
|
||||||
gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
|
gl.FRAMEBUFFER, context.getHitDetectionFramebuffer());
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.vec.Mat4');
|
goog.require('goog.vec.Mat4');
|
||||||
goog.require('ol.ImageBase');
|
goog.require('ol.ImageBase');
|
||||||
goog.require('ol.ViewHint');
|
goog.require('ol.ViewHint');
|
||||||
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.layer.Image');
|
goog.require('ol.layer.Image');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.renderer.Map');
|
goog.require('ol.renderer.Map');
|
||||||
goog.require('ol.renderer.canvas.Layer');
|
goog.require('ol.renderer.canvas.Layer');
|
||||||
|
goog.require('ol.source.ImageVector');
|
||||||
goog.require('ol.vec.Mat4');
|
goog.require('ol.vec.Mat4');
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +37,18 @@ ol.renderer.canvas.ImageLayer = function(mapRenderer, imageLayer) {
|
|||||||
*/
|
*/
|
||||||
this.imageTransform_ = goog.vec.Mat4.createNumber();
|
this.imageTransform_ = goog.vec.Mat4.createNumber();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?goog.vec.Mat4.Number}
|
||||||
|
*/
|
||||||
|
this.imageTransformInv_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
|
this.hitCanvasContext_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.renderer.canvas.ImageLayer, ol.renderer.canvas.Layer);
|
goog.inherits(ol.renderer.canvas.ImageLayer, ol.renderer.canvas.Layer);
|
||||||
|
|
||||||
@@ -42,15 +56,15 @@ goog.inherits(ol.renderer.canvas.ImageLayer, ol.renderer.canvas.Layer);
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
|
ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(coordinate, frameState, callback, thisArg) {
|
||||||
var layer = this.getLayer();
|
var layer = this.getLayer();
|
||||||
var source = layer.getSource();
|
var source = layer.getSource();
|
||||||
var resolution = frameState.viewState.resolution;
|
var resolution = frameState.viewState.resolution;
|
||||||
var rotation = frameState.viewState.rotation;
|
var rotation = frameState.viewState.rotation;
|
||||||
var skippedFeatureUids = frameState.skippedFeatureUids;
|
var skippedFeatureUids = frameState.skippedFeatureUids;
|
||||||
return source.forEachFeatureAtPixel(
|
return source.forEachFeatureAtCoordinate(
|
||||||
resolution, rotation, coordinate, skippedFeatureUids,
|
coordinate, resolution, rotation, skippedFeatureUids,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
@@ -61,6 +75,55 @@ ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg) {
|
||||||
|
if (goog.isNull(this.getImage())) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
|
||||||
|
// for ImageVector sources use the original hit-detection logic,
|
||||||
|
// so that for example also transparent polygons are detected
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
|
var hasFeature = this.forEachFeatureAtCoordinate(
|
||||||
|
coordinate, frameState, goog.functions.TRUE, this);
|
||||||
|
|
||||||
|
if (hasFeature) {
|
||||||
|
return callback.call(thisArg, this.getLayer());
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// for all other image sources directly check the image
|
||||||
|
if (goog.isNull(this.imageTransformInv_)) {
|
||||||
|
this.imageTransformInv_ = goog.vec.Mat4.createNumber();
|
||||||
|
goog.vec.Mat4.invert(this.imageTransform_, this.imageTransformInv_);
|
||||||
|
}
|
||||||
|
|
||||||
|
var pixelOnCanvas =
|
||||||
|
this.getPixelOnCanvas(pixel, this.imageTransformInv_);
|
||||||
|
|
||||||
|
if (goog.isNull(this.hitCanvasContext_)) {
|
||||||
|
this.hitCanvasContext_ = ol.dom.createCanvasContext2D(1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hitCanvasContext_.clearRect(0, 0, 1, 1);
|
||||||
|
this.hitCanvasContext_.drawImage(
|
||||||
|
this.getImage(), pixelOnCanvas[0], pixelOnCanvas[1], 1, 1, 0, 0, 1, 1);
|
||||||
|
|
||||||
|
var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
|
||||||
|
if (imageData[3] > 0) {
|
||||||
|
return callback.call(thisArg, this.getLayer());
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -135,6 +198,7 @@ ol.renderer.canvas.ImageLayer.prototype.prepareFrame =
|
|||||||
viewRotation,
|
viewRotation,
|
||||||
imagePixelRatio * (imageExtent[0] - viewCenter[0]) / imageResolution,
|
imagePixelRatio * (imageExtent[0] - viewCenter[0]) / imageResolution,
|
||||||
imagePixelRatio * (viewCenter[1] - imageExtent[3]) / imageResolution);
|
imagePixelRatio * (viewCenter[1] - imageExtent[3]) / imageResolution);
|
||||||
|
this.imageTransformInv_ = null;
|
||||||
this.updateAttributions(frameState.attributions, image.getAttributions());
|
this.updateAttributions(frameState.attributions, image.getAttributions());
|
||||||
this.updateLogos(frameState, imageSource);
|
this.updateLogos(frameState, imageSource);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,6 +216,21 @@ ol.renderer.canvas.Layer.prototype.getTransform = function(frameState) {
|
|||||||
ol.renderer.canvas.Layer.prototype.prepareFrame = goog.abstractMethod;
|
ol.renderer.canvas.Layer.prototype.prepareFrame = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Pixel} pixelOnMap Pixel.
|
||||||
|
* @param {goog.vec.Mat4.Number} imageTransformInv The transformation matrix
|
||||||
|
* to convert from a map pixel to a canvas pixel.
|
||||||
|
* @return {ol.Pixel}
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.renderer.canvas.Layer.prototype.getPixelOnCanvas =
|
||||||
|
function(pixelOnMap, imageTransformInv) {
|
||||||
|
var pixelOnCanvas = [0, 0];
|
||||||
|
ol.vec.Mat4.multVec2(imageTransformInv, pixelOnMap, pixelOnCanvas);
|
||||||
|
return pixelOnCanvas;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Size} size Size.
|
* @param {ol.Size} size Size.
|
||||||
* @return {boolean} True when the canvas with the current size does not exceed
|
* @return {boolean} True when the canvas with the current size does not exceed
|
||||||
|
|||||||
@@ -60,6 +60,12 @@ ol.renderer.canvas.TileLayer = function(mapRenderer, tileLayer) {
|
|||||||
*/
|
*/
|
||||||
this.imageTransform_ = goog.vec.Mat4.createNumber();
|
this.imageTransform_ = goog.vec.Mat4.createNumber();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?goog.vec.Mat4.Number}
|
||||||
|
*/
|
||||||
|
this.imageTransformInv_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -408,6 +414,35 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame =
|
|||||||
viewState.rotation,
|
viewState.rotation,
|
||||||
(origin[0] - center[0]) / tilePixelResolution,
|
(origin[0] - center[0]) / tilePixelResolution,
|
||||||
(center[1] - origin[1]) / tilePixelResolution);
|
(center[1] - origin[1]) / tilePixelResolution);
|
||||||
|
this.imageTransformInv_ = null;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg) {
|
||||||
|
if (goog.isNull(this.context_)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goog.isNull(this.imageTransformInv_)) {
|
||||||
|
this.imageTransformInv_ = goog.vec.Mat4.createNumber();
|
||||||
|
goog.vec.Mat4.invert(this.imageTransform_, this.imageTransformInv_);
|
||||||
|
}
|
||||||
|
|
||||||
|
var pixelOnCanvas =
|
||||||
|
this.getPixelOnCanvas(pixel, this.imageTransformInv_);
|
||||||
|
|
||||||
|
var imageData = this.context_.getImageData(
|
||||||
|
pixelOnCanvas[0], pixelOnCanvas[1], 1, 1).data;
|
||||||
|
|
||||||
|
if (imageData[3] > 0) {
|
||||||
|
return callback.call(thisArg, this.getLayer());
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame =
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
|
ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(coordinate, frameState, callback, thisArg) {
|
||||||
if (goog.isNull(this.replayGroup_)) {
|
if (goog.isNull(this.replayGroup_)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -126,8 +126,8 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
|
|||||||
var layer = this.getLayer();
|
var layer = this.getLayer();
|
||||||
/** @type {Object.<string, boolean>} */
|
/** @type {Object.<string, boolean>} */
|
||||||
var features = {};
|
var features = {};
|
||||||
return this.replayGroup_.forEachGeometryAtPixel(resolution,
|
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
|
||||||
rotation, coordinate, frameState.skippedFeatureUids,
|
resolution, rotation, frameState.skippedFeatureUids,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
|
|||||||
@@ -47,15 +47,15 @@ goog.inherits(ol.renderer.dom.ImageLayer, ol.renderer.dom.Layer);
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel =
|
ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(coordinate, frameState, callback, thisArg) {
|
||||||
var layer = this.getLayer();
|
var layer = this.getLayer();
|
||||||
var source = layer.getSource();
|
var source = layer.getSource();
|
||||||
var resolution = frameState.viewState.resolution;
|
var resolution = frameState.viewState.resolution;
|
||||||
var rotation = frameState.viewState.rotation;
|
var rotation = frameState.viewState.rotation;
|
||||||
var skippedFeatureUids = frameState.skippedFeatureUids;
|
var skippedFeatureUids = frameState.skippedFeatureUids;
|
||||||
return source.forEachFeatureAtPixel(
|
return source.forEachFeatureAtCoordinate(
|
||||||
resolution, rotation, coordinate, skippedFeatureUids,
|
coordinate, resolution, rotation, skippedFeatureUids,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ ol.renderer.dom.VectorLayer.prototype.dispatchEvent_ =
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.dom.VectorLayer.prototype.forEachFeatureAtPixel =
|
ol.renderer.dom.VectorLayer.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(coordinate, frameState, callback, thisArg) {
|
||||||
if (goog.isNull(this.replayGroup_)) {
|
if (goog.isNull(this.replayGroup_)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -186,8 +186,8 @@ ol.renderer.dom.VectorLayer.prototype.forEachFeatureAtPixel =
|
|||||||
var layer = this.getLayer();
|
var layer = this.getLayer();
|
||||||
/** @type {Object.<string, boolean>} */
|
/** @type {Object.<string, boolean>} */
|
||||||
var features = {};
|
var features = {};
|
||||||
return this.replayGroup_.forEachGeometryAtPixel(resolution,
|
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
|
||||||
rotation, coordinate, frameState.skippedFeatureUids,
|
resolution, rotation, frameState.skippedFeatureUids,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
|
|||||||
@@ -53,15 +53,37 @@ goog.inherits(ol.renderer.Layer, goog.Disposable);
|
|||||||
* @return {T|undefined} Callback result.
|
* @return {T|undefined} Callback result.
|
||||||
* @template S,T
|
* @template S,T
|
||||||
*/
|
*/
|
||||||
ol.renderer.Layer.prototype.forEachFeatureAtPixel = goog.nullFunction;
|
ol.renderer.Layer.prototype.forEachFeatureAtCoordinate = goog.nullFunction;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {olx.FrameState} frameState Frame state.
|
||||||
|
* @param {function(this: S, ol.layer.Layer): T} callback Layer callback.
|
||||||
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
|
* @return {T|undefined} Callback result.
|
||||||
|
* @template S,T
|
||||||
|
*/
|
||||||
|
ol.renderer.Layer.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg) {
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
|
var hasFeature = this.forEachFeatureAtCoordinate(
|
||||||
|
coordinate, frameState, goog.functions.TRUE, this);
|
||||||
|
|
||||||
|
if (hasFeature) {
|
||||||
|
return callback.call(thisArg, this.layer_);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {olx.FrameState} frameState Frame state.
|
* @param {olx.FrameState} frameState Frame state.
|
||||||
* @return {boolean} Is there a feature at the given pixel?
|
* @return {boolean} Is there a feature at the given coordinate?
|
||||||
*/
|
*/
|
||||||
ol.renderer.Layer.prototype.hasFeatureAtPixel = goog.functions.FALSE;
|
ol.renderer.Layer.prototype.hasFeatureAtCoordinate = goog.functions.FALSE;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ ol.renderer.Map.expireIconCache_ = function(map, frameState) {
|
|||||||
* @return {T|undefined} Callback result.
|
* @return {T|undefined} Callback result.
|
||||||
* @template S,T,U
|
* @template S,T,U
|
||||||
*/
|
*/
|
||||||
ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
ol.renderer.Map.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg,
|
function(coordinate, frameState, callback, thisArg,
|
||||||
layerFilter, thisArg2) {
|
layerFilter, thisArg2) {
|
||||||
var result;
|
var result;
|
||||||
@@ -131,8 +131,8 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
|||||||
if (!goog.isNull(this.replayGroup)) {
|
if (!goog.isNull(this.replayGroup)) {
|
||||||
/** @type {Object.<string, boolean>} */
|
/** @type {Object.<string, boolean>} */
|
||||||
var features = {};
|
var features = {};
|
||||||
result = this.replayGroup.forEachGeometryAtPixel(viewResolution,
|
result = this.replayGroup.forEachFeatureAtCoordinate(coordinate,
|
||||||
viewRotation, coordinate, {},
|
viewResolution, viewRotation, {},
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
@@ -158,7 +158,7 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
|||||||
if (ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
|
if (ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
|
||||||
layerFilter.call(thisArg2, layer)) {
|
layerFilter.call(thisArg2, layer)) {
|
||||||
var layerRenderer = this.getLayerRenderer(layer);
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
result = layerRenderer.forEachFeatureAtPixel(
|
result = layerRenderer.forEachFeatureAtCoordinate(
|
||||||
coordinate, frameState, callback, thisArg);
|
coordinate, frameState, callback, thisArg);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
@@ -169,6 +169,60 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
|
* @param {function(this: S, ol.layer.Layer): T} callback Layer
|
||||||
|
* callback.
|
||||||
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
|
* @param {function(this: U, ol.layer.Layer): boolean} layerFilter Layer filter
|
||||||
|
* function, only layers which are visible and for which this function
|
||||||
|
* returns `true` will be tested for features. By default, all visible
|
||||||
|
* layers will be tested.
|
||||||
|
* @param {U} thisArg2 Value to use as `this` when executing `layerFilter`.
|
||||||
|
* @return {T|undefined} Callback result.
|
||||||
|
* @template S,T,U
|
||||||
|
*/
|
||||||
|
ol.renderer.Map.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg,
|
||||||
|
layerFilter, thisArg2) {
|
||||||
|
var result;
|
||||||
|
var viewState = frameState.viewState;
|
||||||
|
var viewResolution = viewState.resolution;
|
||||||
|
var viewRotation = viewState.rotation;
|
||||||
|
|
||||||
|
if (!goog.isNull(this.replayGroup)) {
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
|
var hasFeature = this.replayGroup.forEachFeatureAtCoordinate(coordinate,
|
||||||
|
viewResolution, viewRotation, {}, goog.functions.TRUE);
|
||||||
|
|
||||||
|
if (hasFeature) {
|
||||||
|
result = callback.call(thisArg, null);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var layerStates = frameState.layerStatesArray;
|
||||||
|
var numLayers = layerStates.length;
|
||||||
|
var i;
|
||||||
|
for (i = numLayers - 1; i >= 0; --i) {
|
||||||
|
var layerState = layerStates[i];
|
||||||
|
var layer = layerState.layer;
|
||||||
|
if (ol.layer.Layer.visibleAtResolution(layerState, viewResolution) &&
|
||||||
|
layerFilter.call(thisArg2, layer)) {
|
||||||
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
|
result = layerRenderer.forEachLayerAtPixel(
|
||||||
|
pixel, frameState, callback, thisArg);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {olx.FrameState} frameState FrameState.
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
@@ -177,12 +231,12 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
|||||||
* returns `true` will be tested for features. By default, all visible
|
* returns `true` will be tested for features. By default, all visible
|
||||||
* layers will be tested.
|
* layers will be tested.
|
||||||
* @param {U} thisArg Value to use as `this` when executing `layerFilter`.
|
* @param {U} thisArg Value to use as `this` when executing `layerFilter`.
|
||||||
* @return {boolean} Is there a feature at the given pixel?
|
* @return {boolean} Is there a feature at the given coordinate?
|
||||||
* @template U
|
* @template U
|
||||||
*/
|
*/
|
||||||
ol.renderer.Map.prototype.hasFeatureAtPixel =
|
ol.renderer.Map.prototype.hasFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, layerFilter, thisArg) {
|
function(coordinate, frameState, layerFilter, thisArg) {
|
||||||
var hasFeature = this.forEachFeatureAtPixel(
|
var hasFeature = this.forEachFeatureAtCoordinate(
|
||||||
coordinate, frameState, goog.functions.TRUE, this, layerFilter, thisArg);
|
coordinate, frameState, goog.functions.TRUE, this, layerFilter, thisArg);
|
||||||
|
|
||||||
return goog.isDef(hasFeature);
|
return goog.isDef(hasFeature);
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ goog.require('ol.Coordinate');
|
|||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
goog.require('ol.ImageBase');
|
goog.require('ol.ImageBase');
|
||||||
goog.require('ol.ViewHint');
|
goog.require('ol.ViewHint');
|
||||||
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.layer.Image');
|
goog.require('ol.layer.Image');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
goog.require('ol.renderer.webgl.Layer');
|
goog.require('ol.renderer.webgl.Layer');
|
||||||
|
goog.require('ol.source.ImageVector');
|
||||||
|
goog.require('ol.vec.Mat4');
|
||||||
goog.require('ol.webgl.Context');
|
goog.require('ol.webgl.Context');
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +35,18 @@ ol.renderer.webgl.ImageLayer = function(mapRenderer, imageLayer) {
|
|||||||
*/
|
*/
|
||||||
this.image_ = null;
|
this.image_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {CanvasRenderingContext2D}
|
||||||
|
*/
|
||||||
|
this.hitCanvasContext_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?goog.vec.Mat4.Number}
|
||||||
|
*/
|
||||||
|
this.hitTransformationMatrix_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.renderer.webgl.ImageLayer, ol.renderer.webgl.Layer);
|
goog.inherits(ol.renderer.webgl.ImageLayer, ol.renderer.webgl.Layer);
|
||||||
|
|
||||||
@@ -58,15 +73,15 @@ ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtPixel =
|
ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(coordinate, frameState, callback, thisArg) {
|
||||||
var layer = this.getLayer();
|
var layer = this.getLayer();
|
||||||
var source = layer.getSource();
|
var source = layer.getSource();
|
||||||
var resolution = frameState.viewState.resolution;
|
var resolution = frameState.viewState.resolution;
|
||||||
var rotation = frameState.viewState.rotation;
|
var rotation = frameState.viewState.rotation;
|
||||||
var skippedFeatureUids = frameState.skippedFeatureUids;
|
var skippedFeatureUids = frameState.skippedFeatureUids;
|
||||||
return source.forEachFeatureAtPixel(
|
return source.forEachFeatureAtCoordinate(
|
||||||
resolution, rotation, coordinate, skippedFeatureUids,
|
coordinate, resolution, rotation, skippedFeatureUids,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
@@ -143,6 +158,7 @@ ol.renderer.webgl.ImageLayer.prototype.prepareFrame =
|
|||||||
|
|
||||||
this.updateProjectionMatrix_(canvas.width, canvas.height,
|
this.updateProjectionMatrix_(canvas.width, canvas.height,
|
||||||
viewCenter, viewResolution, viewRotation, image.getExtent());
|
viewCenter, viewResolution, viewRotation, image.getExtent());
|
||||||
|
this.hitTransformationMatrix_ = null;
|
||||||
|
|
||||||
// Translate and scale to flip the Y coord.
|
// Translate and scale to flip the Y coord.
|
||||||
var texCoordMatrix = this.texCoordMatrix;
|
var texCoordMatrix = this.texCoordMatrix;
|
||||||
@@ -193,3 +209,114 @@ ol.renderer.webgl.ImageLayer.prototype.updateProjectionMatrix_ =
|
|||||||
goog.vec.Mat4.translate(projectionMatrix, 1, 1, 0);
|
goog.vec.Mat4.translate(projectionMatrix, 1, 1, 0);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtCoordinate =
|
||||||
|
function(coordinate, frameState) {
|
||||||
|
var hasFeature = this.forEachFeatureAtCoordinate(
|
||||||
|
coordinate, frameState, goog.functions.TRUE, this);
|
||||||
|
return goog.isDef(hasFeature);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg) {
|
||||||
|
if (goog.isNull(this.image_) || goog.isNull(this.image_.getImage())) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
|
||||||
|
// for ImageVector sources use the original hit-detection logic,
|
||||||
|
// so that for example also transparent polygons are detected
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
|
var hasFeature = this.forEachFeatureAtCoordinate(
|
||||||
|
coordinate, frameState, goog.functions.TRUE, this);
|
||||||
|
|
||||||
|
if (hasFeature) {
|
||||||
|
return callback.call(thisArg, this.getLayer());
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var imageSize =
|
||||||
|
[this.image_.getImage().width, this.image_.getImage().height];
|
||||||
|
|
||||||
|
if (goog.isNull(this.hitTransformationMatrix_)) {
|
||||||
|
this.hitTransformationMatrix_ = this.getHitTransformationMatrix_(
|
||||||
|
frameState.size, imageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
var pixelOnFrameBuffer = [0, 0];
|
||||||
|
ol.vec.Mat4.multVec2(
|
||||||
|
this.hitTransformationMatrix_, pixel, pixelOnFrameBuffer);
|
||||||
|
|
||||||
|
if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
|
||||||
|
pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) {
|
||||||
|
// outside the image, no need to check
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (goog.isNull(this.hitCanvasContext_)) {
|
||||||
|
this.hitCanvasContext_ = ol.dom.createCanvasContext2D(1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hitCanvasContext_.clearRect(0, 0, 1, 1);
|
||||||
|
this.hitCanvasContext_.drawImage(this.image_.getImage(),
|
||||||
|
pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1, 0, 0, 1, 1);
|
||||||
|
|
||||||
|
var imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data;
|
||||||
|
if (imageData[3] > 0) {
|
||||||
|
return callback.call(thisArg, this.getLayer());
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The transformation matrix to get the pixel on the image for a
|
||||||
|
* pixel on the map.
|
||||||
|
* @param {ol.Size} mapSize
|
||||||
|
* @param {ol.Size} imageSize
|
||||||
|
* @return {goog.vec.Mat4.Number}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.renderer.webgl.ImageLayer.prototype.getHitTransformationMatrix_ =
|
||||||
|
function(mapSize, imageSize) {
|
||||||
|
// the first matrix takes a map pixel, flips the y-axis and scales to
|
||||||
|
// a range between -1 ... 1
|
||||||
|
var mapCoordMatrix = goog.vec.Mat4.createNumber();
|
||||||
|
goog.vec.Mat4.makeIdentity(mapCoordMatrix);
|
||||||
|
goog.vec.Mat4.translate(mapCoordMatrix, -1, -1, 0);
|
||||||
|
goog.vec.Mat4.scale(mapCoordMatrix, 2 / mapSize[0], 2 / mapSize[1], 1);
|
||||||
|
goog.vec.Mat4.translate(mapCoordMatrix, 0, mapSize[1], 0);
|
||||||
|
goog.vec.Mat4.scale(mapCoordMatrix, 1, -1, 1);
|
||||||
|
|
||||||
|
// the second matrix is the inverse of the projection matrix used in the
|
||||||
|
// shader for drawing
|
||||||
|
var projectionMatrixInv = goog.vec.Mat4.createNumber();
|
||||||
|
goog.vec.Mat4.invert(this.projectionMatrix, projectionMatrixInv);
|
||||||
|
|
||||||
|
// the third matrix scales to the image dimensions and flips the y-axis again
|
||||||
|
var imageCoordMatrix = goog.vec.Mat4.createNumber();
|
||||||
|
goog.vec.Mat4.makeIdentity(imageCoordMatrix);
|
||||||
|
goog.vec.Mat4.translate(imageCoordMatrix, 0, imageSize[1], 0);
|
||||||
|
goog.vec.Mat4.scale(imageCoordMatrix, 1, -1, 1);
|
||||||
|
goog.vec.Mat4.scale(imageCoordMatrix, imageSize[0] / 2, imageSize[1] / 2, 1);
|
||||||
|
goog.vec.Mat4.translate(imageCoordMatrix, 1, 1, 0);
|
||||||
|
|
||||||
|
var transformMatrix = goog.vec.Mat4.createNumber();
|
||||||
|
goog.vec.Mat4.multMat(
|
||||||
|
imageCoordMatrix, projectionMatrixInv, transformMatrix);
|
||||||
|
goog.vec.Mat4.multMat(
|
||||||
|
transformMatrix, mapCoordMatrix, transformMatrix);
|
||||||
|
|
||||||
|
return transformMatrix;
|
||||||
|
};
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ ol.renderer.webgl.Map.prototype.renderFrame = function(frameState) {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.Map.prototype.forEachFeatureAtPixel =
|
ol.renderer.webgl.Map.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg,
|
function(coordinate, frameState, callback, thisArg,
|
||||||
layerFilter, thisArg2) {
|
layerFilter, thisArg2) {
|
||||||
var result;
|
var result;
|
||||||
@@ -560,11 +560,10 @@ ol.renderer.webgl.Map.prototype.forEachFeatureAtPixel =
|
|||||||
// use default color values
|
// use default color values
|
||||||
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
|
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
|
||||||
|
|
||||||
result = this.replayGroup.forEachFeatureAtPixel(context,
|
result = this.replayGroup.forEachFeatureAtCoordinate(coordinate,
|
||||||
viewState.center, viewState.resolution, viewState.rotation,
|
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||||
frameState.size, frameState.pixelRatio,
|
frameState.size, frameState.pixelRatio,
|
||||||
d.opacity, d.brightness, d.contrast, d.hue, d.saturation, {},
|
d.opacity, d.brightness, d.contrast, d.hue, d.saturation, {},
|
||||||
coordinate,
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
@@ -590,7 +589,7 @@ ol.renderer.webgl.Map.prototype.forEachFeatureAtPixel =
|
|||||||
if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
|
if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
|
||||||
layerFilter.call(thisArg2, layer)) {
|
layerFilter.call(thisArg2, layer)) {
|
||||||
var layerRenderer = this.getLayerRenderer(layer);
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
result = layerRenderer.forEachFeatureAtPixel(
|
result = layerRenderer.forEachFeatureAtCoordinate(
|
||||||
coordinate, frameState, callback, thisArg);
|
coordinate, frameState, callback, thisArg);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
@@ -604,7 +603,7 @@ ol.renderer.webgl.Map.prototype.forEachFeatureAtPixel =
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.Map.prototype.hasFeatureAtPixel =
|
ol.renderer.webgl.Map.prototype.hasFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, layerFilter, thisArg) {
|
function(coordinate, frameState, layerFilter, thisArg) {
|
||||||
var hasFeature = false;
|
var hasFeature = false;
|
||||||
|
|
||||||
@@ -620,11 +619,10 @@ ol.renderer.webgl.Map.prototype.hasFeatureAtPixel =
|
|||||||
// use default color values
|
// use default color values
|
||||||
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
|
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
|
||||||
|
|
||||||
hasFeature = this.replayGroup.hasFeatureAtPixel(context,
|
hasFeature = this.replayGroup.hasFeatureAtCoordinate(coordinate,
|
||||||
viewState.center, viewState.resolution, viewState.rotation,
|
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||||
frameState.size, frameState.pixelRatio,
|
frameState.size, frameState.pixelRatio,
|
||||||
d.opacity, d.brightness, d.contrast, d.hue, d.saturation, {},
|
d.opacity, d.brightness, d.contrast, d.hue, d.saturation, {});
|
||||||
coordinate);
|
|
||||||
if (hasFeature) {
|
if (hasFeature) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -638,7 +636,8 @@ ol.renderer.webgl.Map.prototype.hasFeatureAtPixel =
|
|||||||
if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
|
if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
|
||||||
layerFilter.call(thisArg, layer)) {
|
layerFilter.call(thisArg, layer)) {
|
||||||
var layerRenderer = this.getLayerRenderer(layer);
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
hasFeature = layerRenderer.hasFeatureAtPixel(coordinate, frameState);
|
hasFeature =
|
||||||
|
layerRenderer.hasFeatureAtCoordinate(coordinate, frameState);
|
||||||
if (hasFeature) {
|
if (hasFeature) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -648,6 +647,57 @@ ol.renderer.webgl.Map.prototype.hasFeatureAtPixel =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg,
|
||||||
|
layerFilter, thisArg2) {
|
||||||
|
if (this.getGL().isContextLost()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var context = this.getContext();
|
||||||
|
var viewState = frameState.viewState;
|
||||||
|
var result;
|
||||||
|
|
||||||
|
// do the hit-detection for the overlays first
|
||||||
|
if (!goog.isNull(this.replayGroup)) {
|
||||||
|
// use default color values
|
||||||
|
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
|
|
||||||
|
var hasFeature = this.replayGroup.hasFeatureAtCoordinate(coordinate,
|
||||||
|
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||||
|
frameState.size, frameState.pixelRatio,
|
||||||
|
d.opacity, d.brightness, d.contrast, d.hue, d.saturation, {});
|
||||||
|
if (hasFeature) {
|
||||||
|
result = callback.call(thisArg, null);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var layerStates = frameState.layerStatesArray;
|
||||||
|
var numLayers = layerStates.length;
|
||||||
|
var i;
|
||||||
|
for (i = numLayers - 1; i >= 0; --i) {
|
||||||
|
var layerState = layerStates[i];
|
||||||
|
var layer = layerState.layer;
|
||||||
|
if (ol.layer.Layer.visibleAtResolution(layerState, viewState.resolution) &&
|
||||||
|
layerFilter.call(thisArg, layer)) {
|
||||||
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
|
result = layerRenderer.forEachLayerAtPixel(
|
||||||
|
pixel, frameState, callback, thisArg);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @const
|
* @const
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ goog.require('ol.math');
|
|||||||
goog.require('ol.renderer.webgl.Layer');
|
goog.require('ol.renderer.webgl.Layer');
|
||||||
goog.require('ol.renderer.webgl.tilelayer.shader');
|
goog.require('ol.renderer.webgl.tilelayer.shader');
|
||||||
goog.require('ol.tilecoord');
|
goog.require('ol.tilecoord');
|
||||||
|
goog.require('ol.vec.Mat4');
|
||||||
goog.require('ol.webgl.Buffer');
|
goog.require('ol.webgl.Buffer');
|
||||||
|
|
||||||
|
|
||||||
@@ -326,3 +327,38 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame =
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg) {
|
||||||
|
if (goog.isNull(this.framebuffer)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
var mapSize = this.getMap().getSize();
|
||||||
|
|
||||||
|
var pixelOnMapScaled = [
|
||||||
|
pixel[0] / mapSize[0],
|
||||||
|
(mapSize[1] - pixel[1]) / mapSize[1]];
|
||||||
|
|
||||||
|
var pixelOnFrameBufferScaled = [0, 0];
|
||||||
|
ol.vec.Mat4.multVec2(
|
||||||
|
this.texCoordMatrix, pixelOnMapScaled, pixelOnFrameBufferScaled);
|
||||||
|
var pixelOnFrameBuffer = [
|
||||||
|
pixelOnFrameBufferScaled[0] * this.framebufferDimension,
|
||||||
|
pixelOnFrameBufferScaled[1] * this.framebufferDimension];
|
||||||
|
|
||||||
|
var gl = this.getWebGLMapRenderer().getContext().getGL();
|
||||||
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
||||||
|
var imageData = new Uint8Array(4);
|
||||||
|
gl.readPixels(pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1,
|
||||||
|
gl.RGBA, gl.UNSIGNED_BYTE, imageData);
|
||||||
|
|
||||||
|
if (imageData[3] > 0) {
|
||||||
|
return callback.call(thisArg, this.getLayer());
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ ol.renderer.webgl.VectorLayer.prototype.disposeInternal = function() {
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtPixel =
|
ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtCoordinate =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(coordinate, frameState, callback, thisArg) {
|
||||||
if (goog.isNull(this.replayGroup_) || goog.isNull(this.layerState_)) {
|
if (goog.isNull(this.replayGroup_) || goog.isNull(this.layerState_)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -118,12 +118,11 @@ ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtPixel =
|
|||||||
var layerState = this.layerState_;
|
var layerState = this.layerState_;
|
||||||
/** @type {Object.<string, boolean>} */
|
/** @type {Object.<string, boolean>} */
|
||||||
var features = {};
|
var features = {};
|
||||||
return this.replayGroup_.forEachFeatureAtPixel(context,
|
return this.replayGroup_.forEachFeatureAtCoordinate(coordinate,
|
||||||
viewState.center, viewState.resolution, viewState.rotation,
|
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||||
frameState.size, frameState.pixelRatio,
|
frameState.size, frameState.pixelRatio,
|
||||||
layerState.opacity, layerState.brightness, layerState.contrast,
|
layerState.opacity, layerState.brightness, layerState.contrast,
|
||||||
layerState.hue, layerState.saturation, frameState.skippedFeatureUids,
|
layerState.hue, layerState.saturation, frameState.skippedFeatureUids,
|
||||||
coordinate,
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
@@ -143,7 +142,7 @@ ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtPixel =
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtPixel =
|
ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtCoordinate =
|
||||||
function(coordinate, frameState) {
|
function(coordinate, frameState) {
|
||||||
if (goog.isNull(this.replayGroup_) || goog.isNull(this.layerState_)) {
|
if (goog.isNull(this.replayGroup_) || goog.isNull(this.layerState_)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -152,12 +151,27 @@ ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtPixel =
|
|||||||
var context = mapRenderer.getContext();
|
var context = mapRenderer.getContext();
|
||||||
var viewState = frameState.viewState;
|
var viewState = frameState.viewState;
|
||||||
var layerState = this.layerState_;
|
var layerState = this.layerState_;
|
||||||
return this.replayGroup_.hasFeatureAtPixel(context,
|
return this.replayGroup_.hasFeatureAtCoordinate(coordinate,
|
||||||
viewState.center, viewState.resolution, viewState.rotation,
|
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||||
frameState.size, frameState.pixelRatio,
|
frameState.size, frameState.pixelRatio,
|
||||||
layerState.opacity, layerState.brightness, layerState.contrast,
|
layerState.opacity, layerState.brightness, layerState.contrast,
|
||||||
layerState.hue, layerState.saturation, frameState.skippedFeatureUids,
|
layerState.hue, layerState.saturation, frameState.skippedFeatureUids);
|
||||||
coordinate);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.renderer.webgl.VectorLayer.prototype.forEachLayerAtPixel =
|
||||||
|
function(pixel, frameState, callback, thisArg) {
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
|
var hasFeature = this.hasFeatureAtCoordinate(coordinate, frameState);
|
||||||
|
|
||||||
|
if (hasFeature) {
|
||||||
|
return callback.call(thisArg, this.getLayer());
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -152,15 +152,15 @@ ol.source.ImageVector.prototype.canvasFunctionInternal_ =
|
|||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.source.ImageVector.prototype.forEachFeatureAtPixel = function(
|
ol.source.ImageVector.prototype.forEachFeatureAtCoordinate = function(
|
||||||
resolution, rotation, coordinate, skippedFeatureUids, callback) {
|
coordinate, resolution, rotation, skippedFeatureUids, callback) {
|
||||||
if (goog.isNull(this.replayGroup_)) {
|
if (goog.isNull(this.replayGroup_)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
/** @type {Object.<string, boolean>} */
|
/** @type {Object.<string, boolean>} */
|
||||||
var features = {};
|
var features = {};
|
||||||
return this.replayGroup_.forEachGeometryAtPixel(
|
return this.replayGroup_.forEachFeatureAtCoordinate(
|
||||||
resolution, 0, coordinate, skippedFeatureUids,
|
coordinate, resolution, 0, skippedFeatureUids,
|
||||||
/**
|
/**
|
||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
|
|||||||
@@ -77,15 +77,15 @@ goog.inherits(ol.source.Source, ol.Observable);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @param {number} rotation Rotation.
|
* @param {number} rotation Rotation.
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
|
||||||
* @param {Object.<string, boolean>} skippedFeatureUids Skipped feature uids.
|
* @param {Object.<string, boolean>} skippedFeatureUids Skipped feature uids.
|
||||||
* @param {function(ol.Feature): T} callback Feature callback.
|
* @param {function(ol.Feature): T} callback Feature callback.
|
||||||
* @return {T|undefined} Callback result.
|
* @return {T|undefined} Callback result.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
ol.source.Source.prototype.forEachFeatureAtPixel =
|
ol.source.Source.prototype.forEachFeatureAtCoordinate =
|
||||||
goog.nullFunction;
|
goog.nullFunction;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ ol.source.Vector.prototype.forEachFeature = function(callback, opt_this) {
|
|||||||
* @return {S|undefined} The return value from the last call to the callback.
|
* @return {S|undefined} The return value from the last call to the callback.
|
||||||
* @template T,S
|
* @template T,S
|
||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.forEachFeatureAtCoordinate =
|
ol.source.Vector.prototype.forEachFeatureAtCoordinateDirect =
|
||||||
function(coordinate, callback, opt_this) {
|
function(coordinate, callback, opt_this) {
|
||||||
var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
|
var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
|
||||||
return this.forEachFeatureInExtent(extent, function(feature) {
|
return this.forEachFeatureInExtent(extent, function(feature) {
|
||||||
@@ -409,7 +409,7 @@ ol.source.Vector.prototype.getFeatures = function() {
|
|||||||
*/
|
*/
|
||||||
ol.source.Vector.prototype.getFeaturesAtCoordinate = function(coordinate) {
|
ol.source.Vector.prototype.getFeaturesAtCoordinate = function(coordinate) {
|
||||||
var features = [];
|
var features = [];
|
||||||
this.forEachFeatureAtCoordinate(coordinate, function(feature) {
|
this.forEachFeatureAtCoordinateDirect(coordinate, function(feature) {
|
||||||
features.push(feature);
|
features.push(feature);
|
||||||
});
|
});
|
||||||
return features;
|
return features;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ describe('ol.renderer.canvas.VectorLayer', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#forEachFeatureAtPixel', function() {
|
describe('#forEachFeatureAtCoordinate', function() {
|
||||||
var renderer;
|
var renderer;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
@@ -70,8 +70,8 @@ describe('ol.renderer.canvas.VectorLayer', function() {
|
|||||||
map.getRenderer(), layer);
|
map.getRenderer(), layer);
|
||||||
var replayGroup = {};
|
var replayGroup = {};
|
||||||
renderer.replayGroup_ = replayGroup;
|
renderer.replayGroup_ = replayGroup;
|
||||||
replayGroup.forEachGeometryAtPixel = function(resolution,
|
replayGroup.forEachFeatureAtCoordinate = function(coordinate,
|
||||||
rotation, coordinate, skippedFeaturesUids, callback) {
|
resolution, rotation, skippedFeaturesUids, callback) {
|
||||||
var geometry = new ol.geom.Point([0, 0]);
|
var geometry = new ol.geom.Point([0, 0]);
|
||||||
var feature = new ol.Feature();
|
var feature = new ol.Feature();
|
||||||
callback(geometry, feature);
|
callback(geometry, feature);
|
||||||
@@ -89,7 +89,7 @@ describe('ol.renderer.canvas.VectorLayer', function() {
|
|||||||
rotation: 0
|
rotation: 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
renderer.forEachFeatureAtPixel(
|
renderer.forEachFeatureAtCoordinate(
|
||||||
coordinate, frameState, spy, undefined);
|
coordinate, frameState, spy, undefined);
|
||||||
expect(spy.callCount).to.be(1);
|
expect(spy.callCount).to.be(1);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user