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
+25 -24
View File
@@ -3,7 +3,6 @@
*/
import Feature from '../Feature.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';
@@ -43,27 +42,29 @@ import {transformGeometryWithOptions} from './Feature.js';
/**
* @const
* @type {Object<import("../geom/GeometryType.js").default, function(EsriJSONGeometry): import("../geom/Geometry.js").default>}
* @type {Object<import("../geom/Geometry.js").Type, function(EsriJSONGeometry): import("../geom/Geometry.js").default>}
*/
const GEOMETRY_READERS = {};
GEOMETRY_READERS[GeometryType.POINT] = readPointGeometry;
GEOMETRY_READERS[GeometryType.LINE_STRING] = readLineStringGeometry;
GEOMETRY_READERS[GeometryType.POLYGON] = readPolygonGeometry;
GEOMETRY_READERS[GeometryType.MULTI_POINT] = readMultiPointGeometry;
GEOMETRY_READERS[GeometryType.MULTI_LINE_STRING] = readMultiLineStringGeometry;
GEOMETRY_READERS[GeometryType.MULTI_POLYGON] = readMultiPolygonGeometry;
const GEOMETRY_READERS = {
Point: readPointGeometry,
LineString: readLineStringGeometry,
Polygon: readPolygonGeometry,
MultiPoint: readMultiPointGeometry,
MultiLineString: readMultiLineStringGeometry,
MultiPolygon: readMultiPolygonGeometry,
};
/**
* @const
* @type {Object<string, function(import("../geom/Geometry.js").default, import("./Feature.js").WriteOptions=): (EsriJSONGeometry)>}
* @type {Object<import("../geom/Geometry.js").Type, function(import("../geom/Geometry.js").default, import("./Feature.js").WriteOptions=): (EsriJSONGeometry)>}
*/
const GEOMETRY_WRITERS = {};
GEOMETRY_WRITERS[GeometryType.POINT] = writePointGeometry;
GEOMETRY_WRITERS[GeometryType.LINE_STRING] = writeLineStringGeometry;
GEOMETRY_WRITERS[GeometryType.POLYGON] = writePolygonGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_POINT] = writeMultiPointGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_LINE_STRING] = writeMultiLineStringGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
const GEOMETRY_WRITERS = {
Point: writePointGeometry,
LineString: writeLineStringGeometry,
Polygon: writePolygonGeometry,
MultiPoint: writeMultiPointGeometry,
MultiLineString: writeMultiLineStringGeometry,
MultiPolygon: writeMultiPolygonGeometry,
};
/**
* @typedef {Object} Options
@@ -255,28 +256,28 @@ function readGeometry(object, opt_options) {
if (!object) {
return null;
}
/** @type {import("../geom/GeometryType.js").default} */
/** @type {import("../geom/Geometry.js").Type} */
let type;
if (typeof object['x'] === 'number' && typeof object['y'] === 'number') {
type = GeometryType.POINT;
type = 'Point';
} else if (object['points']) {
type = GeometryType.MULTI_POINT;
type = 'MultiPoint';
} else if (object['paths']) {
const esriJSONPolyline = /** @type {EsriJSONPolyline} */ (object);
if (esriJSONPolyline.paths.length === 1) {
type = GeometryType.LINE_STRING;
type = 'LineString';
} else {
type = GeometryType.MULTI_LINE_STRING;
type = 'MultiLineString';
}
} else if (object['rings']) {
const esriJSONPolygon = /** @type {EsriJSONPolygon} */ (object);
const layout = getGeometryLayout(esriJSONPolygon);
const rings = convertRings(esriJSONPolygon.rings, layout);
if (rings.length === 1) {
type = GeometryType.POLYGON;
type = 'Polygon';
object = assign({}, object, {['rings']: rings[0]});
} else {
type = GeometryType.MULTI_POLYGON;
type = 'MultiPolygon';
object = assign({}, object, {['rings']: rings});
}
}
+3 -4
View File
@@ -3,7 +3,6 @@
*/
import Feature from '../Feature.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 Point from '../geom/Point.js';
@@ -848,7 +847,7 @@ function writeRte(node, feature, objectStack) {
const context = {node: node};
context['properties'] = properties;
const geometry = feature.getGeometry();
if (geometry.getType() == GeometryType.LINE_STRING) {
if (geometry.getType() == 'LineString') {
const lineString = /** @type {LineString} */ (
transformGeometryWithOptions(geometry, true, options)
);
@@ -882,7 +881,7 @@ function writeTrk(node, feature, objectStack) {
const context = {node: node};
context['properties'] = properties;
const geometry = feature.getGeometry();
if (geometry.getType() == GeometryType.MULTI_LINE_STRING) {
if (geometry.getType() == 'MultiLineString') {
const multiLineString = /** @type {MultiLineString} */ (
transformGeometryWithOptions(geometry, true, options)
);
@@ -932,7 +931,7 @@ function writeWpt(node, feature, objectStack) {
const context = objectStack[objectStack.length - 1];
context['properties'] = feature.getProperties();
const geometry = feature.getGeometry();
if (geometry.getType() == GeometryType.POINT) {
if (geometry.getType() == 'Point') {
const point = /** @type {Point} */ (
transformGeometryWithOptions(geometry, true, options)
);
+16 -17
View File
@@ -4,7 +4,6 @@
import Feature from '../Feature.js';
import GeometryCollection from '../geom/GeometryCollection.js';
import GeometryType from '../geom/GeometryType.js';
import JSONFeature from './JSONFeature.js';
import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js';
@@ -284,46 +283,46 @@ function readGeometry(object, opt_options) {
*/
let geometry;
switch (object['type']) {
case GeometryType.POINT: {
case 'Point': {
geometry = readPointGeometry(/** @type {GeoJSONPoint} */ (object));
break;
}
case GeometryType.LINE_STRING: {
case 'LineString': {
geometry = readLineStringGeometry(
/** @type {GeoJSONLineString} */ (object)
);
break;
}
case GeometryType.POLYGON: {
case 'Polygon': {
geometry = readPolygonGeometry(/** @type {GeoJSONPolygon} */ (object));
break;
}
case GeometryType.MULTI_POINT: {
case 'MultiPoint': {
geometry = readMultiPointGeometry(
/** @type {GeoJSONMultiPoint} */ (object)
);
break;
}
case GeometryType.MULTI_LINE_STRING: {
case 'MultiLineString': {
geometry = readMultiLineStringGeometry(
/** @type {GeoJSONMultiLineString} */ (object)
);
break;
}
case GeometryType.MULTI_POLYGON: {
case 'MultiPolygon': {
geometry = readMultiPolygonGeometry(
/** @type {GeoJSONMultiPolygon} */ (object)
);
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
case 'GeometryCollection': {
geometry = readGeometryCollectionGeometry(
/** @type {GeoJSONGeometryCollection} */ (object)
);
break;
}
default: {
throw new Error('Unsupported GeoJSON type: ' + object.type);
throw new Error('Unsupported GeoJSON type: ' + object['type']);
}
}
return transformGeometryWithOptions(geometry, false, opt_options);
@@ -407,56 +406,56 @@ function writeGeometry(geometry, opt_options) {
/** @type {GeoJSONGeometry} */
let geoJSON;
switch (type) {
case GeometryType.POINT: {
case 'Point': {
geoJSON = writePointGeometry(
/** @type {Point} */ (geometry),
opt_options
);
break;
}
case GeometryType.LINE_STRING: {
case 'LineString': {
geoJSON = writeLineStringGeometry(
/** @type {LineString} */ (geometry),
opt_options
);
break;
}
case GeometryType.POLYGON: {
case 'Polygon': {
geoJSON = writePolygonGeometry(
/** @type {Polygon} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_POINT: {
case 'MultiPoint': {
geoJSON = writeMultiPointGeometry(
/** @type {MultiPoint} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_LINE_STRING: {
case 'MultiLineString': {
geoJSON = writeMultiLineStringGeometry(
/** @type {MultiLineString} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_POLYGON: {
case 'MultiPolygon': {
geoJSON = writeMultiPolygonGeometry(
/** @type {MultiPolygon} */ (geometry),
opt_options
);
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
case 'GeometryCollection': {
geoJSON = writeGeometryCollectionGeometry(
/** @type {GeometryCollection} */ (geometry),
opt_options
);
break;
}
case GeometryType.CIRCLE: {
case 'Circle': {
geoJSON = {
type: 'GeometryCollection',
geometries: [],
+32 -65
View File
@@ -5,7 +5,6 @@ import Feature from '../Feature.js';
import Fill from '../style/Fill.js';
import GeometryCollection from '../geom/GeometryCollection.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js';
import Icon from '../style/Icon.js';
import IconAnchorUnits from '../style/IconAnchorUnits.js';
import IconOrigin from '../style/IconOrigin.js';
@@ -1012,16 +1011,12 @@ function createFeatureStyleFunction(
.getGeometriesArrayRecursive()
.filter(function (geometry) {
const type = geometry.getType();
return (
type === GeometryType.POINT ||
type === GeometryType.MULTI_POINT
);
return type === 'Point' || type === 'MultiPoint';
});
drawName = multiGeometryPoints.length > 0;
} else {
const type = geometry.getType();
drawName =
type === GeometryType.POINT || type === GeometryType.MULTI_POINT;
drawName = type === 'Point' || type === 'MultiPoint';
}
}
}
@@ -1759,7 +1754,7 @@ function readMultiGeometry(node, objectStack) {
if (homogeneous) {
let layout;
let flatCoordinates;
if (type == GeometryType.POINT) {
if (type == 'Point') {
const point = geometries[0];
layout = point.getLayout();
flatCoordinates = point.getFlatCoordinates();
@@ -1769,13 +1764,13 @@ function readMultiGeometry(node, objectStack) {
}
multiGeometry = new MultiPoint(flatCoordinates, layout);
setCommonGeometryProperties(multiGeometry, geometries);
} else if (type == GeometryType.LINE_STRING) {
} else if (type == 'LineString') {
multiGeometry = new MultiLineString(geometries);
setCommonGeometryProperties(multiGeometry, geometries);
} else if (type == GeometryType.POLYGON) {
} else if (type == 'Polygon') {
multiGeometry = new MultiPolygon(geometries);
setCommonGeometryProperties(multiGeometry, geometries);
} else if (type == GeometryType.GEOMETRY_COLLECTION) {
} else if (type == 'GeometryCollection') {
multiGeometry = new GeometryCollection(geometries);
} else {
assert(false, 37); // Unknown geometry type found
@@ -1919,7 +1914,7 @@ function readStyle(node, objectStack) {
geometry: function (feature) {
const geometry = feature.getGeometry();
const type = geometry.getType();
if (type === GeometryType.GEOMETRY_COLLECTION) {
if (type === 'GeometryCollection') {
const collection =
/** @type {import("../geom/GeometryCollection").default} */ (
geometry
@@ -1929,16 +1924,10 @@ function readStyle(node, objectStack) {
.getGeometriesArrayRecursive()
.filter(function (geometry) {
const type = geometry.getType();
return (
type !== GeometryType.POLYGON &&
type !== GeometryType.MULTI_POLYGON
);
return type !== 'Polygon' && type !== 'MultiPolygon';
})
);
} else if (
type !== GeometryType.POLYGON &&
type !== GeometryType.MULTI_POLYGON
) {
} else if (type !== 'Polygon' && type !== 'MultiPolygon') {
return geometry;
}
},
@@ -1952,7 +1941,7 @@ function readStyle(node, objectStack) {
geometry: function (feature) {
const geometry = feature.getGeometry();
const type = geometry.getType();
if (type === GeometryType.GEOMETRY_COLLECTION) {
if (type === 'GeometryCollection') {
const collection =
/** @type {import("../geom/GeometryCollection").default} */ (
geometry
@@ -1962,16 +1951,10 @@ function readStyle(node, objectStack) {
.getGeometriesArrayRecursive()
.filter(function (geometry) {
const type = geometry.getType();
return (
type === GeometryType.POLYGON ||
type === GeometryType.MULTI_POLYGON
);
return type === 'Polygon' || type === 'MultiPolygon';
})
);
} else if (
type === GeometryType.POLYGON ||
type === GeometryType.MULTI_POLYGON
) {
} else if (type === 'Polygon' || type === 'MultiPolygon') {
return geometry;
}
},
@@ -2868,27 +2851,27 @@ function writeMultiGeometry(node, geometry, objectStack) {
let geometries = [];
/** @type {function(*, Array<*>, string=): (Node|undefined)} */
let factory;
if (type === GeometryType.GEOMETRY_COLLECTION) {
if (type === 'GeometryCollection') {
/** @type {GeometryCollection} */ (geometry)
.getGeometriesArrayRecursive()
.forEach(function (geometry) {
const type = geometry.getType();
if (type === GeometryType.MULTI_POINT) {
if (type === 'MultiPoint') {
geometries = geometries.concat(
/** @type {MultiPoint} */ (geometry).getPoints()
);
} else if (type === GeometryType.MULTI_LINE_STRING) {
} else if (type === 'MultiLineString') {
geometries = geometries.concat(
/** @type {MultiLineString} */ (geometry).getLineStrings()
);
} else if (type === GeometryType.MULTI_POLYGON) {
} else if (type === 'MultiPolygon') {
geometries = geometries.concat(
/** @type {MultiPolygon} */ (geometry).getPolygons()
);
} else if (
type === GeometryType.POINT ||
type === GeometryType.LINE_STRING ||
type === GeometryType.POLYGON
type === 'Point' ||
type === 'LineString' ||
type === 'Polygon'
) {
geometries.push(geometry);
} else {
@@ -2896,13 +2879,13 @@ function writeMultiGeometry(node, geometry, objectStack) {
}
});
factory = GEOMETRY_NODE_FACTORY;
} else if (type === GeometryType.MULTI_POINT) {
} else if (type === 'MultiPoint') {
geometries = /** @type {MultiPoint} */ (geometry).getPoints();
factory = POINT_NODE_FACTORY;
} else if (type === GeometryType.MULTI_LINE_STRING) {
} else if (type === 'MultiLineString') {
geometries = /** @type {MultiLineString} */ (geometry).getLineStrings();
factory = LINE_STRING_NODE_FACTORY;
} else if (type === GeometryType.MULTI_POLYGON) {
} else if (type === 'MultiPolygon') {
geometries = /** @type {MultiPolygon} */ (geometry).getPolygons();
factory = POLYGON_NODE_FACTORY;
} else {
@@ -3036,22 +3019,18 @@ function writePlacemark(node, feature, objectStack) {
const geometry = style.getGeometryFunction()(feature);
if (geometry) {
const type = geometry.getType();
if (type === GeometryType.GEOMETRY_COLLECTION) {
if (type === 'GeometryCollection') {
return /** @type {GeometryCollection} */ (geometry)
.getGeometriesArrayRecursive()
.filter(function (geometry) {
const type = geometry.getType();
return (
type === GeometryType.POINT ||
type === GeometryType.MULTI_POINT
);
return type === 'Point' || type === 'MultiPoint';
}).length;
}
return (
type === GeometryType.POINT || type === GeometryType.MULTI_POINT
);
return type === 'Point' || type === 'MultiPoint';
}
});
('Point');
}
if (this.writeStyles_) {
let lineStyles = styleArray;
@@ -3061,42 +3040,30 @@ function writePlacemark(node, feature, objectStack) {
const geometry = style.getGeometryFunction()(feature);
if (geometry) {
const type = geometry.getType();
if (type === GeometryType.GEOMETRY_COLLECTION) {
if (type === 'GeometryCollection') {
return /** @type {GeometryCollection} */ (geometry)
.getGeometriesArrayRecursive()
.filter(function (geometry) {
const type = geometry.getType();
return (
type === GeometryType.LINE_STRING ||
type === GeometryType.MULTI_LINE_STRING
);
return type === 'LineString' || type === 'MultiLineString';
}).length;
}
return (
type === GeometryType.LINE_STRING ||
type === GeometryType.MULTI_LINE_STRING
);
return type === 'LineString' || type === 'MultiLineString';
}
});
polyStyles = styleArray.filter(function (style) {
const geometry = style.getGeometryFunction()(feature);
if (geometry) {
const type = geometry.getType();
if (type === GeometryType.GEOMETRY_COLLECTION) {
if (type === 'GeometryCollection') {
return /** @type {GeometryCollection} */ (geometry)
.getGeometriesArrayRecursive()
.filter(function (geometry) {
const type = geometry.getType();
return (
type === GeometryType.POLYGON ||
type === GeometryType.MULTI_POLYGON
);
return type === 'Polygon' || type === 'MultiPolygon';
}).length;
}
return (
type === GeometryType.POLYGON ||
type === GeometryType.MULTI_POLYGON
);
return type === 'Polygon' || type === 'MultiPolygon';
}
});
}
+10 -15
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.
}
+16 -14
View File
@@ -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) {
+17 -16
View File
@@ -4,7 +4,6 @@
import Feature from '../Feature.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';
@@ -79,13 +78,18 @@ const TokenType = {
};
/**
* @const
* @type {Object<string, string>}
* @type {Object<import("../geom/Geometry.js").Type, string>}
*/
const WKTGeometryType = {};
for (const type in GeometryType) {
WKTGeometryType[type] = GeometryType[type].toUpperCase();
}
const wktTypeLookup = {
Point: 'POINT',
LineString: 'LINESTRING',
Polygon: 'POLYGON',
MultiPoint: 'MULTIPOINT',
MultiLineString: 'MULTILINESTRING',
MultiPolygon: 'MULTIPOLYGON',
GeometryCollection: 'GEOMETRYCOLLECTION',
Circle: 'CIRCLE',
};
/**
* Class to tokenize a WKT string.
@@ -648,10 +652,7 @@ class WKT extends TextFeature {
readFeaturesFromText(text, opt_options) {
let geometries = [];
const geometry = this.readGeometryFromText(text, opt_options);
if (
this.splitCollection_ &&
geometry.getType() == GeometryType.GEOMETRY_COLLECTION
) {
if (this.splitCollection_ && geometry.getType() == 'GeometryCollection') {
geometries = /** @type {GeometryCollection} */ (
geometry
).getGeometriesArray();
@@ -847,22 +848,22 @@ const GeometryEncoder = {
* @return {string} WKT string for the geometry.
*/
function encode(geom) {
let type = geom.getType();
const type = geom.getType();
const geometryEncoder = GeometryEncoder[type];
const enc = geometryEncoder(geom);
type = type.toUpperCase();
let wktType = wktTypeLookup[type];
if (typeof (/** @type {?} */ (geom).getFlatCoordinates) === 'function') {
const dimInfo = encodeGeometryLayout(
/** @type {import("../geom/SimpleGeometry.js").default} */ (geom)
);
if (dimInfo.length > 0) {
type += ' ' + dimInfo;
wktType += ' ' + dimInfo;
}
}
if (enc.length === 0) {
return type + ' ' + EMPTY;
return wktType + ' ' + EMPTY;
}
return type + '(' + enc + ')';
return wktType + '(' + enc + ')';
}
export default WKT;