Merge pull request #1514 from twpayne/vector-api-circle
[vector-api] Add ol.geom.Circle
This commit is contained in:
@@ -263,6 +263,39 @@ ol.render.canvas.Immediate.prototype.drawAsync = function(zIndex, callback) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.canvas.Immediate.prototype.drawCircleGeometry =
|
||||
function(circleGeometry, data) {
|
||||
/*
|
||||
if (!ol.extent.intersects(this.extent_, circleGeometry.getExtent())) {
|
||||
return;
|
||||
}
|
||||
var state = this.state_;
|
||||
if (!goog.isDef(state.fillStyle) && !goog.isDef(state.strokeStyle)) {
|
||||
return;
|
||||
}
|
||||
this.setFillStrokeStyles_();
|
||||
var context = this.context_;
|
||||
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||
circleGeometry, this.transform_, this.pixelCoordinates_);
|
||||
var dx = pixelCoordinates[2] - pixelCoordinates[0];
|
||||
var dy = pixelCoordinates[3] - pixelCoordinates[1];
|
||||
var radius = Math.sqrt(dx * dx + dy * dy);
|
||||
context.beginPath();
|
||||
context.arc(pixelCoordinates[0], pixelCoordinates[1], radius, 0, 2 * Math.PI);
|
||||
if (goog.isDef(state.fillStyle)) {
|
||||
context.fill();
|
||||
}
|
||||
if (goog.isDef(state.strokeStyle)) {
|
||||
goog.asserts.assert(goog.isDef(state.lineWidth));
|
||||
context.stroke();
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -597,5 +630,6 @@ ol.render.canvas.Immediate.GEOMETRY_RENDERES_ = {
|
||||
ol.render.canvas.Immediate.prototype.drawMultiLineStringGeometry,
|
||||
'MultiPolygon': ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry,
|
||||
'GeometryCollection':
|
||||
ol.render.canvas.Immediate.prototype.drawGeometryCollectionGeometry
|
||||
ol.render.canvas.Immediate.prototype.drawGeometryCollectionGeometry,
|
||||
'Circle': ol.render.canvas.Immediate.prototype.drawCircleGeometry
|
||||
};
|
||||
|
||||
@@ -27,14 +27,15 @@ goog.require('ol.vec.Mat4');
|
||||
ol.render.canvas.Instruction = {
|
||||
BEGIN_GEOMETRY: 0,
|
||||
BEGIN_PATH: 1,
|
||||
CLOSE_PATH: 2,
|
||||
DRAW_IMAGE: 3,
|
||||
END_GEOMETRY: 4,
|
||||
FILL: 5,
|
||||
MOVE_TO_LINE_TO: 6,
|
||||
SET_FILL_STYLE: 7,
|
||||
SET_STROKE_STYLE: 8,
|
||||
STROKE: 9
|
||||
CIRCLE: 2,
|
||||
CLOSE_PATH: 3,
|
||||
DRAW_IMAGE: 4,
|
||||
END_GEOMETRY: 5,
|
||||
FILL: 6,
|
||||
MOVE_TO_LINE_TO: 7,
|
||||
SET_FILL_STYLE: 8,
|
||||
SET_STROKE_STYLE: 9,
|
||||
STROKE: 10
|
||||
};
|
||||
|
||||
|
||||
@@ -178,7 +179,7 @@ ol.render.canvas.Replay.prototype.replay_ =
|
||||
}
|
||||
var i = 0; // instruction index
|
||||
var ii = instructions.length; // end of instructions
|
||||
var d; // data index
|
||||
var d = 0; // data index
|
||||
var dd; // end of per-instruction data
|
||||
var localTransform = this.tmpLocalTransform_;
|
||||
while (i < ii) {
|
||||
@@ -198,6 +199,18 @@ ol.render.canvas.Replay.prototype.replay_ =
|
||||
context.beginPath();
|
||||
++i;
|
||||
break;
|
||||
case ol.render.canvas.Instruction.CIRCLE:
|
||||
var x1 = pixelCoordinates[d];
|
||||
var y1 = pixelCoordinates[d + 1];
|
||||
var x2 = pixelCoordinates[d + 2];
|
||||
var y2 = pixelCoordinates[d + 3];
|
||||
var dx = x2 - x1;
|
||||
var dy = y2 - y1;
|
||||
var r = Math.sqrt(dx * dx + dy * dy);
|
||||
context.arc(x1, y1, r, 0, 2 * Math.PI, true);
|
||||
d += 4;
|
||||
++i;
|
||||
break;
|
||||
case ol.render.canvas.Instruction.CLOSE_PATH:
|
||||
context.closePath();
|
||||
++i;
|
||||
@@ -379,6 +392,12 @@ ol.render.canvas.Replay.prototype.reverseHitDetectionInstructions_ =
|
||||
ol.render.canvas.Replay.prototype.drawAsync = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.canvas.Replay.prototype.drawCircleGeometry = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -997,6 +1016,57 @@ ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.canvas.PolygonReplay.prototype.drawCircleGeometry =
|
||||
function(circleGeometry, data) {
|
||||
var state = this.state_;
|
||||
goog.asserts.assert(!goog.isNull(state));
|
||||
var fillStyle = state.fillStyle;
|
||||
var strokeStyle = state.strokeStyle;
|
||||
if (!goog.isDef(fillStyle) && !goog.isDef(strokeStyle)) {
|
||||
return;
|
||||
}
|
||||
if (goog.isDef(strokeStyle)) {
|
||||
goog.asserts.assert(goog.isDef(state.lineWidth));
|
||||
}
|
||||
ol.extent.extend(this.extent_, circleGeometry.getExtent());
|
||||
this.setFillStrokeStyles_();
|
||||
this.beginGeometry(circleGeometry);
|
||||
// always fill the circle for hit detection
|
||||
this.hitDetectionInstructions.push(
|
||||
[ol.render.canvas.Instruction.SET_FILL_STYLE,
|
||||
ol.color.asString(ol.render.canvas.defaultFillStyle)]);
|
||||
if (goog.isDef(state.strokeStyle)) {
|
||||
this.hitDetectionInstructions.push(
|
||||
[ol.render.canvas.Instruction.SET_STROKE_STYLE,
|
||||
state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
|
||||
state.miterLimit, state.lineDash]);
|
||||
}
|
||||
var flatCoordinates = circleGeometry.getFlatCoordinates();
|
||||
var stride = circleGeometry.getStride();
|
||||
this.appendFlatCoordinates(
|
||||
flatCoordinates, 0, flatCoordinates.length, stride, false);
|
||||
var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH];
|
||||
var circleInstruction = [ol.render.canvas.Instruction.CIRCLE];
|
||||
this.instructions.push(beginPathInstruction, circleInstruction);
|
||||
this.hitDetectionInstructions.push(beginPathInstruction, circleInstruction);
|
||||
this.endGeometry(circleGeometry, data);
|
||||
var fillInstruction = [ol.render.canvas.Instruction.FILL];
|
||||
this.hitDetectionInstructions.push(fillInstruction);
|
||||
if (goog.isDef(state.fillStyle)) {
|
||||
this.instructions.push(fillInstruction);
|
||||
}
|
||||
if (goog.isDef(state.strokeStyle)) {
|
||||
goog.asserts.assert(goog.isDef(state.lineWidth));
|
||||
var strokeInstruction = [ol.render.canvas.Instruction.STROKE];
|
||||
this.instructions.push(strokeInstruction);
|
||||
this.hitDetectionInstructions.push(strokeInstruction);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,15 @@ ol.render.IRender.prototype.drawAsync = function(zIndex, callback) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Circle} circleGeometry Circle geometry.
|
||||
* @param {Object} data Opaque data object,
|
||||
*/
|
||||
ol.render.IRender.prototype.drawCircleGeometry =
|
||||
function(circleGeometry, data) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {ol.style.Style} style Style.
|
||||
|
||||
+26
-1
@@ -1,6 +1,7 @@
|
||||
goog.provide('ol.renderer.vector');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.geom.Circle');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
@@ -12,6 +13,29 @@ goog.require('ol.render.IReplayGroup');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.render.IReplayGroup} replayGroup Replay group.
|
||||
* @param {ol.geom.Geometry} geometry Geometry.
|
||||
* @param {ol.style.Style} style Style.
|
||||
* @param {Object} data Opaque data object.
|
||||
* @private
|
||||
*/
|
||||
ol.renderer.vector.renderCircleGeometry_ =
|
||||
function(replayGroup, geometry, style, data) {
|
||||
var fillStyle = style.getFill();
|
||||
var strokeStyle = style.getStroke();
|
||||
if (goog.isNull(fillStyle) && goog.isNull(strokeStyle)) {
|
||||
return;
|
||||
}
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Circle);
|
||||
var circleGeometry = /** @type {ol.geom.Circle} */ (geometry);
|
||||
var replay = replayGroup.getReplay(
|
||||
style.getZIndex(), ol.render.ReplayType.POLYGON);
|
||||
replay.setFillStrokeStyle(fillStyle, strokeStyle);
|
||||
replay.drawCircleGeometry(circleGeometry, data);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.render.IReplayGroup} replayGroup Replay group.
|
||||
* @param {ol.Feature} feature Feature.
|
||||
@@ -196,5 +220,6 @@ ol.renderer.vector.GEOMETRY_RENDERERS_ = {
|
||||
'MultiPoint': ol.renderer.vector.renderMultiPointGeometry_,
|
||||
'MultiLineString': ol.renderer.vector.renderMultiLineStringGeometry_,
|
||||
'MultiPolygon': ol.renderer.vector.renderMultiPolygonGeometry_,
|
||||
'GeometryCollection': ol.renderer.vector.renderGeometryCollectionGeometry_
|
||||
'GeometryCollection': ol.renderer.vector.renderGeometryCollectionGeometry_,
|
||||
'Circle': ol.renderer.vector.renderCircleGeometry_
|
||||
};
|
||||
|
||||
@@ -20,6 +20,14 @@ ol.render.webgl.Immediate.prototype.drawAsync = function(zIndex, callback) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.render.webgl.Immediate.prototype.drawCircleGeometry =
|
||||
function(circleGeometry, data) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user