Hit detection refactoring
Get the frame state from the map instead of storing values in the layer renderers.
This commit is contained in:
@@ -457,9 +457,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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1317,7 +1317,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) {
|
||||
|
||||
|
||||
@@ -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,20 +89,18 @@ 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.
|
||||
@@ -183,8 +169,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 +209,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user