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,9 +1,9 @@
|
||||
import Executor from '../../../../../src/ol/render/canvas/Executor.js';
|
||||
import Feature from '../../../../../src/ol/Feature.js';
|
||||
import MultiPolygon from '../../../../../src/ol/geom/MultiPolygon.js';
|
||||
import Polygon from '../../../../../src/ol/geom/Polygon.js';
|
||||
import TextBuilder from '../../../../../src/ol/render/canvas/TextBuilder.js';
|
||||
import Executor from '../../../../../src/ol/render/canvas/Executor.js';
|
||||
import Text from '../../../../../src/ol/style/Text.js';
|
||||
import TextBuilder from '../../../../../src/ol/render/canvas/TextBuilder.js';
|
||||
import {create as createTransform} from '../../../../../src/ol/transform.js';
|
||||
|
||||
function createBuilder() {
|
||||
@@ -12,76 +12,111 @@ function createBuilder() {
|
||||
|
||||
function createContext() {
|
||||
return {
|
||||
fill: function() {},
|
||||
stroke: function() {},
|
||||
beginPath: function() {},
|
||||
clip: function() {},
|
||||
moveTo: function() {},
|
||||
lineTo: function() {},
|
||||
closePath: function() {},
|
||||
setLineDash: function() {},
|
||||
save: function() {},
|
||||
restore: function() {}
|
||||
fill: function () {},
|
||||
stroke: function () {},
|
||||
beginPath: function () {},
|
||||
clip: function () {},
|
||||
moveTo: function () {},
|
||||
lineTo: function () {},
|
||||
closePath: function () {},
|
||||
setLineDash: function () {},
|
||||
save: function () {},
|
||||
restore: function () {},
|
||||
};
|
||||
}
|
||||
|
||||
function executeInstructions(builder, expectedDrawTextImageCalls, expectedBuilderImageCalls) {
|
||||
function executeInstructions(
|
||||
builder,
|
||||
expectedDrawTextImageCalls,
|
||||
expectedBuilderImageCalls
|
||||
) {
|
||||
const transform = createTransform();
|
||||
const context = createContext();
|
||||
const executor = new Executor(0.02, 1, false, builder.finish());
|
||||
sinon.spy(executor, 'drawLabelWithPointPlacement_');
|
||||
const replayImageOrLabelStub = sinon.stub(executor, 'replayImageOrLabel_');
|
||||
executor.execute(context, transform);
|
||||
expect(executor.drawLabelWithPointPlacement_.callCount).to.be(expectedDrawTextImageCalls);
|
||||
expect(executor.drawLabelWithPointPlacement_.callCount).to.be(
|
||||
expectedDrawTextImageCalls
|
||||
);
|
||||
expect(replayImageOrLabelStub.callCount).to.be(expectedBuilderImageCalls);
|
||||
}
|
||||
|
||||
describe('ol.render.canvas.TextBuilder', function() {
|
||||
|
||||
it('renders polygon labels only when they fit', function() {
|
||||
describe('ol.render.canvas.TextBuilder', function () {
|
||||
it('renders polygon labels only when they fit', function () {
|
||||
let builder = createBuilder();
|
||||
const geometry = new Polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]]);
|
||||
const geometry = new Polygon([
|
||||
[
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[1, 1],
|
||||
[1, 0],
|
||||
[0, 0],
|
||||
],
|
||||
]);
|
||||
const feature = new Feature(geometry);
|
||||
|
||||
builder.setTextStyle(new Text({
|
||||
text: 'This is a long text'
|
||||
}));
|
||||
builder.setTextStyle(
|
||||
new Text({
|
||||
text: 'This is a long text',
|
||||
})
|
||||
);
|
||||
builder.drawText(geometry, feature);
|
||||
expect(builder.instructions.length).to.be(3);
|
||||
executeInstructions(builder, 1, 0);
|
||||
|
||||
|
||||
builder = createBuilder();
|
||||
builder.setTextStyle(new Text({
|
||||
text: 'short'
|
||||
}));
|
||||
builder.setTextStyle(
|
||||
new Text({
|
||||
text: 'short',
|
||||
})
|
||||
);
|
||||
builder.drawText(geometry, feature);
|
||||
expect(builder.instructions.length).to.be(3);
|
||||
executeInstructions(builder, 1, 1);
|
||||
});
|
||||
|
||||
it('renders multipolygon labels only when they fit', function() {
|
||||
it('renders multipolygon labels only when they fit', function () {
|
||||
const geometry = new MultiPolygon([
|
||||
[[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]],
|
||||
[[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
|
||||
[
|
||||
[
|
||||
[0, 0],
|
||||
[0, 1],
|
||||
[1, 1],
|
||||
[1, 0],
|
||||
[0, 0],
|
||||
],
|
||||
],
|
||||
[
|
||||
[
|
||||
[1, 1],
|
||||
[1, 2],
|
||||
[2, 2],
|
||||
[2, 1],
|
||||
[1, 1],
|
||||
],
|
||||
],
|
||||
]);
|
||||
const feature = new Feature(geometry);
|
||||
|
||||
let builder = createBuilder();
|
||||
builder.setTextStyle(new Text({
|
||||
text: 'This is a long text'
|
||||
}));
|
||||
builder.setTextStyle(
|
||||
new Text({
|
||||
text: 'This is a long text',
|
||||
})
|
||||
);
|
||||
builder.drawText(geometry, feature);
|
||||
expect(builder.instructions.length).to.be(3);
|
||||
executeInstructions(builder, 1, 0);
|
||||
|
||||
builder = createBuilder();
|
||||
builder.setTextStyle(new Text({
|
||||
text: 'short'
|
||||
}));
|
||||
builder.setTextStyle(
|
||||
new Text({
|
||||
text: 'short',
|
||||
})
|
||||
);
|
||||
builder.drawText(geometry, feature);
|
||||
expect(builder.instructions.length).to.be(3);
|
||||
executeInstructions(builder, 1, 2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user