Use union instead of enum for geometry type

This commit is contained in:
Tim Schaub
2021-09-04 17:39:54 -06:00
committed by Andreas Hocevar
parent 04ad0e0c5a
commit 9a6f8493fb
35 changed files with 296 additions and 378 deletions

View File

@@ -6,7 +6,6 @@
import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
import FormatType from './FormatType.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js';
import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js';
import MultiPoint from '../geom/MultiPoint.js';
@@ -202,7 +201,7 @@ class MVT extends FeatureFormat {
feature.transform(options.dataProjection);
} else {
let geom;
if (geometryType == GeometryType.POLYGON) {
if (geometryType == 'Polygon') {
const endss = inflateEnds(flatCoordinates, ends);
geom =
endss.length > 1
@@ -210,15 +209,13 @@ class MVT extends FeatureFormat {
: new Polygon(flatCoordinates, GeometryLayout.XY, ends);
} else {
geom =
geometryType === GeometryType.POINT
geometryType === 'Point'
? new Point(flatCoordinates, GeometryLayout.XY)
: geometryType === GeometryType.LINE_STRING
: geometryType === 'LineString'
? new LineString(flatCoordinates, GeometryLayout.XY)
: geometryType === GeometryType.POLYGON
? new Polygon(flatCoordinates, GeometryLayout.XY, ends)
: geometryType === GeometryType.MULTI_POINT
: geometryType === 'MultiPoint'
? new MultiPoint(flatCoordinates, GeometryLayout.XY)
: geometryType === GeometryType.MULTI_LINE_STRING
: geometryType === 'MultiLineString'
? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends)
: null;
}
@@ -421,19 +418,17 @@ function readRawFeature(pbf, layer, i) {
* @param {number} type The raw feature's geometry type
* @param {number} numEnds Number of ends of the flat coordinates of the
* geometry.
* @return {import("../geom/GeometryType.js").default} The geometry type.
* @return {import("../geom/Geometry.js").Type} The geometry type.
*/
function getGeometryType(type, numEnds) {
/** @type {import("../geom/GeometryType.js").default} */
/** @type {import("../geom/Geometry.js").Type} */
let geometryType;
if (type === 1) {
geometryType =
numEnds === 1 ? GeometryType.POINT : GeometryType.MULTI_POINT;
geometryType = numEnds === 1 ? 'Point' : 'MultiPoint';
} else if (type === 2) {
geometryType =
numEnds === 1 ? GeometryType.LINE_STRING : GeometryType.MULTI_LINE_STRING;
geometryType = numEnds === 1 ? 'LineString' : 'MultiLineString';
} else if (type === 3) {
geometryType = GeometryType.POLYGON;
geometryType = 'Polygon';
// MultiPolygon not relevant for rendering - winding order determines
// outer rings of polygons.
}