Use union instead of enum for geometry type
This commit is contained in:
committed by
Andreas Hocevar
parent
04ad0e0c5a
commit
9a6f8493fb
+16
-14
@@ -6,7 +6,6 @@ import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
|
||||
import FormatType from './FormatType.js';
|
||||
import GeometryCollection from '../geom/GeometryCollection.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';
|
||||
@@ -579,14 +578,17 @@ class WkbWriter {
|
||||
* @param {number} [srid] SRID
|
||||
*/
|
||||
writeGeometry(geom, srid) {
|
||||
/**
|
||||
* @type {Object<import("../geom/Geometry.js").Type, WKBGeometryType>}
|
||||
*/
|
||||
const wkblut = {
|
||||
[GeometryType.POINT]: WKBGeometryType.POINT,
|
||||
[GeometryType.LINE_STRING]: WKBGeometryType.LINE_STRING,
|
||||
[GeometryType.POLYGON]: WKBGeometryType.POLYGON,
|
||||
[GeometryType.MULTI_POINT]: WKBGeometryType.MULTI_POINT,
|
||||
[GeometryType.MULTI_LINE_STRING]: WKBGeometryType.MULTI_LINE_STRING,
|
||||
[GeometryType.MULTI_POLYGON]: WKBGeometryType.MULTI_POLYGON,
|
||||
[GeometryType.GEOMETRY_COLLECTION]: WKBGeometryType.GEOMETRY_COLLECTION,
|
||||
Point: WKBGeometryType.POINT,
|
||||
LineString: WKBGeometryType.LINE_STRING,
|
||||
Polygon: WKBGeometryType.POLYGON,
|
||||
MultiPoint: WKBGeometryType.MULTI_POINT,
|
||||
MultiLineString: WKBGeometryType.MULTI_LINE_STRING,
|
||||
MultiPolygon: WKBGeometryType.MULTI_POLYGON,
|
||||
GeometryCollection: WKBGeometryType.GEOMETRY_COLLECTION,
|
||||
};
|
||||
const geomType = geom.getType();
|
||||
const typeId = wkblut[geomType];
|
||||
@@ -604,12 +606,12 @@ class WkbWriter {
|
||||
|
||||
if (geom instanceof SimpleGeometry) {
|
||||
const writerLUT = {
|
||||
[GeometryType.POINT]: this.writePoint,
|
||||
[GeometryType.LINE_STRING]: this.writeLineString,
|
||||
[GeometryType.POLYGON]: this.writePolygon,
|
||||
[GeometryType.MULTI_POINT]: this.writeMultiPoint,
|
||||
[GeometryType.MULTI_LINE_STRING]: this.writeMultiLineString,
|
||||
[GeometryType.MULTI_POLYGON]: this.writeMultiPolygon,
|
||||
Point: this.writePoint,
|
||||
LineString: this.writeLineString,
|
||||
Polygon: this.writePolygon,
|
||||
MultiPoint: this.writeMultiPoint,
|
||||
MultiLineString: this.writeMultiLineString,
|
||||
MultiPolygon: this.writeMultiPolygon,
|
||||
};
|
||||
writerLUT[geomType].call(this, geom.getCoordinates(), geom.getLayout());
|
||||
} else if (geom instanceof GeometryCollection) {
|
||||
|
||||
Reference in New Issue
Block a user