Merge pull request #1504 from elemoine/vector-api-image-vector-hit-detection
[vector-api] Vector image hit detection
This commit is contained in:
@@ -498,9 +498,13 @@ ol.Map.prototype.disposeInternal = function() {
|
||||
*/
|
||||
ol.Map.prototype.forEachFeatureAtPixel =
|
||||
function(pixel, callback, opt_obj, opt_layerFunction, opt_obj2) {
|
||||
// FIXME this function should probably take an options object
|
||||
if (goog.isNull(this.frameState_)) {
|
||||
return;
|
||||
}
|
||||
var coordinate = this.getCoordinateFromPixel(pixel);
|
||||
return this.renderer_.forEachFeatureAtPixel(
|
||||
pixel, callback, opt_obj, opt_layerFunction, opt_obj2);
|
||||
coordinate, this.frameState_, callback, opt_obj,
|
||||
opt_layerFunction, opt_obj2);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1329,7 +1329,7 @@ ol.render.canvas.ReplayGroup.prototype.replay_ =
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.render.canvas.ReplayGroup.prototype.forEachGeometryAtCoordinate = function(
|
||||
ol.render.canvas.ReplayGroup.prototype.forEachGeometryAtPixel = function(
|
||||
extent, resolution, rotation, coordinate,
|
||||
renderGeometryFunction, callback) {
|
||||
|
||||
|
||||
@@ -41,6 +41,28 @@ ol.renderer.canvas.ImageLayer = function(mapRenderer, imageLayer) {
|
||||
goog.inherits(ol.renderer.canvas.ImageLayer, ol.renderer.canvas.Layer);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
|
||||
function(coordinate, frameState, callback, opt_obj) {
|
||||
var layer = this.getLayer();
|
||||
var source = layer.getSource();
|
||||
goog.asserts.assertInstanceof(source, ol.source.Image);
|
||||
var extent = frameState.extent;
|
||||
var resolution = frameState.view2DState.resolution;
|
||||
var rotation = frameState.view2DState.rotation;
|
||||
return source.forEachFeatureAtPixel(extent, resolution, rotation, coordinate,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(feature) {
|
||||
return callback.call(opt_obj, feature, this);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -32,12 +32,6 @@ ol.renderer.canvas.VectorLayer = function(mapRenderer, vectorLayer) {
|
||||
*/
|
||||
this.dirty_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Extent}
|
||||
*/
|
||||
this.frameStateExtent_ = ol.extent.createEmpty();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
@@ -50,12 +44,6 @@ ol.renderer.canvas.VectorLayer = function(mapRenderer, vectorLayer) {
|
||||
*/
|
||||
this.renderedResolution_ = NaN;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.renderedRotation_ = NaN;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.Extent}
|
||||
@@ -101,23 +89,22 @@ ol.renderer.canvas.VectorLayer.prototype.composeFrame =
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
|
||||
function(pixel, callback, opt_obj) {
|
||||
function(coordinate, frameState, callback, opt_obj) {
|
||||
if (goog.isNull(this.replayGroup_)) {
|
||||
return undefined;
|
||||
} else {
|
||||
goog.asserts.assert(!ol.extent.isEmpty(this.frameStateExtent_));
|
||||
goog.asserts.assert(!isNaN(this.renderedResolution_));
|
||||
goog.asserts.assert(!isNaN(this.renderedRotation_));
|
||||
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||
var extent = frameState.extent;
|
||||
var resolution = frameState.view2DState.resolution;
|
||||
var rotation = frameState.view2DState.rotation;
|
||||
var layer = this.getLayer();
|
||||
var renderGeometryFunction = this.getRenderGeometryFunction_();
|
||||
goog.asserts.assert(goog.isFunction(renderGeometryFunction));
|
||||
return this.replayGroup_.forEachGeometryAtCoordinate(this.frameStateExtent_,
|
||||
this.renderedResolution_, this.renderedRotation_, coordinate,
|
||||
renderGeometryFunction,
|
||||
return this.replayGroup_.forEachGeometryAtPixel(extent, resolution,
|
||||
rotation, coordinate, renderGeometryFunction,
|
||||
/**
|
||||
* @param {ol.geom.Geometry} geometry Geometry.
|
||||
* @param {Object} data Data.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(geometry, data) {
|
||||
var feature = /** @type {ol.Feature} */ (data);
|
||||
@@ -183,8 +170,6 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
||||
var frameStateResolution = frameState.view2DState.resolution;
|
||||
var pixelRatio = frameState.devicePixelRatio;
|
||||
|
||||
this.frameStateExtent_ = frameStateExtent;
|
||||
|
||||
if (!this.dirty_ &&
|
||||
this.renderedResolution_ == frameStateResolution &&
|
||||
this.renderedRevision_ == vectorSource.getRevision() &&
|
||||
@@ -225,7 +210,6 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
||||
|
||||
this.renderedResolution_ = frameStateResolution;
|
||||
this.renderedRevision_ = vectorSource.getRevision();
|
||||
this.renderedRotation_ = frameState.view2DState.rotation;
|
||||
if (!replayGroup.isEmpty()) {
|
||||
this.replayGroup_ = replayGroup;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,28 @@ ol.renderer.dom.ImageLayer = function(mapRenderer, imageLayer) {
|
||||
goog.inherits(ol.renderer.dom.ImageLayer, ol.renderer.dom.Layer);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtPixel =
|
||||
function(coordinate, frameState, callback, opt_obj) {
|
||||
var layer = this.getLayer();
|
||||
var source = layer.getSource();
|
||||
goog.asserts.assertInstanceof(source, ol.source.Image);
|
||||
var extent = frameState.extent;
|
||||
var resolution = frameState.view2DState.resolution;
|
||||
var rotation = frameState.view2DState.rotation;
|
||||
return source.forEachFeatureAtPixel(extent, resolution, rotation, coordinate,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(feature) {
|
||||
return callback.call(opt_obj, feature, this);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -45,7 +45,8 @@ goog.inherits(ol.renderer.Layer, goog.Disposable);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Pixel} pixel Pixel.
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {ol.FrameState} frameState Frame state.
|
||||
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
|
||||
* callback.
|
||||
* @param {S=} opt_obj Scope.
|
||||
|
||||
@@ -81,7 +81,8 @@ ol.renderer.Map.prototype.disposeInternal = function() {
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Pixel} pixel Pixel.
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {ol.FrameState} frameState FrameState.
|
||||
* @param {function(this: S, ol.Feature, ol.layer.Layer): T} callback Feature
|
||||
* callback.
|
||||
* @param {S=} opt_obj Scope for feature callback.
|
||||
@@ -92,7 +93,8 @@ ol.renderer.Map.prototype.disposeInternal = function() {
|
||||
* @template S,T,U
|
||||
*/
|
||||
ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
||||
function(pixel, callback, opt_obj, opt_layerFunction, opt_obj2) {
|
||||
function(coordinate, frameState, callback, opt_obj,
|
||||
opt_layerFunction, opt_obj2) {
|
||||
var layerFunction = goog.isDef(opt_layerFunction) ?
|
||||
opt_layerFunction : goog.functions.TRUE;
|
||||
var layersArray = this.map_.getLayerGroup().getLayersArray();
|
||||
@@ -101,8 +103,8 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
||||
var layer = layersArray[i];
|
||||
if (layer.getVisible() && layerFunction.call(opt_obj2, layer)) {
|
||||
var layerRenderer = this.getLayerRenderer(layer);
|
||||
var result =
|
||||
layerRenderer.forEachFeatureAtPixel(pixel, callback, opt_obj);
|
||||
var result = layerRenderer.forEachFeatureAtPixel(
|
||||
coordinate, frameState, callback, opt_obj);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,28 @@ ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.renderer.webgl.ImageLayer.prototype.forEachFeatureAtPixel =
|
||||
function(coordinate, frameState, callback, opt_obj) {
|
||||
var layer = this.getLayer();
|
||||
var source = layer.getSource();
|
||||
goog.asserts.assertInstanceof(source, ol.source.Image);
|
||||
var extent = frameState.extent;
|
||||
var resolution = frameState.view2DState.resolution;
|
||||
var rotation = frameState.view2DState.rotation;
|
||||
return source.forEachFeatureAtPixel(extent, resolution, rotation, coordinate,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(feature) {
|
||||
return callback.call(opt_obj, feature, this);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -73,6 +73,12 @@ ol.source.ImageVector = function(options) {
|
||||
*/
|
||||
this.canvasSize_ = [0, 0];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.render.canvas.ReplayGroup}
|
||||
*/
|
||||
this.replayGroup_ = null;
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
canvasFunction: goog.bind(this.canvasFunctionInternal_, this),
|
||||
@@ -135,10 +141,35 @@ ol.source.ImageVector.prototype.canvasFunctionInternal_ =
|
||||
replayGroup.replay(this.canvasContext_, extent, pixelRatio, transform,
|
||||
goog.functions.TRUE);
|
||||
|
||||
this.replayGroup_ = replayGroup;
|
||||
|
||||
return this.canvasElement_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.ImageVector.prototype.forEachFeatureAtPixel =
|
||||
function(extent, resolution, rotation, coordinate, callback) {
|
||||
if (goog.isNull(this.replayGroup_)) {
|
||||
return undefined;
|
||||
} else {
|
||||
return this.replayGroup_.forEachGeometryAtPixel(
|
||||
extent, resolution, 0, coordinate, goog.functions.TRUE,
|
||||
/**
|
||||
* @param {ol.geom.Geometry} geometry Geometry.
|
||||
* @param {Object} data Data.
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function(geometry, data) {
|
||||
var feature = /** @type {ol.Feature} */ (data);
|
||||
return callback(feature);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
|
||||
@@ -93,6 +93,19 @@ ol.source.Source.prototype.dispatchChangeEvent = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {function(ol.Feature): T} callback Feature callback.
|
||||
* @return {T|undefined} Callback result.
|
||||
* @template T
|
||||
*/
|
||||
ol.source.Source.prototype.forEachFeatureAtPixel =
|
||||
goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.Attribution>} Attributions.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user