Small fix for hit detection on a canvas layer as an illegal feature id might result at a location where the edge of one feature intersects the interior of another. This is due to antialiasing on the hit context canvas which can't be turned off, unfortunately.
This commit is contained in:
@@ -786,7 +786,7 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
* layer.
|
||||
*/
|
||||
getFeatureIdFromEvent: function(evt) {
|
||||
var feature;
|
||||
var featureId, feature;
|
||||
if (this.hitDetection) {
|
||||
// this dragging check should go in the feature handler
|
||||
if (!this.map.dragging) {
|
||||
@@ -797,7 +797,14 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
if (data[3] === 255) { // antialiased
|
||||
var id = data[2] + (256 * (data[1] + (256 * data[0])));
|
||||
if (id) {
|
||||
feature = this.features["OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow)][0];
|
||||
featureId = "OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow);
|
||||
try {
|
||||
feature = this.features["OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow)][0];
|
||||
} catch(err) {
|
||||
// Because of antialiasing on the canvas, when the hit location is at a point where the edge of
|
||||
// one symbol intersects the interior of another symbol, a wrong hit color (and therefore id) results.
|
||||
// todo: set Antialiasing = 'off' on the hitContext as soon as browsers allow it.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user