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:
+53
-50
@@ -2,18 +2,17 @@
|
||||
* @module ol/format/OSMXML
|
||||
*/
|
||||
// FIXME add typedef for stack state objects
|
||||
import {extend} from '../array.js';
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {isEmpty} from '../obj.js';
|
||||
import XMLFeature from './XMLFeature.js';
|
||||
import {extend} from '../array.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {pushParseAndPop, makeStructureNS} from '../xml.js';
|
||||
|
||||
import {isEmpty} from '../obj.js';
|
||||
import {makeStructureNS, pushParseAndPop} from '../xml.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -21,30 +20,25 @@ import {pushParseAndPop, makeStructureNS} from '../xml.js';
|
||||
*/
|
||||
const NAMESPACE_URIS = [null];
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WAY_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'nd': readNd,
|
||||
'tag': readTag,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const WAY_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'nd': readNd,
|
||||
'tag': readTag
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'node': readNode,
|
||||
'way': readWay
|
||||
});
|
||||
|
||||
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'node': readNode,
|
||||
'way': readWay,
|
||||
});
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -72,11 +66,16 @@ class OSMXML extends XMLFeature {
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
const options = this.getReadOptions(node, opt_options);
|
||||
if (node.localName == 'osm') {
|
||||
const state = pushParseAndPop({
|
||||
nodes: {},
|
||||
ways: [],
|
||||
features: []
|
||||
}, PARSERS, node, [options]);
|
||||
const state = pushParseAndPop(
|
||||
{
|
||||
nodes: {},
|
||||
ways: [],
|
||||
features: [],
|
||||
},
|
||||
PARSERS,
|
||||
node,
|
||||
[options]
|
||||
);
|
||||
// parse nodes in ways
|
||||
for (let j = 0; j < state.ways.length; j++) {
|
||||
const values = /** @type {Object} */ (state.ways[j]);
|
||||
@@ -89,7 +88,9 @@ class OSMXML extends XMLFeature {
|
||||
let geometry;
|
||||
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
|
||||
// closed way
|
||||
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
|
||||
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
} else {
|
||||
geometry = new LineString(flatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
@@ -105,20 +106,16 @@ class OSMXML extends XMLFeature {
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const NODE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'tag': readTag
|
||||
});
|
||||
|
||||
const NODE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'tag': readTag,
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
@@ -131,13 +128,18 @@ function readNode(node, objectStack) {
|
||||
/** @type {import("../coordinate.js").Coordinate} */
|
||||
const coordinates = [
|
||||
parseFloat(node.getAttribute('lon')),
|
||||
parseFloat(node.getAttribute('lat'))
|
||||
parseFloat(node.getAttribute('lat')),
|
||||
];
|
||||
state.nodes[id] = coordinates;
|
||||
|
||||
const values = pushParseAndPop({
|
||||
tags: {}
|
||||
}, NODE_PARSERS, node, objectStack);
|
||||
const values = pushParseAndPop(
|
||||
{
|
||||
tags: {},
|
||||
},
|
||||
NODE_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
if (!isEmpty(values.tags)) {
|
||||
const geometry = new Point(coordinates);
|
||||
transformGeometryWithOptions(geometry, false, options);
|
||||
@@ -148,23 +150,26 @@ function readNode(node, objectStack) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
*/
|
||||
function readWay(node, objectStack) {
|
||||
const id = node.getAttribute('id');
|
||||
const values = pushParseAndPop({
|
||||
id: id,
|
||||
ndrefs: [],
|
||||
tags: {}
|
||||
}, WAY_PARSERS, node, objectStack);
|
||||
const values = pushParseAndPop(
|
||||
{
|
||||
id: id,
|
||||
ndrefs: [],
|
||||
tags: {},
|
||||
},
|
||||
WAY_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
const state = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||
state.ways.push(values);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -174,7 +179,6 @@ function readNd(node, objectStack) {
|
||||
values.ndrefs.push(node.getAttribute('ref'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -184,5 +188,4 @@ function readTag(node, objectStack) {
|
||||
values.tags[node.getAttribute('k')] = node.getAttribute('v');
|
||||
}
|
||||
|
||||
|
||||
export default OSMXML;
|
||||
|
||||
Reference in New Issue
Block a user