First step in uncoupling replay creation and rendering
Signed-off-by: Guillaume Beraudo <guillaume.beraudo@camptocamp.com>
This commit is contained in:
@@ -185,6 +185,7 @@ class CanvasImageReplay extends CanvasReplay {
|
|||||||
this.rotateWithView_ = undefined;
|
this.rotateWithView_ = undefined;
|
||||||
this.rotation_ = undefined;
|
this.rotation_ = undefined;
|
||||||
this.width_ = undefined;
|
this.width_ = undefined;
|
||||||
|
return super.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class CanvasLineStringReplay extends CanvasReplay {
|
|||||||
}
|
}
|
||||||
this.reverseHitDetectionInstructions();
|
this.reverseHitDetectionInstructions();
|
||||||
this.state = null;
|
this.state = null;
|
||||||
|
return super.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ class CanvasPolygonReplay extends CanvasReplay {
|
|||||||
coordinates[i] = snap(coordinates[i], tolerance);
|
coordinates[i] = snap(coordinates[i], tolerance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return super.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,6 +28,16 @@ import {
|
|||||||
} from '../../transform.js';
|
} from '../../transform.js';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} SerializableInstructions
|
||||||
|
* @property {Array<*>} instructions The rendering instructions.
|
||||||
|
* @property {Array<*>} hitDetectionInstructions The rendering hit detection instructions.
|
||||||
|
* @property {Array<number>} coordinates The array of all coordinates.
|
||||||
|
* @property {!Object<string, import("../canvas.js").TextState>} textStates The text states (decluttering).
|
||||||
|
* @property {!Object<string, import("../canvas.js").FillState>} fillStates The fill states (decluttering).
|
||||||
|
* @property {!Object<string, import("../canvas.js").StrokeState>} strokeStates The stoke states (decluttering).
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {import("../../extent.js").Extent}
|
* @type {import("../../extent.js").Extent}
|
||||||
*/
|
*/
|
||||||
@@ -169,6 +179,16 @@ class CanvasReplay extends VectorContext {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {CanvasRenderingContext2D} context Context.
|
* @param {CanvasRenderingContext2D} context Context.
|
||||||
* @param {import("../../coordinate.js").Coordinate} p1 1st point of the background box.
|
* @param {import("../../coordinate.js").Coordinate} p1 1st point of the background box.
|
||||||
@@ -456,9 +476,15 @@ class CanvasReplay extends VectorContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME empty description for jsdoc
|
* @return {Object} the serializable instructions.
|
||||||
*/
|
*/
|
||||||
finish() {}
|
finish() {
|
||||||
|
return {
|
||||||
|
instructions: this.instructions,
|
||||||
|
hitDetectionInstructions: this.hitDetectionInstructions,
|
||||||
|
coordinates: this.coordinates
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
@@ -150,6 +150,22 @@ class CanvasReplayGroup extends ReplayGroup {
|
|||||||
context.clip();
|
context.clip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recreate replays and populate them using the provided instructions.
|
||||||
|
* @param {!Object<string, !Object<ReplayType, import("./Replay.js").SerializableInstructions>>} allInstructions The serializable instructions
|
||||||
|
*/
|
||||||
|
replaceInstructions(allInstructions) {
|
||||||
|
this.replaysByZIndex_ = {};
|
||||||
|
for (const zIndex in allInstructions) {
|
||||||
|
const instructionByZindex = allInstructions[zIndex];
|
||||||
|
for (const replayType in instructionByZindex) {
|
||||||
|
const instructions = instructionByZindex[replayType];
|
||||||
|
const replay = this.getReplay(zIndex, replayType);
|
||||||
|
replay.replaceInstructions(instructions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array<ReplayType>} replays Replays.
|
* @param {Array<ReplayType>} replays Replays.
|
||||||
* @return {boolean} Has replays of the provided types.
|
* @return {boolean} Has replays of the provided types.
|
||||||
@@ -167,15 +183,19 @@ class CanvasReplayGroup extends ReplayGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXME empty description for jsdoc
|
* @return {!Object<string, !Object<ReplayType, import("./Replay.js").SerializableInstructions>>} The serializable instructions
|
||||||
*/
|
*/
|
||||||
finish() {
|
finish() {
|
||||||
|
const replaysInstructions = {};
|
||||||
for (const zKey in this.replaysByZIndex_) {
|
for (const zKey in this.replaysByZIndex_) {
|
||||||
|
replaysInstructions[zKey] = replaysInstructions[zKey] || {};
|
||||||
const replays = this.replaysByZIndex_[zKey];
|
const replays = this.replaysByZIndex_[zKey];
|
||||||
for (const replayKey in replays) {
|
for (const replayKey in replays) {
|
||||||
replays[replayKey].finish();
|
const replayInstructions = replays[replayKey].finish();
|
||||||
|
replaysInstructions[zKey][replayKey] = replayInstructions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return replaysInstructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -126,7 +126,27 @@ class CanvasTextReplay extends CanvasReplay {
|
|||||||
this.widths_ = {};
|
this.widths_ = {};
|
||||||
|
|
||||||
labelCache.prune();
|
labelCache.prune();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
finish() {
|
||||||
|
const instructions = super.finish();
|
||||||
|
instructions.textStates = this.textStates;
|
||||||
|
instructions.fillStates = this.fillStates;
|
||||||
|
instructions.strokeStates = this.strokeStates;
|
||||||
|
return instructions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
replaceInstructions(instructions) {
|
||||||
|
super.replaceInstructions(instructions);
|
||||||
|
this.textStates = instructions.textStates;
|
||||||
|
this.fillStates = instructions.fillStates;
|
||||||
|
this.strokeStates = instructions.strokeStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -480,13 +480,18 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
|||||||
} else {
|
} else {
|
||||||
vectorSource.forEachFeatureInExtent(extent, render);
|
vectorSource.forEachFeatureInExtent(extent, render);
|
||||||
}
|
}
|
||||||
replayGroup.finish();
|
|
||||||
|
const replayGroupInstructions = replayGroup.finish();
|
||||||
|
const renderingReplayGroup = new CanvasReplayGroup(
|
||||||
|
getRenderTolerance(resolution, pixelRatio), extent, resolution,
|
||||||
|
pixelRatio, vectorSource.getOverlaps(), this.declutterTree_, vectorLayer.getRenderBuffer());
|
||||||
|
renderingReplayGroup.replaceInstructions(replayGroupInstructions);
|
||||||
|
|
||||||
this.renderedResolution_ = resolution;
|
this.renderedResolution_ = resolution;
|
||||||
this.renderedRevision_ = vectorLayerRevision;
|
this.renderedRevision_ = vectorLayerRevision;
|
||||||
this.renderedRenderOrder_ = vectorLayerRenderOrder;
|
this.renderedRenderOrder_ = vectorLayerRenderOrder;
|
||||||
this.renderedExtent_ = extent;
|
this.renderedExtent_ = extent;
|
||||||
this.replayGroup_ = replayGroup;
|
this.replayGroup_ = renderingReplayGroup;
|
||||||
|
|
||||||
this.replayGroupChanged = true;
|
this.replayGroupChanged = true;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -226,8 +226,11 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
|||||||
render.call(this, feature);
|
render.call(this, feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
replayGroup.finish();
|
const replayGroupInstructions = replayGroup.finish();
|
||||||
sourceTile.setReplayGroup(layer, tile.tileCoord.toString(), replayGroup);
|
const renderingReplayGroup = new CanvasReplayGroup(0, sharedExtent, resolution,
|
||||||
|
pixelRatio, source.getOverlaps(), this.declutterTree_, layer.getRenderBuffer());
|
||||||
|
renderingReplayGroup.replaceInstructions(replayGroupInstructions);
|
||||||
|
sourceTile.setReplayGroup(layer, tile.tileCoord.toString(), renderingReplayGroup);
|
||||||
}
|
}
|
||||||
replayState.renderedRevision = revision;
|
replayState.renderedRevision = revision;
|
||||||
replayState.renderedRenderOrder = renderOrder;
|
replayState.renderedRenderOrder = renderOrder;
|
||||||
|
|||||||
Reference in New Issue
Block a user