Merge pull request #1354 from elemoine/vector-api-hit-rotation

[vector-api] hit detect rotated features
This commit is contained in:
Éric Lemoine
2013-12-11 07:15:46 -08:00
2 changed files with 15 additions and 3 deletions

View File

@@ -1165,6 +1165,7 @@ ol.render.canvas.ReplayGroup.prototype.replayForward_ =
/**
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @param {number} rotation Rotation.
* @param {ol.Coordinate} coordinate Coordinate.
* @param {function(ol.geom.Geometry): boolean} renderGeometryFunction Render
* geometry function.
@@ -1173,11 +1174,13 @@ ol.render.canvas.ReplayGroup.prototype.replayForward_ =
* @template T
*/
ol.render.canvas.ReplayGroup.prototype.forEachGeometryAtCoordinate = function(
extent, resolution, coordinate, renderGeometryFunction, callback) {
extent, resolution, rotation, coordinate,
renderGeometryFunction, callback) {
var transform = this.hitDetectionTransform_;
ol.vec.Mat4.makeTransform2D(transform, 0.5, 0.5,
1 / resolution, -1 / resolution, 0, -coordinate[0], -coordinate[1]);
1 / resolution, -1 / resolution, -rotation,
-coordinate[0], -coordinate[1]);
/** @type {Array.<number>} */
var zs = goog.array.map(goog.object.getKeys(this.replayesByZIndex_), Number);

View File

@@ -41,6 +41,12 @@ ol.renderer.canvas.VectorLayer = function(mapRenderer, vectorLayer) {
*/
this.renderedResolution_ = NaN;
/**
* @private
* @type {number}
*/
this.renderedRotation_ = NaN;
/**
* @private
* @type {ol.Extent}
@@ -91,12 +97,14 @@ ol.renderer.canvas.VectorLayer.prototype.forEachFeatureAtPixel =
} else {
goog.asserts.assert(!ol.extent.isEmpty(this.renderedExtent_));
goog.asserts.assert(!isNaN(this.renderedResolution_));
goog.asserts.assert(!isNaN(this.renderedRotation_));
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
var layer = this.getLayer();
var renderGeometryFunction = this.getRenderGeometryFunction_();
goog.asserts.assert(goog.isFunction(renderGeometryFunction));
return this.replayGroup_.forEachGeometryAtCoordinate(this.renderedExtent_,
this.renderedResolution_, coordinate, renderGeometryFunction,
this.renderedResolution_, this.renderedRotation_, coordinate,
renderGeometryFunction,
/**
* @param {ol.geom.Geometry} geometry Geometry.
* @param {Object} data Data.
@@ -200,6 +208,7 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
this.renderedResolution_ = frameStateResolution;
this.renderedRevision_ = vectorSource.getRevision();
this.renderedRotation_ = frameState.view2DState.rotation;
if (!replayGroup.isEmpty()) {
this.replayGroup_ = replayGroup;
}