Move the temporary arrays to the module level
No need to create a new variable for each instance.
This commit is contained in:
@@ -58,17 +58,17 @@ const Geometry = function() {
|
|||||||
*/
|
*/
|
||||||
this.simplifiedGeometryRevision = 0;
|
this.simplifiedGeometryRevision = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {module:ol/transform~Transform}
|
|
||||||
*/
|
|
||||||
this.tmpTransform_ = createTransform();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inherits(Geometry, BaseObject);
|
inherits(Geometry, BaseObject);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {module:ol/transform~Transform}
|
||||||
|
*/
|
||||||
|
const tmpTransform = createTransform();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a complete copy of the geometry.
|
* Make a complete copy of the geometry.
|
||||||
* @abstract
|
* @abstract
|
||||||
@@ -254,7 +254,6 @@ Geometry.prototype.translate = function(deltaX, deltaY) {};
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
Geometry.prototype.transform = function(source, destination) {
|
Geometry.prototype.transform = function(source, destination) {
|
||||||
const tmpTransform = this.tmpTransform_;
|
|
||||||
source = getProjection(source);
|
source = getProjection(source);
|
||||||
const transformFn = source.getUnits() == Units.TILE_PIXELS ?
|
const transformFn = source.getUnits() == Units.TILE_PIXELS ?
|
||||||
function(inCoordinates, outCoordinates, stride) {
|
function(inCoordinates, outCoordinates, stride) {
|
||||||
|
|||||||
@@ -47,12 +47,6 @@ const CanvasReplay = function(tolerance, maxExtent, resolution, pixelRatio, over
|
|||||||
*/
|
*/
|
||||||
this.declutterTree = declutterTree;
|
this.declutterTree = declutterTree;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {module:ol/extent~Extent}
|
|
||||||
*/
|
|
||||||
this.tmpExtent_ = createEmpty();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -163,12 +157,6 @@ const CanvasReplay = function(tolerance, maxExtent, resolution, pixelRatio, over
|
|||||||
*/
|
*/
|
||||||
this.viewRotation_ = 0;
|
this.viewRotation_ = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {!module:ol/transform~Transform}
|
|
||||||
*/
|
|
||||||
this.tmpLocalTransform_ = createTransform();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {!module:ol/transform~Transform}
|
* @type {!module:ol/transform~Transform}
|
||||||
@@ -179,6 +167,17 @@ const CanvasReplay = function(tolerance, maxExtent, resolution, pixelRatio, over
|
|||||||
inherits(CanvasReplay, VectorContext);
|
inherits(CanvasReplay, VectorContext);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {module:ol/extent~Extent}
|
||||||
|
*/
|
||||||
|
const tmpExtent = createEmpty();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {!module:ol/transform~Transform}
|
||||||
|
*/
|
||||||
|
const tmpTransform = createTransform();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {CanvasRenderingContext2D} context Context.
|
* @param {CanvasRenderingContext2D} context Context.
|
||||||
* @param {module:ol/coordinate~Coordinate} p1 1st point of the background box.
|
* @param {module:ol/coordinate~Coordinate} p1 1st point of the background box.
|
||||||
@@ -231,7 +230,6 @@ CanvasReplay.prototype.replayImage_ = function(context, x, y, image,
|
|||||||
anchorX, anchorY, declutterGroup, height, opacity, originX, originY,
|
anchorX, anchorY, declutterGroup, height, opacity, originX, originY,
|
||||||
rotation, scale, snapToPixel, width, padding, fillInstruction, strokeInstruction) {
|
rotation, scale, snapToPixel, width, padding, fillInstruction, strokeInstruction) {
|
||||||
const fillStroke = fillInstruction || strokeInstruction;
|
const fillStroke = fillInstruction || strokeInstruction;
|
||||||
const localTransform = this.tmpLocalTransform_;
|
|
||||||
anchorX *= scale;
|
anchorX *= scale;
|
||||||
anchorY *= scale;
|
anchorY *= scale;
|
||||||
x -= anchorX;
|
x -= anchorX;
|
||||||
@@ -239,7 +237,6 @@ CanvasReplay.prototype.replayImage_ = function(context, x, y, image,
|
|||||||
|
|
||||||
const w = (width + originX > image.width) ? image.width - originX : width;
|
const w = (width + originX > image.width) ? image.width - originX : width;
|
||||||
const h = (height + originY > image.height) ? image.height - originY : height;
|
const h = (height + originY > image.height) ? image.height - originY : height;
|
||||||
const box = this.tmpExtent_;
|
|
||||||
const boxW = padding[3] + w * scale + padding[1];
|
const boxW = padding[3] + w * scale + padding[1];
|
||||||
const boxH = padding[0] + h * scale + padding[2];
|
const boxH = padding[0] + h * scale + padding[2];
|
||||||
const boxX = x - padding[3];
|
const boxX = x - padding[3];
|
||||||
@@ -264,22 +261,21 @@ CanvasReplay.prototype.replayImage_ = function(context, x, y, image,
|
|||||||
if (rotation !== 0) {
|
if (rotation !== 0) {
|
||||||
const centerX = x + anchorX;
|
const centerX = x + anchorX;
|
||||||
const centerY = y + anchorY;
|
const centerY = y + anchorY;
|
||||||
transform = composeTransform(localTransform,
|
transform = composeTransform(tmpTransform, centerX, centerY, 1, 1, rotation, -centerX, -centerY);
|
||||||
centerX, centerY, 1, 1, rotation, -centerX, -centerY);
|
|
||||||
|
|
||||||
createOrUpdateEmpty(box);
|
createOrUpdateEmpty(tmpExtent);
|
||||||
extendCoordinate(box, applyTransform(localTransform, p1));
|
extendCoordinate(tmpExtent, applyTransform(tmpTransform, p1));
|
||||||
extendCoordinate(box, applyTransform(localTransform, p2));
|
extendCoordinate(tmpExtent, applyTransform(tmpTransform, p2));
|
||||||
extendCoordinate(box, applyTransform(localTransform, p3));
|
extendCoordinate(tmpExtent, applyTransform(tmpTransform, p3));
|
||||||
extendCoordinate(box, applyTransform(localTransform, p4));
|
extendCoordinate(tmpExtent, applyTransform(tmpTransform, p4));
|
||||||
} else {
|
} else {
|
||||||
createOrUpdate(boxX, boxY, boxX + boxW, boxY + boxH, box);
|
createOrUpdate(boxX, boxY, boxX + boxW, boxY + boxH, tmpExtent);
|
||||||
}
|
}
|
||||||
const canvas = context.canvas;
|
const canvas = context.canvas;
|
||||||
const strokePadding = strokeInstruction ? (strokeInstruction[2] * scale / 2) : 0;
|
const strokePadding = strokeInstruction ? (strokeInstruction[2] * scale / 2) : 0;
|
||||||
const intersects =
|
const intersects =
|
||||||
box[0] - strokePadding <= canvas.width && box[2] + strokePadding >= 0 &&
|
tmpExtent[0] - strokePadding <= canvas.width && tmpExtent[2] + strokePadding >= 0 &&
|
||||||
box[1] - strokePadding <= canvas.height && box[3] + strokePadding >= 0;
|
tmpExtent[1] - strokePadding <= canvas.height && tmpExtent[3] + strokePadding >= 0;
|
||||||
|
|
||||||
if (snapToPixel) {
|
if (snapToPixel) {
|
||||||
x = Math.round(x);
|
x = Math.round(x);
|
||||||
@@ -290,7 +286,7 @@ CanvasReplay.prototype.replayImage_ = function(context, x, y, image,
|
|||||||
if (!intersects && declutterGroup[4] == 1) {
|
if (!intersects && declutterGroup[4] == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
extend(declutterGroup, box);
|
extend(declutterGroup, tmpExtent);
|
||||||
const declutterArgs = intersects ?
|
const declutterArgs = intersects ?
|
||||||
[context, transform ? transform.slice(0) : null, opacity, image, originX, originY, w, h, x, y, scale] :
|
[context, transform ? transform.slice(0) : null, opacity, image, originX, originY, w, h, x, y, scale] :
|
||||||
null;
|
null;
|
||||||
|
|||||||
Reference in New Issue
Block a user