From dd73ac8892c48437ae9007c31f8a4e342461d976 Mon Sep 17 00:00:00 2001 From: simonseyock Date: Sat, 29 Apr 2017 11:28:40 +0200 Subject: [PATCH] ol.style.RegularShape#getPoints returns now same amount of points as provided to the constructor --- src/ol/style/regularshape.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ol/style/regularshape.js b/src/ol/style/regularshape.js index 0303dc86a4..1b376b043b 100644 --- a/src/ol/style/regularshape.js +++ b/src/ol/style/regularshape.js @@ -146,7 +146,7 @@ ol.inherits(ol.style.RegularShape, ol.style.Image); ol.style.RegularShape.prototype.clone = function() { var style = new ol.style.RegularShape({ fill: this.getFill() ? this.getFill().clone() : undefined, - points: this.getRadius2() !== this.getRadius() ? this.getPoints() / 2 : this.getPoints(), + points: this.getPoints(), radius: this.getRadius(), radius2: this.getRadius2(), angle: this.getAngle(), @@ -424,16 +424,17 @@ ol.style.RegularShape.prototype.draw_ = function(renderOptions, context, x, y) { context.beginPath(); - if (this.points_ === Infinity) { + var points = this.points_; + if (points === Infinity) { context.arc( renderOptions.size / 2, renderOptions.size / 2, this.radius_, 0, 2 * Math.PI, true); } else { if (this.radius2_ !== this.radius_) { - this.points_ = 2 * this.points_; + points = 2 * points; } - for (i = 0; i <= this.points_; i++) { - angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_; + for (i = 0; i <= points; i++) { + angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_; radiusC = i % 2 === 0 ? this.radius_ : this.radius2_; context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0), renderOptions.size / 2 + radiusC * Math.sin(angle0)); @@ -496,17 +497,18 @@ ol.style.RegularShape.prototype.drawHitDetectionCanvas_ = function(renderOptions context.beginPath(); - if (this.points_ === Infinity) { + var points = this.points_; + if (points === Infinity) { context.arc( renderOptions.size / 2, renderOptions.size / 2, this.radius_, 0, 2 * Math.PI, true); } else { if (this.radius2_ !== this.radius_) { - this.points_ = 2 * this.points_; + points = 2 * points; } var i, radiusC, angle0; - for (i = 0; i <= this.points_; i++) { - angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_; + for (i = 0; i <= points; i++) { + angle0 = i * 2 * Math.PI / points - Math.PI / 2 + this.angle_; radiusC = i % 2 === 0 ? this.radius_ : this.radius2_; context.lineTo(renderOptions.size / 2 + radiusC * Math.cos(angle0), renderOptions.size / 2 + radiusC * Math.sin(angle0));