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:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -2,12 +2,18 @@
* @module ol/source/ImageMapGuide
*/
import ImageWrapper from '../Image.js';
import EventType from '../events/EventType.js';
import {containsExtent, getCenter, getHeight, getWidth, scaleFromCenter} from '../extent.js';
import {assign} from '../obj.js';
import ImageSource, {defaultImageLoadFunction} from './Image.js';
import ImageWrapper from '../Image.js';
import {appendParams} from '../uri.js';
import {assign} from '../obj.js';
import {
containsExtent,
getCenter,
getHeight,
getWidth,
scaleFromCenter,
} from '../extent.js';
/**
* @typedef {Object} Options
@@ -29,7 +35,6 @@ import {appendParams} from '../uri.js';
* @property {Object} [params] Additional parameters.
*/
/**
* @classdesc
* Source for images from Mapguide servers
@@ -42,10 +47,9 @@ class ImageMapGuide extends ImageSource {
* @param {Options} options ImageMapGuide options.
*/
constructor(options) {
super({
projection: options.projection,
resolutions: options.resolutions
resolutions: options.resolutions,
});
/**
@@ -53,14 +57,14 @@ class ImageMapGuide extends ImageSource {
* @type {?string}
*/
this.crossOrigin_ =
options.crossOrigin !== undefined ? options.crossOrigin : null;
options.crossOrigin !== undefined ? options.crossOrigin : null;
/**
* @private
* @type {number}
*/
this.displayDpi_ = options.displayDpi !== undefined ?
options.displayDpi : 96;
this.displayDpi_ =
options.displayDpi !== undefined ? options.displayDpi : 96;
/**
* @private
@@ -78,8 +82,10 @@ class ImageMapGuide extends ImageSource {
* @private
* @type {import("../Image.js").LoadFunction}
*/
this.imageLoadFunction_ = options.imageLoadFunction !== undefined ?
options.imageLoadFunction : defaultImageLoadFunction;
this.imageLoadFunction_ =
options.imageLoadFunction !== undefined
? options.imageLoadFunction
: defaultImageLoadFunction;
/**
* @private
@@ -91,8 +97,8 @@ class ImageMapGuide extends ImageSource {
* @private
* @type {number}
*/
this.metersPerUnit_ = options.metersPerUnit !== undefined ?
options.metersPerUnit : 1;
this.metersPerUnit_ =
options.metersPerUnit !== undefined ? options.metersPerUnit : 1;
/**
* @private
@@ -104,8 +110,8 @@ class ImageMapGuide extends ImageSource {
* @private
* @type {boolean}
*/
this.useOverlay_ = options.useOverlay !== undefined ?
options.useOverlay : false;
this.useOverlay_ =
options.useOverlay !== undefined ? options.useOverlay : false;
/**
* @private
@@ -118,7 +124,6 @@ class ImageMapGuide extends ImageSource {
* @type {number}
*/
this.renderedRevision_ = 0;
}
/**
@@ -143,11 +148,13 @@ class ImageMapGuide extends ImageSource {
pixelRatio = this.hidpi_ ? pixelRatio : 1;
let image = this.image_;
if (image &&
this.renderedRevision_ == this.getRevision() &&
image.getResolution() == resolution &&
image.getPixelRatio() == pixelRatio &&
containsExtent(image.getExtent(), extent)) {
if (
image &&
this.renderedRevision_ == this.getRevision() &&
image.getResolution() == resolution &&
image.getPixelRatio() == pixelRatio &&
containsExtent(image.getExtent(), extent)
) {
return image;
}
@@ -160,12 +167,25 @@ class ImageMapGuide extends ImageSource {
const size = [width * pixelRatio, height * pixelRatio];
if (this.url_ !== undefined) {
const imageUrl = this.getUrl(this.url_, this.params_, extent, size,
projection);
image = new ImageWrapper(extent, resolution, pixelRatio,
imageUrl, this.crossOrigin_,
this.imageLoadFunction_);
image.addEventListener(EventType.CHANGE, this.handleImageChange.bind(this));
const imageUrl = this.getUrl(
this.url_,
this.params_,
extent,
size,
projection
);
image = new ImageWrapper(
extent,
resolution,
pixelRatio,
imageUrl,
this.crossOrigin_,
this.imageLoadFunction_
);
image.addEventListener(
EventType.CHANGE,
this.handleImageChange.bind(this)
);
} else {
image = null;
}
@@ -203,11 +223,12 @@ class ImageMapGuide extends ImageSource {
* @return {string} The mapagent map image request URL.
*/
getUrl(baseUrl, params, extent, size, projection) {
const scale = getScale(extent, size,
this.metersPerUnit_, this.displayDpi_);
const scale = getScale(extent, size, this.metersPerUnit_, this.displayDpi_);
const center = getCenter(extent);
const baseParams = {
'OPERATION': this.useOverlay_ ? 'GETDYNAMICMAPOVERLAYIMAGE' : 'GETMAPIMAGE',
'OPERATION': this.useOverlay_
? 'GETDYNAMICMAPOVERLAYIMAGE'
: 'GETMAPIMAGE',
'VERSION': '2.0.0',
'LOCALE': 'en',
'CLIENTAGENT': 'ol/source/ImageMapGuide source',
@@ -217,7 +238,7 @@ class ImageMapGuide extends ImageSource {
'SETDISPLAYHEIGHT': Math.round(size[1]),
'SETVIEWSCALE': scale,
'SETVIEWCENTERX': center[0],
'SETVIEWCENTERY': center[1]
'SETVIEWCENTERY': center[1],
};
assign(baseParams, params);
return appendParams(baseUrl, baseParams);
@@ -235,7 +256,6 @@ class ImageMapGuide extends ImageSource {
}
}
/**
* @param {import("../extent.js").Extent} extent The map extents.
* @param {import("../size.js").Size} size The viewport size.
@@ -250,11 +270,10 @@ function getScale(extent, size, metersPerUnit, dpi) {
const devH = size[1];
const mpp = 0.0254 / dpi;
if (devH * mcsW > devW * mcsH) {
return mcsW * metersPerUnit / (devW * mpp); // width limited
return (mcsW * metersPerUnit) / (devW * mpp); // width limited
} else {
return mcsH * metersPerUnit / (devH * mpp); // height limited
return (mcsH * metersPerUnit) / (devH * mpp); // height limited
}
}
export default ImageMapGuide;