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,13 +1,12 @@
|
||||
/**
|
||||
* @module ol/Image
|
||||
*/
|
||||
import EventType from './events/EventType.js';
|
||||
import ImageBase from './ImageBase.js';
|
||||
import ImageState from './ImageState.js';
|
||||
import {listenOnce, unlistenByKey} from './events.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import {getHeight} from './extent.js';
|
||||
import {IMAGE_DECODE} from './has.js';
|
||||
|
||||
import {getHeight} from './extent.js';
|
||||
import {listenOnce, unlistenByKey} from './events.js';
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/Image~Image} for the image and a
|
||||
@@ -27,9 +26,7 @@ import {IMAGE_DECODE} from './has.js';
|
||||
* @api
|
||||
*/
|
||||
|
||||
|
||||
class ImageWrapper extends ImageBase {
|
||||
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
@@ -38,8 +35,14 @@ class ImageWrapper extends ImageBase {
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {LoadFunction} imageLoadFunction Image load function.
|
||||
*/
|
||||
constructor(extent, resolution, pixelRatio, src, crossOrigin, imageLoadFunction) {
|
||||
|
||||
constructor(
|
||||
extent,
|
||||
resolution,
|
||||
pixelRatio,
|
||||
src,
|
||||
crossOrigin,
|
||||
imageLoadFunction
|
||||
) {
|
||||
super(extent, resolution, pixelRatio, ImageState.IDLE);
|
||||
|
||||
/**
|
||||
@@ -74,7 +77,6 @@ class ImageWrapper extends ImageBase {
|
||||
* @type {LoadFunction}
|
||||
*/
|
||||
this.imageLoadFunction_ = imageLoadFunction;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,35 +163,39 @@ export function listenImage(image, loadHandler, errorHandler) {
|
||||
if (img.src && IMAGE_DECODE) {
|
||||
const promise = img.decode();
|
||||
let listening = true;
|
||||
const unlisten = function() {
|
||||
const unlisten = function () {
|
||||
listening = false;
|
||||
};
|
||||
promise.then(function() {
|
||||
if (listening) {
|
||||
loadHandler();
|
||||
}
|
||||
}).catch(function(error) {
|
||||
if (listening) {
|
||||
// FIXME: Unconditionally call errorHandler() when this bug is fixed upstream:
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=198527
|
||||
if (error.name === 'EncodingError' && error.message === 'Invalid image type.') {
|
||||
promise
|
||||
.then(function () {
|
||||
if (listening) {
|
||||
loadHandler();
|
||||
} else {
|
||||
errorHandler();
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
if (listening) {
|
||||
// FIXME: Unconditionally call errorHandler() when this bug is fixed upstream:
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=198527
|
||||
if (
|
||||
error.name === 'EncodingError' &&
|
||||
error.message === 'Invalid image type.'
|
||||
) {
|
||||
loadHandler();
|
||||
} else {
|
||||
errorHandler();
|
||||
}
|
||||
}
|
||||
});
|
||||
return unlisten;
|
||||
}
|
||||
|
||||
const listenerKeys = [
|
||||
listenOnce(img, EventType.LOAD, loadHandler),
|
||||
listenOnce(img, EventType.ERROR, errorHandler)
|
||||
listenOnce(img, EventType.ERROR, errorHandler),
|
||||
];
|
||||
return function unlisten() {
|
||||
listenerKeys.forEach(unlistenByKey);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export default ImageWrapper;
|
||||
|
||||
Reference in New Issue
Block a user