Simplify custom circle rendering
This commit is contained in:
committed by
changqing
parent
3393de3c54
commit
c4f5709349
@@ -11,10 +11,10 @@ const circleFeature = new Feature({
|
|||||||
});
|
});
|
||||||
circleFeature.setStyle(
|
circleFeature.setStyle(
|
||||||
new Style({
|
new Style({
|
||||||
renderer(coordinate, state) {
|
renderer(coordinates, state) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('This circle is rendered by the code below.', Date.now());
|
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 ctx = state.context;
|
||||||
const dx = x1 - x;
|
const dx = x1 - x;
|
||||||
const dy = y1 - y;
|
const dy = y1 - y;
|
||||||
|
|||||||
@@ -303,7 +303,10 @@ class CanvasBuilder extends VectorContext {
|
|||||||
renderer,
|
renderer,
|
||||||
inflateCoordinatesArray,
|
inflateCoordinatesArray,
|
||||||
]);
|
]);
|
||||||
} else if (type == GeometryType.LINE_STRING) {
|
} else if (
|
||||||
|
type == GeometryType.LINE_STRING ||
|
||||||
|
type == GeometryType.CIRCLE
|
||||||
|
) {
|
||||||
flatCoordinates = geometry.getFlatCoordinates();
|
flatCoordinates = geometry.getFlatCoordinates();
|
||||||
builderEnd = this.appendFlatLineCoordinates(
|
builderEnd = this.appendFlatLineCoordinates(
|
||||||
flatCoordinates,
|
flatCoordinates,
|
||||||
@@ -345,26 +348,6 @@ class CanvasBuilder extends VectorContext {
|
|||||||
geometry,
|
geometry,
|
||||||
renderer,
|
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);
|
this.endGeometry(feature);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -731,7 +731,6 @@ class Executor {
|
|||||||
const geometry = /** @type {import("../../geom/SimpleGeometry.js").default} */ (instruction[3]);
|
const geometry = /** @type {import("../../geom/SimpleGeometry.js").default} */ (instruction[3]);
|
||||||
const renderer = instruction[4];
|
const renderer = instruction[4];
|
||||||
const fn = instruction.length == 6 ? instruction[5] : undefined;
|
const fn = instruction.length == 6 ? instruction[5] : undefined;
|
||||||
const coordsLength = instruction.length >= 7 ? instruction[6] : 2;
|
|
||||||
state.geometry = geometry;
|
state.geometry = geometry;
|
||||||
state.feature = feature;
|
state.feature = feature;
|
||||||
if (!(i in coordinateCache)) {
|
if (!(i in coordinateCache)) {
|
||||||
@@ -741,10 +740,9 @@ class Executor {
|
|||||||
if (fn) {
|
if (fn) {
|
||||||
fn(pixelCoordinates, d, dd, 2, coords);
|
fn(pixelCoordinates, d, dd, 2, coords);
|
||||||
} else {
|
} else {
|
||||||
for (let index = 0; index < coordsLength; index++) {
|
coords[0] = pixelCoordinates[d];
|
||||||
coords[index] = pixelCoordinates[d + index];
|
coords[1] = pixelCoordinates[d + 1];
|
||||||
}
|
coords.length = 2;
|
||||||
coords.length = coordsLength;
|
|
||||||
}
|
}
|
||||||
renderer(coords, state);
|
renderer(coords, state);
|
||||||
++i;
|
++i;
|
||||||
|
|||||||
Reference in New Issue
Block a user