Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
/**
|
||||
* @module ol/render/canvas/LineStringBuilder
|
||||
*/
|
||||
import CanvasInstruction, {strokeInstruction, beginPathInstruction} from './Instruction.js';
|
||||
import CanvasBuilder from './Builder.js';
|
||||
import CanvasInstruction, {
|
||||
beginPathInstruction,
|
||||
strokeInstruction,
|
||||
} from './Instruction.js';
|
||||
|
||||
class CanvasLineStringBuilder extends CanvasBuilder {
|
||||
/**
|
||||
@@ -26,8 +29,18 @@ class CanvasLineStringBuilder extends CanvasBuilder {
|
||||
drawFlatCoordinates_(flatCoordinates, offset, end, stride) {
|
||||
const myBegin = this.coordinates.length;
|
||||
const myEnd = this.appendFlatCoordinates(
|
||||
flatCoordinates, offset, end, stride, false, false);
|
||||
const moveToLineToInstruction = [CanvasInstruction.MOVE_TO_LINE_TO, myBegin, myEnd];
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
false,
|
||||
false
|
||||
);
|
||||
const moveToLineToInstruction = [
|
||||
CanvasInstruction.MOVE_TO_LINE_TO,
|
||||
myBegin,
|
||||
myEnd,
|
||||
];
|
||||
this.instructions.push(moveToLineToInstruction);
|
||||
this.hitDetectionInstructions.push(moveToLineToInstruction);
|
||||
return end;
|
||||
@@ -46,14 +59,27 @@ class CanvasLineStringBuilder extends CanvasBuilder {
|
||||
}
|
||||
this.updateStrokeStyle(state, this.applyStroke);
|
||||
this.beginGeometry(lineStringGeometry, feature);
|
||||
this.hitDetectionInstructions.push([
|
||||
CanvasInstruction.SET_STROKE_STYLE,
|
||||
state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
|
||||
state.miterLimit, state.lineDash, state.lineDashOffset
|
||||
], beginPathInstruction);
|
||||
this.hitDetectionInstructions.push(
|
||||
[
|
||||
CanvasInstruction.SET_STROKE_STYLE,
|
||||
state.strokeStyle,
|
||||
state.lineWidth,
|
||||
state.lineCap,
|
||||
state.lineJoin,
|
||||
state.miterLimit,
|
||||
state.lineDash,
|
||||
state.lineDashOffset,
|
||||
],
|
||||
beginPathInstruction
|
||||
);
|
||||
const flatCoordinates = lineStringGeometry.getFlatCoordinates();
|
||||
const stride = lineStringGeometry.getStride();
|
||||
this.drawFlatCoordinates_(flatCoordinates, 0, flatCoordinates.length, stride);
|
||||
this.drawFlatCoordinates_(
|
||||
flatCoordinates,
|
||||
0,
|
||||
flatCoordinates.length,
|
||||
stride
|
||||
);
|
||||
this.hitDetectionInstructions.push(strokeInstruction);
|
||||
this.endGeometry(feature);
|
||||
}
|
||||
@@ -71,17 +97,30 @@ class CanvasLineStringBuilder extends CanvasBuilder {
|
||||
}
|
||||
this.updateStrokeStyle(state, this.applyStroke);
|
||||
this.beginGeometry(multiLineStringGeometry, feature);
|
||||
this.hitDetectionInstructions.push([
|
||||
CanvasInstruction.SET_STROKE_STYLE,
|
||||
state.strokeStyle, state.lineWidth, state.lineCap, state.lineJoin,
|
||||
state.miterLimit, state.lineDash, state.lineDashOffset
|
||||
], beginPathInstruction);
|
||||
this.hitDetectionInstructions.push(
|
||||
[
|
||||
CanvasInstruction.SET_STROKE_STYLE,
|
||||
state.strokeStyle,
|
||||
state.lineWidth,
|
||||
state.lineCap,
|
||||
state.lineJoin,
|
||||
state.miterLimit,
|
||||
state.lineDash,
|
||||
state.lineDashOffset,
|
||||
],
|
||||
beginPathInstruction
|
||||
);
|
||||
const ends = multiLineStringGeometry.getEnds();
|
||||
const flatCoordinates = multiLineStringGeometry.getFlatCoordinates();
|
||||
const stride = multiLineStringGeometry.getStride();
|
||||
let offset = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
offset = this.drawFlatCoordinates_(flatCoordinates, offset, /** @type {number} */ (ends[i]), stride);
|
||||
offset = this.drawFlatCoordinates_(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
/** @type {number} */ (ends[i]),
|
||||
stride
|
||||
);
|
||||
}
|
||||
this.hitDetectionInstructions.push(strokeInstruction);
|
||||
this.endGeometry(feature);
|
||||
@@ -92,7 +131,10 @@ class CanvasLineStringBuilder extends CanvasBuilder {
|
||||
*/
|
||||
finish() {
|
||||
const state = this.state;
|
||||
if (state.lastStroke != undefined && state.lastStroke != this.coordinates.length) {
|
||||
if (
|
||||
state.lastStroke != undefined &&
|
||||
state.lastStroke != this.coordinates.length
|
||||
) {
|
||||
this.instructions.push(strokeInstruction);
|
||||
}
|
||||
this.reverseHitDetectionInstructions();
|
||||
@@ -104,7 +146,10 @@ class CanvasLineStringBuilder extends CanvasBuilder {
|
||||
* @param {import("../canvas.js").FillStrokeState} state State.
|
||||
*/
|
||||
applyStroke(state) {
|
||||
if (state.lastStroke != undefined && state.lastStroke != this.coordinates.length) {
|
||||
if (
|
||||
state.lastStroke != undefined &&
|
||||
state.lastStroke != this.coordinates.length
|
||||
) {
|
||||
this.instructions.push(strokeInstruction);
|
||||
state.lastStroke = this.coordinates.length;
|
||||
}
|
||||
@@ -114,5 +159,4 @@ class CanvasLineStringBuilder extends CanvasBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default CanvasLineStringBuilder;
|
||||
|
||||
Reference in New Issue
Block a user