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:
+66
-34
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/TopoJSON
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
@@ -11,6 +10,7 @@ import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @typedef {import("topojson-specification").Topology} TopoJSONTopology
|
||||
@@ -48,7 +48,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* be read from all children.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading data in the TopoJSON format.
|
||||
@@ -56,7 +55,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* @api
|
||||
*/
|
||||
class TopoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
@@ -81,9 +79,8 @@ class TopoJSON extends JSONFeature {
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
*/
|
||||
this.dataProjection = getProjection(
|
||||
options.dataProjection ?
|
||||
options.dataProjection : 'EPSG:4326');
|
||||
|
||||
options.dataProjection ? options.dataProjection : 'EPSG:4326'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +92,9 @@ class TopoJSON extends JSONFeature {
|
||||
readFeaturesFromObject(object, opt_options) {
|
||||
if (object.type == 'Topology') {
|
||||
const topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
|
||||
let transform, scale = null, translate = null;
|
||||
let transform,
|
||||
scale = null,
|
||||
translate = null;
|
||||
if (topoJSONTopology['transform']) {
|
||||
transform = topoJSONTopology['transform'];
|
||||
scale = transform['scale'];
|
||||
@@ -115,13 +114,36 @@ class TopoJSON extends JSONFeature {
|
||||
continue;
|
||||
}
|
||||
if (topoJSONFeatures[objectName].type === 'GeometryCollection') {
|
||||
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[objectName]);
|
||||
features.push.apply(features, readFeaturesFromGeometryCollection(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[
|
||||
objectName
|
||||
]);
|
||||
features.push.apply(
|
||||
features,
|
||||
readFeaturesFromGeometryCollection(
|
||||
feature,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
objectName,
|
||||
opt_options
|
||||
)
|
||||
);
|
||||
} else {
|
||||
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[objectName]);
|
||||
features.push(readFeatureFromGeometry(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[
|
||||
objectName
|
||||
]);
|
||||
features.push(
|
||||
readFeatureFromGeometry(
|
||||
feature,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
objectName,
|
||||
opt_options
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return features;
|
||||
@@ -138,10 +160,8 @@ class TopoJSON extends JSONFeature {
|
||||
readProjectionFromObject(object) {
|
||||
return this.dataProjection;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, function(TopoJSONGeometry, Array, ...Array=): import("../geom/Geometry.js").default>}
|
||||
@@ -152,10 +172,9 @@ const GEOMETRY_READERS = {
|
||||
'Polygon': readPolygonGeometry,
|
||||
'MultiPoint': readMultiPointGeometry,
|
||||
'MultiLineString': readMultiLineStringGeometry,
|
||||
'MultiPolygon': readMultiPolygonGeometry
|
||||
'MultiPolygon': readMultiPolygonGeometry,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate arcs into a coordinate array.
|
||||
* @param {Array<number>} indices Indices of arcs to concatenate. Negative
|
||||
@@ -190,7 +209,6 @@ function concatenateArcs(indices, arcs) {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a point from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -207,7 +225,6 @@ function readPointGeometry(object, scale, translate) {
|
||||
return new Point(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-point from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -226,7 +243,6 @@ function readMultiPointGeometry(object, scale, translate) {
|
||||
return new MultiPoint(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a linestring from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -239,7 +255,6 @@ function readLineStringGeometry(object, arcs) {
|
||||
return new LineString(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-linestring from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -255,7 +270,6 @@ function readMultiLineStringGeometry(object, arcs) {
|
||||
return new MultiLineString(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a polygon from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -271,7 +285,6 @@ function readPolygonGeometry(object, arcs) {
|
||||
return new Polygon(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-polygon from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -294,7 +307,6 @@ function readMultiPolygonGeometry(object, arcs) {
|
||||
return new MultiPolygon(coordinates);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create features from a TopoJSON GeometryCollection object.
|
||||
*
|
||||
@@ -309,17 +321,31 @@ function readMultiPolygonGeometry(object, arcs) {
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @return {Array<Feature>} Array of features.
|
||||
*/
|
||||
function readFeaturesFromGeometryCollection(collection, arcs, scale, translate, property, name, opt_options) {
|
||||
function readFeaturesFromGeometryCollection(
|
||||
collection,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
name,
|
||||
opt_options
|
||||
) {
|
||||
const geometries = collection['geometries'];
|
||||
const features = [];
|
||||
for (let i = 0, ii = geometries.length; i < ii; ++i) {
|
||||
features[i] = readFeatureFromGeometry(
|
||||
geometries[i], arcs, scale, translate, property, name, opt_options);
|
||||
geometries[i],
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
name,
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a feature from a TopoJSON geometry object.
|
||||
*
|
||||
@@ -333,17 +359,27 @@ function readFeaturesFromGeometryCollection(collection, arcs, scale, translate,
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @return {Feature} Feature.
|
||||
*/
|
||||
function readFeatureFromGeometry(object, arcs, scale, translate, property, name, opt_options) {
|
||||
function readFeatureFromGeometry(
|
||||
object,
|
||||
arcs,
|
||||
scale,
|
||||
translate,
|
||||
property,
|
||||
name,
|
||||
opt_options
|
||||
) {
|
||||
let geometry;
|
||||
const type = object.type;
|
||||
const geometryReader = GEOMETRY_READERS[type];
|
||||
if ((type === 'Point') || (type === 'MultiPoint')) {
|
||||
if (type === 'Point' || type === 'MultiPoint') {
|
||||
geometry = geometryReader(object, scale, translate);
|
||||
} else {
|
||||
geometry = geometryReader(object, arcs);
|
||||
}
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(transformGeometryWithOptions(geometry, false, opt_options));
|
||||
feature.setGeometry(
|
||||
transformGeometryWithOptions(geometry, false, opt_options)
|
||||
);
|
||||
if (object.id !== undefined) {
|
||||
feature.setId(object.id);
|
||||
}
|
||||
@@ -360,7 +396,6 @@ function readFeatureFromGeometry(object, arcs, scale, translate, property, name,
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to array of arcs. The provided array of arcs is
|
||||
* modified in place.
|
||||
@@ -375,7 +410,6 @@ function transformArcs(arcs, scale, translate) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to an arc. The provided arc is modified in place.
|
||||
*
|
||||
@@ -396,7 +430,6 @@ function transformArc(arc, scale, translate) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to a vertex. The provided vertex is modified in
|
||||
* place.
|
||||
@@ -410,5 +443,4 @@ function transformVertex(vertex, scale, translate) {
|
||||
vertex[1] = vertex[1] * scale[1] + translate[1];
|
||||
}
|
||||
|
||||
|
||||
export default TopoJSON;
|
||||
|
||||
Reference in New Issue
Block a user