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.
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
/**
|
|
* A worker that does cpu-heavy tasks related to webgl rendering.
|
|
* @module ol/worker/webgl
|
|
*/
|
|
import {
|
|
WebGLWorkerMessageType,
|
|
writePointFeatureToBuffers,
|
|
} from '../renderer/webgl/Layer.js';
|
|
import {assign} from '../obj.js';
|
|
|
|
/** @type {any} */
|
|
const worker = self;
|
|
|
|
worker.onmessage = (event) => {
|
|
const received = event.data;
|
|
if (received.type === WebGLWorkerMessageType.GENERATE_BUFFERS) {
|
|
// This is specific to point features (x, y, index)
|
|
const baseVertexAttrsCount = 3;
|
|
const baseInstructionsCount = 2;
|
|
|
|
const customAttrsCount = received.customAttributesCount;
|
|
const instructionsCount = baseInstructionsCount + customAttrsCount;
|
|
const renderInstructions = new Float32Array(received.renderInstructions);
|
|
|
|
const elementsCount = renderInstructions.length / instructionsCount;
|
|
const indicesCount = elementsCount * 6;
|
|
const verticesCount =
|
|
elementsCount * 4 * (customAttrsCount + baseVertexAttrsCount);
|
|
const indexBuffer = new Uint32Array(indicesCount);
|
|
const vertexBuffer = new Float32Array(verticesCount);
|
|
|
|
let bufferPositions = null;
|
|
for (let i = 0; i < renderInstructions.length; i += instructionsCount) {
|
|
bufferPositions = writePointFeatureToBuffers(
|
|
renderInstructions,
|
|
i,
|
|
vertexBuffer,
|
|
indexBuffer,
|
|
customAttrsCount,
|
|
bufferPositions
|
|
);
|
|
}
|
|
|
|
/** @type {import('../renderer/webgl/Layer').WebGLWorkerGenerateBuffersMessage} */
|
|
const message = assign(
|
|
{
|
|
vertexBuffer: vertexBuffer.buffer,
|
|
indexBuffer: indexBuffer.buffer,
|
|
renderInstructions: renderInstructions.buffer,
|
|
},
|
|
received
|
|
);
|
|
|
|
worker.postMessage(message, [
|
|
vertexBuffer.buffer,
|
|
indexBuffer.buffer,
|
|
renderInstructions.buffer,
|
|
]);
|
|
}
|
|
};
|
|
|
|
export let create;
|