Make forEachFeatureAtCoordinate work with variable hitContext size
This commit is contained in:
@@ -65,19 +65,6 @@ ol.render.canvas.ReplayGroup = function(
|
|||||||
* Object.<ol.render.ReplayType, ol.render.canvas.Replay>>}
|
* Object.<ol.render.ReplayType, ol.render.canvas.Replay>>}
|
||||||
*/
|
*/
|
||||||
this.replaysByZIndex_ = {};
|
this.replaysByZIndex_ = {};
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {CanvasRenderingContext2D}
|
|
||||||
*/
|
|
||||||
this.hitDetectionContext_ = ol.dom.createCanvasContext2D(1, 1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ol.Transform}
|
|
||||||
*/
|
|
||||||
this.hitDetectionTransform_ = ol.transform.create();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
ol.inherits(ol.render.canvas.ReplayGroup, ol.render.ReplayGroup);
|
ol.inherits(ol.render.canvas.ReplayGroup, ol.render.ReplayGroup);
|
||||||
|
|
||||||
@@ -111,14 +98,17 @@ ol.render.canvas.ReplayGroup.prototype.finish = function() {
|
|||||||
ol.render.canvas.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
|
ol.render.canvas.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
|
||||||
coordinate, resolution, rotation, skippedFeaturesHash, callback) {
|
coordinate, resolution, rotation, skippedFeaturesHash, callback) {
|
||||||
|
|
||||||
var transform = ol.transform.compose(this.hitDetectionTransform_,
|
var hitTolerance = 10;
|
||||||
0.5, 0.5,
|
var contextSize = hitTolerance * 2 + 1;
|
||||||
|
|
||||||
|
var transform = ol.transform.compose(ol.transform.create(),
|
||||||
|
hitTolerance + 0.5, hitTolerance + 0.5,
|
||||||
1 / resolution, -1 / resolution,
|
1 / resolution, -1 / resolution,
|
||||||
-rotation,
|
-rotation,
|
||||||
-coordinate[0], -coordinate[1]);
|
-coordinate[0], -coordinate[1]);
|
||||||
|
|
||||||
var context = this.hitDetectionContext_;
|
var context = ol.dom.createCanvasContext2D(contextSize, contextSize);
|
||||||
context.clearRect(0, 0, 1, 1);
|
context.clearRect(0, 0, contextSize, contextSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.Extent}
|
* @type {ol.Extent}
|
||||||
@@ -137,14 +127,21 @@ ol.render.canvas.ReplayGroup.prototype.forEachFeatureAtCoordinate = function(
|
|||||||
* @return {?} Callback result.
|
* @return {?} Callback result.
|
||||||
*/
|
*/
|
||||||
function(feature) {
|
function(feature) {
|
||||||
var imageData = context.getImageData(0, 0, 1, 1).data;
|
var imageData;
|
||||||
if (imageData[3] > 0) {
|
for (var i = 0; i < contextSize; i++) {
|
||||||
var result = callback(feature);
|
for (var j = 0; j < contextSize; j++) {
|
||||||
if (result) {
|
imageData = context.getImageData(i, j, i + 1, j + 1).data;
|
||||||
return result;
|
if (imageData[3] > 0) {
|
||||||
|
var result = callback(feature);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
i = contextSize;
|
||||||
|
j = contextSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context.clearRect(0, 0, 1, 1);
|
|
||||||
}
|
}
|
||||||
|
context.clearRect(0, 0, contextSize, contextSize);
|
||||||
}, hitExtent);
|
}, hitExtent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user