Pass instructions to executor constructor

This commit is contained in:
Guillaume Beraudo
2018-11-16 12:36:50 +01:00
parent ce44a9a3e4
commit 81d0bc21d5
6 changed files with 57 additions and 62 deletions

View File

@@ -55,9 +55,9 @@ class CanvasExecutor {
* @param {number} pixelRatio Pixel ratio.
* @param {boolean} overlaps The replay can have overlapping geometries.
* @param {?} declutterTree Declutter tree.
* @param {SerializableInstructions} instructions The serializable instructions
*/
constructor(tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree) {
constructor(tolerance, maxExtent, resolution, pixelRatio, overlaps, declutterTree, instructions) {
/**
* @type {?}
*/
@@ -129,13 +129,13 @@ class CanvasExecutor {
* @protected
* @type {Array<*>}
*/
this.instructions = [];
this.instructions = instructions.instructions;
/**
* @protected
* @type {Array<number>}
*/
this.coordinates = [];
this.coordinates = instructions.coordinates;
/**
* @private
@@ -153,7 +153,7 @@ class CanvasExecutor {
* @protected
* @type {Array<*>}
*/
this.hitDetectionInstructions = [];
this.hitDetectionInstructions = instructions.hitDetectionInstructions;
/**
* @private
@@ -176,17 +176,17 @@ class CanvasExecutor {
/**
* @type {!Object<string, import("../canvas.js").FillState>}
*/
this.fillStates = {};
this.fillStates = instructions.fillStates || {};
/**
* @type {!Object<string, import("../canvas.js").StrokeState>}
*/
this.strokeStates = {};
this.strokeStates = instructions.strokeStates || {};
/**
* @type {!Object<string, import("../canvas.js").TextState>}
*/
this.textStates = {};
this.textStates = instructions.textStates || {};
// Adaptations
@@ -267,20 +267,6 @@ class CanvasExecutor {
return labelCache.get(key);
}
/**
* Recreate replays and populate them using the provided instructions.
* @param {SerializableInstructions} instructions The serializable instructions
*/
replaceInstructions(instructions) {
this.instructions = instructions.instructions;
this.hitDetectionInstructions = instructions.hitDetectionInstructions;
this.coordinates = instructions.coordinates;
// Workaround for decluttered text creation / rendering being coupled
this.textStates = instructions.textStates;
this.fillStates = instructions.fillStates;
this.strokeStates = instructions.strokeStates;
}
/**
* @param {CanvasRenderingContext2D} context Context.
* @param {import("../../coordinate.js").Coordinate} p1 1st point of the background box.

View File

@@ -22,6 +22,8 @@ class ExecutorGroup extends BaseExecutorGroup {
* @param {number} pixelRatio Pixel ratio.
* @param {boolean} overlaps The executor group can have overlapping geometries.
* @param {?} declutterTree Declutter tree for declutter processing in postrender.
* @param {!Object<string, !Object<ReplayType, import("./Builder.js").SerializableInstructions>>} allInstructions
* The serializable instructions.
* @param {number=} opt_renderBuffer Optional rendering buffer.
*/
constructor(
@@ -31,6 +33,7 @@ class ExecutorGroup extends BaseExecutorGroup {
pixelRatio,
overlaps,
declutterTree,
allInstructions,
opt_renderBuffer
) {
super();
@@ -100,6 +103,8 @@ class ExecutorGroup extends BaseExecutorGroup {
* @type {import("../../transform.js").Transform}
*/
this.hitDetectionTransform_ = createTransform();
this.createExectutors_(allInstructions);
}
/**
@@ -118,16 +123,20 @@ class ExecutorGroup extends BaseExecutorGroup {
/**
* Create executors and populate them using the provided instructions.
* @private
* @param {!Object<string, !Object<ReplayType, import("./Builder.js").SerializableInstructions>>} allInstructions The serializable instructions
*/
replaceInstructions(allInstructions) {
this.executorsByZIndex_ = {};
createExectutors_(allInstructions) {
for (const zIndex in allInstructions) {
let executors = this.executorsByZIndex_[zIndex];
if (executors === undefined) {
this.executorsByZIndex_[zIndex] = executors = {};
}
const instructionByZindex = allInstructions[zIndex];
for (const replayType in instructionByZindex) {
const instructions = instructionByZindex[replayType];
const executor = this.getExecutor(zIndex, replayType);
executor.replaceInstructions(instructions);
executors[replayType] = new CanvasExecutor(this.tolerance_, this.maxExtent_,
this.resolution_, this.pixelRatio_, this.overlaps_, this.declutterTree_, instructions);
}
}
}
@@ -301,8 +310,14 @@ class ExecutorGroup extends BaseExecutorGroup {
}
let executor = executors[replayType];
if (executor === undefined) {
// FIXME: it should not be possible to ask for an executor that does not exist
executor = new CanvasExecutor(this.tolerance_, this.maxExtent_,
this.resolution_, this.pixelRatio_, this.overlaps_, this.declutterTree_);
this.resolution_, this.pixelRatio_, this.overlaps_, {
instructions: [],
hitDetectionInstructions: [],
coordinates: []
},
this.declutterTree_);
executors[replayType] = executor;
}
return executor;

View File

@@ -485,8 +485,8 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
const replayGroupInstructions = replayGroup.finish();
const renderingExecutorGroup = new InstructionsGroupExecutor(
getRenderTolerance(resolution, pixelRatio), extent, resolution,
pixelRatio, vectorSource.getOverlaps(), this.declutterTree_, vectorLayer.getRenderBuffer());
renderingExecutorGroup.replaceInstructions(replayGroupInstructions);
pixelRatio, vectorSource.getOverlaps(), this.declutterTree_,
replayGroupInstructions, vectorLayer.getRenderBuffer());
this.renderedResolution_ = resolution;
this.renderedRevision_ = vectorLayerRevision;

View File

@@ -229,8 +229,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
}
const replayGroupInstructions = builderGroup.finish();
const renderingReplayGroup = new CanvasExecutorGroup(0, sharedExtent, resolution,
pixelRatio, source.getOverlaps(), this.declutterTree_, layer.getRenderBuffer());
renderingReplayGroup.replaceInstructions(replayGroupInstructions);
pixelRatio, source.getOverlaps(), this.declutterTree_, replayGroupInstructions, layer.getRenderBuffer());
sourceTile.setExecutorGroup(layer, tile.tileCoord.toString(), renderingReplayGroup);
}
builderState.renderedRevision = revision;