Merge pull request #2238 from fredj/circle-hit-detection
Circle hit detection
This commit is contained in:
@@ -258,6 +258,8 @@ ol.render.canvas.Replay.prototype.replay_ = function(
|
|||||||
++i;
|
++i;
|
||||||
break;
|
break;
|
||||||
case ol.render.canvas.Instruction.CIRCLE:
|
case ol.render.canvas.Instruction.CIRCLE:
|
||||||
|
goog.asserts.assert(goog.isNumber(instruction[1]));
|
||||||
|
d = /** @type {number} */ (instruction[1]);
|
||||||
var x1 = pixelCoordinates[d];
|
var x1 = pixelCoordinates[d];
|
||||||
var y1 = pixelCoordinates[d + 1];
|
var y1 = pixelCoordinates[d + 1];
|
||||||
var x2 = pixelCoordinates[d + 2];
|
var x2 = pixelCoordinates[d + 2];
|
||||||
@@ -266,7 +268,6 @@ ol.render.canvas.Replay.prototype.replay_ = function(
|
|||||||
var dy = y2 - y1;
|
var dy = y2 - y1;
|
||||||
var r = Math.sqrt(dx * dx + dy * dy);
|
var r = Math.sqrt(dx * dx + dy * dy);
|
||||||
context.arc(x1, y1, r, 0, 2 * Math.PI, true);
|
context.arc(x1, y1, r, 0, 2 * Math.PI, true);
|
||||||
d += 4;
|
|
||||||
++i;
|
++i;
|
||||||
break;
|
break;
|
||||||
case ol.render.canvas.Instruction.CLOSE_PATH:
|
case ol.render.canvas.Instruction.CLOSE_PATH:
|
||||||
@@ -1263,13 +1264,13 @@ ol.render.canvas.PolygonReplay.prototype.drawCircleGeometry =
|
|||||||
}
|
}
|
||||||
var flatCoordinates = circleGeometry.getFlatCoordinates();
|
var flatCoordinates = circleGeometry.getFlatCoordinates();
|
||||||
var stride = circleGeometry.getStride();
|
var stride = circleGeometry.getStride();
|
||||||
|
var myBegin = this.coordinates.length;
|
||||||
this.appendFlatCoordinates(
|
this.appendFlatCoordinates(
|
||||||
flatCoordinates, 0, flatCoordinates.length, stride, false);
|
flatCoordinates, 0, flatCoordinates.length, stride, false);
|
||||||
var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH];
|
var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH];
|
||||||
var circleInstruction = [ol.render.canvas.Instruction.CIRCLE];
|
var circleInstruction = [ol.render.canvas.Instruction.CIRCLE, myBegin];
|
||||||
this.instructions.push(beginPathInstruction, circleInstruction);
|
this.instructions.push(beginPathInstruction, circleInstruction);
|
||||||
this.hitDetectionInstructions.push(beginPathInstruction, circleInstruction);
|
this.hitDetectionInstructions.push(beginPathInstruction, circleInstruction);
|
||||||
this.endGeometry(circleGeometry, data);
|
|
||||||
var fillInstruction = [ol.render.canvas.Instruction.FILL];
|
var fillInstruction = [ol.render.canvas.Instruction.FILL];
|
||||||
this.hitDetectionInstructions.push(fillInstruction);
|
this.hitDetectionInstructions.push(fillInstruction);
|
||||||
if (goog.isDef(state.fillStyle)) {
|
if (goog.isDef(state.fillStyle)) {
|
||||||
@@ -1281,6 +1282,7 @@ ol.render.canvas.PolygonReplay.prototype.drawCircleGeometry =
|
|||||||
this.instructions.push(strokeInstruction);
|
this.instructions.push(strokeInstruction);
|
||||||
this.hitDetectionInstructions.push(strokeInstruction);
|
this.hitDetectionInstructions.push(strokeInstruction);
|
||||||
}
|
}
|
||||||
|
this.endGeometry(circleGeometry, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user