diff --git a/src/ol/render/canvas/ReplayGroup.js b/src/ol/render/canvas/ReplayGroup.js
index bdf2577fa1..06c3c0c311 100644
--- a/src/ol/render/canvas/ReplayGroup.js
+++ b/src/ol/render/canvas/ReplayGroup.js
@@ -17,6 +17,22 @@ import CanvasTextReplay from '../canvas/TextReplay.js';
import _ol_render_replay_ from '../replay.js';
import _ol_transform_ from '../../transform.js';
+
+/**
+ * @type {Object.
)>}
+ */
+const BATCH_CONSTRUCTORS = {
+ 'Circle': CanvasPolygonReplay,
+ 'Default': CanvasReplay,
+ 'Image': CanvasImageReplay,
+ 'LineString': CanvasLineStringReplay,
+ 'Polygon': CanvasPolygonReplay,
+ 'Text': CanvasTextReplay
+};
+
+
/**
* @constructor
* @extends {ol.render.ReplayGroup}
@@ -109,9 +125,8 @@ inherits(CanvasReplayGroup, ReplayGroup);
* This cache is used for storing calculated pixel circles for increasing performance.
* It is a static property to allow each Replaygroup to access it.
* @type {Object.>>}
- * @private
*/
-CanvasReplayGroup.circleArrayCache_ = {
+const circleArrayCache = {
0: [[true]]
};
@@ -122,9 +137,8 @@ CanvasReplayGroup.circleArrayCache_ = {
* @param {Array.>} array The array that will be altered.
* @param {number} x X coordinate.
* @param {number} y Y coordinate.
- * @private
*/
-CanvasReplayGroup.fillCircleArrayRowToMiddle_ = function(array, x, y) {
+function fillCircleArrayRowToMiddle(array, x, y) {
let i;
const radius = Math.floor(array.length / 2);
if (x >= radius) {
@@ -136,7 +150,7 @@ CanvasReplayGroup.fillCircleArrayRowToMiddle_ = function(array, x, y) {
array[i][y] = true;
}
}
-};
+}
/**
@@ -146,11 +160,10 @@ CanvasReplayGroup.fillCircleArrayRowToMiddle_ = function(array, x, y) {
* A cache is used to increase performance.
* @param {number} radius Radius.
* @returns {Array.>} An array with marked circle points.
- * @private
*/
-CanvasReplayGroup.getCircleArray_ = function(radius) {
- if (CanvasReplayGroup.circleArrayCache_[radius] !== undefined) {
- return CanvasReplayGroup.circleArrayCache_[radius];
+export function getCircleArray(radius) {
+ if (circleArrayCache[radius] !== undefined) {
+ return circleArrayCache[radius];
}
const arraySize = radius * 2 + 1;
@@ -164,14 +177,14 @@ CanvasReplayGroup.getCircleArray_ = function(radius) {
let error = 0;
while (x >= y) {
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + x, radius + y);
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + y, radius + x);
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - y, radius + x);
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - x, radius + y);
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - x, radius - y);
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius - y, radius - x);
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + y, radius - x);
- CanvasReplayGroup.fillCircleArrayRowToMiddle_(arr, radius + x, radius - y);
+ fillCircleArrayRowToMiddle(arr, radius + x, radius + y);
+ fillCircleArrayRowToMiddle(arr, radius + y, radius + x);
+ fillCircleArrayRowToMiddle(arr, radius - y, radius + x);
+ fillCircleArrayRowToMiddle(arr, radius - x, radius + y);
+ fillCircleArrayRowToMiddle(arr, radius - x, radius - y);
+ fillCircleArrayRowToMiddle(arr, radius - y, radius - x);
+ fillCircleArrayRowToMiddle(arr, radius + y, radius - x);
+ fillCircleArrayRowToMiddle(arr, radius + x, radius - y);
y++;
error += 1 + 2 * y;
@@ -181,9 +194,9 @@ CanvasReplayGroup.getCircleArray_ = function(radius) {
}
}
- CanvasReplayGroup.circleArrayCache_[radius] = arr;
+ circleArrayCache[radius] = arr;
return arr;
-};
+}
/**
@@ -312,7 +325,7 @@ CanvasReplayGroup.prototype.forEachFeatureAtCoordinate = function(
buffer(hitExtent, resolution * (this.renderBuffer_ + hitTolerance), hitExtent);
}
- const mask = CanvasReplayGroup.getCircleArray_(hitTolerance);
+ const mask = getCircleArray(hitTolerance);
let declutteredFeatures;
if (this.declutterTree_) {
declutteredFeatures = this.declutterTree_.all().map(function(entry) {
@@ -412,7 +425,7 @@ CanvasReplayGroup.prototype.getReplay = function(zIndex, replayType) {
}
let replay = replays[replayType];
if (replay === undefined) {
- const Constructor = CanvasReplayGroup.BATCH_CONSTRUCTORS_[replayType];
+ const Constructor = BATCH_CONSTRUCTORS[replayType];
replay = new Constructor(this.tolerance_, this.maxExtent_,
this.resolution_, this.pixelRatio_, this.overlaps_, this.declutterTree_);
replays[replayType] = replay;
@@ -487,20 +500,4 @@ CanvasReplayGroup.prototype.replay = function(context,
context.restore();
};
-
-/**
- * @const
- * @private
- * @type {Object.)>}
- */
-CanvasReplayGroup.BATCH_CONSTRUCTORS_ = {
- 'Circle': CanvasPolygonReplay,
- 'Default': CanvasReplay,
- 'Image': CanvasImageReplay,
- 'LineString': CanvasLineStringReplay,
- 'Polygon': CanvasPolygonReplay,
- 'Text': CanvasTextReplay
-};
export default CanvasReplayGroup;
diff --git a/test/spec/ol/render/canvas/replaygroup.test.js b/test/spec/ol/render/canvas/replaygroup.test.js
index 2c23639f2d..ac00a62a22 100644
--- a/test/spec/ol/render/canvas/replaygroup.test.js
+++ b/test/spec/ol/render/canvas/replaygroup.test.js
@@ -1,4 +1,4 @@
-import CanvasReplayGroup from '../../../../../src/ol/render/canvas/ReplayGroup.js';
+import {getCircleArray} from '../../../../../src/ol/render/canvas/ReplayGroup.js';
describe('ol.render.canvas.ReplayGroup', function() {
@@ -8,7 +8,7 @@ describe('ol.render.canvas.ReplayGroup', function() {
const radius = 10;
const minRadiusSq = Math.pow(radius - Math.SQRT2, 2);
const maxRadiusSq = Math.pow(radius + Math.SQRT2, 2);
- const circleArray = CanvasReplayGroup.getCircleArray_(radius);
+ const circleArray = getCircleArray(radius);
const size = radius * 2 + 1;
expect(circleArray.length).to.be(size);