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
-63
@@ -2,12 +2,9 @@
|
||||
* @module ol/format/EsriJSON
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {containsExtent} from '../extent.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import LinearRing from '../geom/LinearRing.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
@@ -15,10 +12,13 @@ import MultiPoint from '../geom/MultiPoint.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {containsExtent} from '../extent.js';
|
||||
import {deflateCoordinates} from '../geom/flat/deflate.js';
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
import {isEmpty} from '../obj.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
import {isEmpty} from '../obj.js';
|
||||
import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @typedef {import("arcgis-rest-api").Feature} EsriJSONFeature
|
||||
@@ -33,7 +33,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* @typedef {import("arcgis-rest-api").SpatialReferenceWkid} EsriJSONSpatialReferenceWkid
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} EsriJSONMultiPolygon
|
||||
* @property {Array<Array<Array<Array<number>>>>} rings Rings for the MultiPolygon.
|
||||
@@ -42,7 +41,6 @@ import {get as getProjection} from '../proj.js';
|
||||
* @property {EsriJSONSpatialReferenceWkid} [spatialReference] The coordinate reference system.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<import("../geom/GeometryType.js").default, function(EsriJSONGeometry): import("../geom/Geometry.js").default>}
|
||||
@@ -55,7 +53,6 @@ GEOMETRY_READERS[GeometryType.MULTI_POINT] = readMultiPointGeometry;
|
||||
GEOMETRY_READERS[GeometryType.MULTI_LINE_STRING] = readMultiLineStringGeometry;
|
||||
GEOMETRY_READERS[GeometryType.MULTI_POLYGON] = readMultiPolygonGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, function(import("../geom/Geometry.js").default, import("./Feature.js").WriteOptions=): (EsriJSONGeometry)>}
|
||||
@@ -68,13 +65,11 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POINT] = writeMultiPointGeometry;
|
||||
GEOMETRY_WRITERS[GeometryType.MULTI_LINE_STRING] = writeMultiLineStringGeometry;
|
||||
GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [geometryName] Geometry name to use when creating features.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading and writing data in the EsriJSON format.
|
||||
@@ -82,12 +77,10 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
|
||||
* @api
|
||||
*/
|
||||
class EsriJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super();
|
||||
@@ -98,7 +91,6 @@ class EsriJSON extends JSONFeature {
|
||||
* @private
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +112,7 @@ class EsriJSON extends JSONFeature {
|
||||
feature.setProperties(esriJSONFeature.attributes, true);
|
||||
const id = esriJSONFeature.attributes[opt_idField];
|
||||
if (id !== undefined) {
|
||||
feature.setId(/** @type {number} */(id));
|
||||
feature.setId(/** @type {number} */ (id));
|
||||
}
|
||||
}
|
||||
return feature;
|
||||
@@ -140,7 +132,13 @@ class EsriJSON extends JSONFeature {
|
||||
const features = [];
|
||||
const esriJSONFeatures = esriJSONFeatureSet.features;
|
||||
for (let i = 0, ii = esriJSONFeatures.length; i < ii; ++i) {
|
||||
features.push(this.readFeatureFromObject(esriJSONFeatures[i], options, object.objectIdFieldName));
|
||||
features.push(
|
||||
this.readFeatureFromObject(
|
||||
esriJSONFeatures[i],
|
||||
options,
|
||||
object.objectIdFieldName
|
||||
)
|
||||
);
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
@@ -164,8 +162,13 @@ class EsriJSON extends JSONFeature {
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
*/
|
||||
readProjectionFromObject(object) {
|
||||
if (object['spatialReference'] && object['spatialReference']['wkid'] !== undefined) {
|
||||
const spatialReference = /** @type {EsriJSONSpatialReferenceWkid} */ (object['spatialReference']);
|
||||
if (
|
||||
object['spatialReference'] &&
|
||||
object['spatialReference']['wkid'] !== undefined
|
||||
) {
|
||||
const spatialReference = /** @type {EsriJSONSpatialReferenceWkid} */ (object[
|
||||
'spatialReference'
|
||||
]);
|
||||
const crs = spatialReference.wkid;
|
||||
return getProjection('EPSG:' + crs);
|
||||
} else {
|
||||
@@ -200,8 +203,15 @@ class EsriJSON extends JSONFeature {
|
||||
if (geometry) {
|
||||
object['geometry'] = writeGeometry(geometry, opt_options);
|
||||
if (opt_options && opt_options.featureProjection) {
|
||||
object['geometry']['spatialReference'] = /** @type {EsriJSONSpatialReferenceWkid} */({
|
||||
wkid: Number(getProjection(opt_options.featureProjection).getCode().split(':').pop())
|
||||
object['geometry'][
|
||||
'spatialReference'
|
||||
] = /** @type {EsriJSONSpatialReferenceWkid} */ ({
|
||||
wkid: Number(
|
||||
getProjection(opt_options.featureProjection)
|
||||
.getCode()
|
||||
.split(':')
|
||||
.pop()
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -230,12 +240,11 @@ class EsriJSON extends JSONFeature {
|
||||
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||
}
|
||||
return {
|
||||
'features': objects
|
||||
'features': objects,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONGeometry} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
@@ -271,10 +280,13 @@ function readGeometry(object, opt_options) {
|
||||
}
|
||||
}
|
||||
const geometryReader = GEOMETRY_READERS[type];
|
||||
return transformGeometryWithOptions(geometryReader(object), false, opt_options);
|
||||
return transformGeometryWithOptions(
|
||||
geometryReader(object),
|
||||
false,
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines inner and outer rings.
|
||||
* Checks if any polygons in this array contain any other polygons in this
|
||||
@@ -293,8 +305,12 @@ function convertRings(rings, layout) {
|
||||
flatRing.length = 0;
|
||||
deflateCoordinates(flatRing, 0, rings[i], layout.length);
|
||||
// is this ring an outer ring? is it clockwise?
|
||||
const clockwise = linearRingIsClockwise(flatRing, 0,
|
||||
flatRing.length, layout.length);
|
||||
const clockwise = linearRingIsClockwise(
|
||||
flatRing,
|
||||
0,
|
||||
flatRing.length,
|
||||
layout.length
|
||||
);
|
||||
if (clockwise) {
|
||||
outerRings.push([rings[i]]);
|
||||
} else {
|
||||
@@ -327,7 +343,6 @@ function convertRings(rings, layout) {
|
||||
return outerRings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPoint} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} Point.
|
||||
@@ -335,21 +350,20 @@ function convertRings(rings, layout) {
|
||||
function readPointGeometry(object) {
|
||||
let point;
|
||||
if (object.m !== undefined && object.z !== undefined) {
|
||||
point = new Point([object.x, object.y, object.z, object.m],
|
||||
GeometryLayout.XYZM);
|
||||
point = new Point(
|
||||
[object.x, object.y, object.z, object.m],
|
||||
GeometryLayout.XYZM
|
||||
);
|
||||
} else if (object.z !== undefined) {
|
||||
point = new Point([object.x, object.y, object.z],
|
||||
GeometryLayout.XYZ);
|
||||
point = new Point([object.x, object.y, object.z], GeometryLayout.XYZ);
|
||||
} else if (object.m !== undefined) {
|
||||
point = new Point([object.x, object.y, object.m],
|
||||
GeometryLayout.XYM);
|
||||
point = new Point([object.x, object.y, object.m], GeometryLayout.XYM);
|
||||
} else {
|
||||
point = new Point([object.x, object.y]);
|
||||
}
|
||||
return point;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPolyline} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} LineString.
|
||||
@@ -359,7 +373,6 @@ function readLineStringGeometry(object) {
|
||||
return new LineString(object.paths[0], layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPolyline} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} MultiLineString.
|
||||
@@ -369,7 +382,6 @@ function readMultiLineStringGeometry(object) {
|
||||
return new MultiLineString(object.paths, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONHasZM} object Object.
|
||||
* @return {import("../geom/GeometryLayout.js").default} The geometry layout to use.
|
||||
@@ -386,7 +398,6 @@ function getGeometryLayout(object) {
|
||||
return layout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONMultipoint} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} MultiPoint.
|
||||
@@ -396,7 +407,6 @@ function readMultiPointGeometry(object) {
|
||||
return new MultiPoint(object.points, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONMultiPolygon} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} MultiPolygon.
|
||||
@@ -406,7 +416,6 @@ function readMultiPolygonGeometry(object) {
|
||||
return new MultiPolygon(object.rings, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {EsriJSONPolygon} object Object.
|
||||
* @return {import("../geom/Geometry.js").default} Polygon.
|
||||
@@ -416,7 +425,6 @@ function readPolygonGeometry(object) {
|
||||
return new Polygon(object.rings, layout);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Point.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -431,25 +439,25 @@ function writePointGeometry(geometry, opt_options) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
z: coordinates[2]
|
||||
z: coordinates[2],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XYM) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
m: coordinates[2]
|
||||
m: coordinates[2],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XYZM) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
z: coordinates[2],
|
||||
m: coordinates[3]
|
||||
m: coordinates[3],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XY) {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1]
|
||||
y: coordinates[1],
|
||||
};
|
||||
} else {
|
||||
assert(false, 34); // Invalid geometry layout
|
||||
@@ -457,7 +465,6 @@ function writePointGeometry(geometry, opt_options) {
|
||||
return esriJSON;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/SimpleGeometry.js").default} geometry Geometry.
|
||||
* @return {Object} Object with boolean hasZ and hasM keys.
|
||||
@@ -465,14 +472,11 @@ function writePointGeometry(geometry, opt_options) {
|
||||
function getHasZM(geometry) {
|
||||
const layout = geometry.getLayout();
|
||||
return {
|
||||
hasZ: (layout === GeometryLayout.XYZ ||
|
||||
layout === GeometryLayout.XYZM),
|
||||
hasM: (layout === GeometryLayout.XYM ||
|
||||
layout === GeometryLayout.XYZM)
|
||||
hasZ: layout === GeometryLayout.XYZ || layout === GeometryLayout.XYZM,
|
||||
hasM: layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/LineString.js").default} lineString Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -484,12 +488,11 @@ function writeLineStringGeometry(lineString, opt_options) {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
paths: [
|
||||
/** @type {Array<EsriJSONPosition>} */ (lineString.getCoordinates())
|
||||
]
|
||||
/** @type {Array<EsriJSONPosition>} */ (lineString.getCoordinates()),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Polygon.js").default} polygon Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -501,11 +504,12 @@ function writePolygonGeometry(polygon, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (polygon.getCoordinates(false))
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (polygon.getCoordinates(
|
||||
false
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiLineString.js").default} multiLineString Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -516,11 +520,10 @@ function writeMultiLineStringGeometry(multiLineString, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
paths: /** @type {Array<Array<EsriJSONPosition>>} */ (multiLineString.getCoordinates())
|
||||
paths: /** @type {Array<Array<EsriJSONPosition>>} */ (multiLineString.getCoordinates()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiPoint.js").default} multiPoint Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -531,11 +534,10 @@ function writeMultiPointGeometry(multiPoint, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
points: /** @type {Array<EsriJSONPosition>} */ (multiPoint.getCoordinates())
|
||||
points: /** @type {Array<EsriJSONPosition>} */ (multiPoint.getCoordinates()),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiPolygon.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -553,11 +555,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
return {
|
||||
hasZ: hasZM.hasZ,
|
||||
hasM: hasZM.hasM,
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (output)
|
||||
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (output),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
@@ -565,8 +566,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
*/
|
||||
function writeGeometry(geometry, opt_options) {
|
||||
const geometryWriter = GEOMETRY_WRITERS[geometry.getType()];
|
||||
return geometryWriter(transformGeometryWithOptions(geometry, true, opt_options), opt_options);
|
||||
return geometryWriter(
|
||||
transformGeometryWithOptions(geometry, true, opt_options),
|
||||
opt_options
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default EsriJSON;
|
||||
|
||||
Reference in New Issue
Block a user