Fix WKT geometry type lookup and tests
This commit is contained in:
+21
-12
@@ -83,6 +83,15 @@ const TokenType = {
|
|||||||
EOF: 6
|
EOF: 6
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, string>}
|
||||||
|
*/
|
||||||
|
const WKTGeometryType = {};
|
||||||
|
for (const type in GeometryType) {
|
||||||
|
WKTGeometryType[type] = GeometryType[type].toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to tokenize a WKT string.
|
* Class to tokenize a WKT string.
|
||||||
@@ -533,7 +542,7 @@ class Parser {
|
|||||||
if (this.match(TokenType.TEXT)) {
|
if (this.match(TokenType.TEXT)) {
|
||||||
const geomType = token.value;
|
const geomType = token.value;
|
||||||
this.layout_ = this.parseGeometryLayout_();
|
this.layout_ = this.parseGeometryLayout_();
|
||||||
if (geomType == GeometryType.GEOMETRY_COLLECTION.toUpperCase()) {
|
if (geomType == 'GEOMETRYCOLLECTION') {
|
||||||
const geometries = this.parseGeometryCollectionText_();
|
const geometries = this.parseGeometryCollectionText_();
|
||||||
return new GeometryCollection(geometries);
|
return new GeometryCollection(geometries);
|
||||||
} else {
|
} else {
|
||||||
@@ -544,28 +553,28 @@ class Parser {
|
|||||||
|
|
||||||
let coordinates;
|
let coordinates;
|
||||||
switch (geomType) {
|
switch (geomType) {
|
||||||
case GeometryType.POINT: {
|
case 'POINT': {
|
||||||
coordinates = this.parsePointText_();
|
coordinates = this.parsePointText_();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GeometryType.LINESTRING: {
|
case 'LINESTRING': {
|
||||||
coordinates = this.parseLineStringText_();
|
coordinates = this.parseLineStringText_();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GeometryType.POLYGON: {
|
case 'POLYGON': {
|
||||||
coordinates = Parser.prototype.parsePolygonText_();
|
coordinates = this.parsePolygonText_();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GeometryType.MULTIPOINT: {
|
case 'MULTIPOINT': {
|
||||||
coordinates = Parser.prototype.parseMultiPointText_();
|
coordinates = this.parseMultiPointText_();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GeometryType.MULTILINESTRING: {
|
case 'MULTILINESTRING': {
|
||||||
coordinates = Parser.prototype.parseMultiLineStringText_();
|
coordinates = this.parseMultiLineStringText_();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GeometryType.MULTIPOLYGON: {
|
case 'MULTIPOLYGON': {
|
||||||
coordinates = Parser.prototype.parseMultiPolygonText_();
|
coordinates = this.parseMultiPolygonText_();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -574,7 +583,7 @@ class Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!coordinates) {
|
if (!coordinates) {
|
||||||
if (ctor === GeometryConstructor[GeometryType.POINT]) {
|
if (ctor === GeometryConstructor['POINT']) {
|
||||||
coordinates = [NaN, NaN];
|
coordinates = [NaN, NaN];
|
||||||
} else {
|
} else {
|
||||||
coordinates = [];
|
coordinates = [];
|
||||||
|
|||||||
@@ -710,8 +710,14 @@ describe('ol.format.WKT', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Empty geometries read / written correctly', function() {
|
it('Empty geometries read / written correctly', function() {
|
||||||
|
const wkt = 'POINT EMPTY';
|
||||||
|
const geom = format.readGeometry(wkt);
|
||||||
|
const coordinates = geom.getCoordinates();
|
||||||
|
expect(coordinates.length).to.be(2);
|
||||||
|
expect(isNaN(coordinates[0])).to.be(true);
|
||||||
|
expect(isNaN(coordinates[1])).to.be(true);
|
||||||
const wkts = [
|
const wkts = [
|
||||||
'POINT', 'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON'
|
'LINESTRING', 'POLYGON', 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON'
|
||||||
];
|
];
|
||||||
for (let i = 0, ii = wkts.length; i < ii; ++i) {
|
for (let i = 0, ii = wkts.length; i < ii; ++i) {
|
||||||
const wkt = wkts[i] + ' EMPTY';
|
const wkt = wkts[i] + ' EMPTY';
|
||||||
|
|||||||
Reference in New Issue
Block a user