From c4f5709349201e3fb6086446b5678f5b3e50d5f5 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 18 Dec 2020 23:27:11 +0100 Subject: [PATCH] Simplify custom circle rendering --- examples/custom-circle-render.js | 4 ++-- src/ol/render/canvas/Builder.js | 25 ++++--------------------- src/ol/render/canvas/Executor.js | 8 +++----- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/examples/custom-circle-render.js b/examples/custom-circle-render.js index 57c7bf4026..06b1802cfe 100644 --- a/examples/custom-circle-render.js +++ b/examples/custom-circle-render.js @@ -11,10 +11,10 @@ const circleFeature = new Feature({ }); circleFeature.setStyle( new Style({ - renderer(coordinate, state) { + renderer(coordinates, state) { // eslint-disable-next-line no-console console.log('This circle is rendered by the code below.', Date.now()); - const [x, y, x1, y1] = coordinate; + const [[x, y], [x1, y1]] = coordinates; const ctx = state.context; const dx = x1 - x; const dy = y1 - y; diff --git a/src/ol/render/canvas/Builder.js b/src/ol/render/canvas/Builder.js index 8b1b0c53e3..215917d532 100644 --- a/src/ol/render/canvas/Builder.js +++ b/src/ol/render/canvas/Builder.js @@ -303,7 +303,10 @@ class CanvasBuilder extends VectorContext { renderer, inflateCoordinatesArray, ]); - } else if (type == GeometryType.LINE_STRING) { + } else if ( + type == GeometryType.LINE_STRING || + type == GeometryType.CIRCLE + ) { flatCoordinates = geometry.getFlatCoordinates(); builderEnd = this.appendFlatLineCoordinates( flatCoordinates, @@ -345,26 +348,6 @@ class CanvasBuilder extends VectorContext { geometry, renderer, ]); - } else if (type == GeometryType.CIRCLE) { - const flatCoordinates = geometry.getFlatCoordinates(); - this.appendFlatLineCoordinates( - flatCoordinates, - 0, - flatCoordinates.length, - stride, - false, - false - ); - builderEnd = this.coordinates.length; - this.instructions.push([ - CanvasInstruction.CUSTOM, - builderBegin, - builderEnd, - geometry, - renderer, - undefined, - 4, - ]); } this.endGeometry(feature); } diff --git a/src/ol/render/canvas/Executor.js b/src/ol/render/canvas/Executor.js index bf7b6c465b..058961edaf 100644 --- a/src/ol/render/canvas/Executor.js +++ b/src/ol/render/canvas/Executor.js @@ -731,7 +731,6 @@ class Executor { const geometry = /** @type {import("../../geom/SimpleGeometry.js").default} */ (instruction[3]); const renderer = instruction[4]; const fn = instruction.length == 6 ? instruction[5] : undefined; - const coordsLength = instruction.length >= 7 ? instruction[6] : 2; state.geometry = geometry; state.feature = feature; if (!(i in coordinateCache)) { @@ -741,10 +740,9 @@ class Executor { if (fn) { fn(pixelCoordinates, d, dd, 2, coords); } else { - for (let index = 0; index < coordsLength; index++) { - coords[index] = pixelCoordinates[d + index]; - } - coords.length = coordsLength; + coords[0] = pixelCoordinates[d]; + coords[1] = pixelCoordinates[d + 1]; + coords.length = 2; } renderer(coords, state); ++i;