Remove private static members from ol/render/canvas/ReplayGroup

This commit is contained in:
Frederic Junod
2018-02-10 08:54:58 +01:00
parent f5a4fcd3ac
commit 11f464f7ff
2 changed files with 36 additions and 39 deletions

View File

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

View File

@@ -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() { describe('ol.render.canvas.ReplayGroup', function() {
@@ -8,7 +8,7 @@ describe('ol.render.canvas.ReplayGroup', function() {
const radius = 10; const radius = 10;
const minRadiusSq = Math.pow(radius - Math.SQRT2, 2); const minRadiusSq = Math.pow(radius - Math.SQRT2, 2);
const maxRadiusSq = 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; const size = radius * 2 + 1;
expect(circleArray.length).to.be(size); expect(circleArray.length).to.be(size);