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

@@ -2,7 +2,6 @@
* @module ol/View
*/
import BaseObject from './Object.js';
import GeometryType from './geom/GeometryType.js';
import Units from './proj/Units.js';
import ViewHint from './ViewHint.js';
import ViewProperty from './ViewProperty.js';
@@ -1345,7 +1344,7 @@ class View extends BaseObject {
assert(!isEmpty(geometryOrExtent), 25); // Cannot fit empty extent provided as `geometry`
const extent = fromUserExtent(geometryOrExtent, this.getProjection());
geometry = polygonFromExtent(extent);
} else if (geometryOrExtent.getType() === GeometryType.CIRCLE) {
} else if (geometryOrExtent.getType() === 'Circle') {
const extent = fromUserExtent(
geometryOrExtent.getExtent(),
this.getProjection()

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});
}
}

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)
);

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: [],

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';
}
});
}

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.
}

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) {

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;

View File

@@ -1,7 +1,6 @@
/**
* @module ol/geom/Circle
*/
import GeometryType from './GeometryType.js';
import SimpleGeometry from './SimpleGeometry.js';
import {createOrUpdate, forEachCorner, intersects} from '../extent.js';
import {deflateCoordinate} from './flat/deflate.js';
@@ -137,11 +136,11 @@ class Circle extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.CIRCLE;
return 'Circle';
}
/**

View File

@@ -18,6 +18,13 @@ import {get as getProjection, getTransform} from '../proj.js';
import {memoizeOne} from '../functions.js';
import {transform2D} from './flat/transform.js';
/**
* @typedef {'Point' | 'LineString' | 'LinearRing' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection' | 'Circle'} Type
* The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`,
* `'Polygon'`, `'MultiPoint'`, `'MultiLineString'`, `'MultiPolygon'`,
* `'GeometryCollection'`, or `'Circle'`.
*/
/**
* @type {import("../transform.js").Transform}
*/
@@ -237,7 +244,7 @@ class Geometry extends BaseObject {
/**
* Get the type of this geometry.
* @abstract
* @return {import("./GeometryType.js").default} Geometry type.
* @return {Type} Geometry type.
*/
getType() {
return abstract();

View File

@@ -3,7 +3,6 @@
*/
import EventType from '../events/EventType.js';
import Geometry from './Geometry.js';
import GeometryType from './GeometryType.js';
import {
closestSquaredDistanceXY,
createOrUpdateEmpty,
@@ -204,11 +203,11 @@ class GeometryCollection extends Geometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.GEOMETRY_COLLECTION;
return 'GeometryCollection';
}
/**

View File

@@ -1,21 +0,0 @@
/**
* @module ol/geom/GeometryType
*/
/**
* The geometry type. One of `'Point'`, `'LineString'`, `'LinearRing'`,
* `'Polygon'`, `'MultiPoint'`, `'MultiLineString'`, `'MultiPolygon'`,
* `'GeometryCollection'`, `'Circle'`.
* @enum {string}
*/
export default {
POINT: 'Point',
LINE_STRING: 'LineString',
LINEAR_RING: 'LinearRing',
POLYGON: 'Polygon',
MULTI_POINT: 'MultiPoint',
MULTI_LINE_STRING: 'MultiLineString',
MULTI_POLYGON: 'MultiPolygon',
GEOMETRY_COLLECTION: 'GeometryCollection',
CIRCLE: 'Circle',
};

View File

@@ -2,7 +2,6 @@
* @module ol/geom/LineString
*/
import GeometryLayout from './GeometryLayout.js';
import GeometryType from './GeometryType.js';
import SimpleGeometry from './SimpleGeometry.js';
import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js';
import {closestSquaredDistanceXY} from '../extent.js';
@@ -269,11 +268,11 @@ class LineString extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.LINE_STRING;
return 'LineString';
}
/**

View File

@@ -2,7 +2,6 @@
* @module ol/geom/LinearRing
*/
import GeometryLayout from './GeometryLayout.js';
import GeometryType from './GeometryType.js';
import SimpleGeometry from './SimpleGeometry.js';
import {assignClosestPoint, maxSquaredDelta} from './flat/closest.js';
import {closestSquaredDistanceXY} from '../extent.js';
@@ -149,11 +148,11 @@ class LinearRing extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.LINEAR_RING;
return 'LinearRing';
}
/**

View File

@@ -2,7 +2,6 @@
* @module ol/geom/MultiLineString
*/
import GeometryLayout from './GeometryLayout.js';
import GeometryType from './GeometryType.js';
import LineString from './LineString.js';
import SimpleGeometry from './SimpleGeometry.js';
import {arrayMaxSquaredDelta, assignClosestArrayPoint} from './flat/closest.js';
@@ -308,11 +307,11 @@ class MultiLineString extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.MULTI_LINE_STRING;
return 'MultiLineString';
}
/**

View File

@@ -1,7 +1,6 @@
/**
* @module ol/geom/MultiPoint
*/
import GeometryType from './GeometryType.js';
import Point from './Point.js';
import SimpleGeometry from './SimpleGeometry.js';
import {closestSquaredDistanceXY, containsXY} from '../extent.js';
@@ -154,11 +153,11 @@ class MultiPoint extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.MULTI_POINT;
return 'MultiPoint';
}
/**

View File

@@ -2,7 +2,6 @@
* @module ol/geom/MultiPolygon
*/
import GeometryLayout from './GeometryLayout.js';
import GeometryType from './GeometryType.js';
import MultiPoint from './MultiPoint.js';
import Polygon from './Polygon.js';
import SimpleGeometry from './SimpleGeometry.js';
@@ -425,11 +424,11 @@ class MultiPolygon extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.MULTI_POLYGON;
return 'MultiPolygon';
}
/**

View File

@@ -1,7 +1,6 @@
/**
* @module ol/geom/Point
*/
import GeometryType from './GeometryType.js';
import SimpleGeometry from './SimpleGeometry.js';
import {containsXY, createOrUpdateFromCoordinate} from '../extent.js';
import {deflateCoordinate} from './flat/deflate.js';
@@ -81,11 +80,11 @@ class Point extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.POINT;
return 'Point';
}
/**

View File

@@ -2,7 +2,6 @@
* @module ol/geom/Polygon
*/
import GeometryLayout from './GeometryLayout.js';
import GeometryType from './GeometryType.js';
import LinearRing from './LinearRing.js';
import Point from './Point.js';
import SimpleGeometry from './SimpleGeometry.js';
@@ -363,11 +362,11 @@ class Polygon extends SimpleGeometry {
/**
* Get the type of this geometry.
* @return {import("./GeometryType.js").default} Geometry type.
* @return {import("./Geometry.js").Type} Geometry type.
* @api
*/
getType() {
return GeometryType.POLYGON;
return 'Polygon';
}
/**

View File

@@ -6,7 +6,6 @@ import Event from '../events/Event.js';
import EventType from '../events/EventType.js';
import Feature from '../Feature.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js';
import InteractionProperty from './Property.js';
import LineString from '../geom/LineString.js';
import MapBrowserEvent from '../MapBrowserEvent.js';
@@ -35,7 +34,7 @@ import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
/**
* @typedef {Object} Options
* @property {import("../geom/GeometryType.js").default} type Geometry type of
* @property {import("../geom/Geometry.js").Type} type Geometry type of
* the geometries being drawn with this instance.
* @property {number} [clickTolerance=6] The maximum distance in pixels between
* "down" and "up" for a "up" event to be considered a "click" event and
@@ -282,10 +281,10 @@ class Draw extends PointerInteraction {
/**
* Geometry type.
* @type {import("../geom/GeometryType.js").default}
* @type {import("../geom/Geometry.js").Type}
* @private
*/
this.type_ = /** @type {import("../geom/GeometryType.js").default} */ (
this.type_ = /** @type {import("../geom/Geometry.js").Type} */ (
options.type
);
@@ -890,10 +889,7 @@ class Draw extends PointerInteraction {
const sketchPointGeom = this.sketchPoint_.getGeometry();
sketchPointGeom.setCoordinates(coordinate);
}
if (
geometry.getType() === GeometryType.POLYGON &&
this.mode_ !== Mode.POLYGON
) {
if (geometry.getType() === 'Polygon' && this.mode_ !== Mode.POLYGON) {
this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry));
} else if (this.sketchLineCoords_) {
const sketchLineGeom = this.sketchLine_.getGeometry();
@@ -970,7 +966,7 @@ class Draw extends PointerInteraction {
this.createOrUpdateSketchPoint_(finishCoordinate);
}
this.geometryFunction_(coordinates, geometry, projection);
if (geometry.getType() === GeometryType.POLYGON && this.sketchLine_) {
if (geometry.getType() === 'Polygon' && this.sketchLine_) {
this.createOrUpdateCustomSketchLine_(/** @type {Polygon} */ (geometry));
}
} else if (mode === Mode.POLYGON) {
@@ -1019,15 +1015,15 @@ class Draw extends PointerInteraction {
}
// cast multi-part geometries
if (this.type_ === GeometryType.MULTI_POINT) {
if (this.type_ === 'MultiPoint') {
sketchFeature.setGeometry(
new MultiPoint([/** @type {PointCoordType} */ (coordinates)])
);
} else if (this.type_ === GeometryType.MULTI_LINE_STRING) {
} else if (this.type_ === 'MultiLineString') {
sketchFeature.setGeometry(
new MultiLineString([/** @type {LineCoordType} */ (coordinates)])
);
} else if (this.type_ === GeometryType.MULTI_POLYGON) {
} else if (this.type_ === 'MultiPolygon') {
sketchFeature.setGeometry(
new MultiPolygon([/** @type {PolyCoordType} */ (coordinates)])
);
@@ -1274,21 +1270,21 @@ export function createBox() {
/**
* Get the drawing mode. The mode for multi-part geometries is the same as for
* their single-part cousins.
* @param {import("../geom/GeometryType.js").default} type Geometry type.
* @param {import("../geom/Geometry.js").Type} type Geometry type.
* @return {Mode} Drawing mode.
*/
function getMode(type) {
switch (type) {
case GeometryType.POINT:
case GeometryType.MULTI_POINT:
case 'Point':
case 'MultiPoint':
return Mode.POINT;
case GeometryType.LINE_STRING:
case GeometryType.MULTI_LINE_STRING:
case 'LineString':
case 'MultiLineString':
return Mode.LINE_STRING;
case GeometryType.POLYGON:
case GeometryType.MULTI_POLYGON:
case 'Polygon':
case 'MultiPolygon':
return Mode.POLYGON;
case GeometryType.CIRCLE:
case 'Circle':
return Mode.CIRCLE;
default:
throw new Error('Invalid type: ' + type);

View File

@@ -3,7 +3,6 @@
*/
import Event from '../events/Event.js';
import Feature from '../Feature.js';
import GeometryType from '../geom/GeometryType.js';
import MapBrowserEventType from '../MapBrowserEventType.js';
import Point from '../geom/Point.js';
import PointerInteraction from './Pointer.js';
@@ -478,7 +477,7 @@ class Extent extends PointerInteraction {
function getDefaultExtentStyleFunction() {
const style = createEditingStyle();
return function (feature, resolution) {
return style[GeometryType.POLYGON];
return style['Polygon'];
};
}
@@ -490,7 +489,7 @@ function getDefaultExtentStyleFunction() {
function getDefaultPointerStyleFunction() {
const style = createEditingStyle();
return function (feature, resolution) {
return style[GeometryType.POINT];
return style['Point'];
};
}

View File

@@ -6,7 +6,6 @@ import CollectionEventType from '../CollectionEventType.js';
import Event from '../events/Event.js';
import EventType from '../events/EventType.js';
import Feature from '../Feature.js';
import GeometryType from '../geom/GeometryType.js';
import MapBrowserEventType from '../MapBrowserEventType.js';
import Point from '../geom/Point.js';
import PointerInteraction from './Pointer.js';
@@ -905,38 +904,38 @@ class Modify extends PointerInteraction {
}
switch (geometry.getType()) {
case GeometryType.POINT:
case 'Point':
coordinates = vertex;
segment[0] = vertex;
segment[1] = vertex;
break;
case GeometryType.MULTI_POINT:
case 'MultiPoint':
coordinates = geometry.getCoordinates();
coordinates[segmentData.index] = vertex;
segment[0] = vertex;
segment[1] = vertex;
break;
case GeometryType.LINE_STRING:
case 'LineString':
coordinates = geometry.getCoordinates();
coordinates[segmentData.index + index] = vertex;
segment[index] = vertex;
break;
case GeometryType.MULTI_LINE_STRING:
case 'MultiLineString':
coordinates = geometry.getCoordinates();
coordinates[depth[0]][segmentData.index + index] = vertex;
segment[index] = vertex;
break;
case GeometryType.POLYGON:
case 'Polygon':
coordinates = geometry.getCoordinates();
coordinates[depth[0]][segmentData.index + index] = vertex;
segment[index] = vertex;
break;
case GeometryType.MULTI_POLYGON:
case 'MultiPolygon':
coordinates = geometry.getCoordinates();
coordinates[depth[1]][depth[0]][segmentData.index + index] = vertex;
segment[index] = vertex;
break;
case GeometryType.CIRCLE:
case 'Circle':
segment[0] = vertex;
segment[1] = vertex;
if (segmentData.index === CIRCLE_CENTER_INDEX) {
@@ -1011,7 +1010,7 @@ class Modify extends PointerInteraction {
}
if (
segmentDataMatch.geometry.getType() === GeometryType.CIRCLE &&
segmentDataMatch.geometry.getType() === 'Circle' &&
segmentDataMatch.index === CIRCLE_CIRCUMFERENCE_INDEX
) {
const closestVertex = closestOnSegmentData(
@@ -1049,15 +1048,15 @@ class Modify extends PointerInteraction {
let coordinates = segmentDataMatch.geometry.getCoordinates();
switch (segmentDataMatch.geometry.getType()) {
// prevent dragging closed linestrings by the connecting node
case GeometryType.LINE_STRING:
case GeometryType.MULTI_LINE_STRING:
case 'LineString':
case 'MultiLineString':
continue;
// if dragging the first vertex of a polygon, ensure the other segment
// belongs to the closing vertex of the linear ring
case GeometryType.MULTI_POLYGON:
case 'MultiPolygon':
coordinates = coordinates[depth[1]];
/* falls through */
case GeometryType.POLYGON:
case 'Polygon':
if (
segmentDataMatch.index !==
coordinates[depth[0]].length - 2
@@ -1105,7 +1104,7 @@ class Modify extends PointerInteraction {
for (let i = this.dragSegments_.length - 1; i >= 0; --i) {
const segmentData = this.dragSegments_[i][0];
const geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE) {
if (geometry.getType() === 'Circle') {
// Update a circle object in the R* bush:
const coordinates = geometry.getCenter();
const centerSegmentData = segmentData.featureSegments[0];
@@ -1190,7 +1189,7 @@ class Modify extends PointerInteraction {
feature.getGeometry()
);
if (
geometry.getType() === GeometryType.POINT &&
geometry.getType() === 'Point' &&
includes(this.features_.getArray(), feature)
) {
hitPointGeometry = geometry;
@@ -1237,7 +1236,7 @@ class Modify extends PointerInteraction {
this.delta_[1] = vertex[1] - pixelCoordinate[1];
}
if (
node.geometry.getType() === GeometryType.CIRCLE &&
node.geometry.getType() === 'Circle' &&
node.index === CIRCLE_CIRCUMFERENCE_INDEX
) {
this.snappedToVertex_ = true;
@@ -1313,19 +1312,19 @@ class Modify extends PointerInteraction {
}
switch (geometry.getType()) {
case GeometryType.MULTI_LINE_STRING:
case 'MultiLineString':
coordinates = geometry.getCoordinates();
coordinates[depth[0]].splice(index + 1, 0, vertex);
break;
case GeometryType.POLYGON:
case 'Polygon':
coordinates = geometry.getCoordinates();
coordinates[depth[0]].splice(index + 1, 0, vertex);
break;
case GeometryType.MULTI_POLYGON:
case 'MultiPolygon':
coordinates = geometry.getCoordinates();
coordinates[depth[1]][depth[0]].splice(index + 1, 0, vertex);
break;
case GeometryType.LINE_STRING:
case 'LineString':
coordinates = geometry.getCoordinates();
coordinates.splice(index + 1, 0, vertex);
break;
@@ -1441,22 +1440,22 @@ class Modify extends PointerInteraction {
component = coordinates;
deleted = false;
switch (geometry.getType()) {
case GeometryType.MULTI_LINE_STRING:
case 'MultiLineString':
if (coordinates[segmentData.depth[0]].length > 2) {
coordinates[segmentData.depth[0]].splice(index, 1);
deleted = true;
}
break;
case GeometryType.LINE_STRING:
case 'LineString':
if (coordinates.length > 2) {
coordinates.splice(index, 1);
deleted = true;
}
break;
case GeometryType.MULTI_POLYGON:
case 'MultiPolygon':
component = component[segmentData.depth[1]];
/* falls through */
case GeometryType.POLYGON:
case 'Polygon':
component = component[segmentData.depth[0]];
if (component.length > 4) {
if (index == component.length - 1) {
@@ -1575,7 +1574,7 @@ function projectedDistanceToSegmentDataSquared(
) {
const geometry = segmentData.geometry;
if (geometry.getType() === GeometryType.CIRCLE) {
if (geometry.getType() === 'Circle') {
let circleGeometry = /** @type {import("../geom/Circle.js").default} */ (
geometry
);
@@ -1617,7 +1616,7 @@ function closestOnSegmentData(pointCoordinates, segmentData, projection) {
const geometry = segmentData.geometry;
if (
geometry.getType() === GeometryType.CIRCLE &&
geometry.getType() === 'Circle' &&
segmentData.index === CIRCLE_CIRCUMFERENCE_INDEX
) {
let circleGeometry = /** @type {import("../geom/Circle.js").default} */ (
@@ -1651,7 +1650,7 @@ function closestOnSegmentData(pointCoordinates, segmentData, projection) {
function getDefaultStyleFunction() {
const style = createEditingStyle();
return function (feature, resolution) {
return style[GeometryType.POINT];
return style['Point'];
};
}

View File

@@ -4,7 +4,6 @@
import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js';
import Event from '../events/Event.js';
import GeometryType from '../geom/GeometryType.js';
import Interaction from './Interaction.js';
import VectorLayer from '../layer/Vector.js';
import {TRUE} from '../functions.js';
@@ -569,11 +568,8 @@ class Select extends Interaction {
*/
function getDefaultStyleFunction() {
const styles = createEditingStyle();
extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]);
extend(
styles[GeometryType.GEOMETRY_COLLECTION],
styles[GeometryType.LINE_STRING]
);
extend(styles['Polygon'], styles['LineString']);
extend(styles['GeometryCollection'], styles['LineString']);
return function (feature) {
if (!feature.getGeometry()) {

View File

@@ -3,7 +3,6 @@
*/
import CollectionEventType from '../CollectionEventType.js';
import EventType from '../events/EventType.js';
import GeometryType from '../geom/GeometryType.js';
import PointerInteraction from './Pointer.js';
import RBush from '../structs/RBush.js';
import VectorEventType from '../source/VectorEventType.js';

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,
MultiLineString,
@@ -45,7 +44,7 @@ const tmpTransform = createTransform();
*/
class RenderFeature {
/**
* @param {import("../geom/GeometryType.js").default} type Geometry type.
* @param {import("../geom/Geometry.js").Type} type Geometry type.
* @param {Array<number>} flatCoordinates Flat coordinates. These always need
* to be right-handed for polygons.
* @param {Array<number>|Array<Array<number>>} ends Ends or Endss.
@@ -72,7 +71,7 @@ class RenderFeature {
/**
* @private
* @type {import("../geom/GeometryType.js").default}
* @type {import("../geom/Geometry.js").Type}
*/
this.type_ = type;
@@ -125,7 +124,7 @@ class RenderFeature {
getExtent() {
if (!this.extent_) {
this.extent_ =
this.type_ === GeometryType.POINT
this.type_ === 'Point'
? createOrUpdateFromCoordinate(this.flatCoordinates_)
: createOrUpdateFromFlatCoordinates(
this.flatCoordinates_,
@@ -283,7 +282,7 @@ class RenderFeature {
/**
* Get the type of this feature's geometry.
* @return {import("../geom/GeometryType.js").default} Geometry type.
* @return {import("../geom/Geometry.js").Type} Geometry type.
* @api
*/
getType() {

View File

@@ -2,7 +2,6 @@
* @module ol/render/canvas/Builder
*/
import CanvasInstruction from './Instruction.js';
import GeometryType from '../../geom/GeometryType.js';
import Relationship from '../../extent/Relationship.js';
import VectorContext from '../VectorContext.js';
import {asColorLike} from '../../colorlike.js';
@@ -260,7 +259,7 @@ class CanvasBuilder extends VectorContext {
let offset;
switch (type) {
case GeometryType.MULTI_POLYGON:
case 'MultiPolygon':
flatCoordinates =
/** @type {import("../../geom/MultiPolygon.js").default} */ (
geometry
@@ -299,11 +298,11 @@ class CanvasBuilder extends VectorContext {
inflateMultiCoordinatesArray,
]);
break;
case GeometryType.POLYGON:
case GeometryType.MULTI_LINE_STRING:
case 'Polygon':
case 'MultiLineString':
builderEnds = [];
flatCoordinates =
type == GeometryType.POLYGON
type == 'Polygon'
? /** @type {import("../../geom/Polygon.js").default} */ (
geometry
).getOrientedFlatCoordinates()
@@ -334,8 +333,8 @@ class CanvasBuilder extends VectorContext {
inflateCoordinatesArray,
]);
break;
case GeometryType.LINE_STRING:
case GeometryType.CIRCLE:
case 'LineString':
case 'Circle':
flatCoordinates = geometry.getFlatCoordinates();
builderEnd = this.appendFlatLineCoordinates(
flatCoordinates,
@@ -362,7 +361,7 @@ class CanvasBuilder extends VectorContext {
inflateCoordinates,
]);
break;
case GeometryType.MULTI_POINT:
case 'MultiPoint':
flatCoordinates = geometry.getFlatCoordinates();
builderEnd = this.appendFlatPointCoordinates(flatCoordinates, stride);
@@ -385,7 +384,7 @@ class CanvasBuilder extends VectorContext {
]);
}
break;
case GeometryType.POINT:
case 'Point':
flatCoordinates = geometry.getFlatCoordinates();
this.coordinates.push(flatCoordinates[0], flatCoordinates[1]);
builderEnd = this.coordinates.length;

View File

@@ -5,7 +5,6 @@
// FIXME need to handle large thick features (where pixel size matters)
// FIXME add offset and end to ol/geom/flat/transform~transform2D?
import GeometryType from '../../geom/GeometryType.js';
import VectorContext from '../VectorContext.js';
import {asColorLike} from '../../colorlike.js';
import {
@@ -549,46 +548,46 @@ class CanvasImmediateRenderer extends VectorContext {
drawGeometry(geometry) {
const type = geometry.getType();
switch (type) {
case GeometryType.POINT:
case 'Point':
this.drawPoint(
/** @type {import("../../geom/Point.js").default} */ (geometry)
);
break;
case GeometryType.LINE_STRING:
case 'LineString':
this.drawLineString(
/** @type {import("../../geom/LineString.js").default} */ (geometry)
);
break;
case GeometryType.POLYGON:
case 'Polygon':
this.drawPolygon(
/** @type {import("../../geom/Polygon.js").default} */ (geometry)
);
break;
case GeometryType.MULTI_POINT:
case 'MultiPoint':
this.drawMultiPoint(
/** @type {import("../../geom/MultiPoint.js").default} */ (geometry)
);
break;
case GeometryType.MULTI_LINE_STRING:
case 'MultiLineString':
this.drawMultiLineString(
/** @type {import("../../geom/MultiLineString.js").default} */ (
geometry
)
);
break;
case GeometryType.MULTI_POLYGON:
case 'MultiPolygon':
this.drawMultiPolygon(
/** @type {import("../../geom/MultiPolygon.js").default} */ (geometry)
);
break;
case GeometryType.GEOMETRY_COLLECTION:
case 'GeometryCollection':
this.drawGeometryCollection(
/** @type {import("../../geom/GeometryCollection.js").default} */ (
geometry
)
);
break;
case GeometryType.CIRCLE:
case 'Circle':
this.drawCircle(
/** @type {import("../../geom/Circle.js").default} */ (geometry)
);

View File

@@ -3,7 +3,6 @@
*/
import CanvasBuilder from './Builder.js';
import CanvasInstruction from './Instruction.js';
import GeometryType from '../../geom/GeometryType.js';
import TextPlacement from '../../style/TextPlacement.js';
import {asColorLike} from '../../colorlike.js';
import {
@@ -179,27 +178,27 @@ class CanvasTextBuilder extends CanvasBuilder {
if (
textState.placement === TextPlacement.LINE &&
(geometryType == GeometryType.LINE_STRING ||
geometryType == GeometryType.MULTI_LINE_STRING ||
geometryType == GeometryType.POLYGON ||
geometryType == GeometryType.MULTI_POLYGON)
(geometryType == 'LineString' ||
geometryType == 'MultiLineString' ||
geometryType == 'Polygon' ||
geometryType == 'MultiPolygon')
) {
if (!intersects(this.getBufferedMaxExtent(), geometry.getExtent())) {
return;
}
let ends;
flatCoordinates = geometry.getFlatCoordinates();
if (geometryType == GeometryType.LINE_STRING) {
if (geometryType == 'LineString') {
ends = [flatCoordinates.length];
} else if (geometryType == GeometryType.MULTI_LINE_STRING) {
} else if (geometryType == 'MultiLineString') {
ends = /** @type {import("../../geom/MultiLineString.js").default} */ (
geometry
).getEnds();
} else if (geometryType == GeometryType.POLYGON) {
} else if (geometryType == 'Polygon') {
ends = /** @type {import("../../geom/Polygon.js").default} */ (geometry)
.getEnds()
.slice(0, 1);
} else if (geometryType == GeometryType.MULTI_POLYGON) {
} else if (geometryType == 'MultiPolygon') {
const endss =
/** @type {import("../../geom/MultiPolygon.js").default} */ (
geometry
@@ -240,33 +239,33 @@ class CanvasTextBuilder extends CanvasBuilder {
} else {
let geometryWidths = textState.overflow ? null : [];
switch (geometryType) {
case GeometryType.POINT:
case GeometryType.MULTI_POINT:
case 'Point':
case 'MultiPoint':
flatCoordinates =
/** @type {import("../../geom/MultiPoint.js").default} */ (
geometry
).getFlatCoordinates();
break;
case GeometryType.LINE_STRING:
case 'LineString':
flatCoordinates =
/** @type {import("../../geom/LineString.js").default} */ (
geometry
).getFlatMidpoint();
break;
case GeometryType.CIRCLE:
case 'Circle':
flatCoordinates =
/** @type {import("../../geom/Circle.js").default} */ (
geometry
).getCenter();
break;
case GeometryType.MULTI_LINE_STRING:
case 'MultiLineString':
flatCoordinates =
/** @type {import("../../geom/MultiLineString.js").default} */ (
geometry
).getFlatMidpoints();
stride = 2;
break;
case GeometryType.POLYGON:
case 'Polygon':
flatCoordinates =
/** @type {import("../../geom/Polygon.js").default} */ (
geometry
@@ -276,7 +275,7 @@ class CanvasTextBuilder extends CanvasBuilder {
}
stride = 3;
break;
case GeometryType.MULTI_POLYGON:
case 'MultiPolygon':
const interiorPoints =
/** @type {import("../../geom/MultiPolygon.js").default} */ (
geometry

View File

@@ -3,7 +3,6 @@
*/
import CanvasImmediateRenderer from './Immediate.js';
import GeometryType from '../../geom/GeometryType.js';
import IconAnchorUnits from '../../style/IconAnchorUnits.js';
import {Icon} from '../../style.js';
import {clamp} from '../../math.js';
@@ -121,10 +120,10 @@ export function createHitDetectionImageData(
if (!byGeometryType) {
byGeometryType = {};
featuresByZIndex[zIndex] = byGeometryType;
byGeometryType[GeometryType.POLYGON] = [];
byGeometryType[GeometryType.CIRCLE] = [];
byGeometryType[GeometryType.LINE_STRING] = [];
byGeometryType[GeometryType.POINT] = [];
byGeometryType['Polygon'] = [];
byGeometryType['Circle'] = [];
byGeometryType['LineString'] = [];
byGeometryType['Point'] = [];
}
byGeometryType[geometry.getType().replace('Multi', '')].push(
geometry,

View File

@@ -2,7 +2,6 @@
* @module ol/renderer/vector
*/
import BuilderType from '../render/canvas/BuilderType.js';
import GeometryType from '../geom/GeometryType.js';
import ImageState from '../ImageState.js';
import {getUid} from '../util.js';
@@ -24,7 +23,7 @@ const SIMPLIFY_TOLERANCE = 0.5;
/**
* @const
* @type {Object<import("../geom/GeometryType.js").default,
* @type {Object<import("../geom/Geometry.js").Type,
* function(import("../render/canvas/BuilderGroup.js").default, import("../geom/Geometry.js").default,
* import("../style/Style.js").default, Object): void>}
*/
@@ -193,7 +192,7 @@ function renderFeatureInternal(
* @param {import("../Feature.js").FeatureLike} feature Feature.
*/
function renderGeometry(replayGroup, geometry, style, feature) {
if (geometry.getType() == GeometryType.GEOMETRY_COLLECTION) {
if (geometry.getType() == 'GeometryCollection') {
const geometries =
/** @type {import("../geom/GeometryCollection.js").default} */ (
geometry

View File

@@ -2,7 +2,6 @@
* @module ol/renderer/webgl/PointsLayer
*/
import BaseVector from '../../layer/BaseVector.js';
import GeometryType from '../../geom/GeometryType.js';
import VectorEventType from '../../source/VectorEventType.js';
import ViewHint from '../../ViewHint.js';
import WebGLArrayBuffer from '../../webgl/Buffer.js';
@@ -599,7 +598,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
geometry = /** @type {import("../../geom").Point} */ (
featureCache.geometry
);
if (!geometry || geometry.getType() !== GeometryType.POINT) {
if (!geometry || geometry.getType() !== 'Point') {
continue;
}

View File

@@ -4,7 +4,6 @@
import EventType from '../events/EventType.js';
import Feature from '../Feature.js';
import GeometryType from '../geom/GeometryType.js';
import Point from '../geom/Point.js';
import VectorSource from './Vector.js';
import {add as addCoordinate, scale as scaleCoordinate} from '../coordinate.js';
@@ -116,7 +115,7 @@ class Cluster extends VectorSource {
options.geometryFunction ||
function (feature) {
const geometry = /** @type {Point} */ (feature.getGeometry());
assert(geometry.getType() == GeometryType.POINT, 10); // The default `geometryFunction` can only handle `Point` geometries
assert(geometry.getType() == 'Point', 10); // The default `geometryFunction` can only handle `Point` geometries
return geometry;
};

View File

@@ -1,7 +1,6 @@
/**
* @module ol/sphere
*/
import GeometryType from './geom/GeometryType.js';
import {toDegrees, toRadians} from './math.js';
/**
@@ -78,26 +77,26 @@ export function getLength(geometry, opt_options) {
const radius = options.radius || DEFAULT_RADIUS;
const projection = options.projection || 'EPSG:3857';
const type = geometry.getType();
if (type !== GeometryType.GEOMETRY_COLLECTION) {
if (type !== 'GeometryCollection') {
geometry = geometry.clone().transform(projection, 'EPSG:4326');
}
let length = 0;
let coordinates, coords, i, ii, j, jj;
switch (type) {
case GeometryType.POINT:
case GeometryType.MULTI_POINT: {
case 'Point':
case 'MultiPoint': {
break;
}
case GeometryType.LINE_STRING:
case GeometryType.LINEAR_RING: {
case 'LineString':
case 'LinearRing': {
coordinates = /** @type {import("./geom/SimpleGeometry.js").default} */ (
geometry
).getCoordinates();
length = getLengthInternal(coordinates, radius);
break;
}
case GeometryType.MULTI_LINE_STRING:
case GeometryType.POLYGON: {
case 'MultiLineString':
case 'Polygon': {
coordinates = /** @type {import("./geom/SimpleGeometry.js").default} */ (
geometry
).getCoordinates();
@@ -106,7 +105,7 @@ export function getLength(geometry, opt_options) {
}
break;
}
case GeometryType.MULTI_POLYGON: {
case 'MultiPolygon': {
coordinates = /** @type {import("./geom/SimpleGeometry.js").default} */ (
geometry
).getCoordinates();
@@ -118,7 +117,7 @@ export function getLength(geometry, opt_options) {
}
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
case 'GeometryCollection': {
const geometries =
/** @type {import("./geom/GeometryCollection.js").default} */ (
geometry
@@ -181,20 +180,20 @@ export function getArea(geometry, opt_options) {
const radius = options.radius || DEFAULT_RADIUS;
const projection = options.projection || 'EPSG:3857';
const type = geometry.getType();
if (type !== GeometryType.GEOMETRY_COLLECTION) {
if (type !== 'GeometryCollection') {
geometry = geometry.clone().transform(projection, 'EPSG:4326');
}
let area = 0;
let coordinates, coords, i, ii, j, jj;
switch (type) {
case GeometryType.POINT:
case GeometryType.MULTI_POINT:
case GeometryType.LINE_STRING:
case GeometryType.MULTI_LINE_STRING:
case GeometryType.LINEAR_RING: {
case 'Point':
case 'MultiPoint':
case 'LineString':
case 'MultiLineString':
case 'LinearRing': {
break;
}
case GeometryType.POLYGON: {
case 'Polygon': {
coordinates = /** @type {import("./geom/Polygon.js").default} */ (
geometry
).getCoordinates();
@@ -204,7 +203,7 @@ export function getArea(geometry, opt_options) {
}
break;
}
case GeometryType.MULTI_POLYGON: {
case 'MultiPolygon': {
coordinates = /** @type {import("./geom/SimpleGeometry.js").default} */ (
geometry
).getCoordinates();
@@ -217,7 +216,7 @@ export function getArea(geometry, opt_options) {
}
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
case 'GeometryCollection': {
const geometries =
/** @type {import("./geom/GeometryCollection.js").default} */ (
geometry

View File

@@ -4,7 +4,6 @@
import CircleStyle from './Circle.js';
import Fill from './Fill.js';
import GeometryType from '../geom/GeometryType.js';
import Stroke from './Stroke.js';
import {assert} from '../asserts.js';
@@ -89,23 +88,22 @@ import {assert} from '../asserts.js';
*
* A separate editing style has the following defaults:
* ```js
* import GeometryType from 'ol/geom/GeometryType';
* import {Circle, Fill, Stroke, Style} from 'ol/style';
*
* const styles = {};
* const white = [255, 255, 255, 1];
* const blue = [0, 153, 255, 1];
* const width = 3;
* styles[GeometryType.POLYGON] = [
* styles['Polygon'] = [
* new Style({
* fill: new Fill({
* color: [255, 255, 255, 0.5],
* }),
* }),
* ];
* styles[GeometryType.MULTI_POLYGON] = styles[GeometryType.POLYGON];
*
* styles[GeometryType.LINE_STRING] = [
* styles['MultiPolygon'] =
* styles['Polygon'];
* styles['LineString'] = [
* new Style({
* stroke: new Stroke({
* color: white,
@@ -119,13 +117,13 @@ import {assert} from '../asserts.js';
* }),
* }),
* ];
* styles[GeometryType.MULTI_LINE_STRING] = styles[GeometryType.LINE_STRING];
* styles['MultiLineString'] = styles['LineString'];
*
* styles[GeometryType.CIRCLE] = styles[GeometryType.POLYGON].concat(
* styles[GeometryType.LINE_STRING]
* styles['Circle'] = styles['Polygon'].concat(
* styles['LineString']
* );
*
* styles[GeometryType.POINT] = [
* styles['Point'] = [
* new Style({
* image: new Circle({
* radius: width * 2,
@@ -140,11 +138,13 @@ import {assert} from '../asserts.js';
* zIndex: Infinity,
* }),
* ];
* styles[GeometryType.MULTI_POINT] = styles[GeometryType.POINT];
*
* styles[GeometryType.GEOMETRY_COLLECTION] = styles[
* GeometryType.POLYGON
* ].concat(styles[GeometryType.LINE_STRING], styles[GeometryType.POINT]);
* styles['MultiPoint'] =
* styles['Point'];
* styles['GeometryCollection'] =
* styles['Polygon'].concat(
* styles['LineString'],
* styles['Point']
* );
* ```
*
* @api
@@ -494,24 +494,24 @@ export function createDefaultStyle(feature, resolution) {
/**
* Default styles for editing features.
* @return {Object<import("../geom/GeometryType.js").default, Array<Style>>} Styles
* @return {Object<import("../geom/Geometry.js").Type, Array<Style>>} Styles
*/
export function createEditingStyle() {
/** @type {Object<import("../geom/GeometryType.js").default, Array<Style>>} */
/** @type {Object<import("../geom/Geometry.js").Type, Array<Style>>} */
const styles = {};
const white = [255, 255, 255, 1];
const blue = [0, 153, 255, 1];
const width = 3;
styles[GeometryType.POLYGON] = [
styles['Polygon'] = [
new Style({
fill: new Fill({
color: [255, 255, 255, 0.5],
}),
}),
];
styles[GeometryType.MULTI_POLYGON] = styles[GeometryType.POLYGON];
styles['MultiPolygon'] = styles['Polygon'];
styles[GeometryType.LINE_STRING] = [
styles['LineString'] = [
new Style({
stroke: new Stroke({
color: white,
@@ -525,13 +525,11 @@ export function createEditingStyle() {
}),
}),
];
styles[GeometryType.MULTI_LINE_STRING] = styles[GeometryType.LINE_STRING];
styles['MultiLineString'] = styles['LineString'];
styles[GeometryType.CIRCLE] = styles[GeometryType.POLYGON].concat(
styles[GeometryType.LINE_STRING]
);
styles['Circle'] = styles['Polygon'].concat(styles['LineString']);
styles[GeometryType.POINT] = [
styles['Point'] = [
new Style({
image: new CircleStyle({
radius: width * 2,
@@ -546,11 +544,12 @@ export function createEditingStyle() {
zIndex: Infinity,
}),
];
styles[GeometryType.MULTI_POINT] = styles[GeometryType.POINT];
styles['MultiPoint'] = styles['Point'];
styles[GeometryType.GEOMETRY_COLLECTION] = styles[
GeometryType.POLYGON
].concat(styles[GeometryType.LINE_STRING], styles[GeometryType.POINT]);
styles['GeometryCollection'] = styles['Polygon'].concat(
styles['LineString'],
styles['Point']
);
return styles;
}

View File

@@ -5,7 +5,6 @@ import Draw, {
} from '../../../../../src/ol/interaction/Draw.js';
import Feature from '../../../../../src/ol/Feature.js';
import GeometryLayout from '../../../../../src/ol/geom/GeometryLayout.js';
import GeometryType from '../../../../../src/ol/geom/GeometryType.js';
import Interaction from '../../../../../src/ol/interaction/Interaction.js';
import LineString from '../../../../../src/ol/geom/LineString.js';
import Map from '../../../../../src/ol/Map.js';
@@ -648,7 +647,7 @@ describe('ol.interaction.Draw', function () {
simulateEvent('pointerdown', x, y);
simulateEvent('pointerup', x, y);
}
if (amount > 1 && type !== GeometryType.CIRCLE) {
if (amount > 1 && type !== 'Circle') {
const [x, y] = testCoordinates[amount - 1];
simulateEvent('pointerdown', x, y);
simulateEvent('pointerup', x, y);
@@ -664,25 +663,25 @@ describe('ol.interaction.Draw', function () {
expect(source.getFeatures()).to.have.length(1);
}
it('calls finishCondition:true for POINT type', function () {
testFinishConditionTrue(GeometryType.POINT, 1);
testFinishConditionTrue('Point', 1);
});
it('calls finishCondition:true for MULTI_POINT type', function () {
testFinishConditionTrue(GeometryType.MULTI_POINT, 1);
testFinishConditionTrue('MultiPoint', 1);
});
it('calls finishCondition:true for LINE_STRING type', function () {
testFinishConditionTrue(GeometryType.LINE_STRING, 2);
testFinishConditionTrue('LineString', 2);
});
it('calls finishCondition:true for MULTI_LINE_STRING type', function () {
testFinishConditionTrue(GeometryType.MULTI_LINE_STRING, 2);
testFinishConditionTrue('MultiLineString', 2);
});
it('calls finishCondition:true for CIRCLE type', function () {
testFinishConditionTrue(GeometryType.CIRCLE, 2);
testFinishConditionTrue('Circle', 2);
});
it('calls finishCondition:true for POLYGON type', function () {
testFinishConditionTrue(GeometryType.POLYGON, 3);
testFinishConditionTrue('Polygon', 3);
});
it('calls finishCondition:true for MULTI_POLYGON type', function () {
testFinishConditionTrue(GeometryType.MULTI_POLYGON, 3);
testFinishConditionTrue('MultiPolygon', 3);
});
function testFinishConditionFalse(type, amount) {
@@ -694,25 +693,25 @@ describe('ol.interaction.Draw', function () {
expect(source.getFeatures()).to.have.length(0);
}
it('calls finishCondition:false for POINT type', function () {
testFinishConditionFalse(GeometryType.POINT, 1);
testFinishConditionFalse('Point', 1);
});
it('calls finishCondition:false for MULTI_POINT type', function () {
testFinishConditionFalse(GeometryType.MULTI_POINT, 1);
testFinishConditionFalse('MultiPoint', 1);
});
it('calls finishCondition:false for LINE_STRING type', function () {
testFinishConditionFalse(GeometryType.LINE_STRING, 2);
testFinishConditionFalse('LineString', 2);
});
it('calls finishCondition:false for MULTI_LINE_STRING type', function () {
testFinishConditionFalse(GeometryType.MULTI_LINE_STRING, 2);
testFinishConditionFalse('MultiLineString', 2);
});
it('calls finishCondition:false for CIRCLE type', function () {
testFinishConditionFalse(GeometryType.CIRCLE, 2);
testFinishConditionFalse('Circle', 2);
});
it('calls finishCondition:false for POLYGON type', function () {
testFinishConditionFalse(GeometryType.POLYGON, 3);
testFinishConditionFalse('Polygon', 3);
});
it('calls finishCondition:false for MULTI_POLYGON type', function () {
testFinishConditionFalse(GeometryType.MULTI_POLYGON, 3);
testFinishConditionFalse('MultiPolygon', 3);
});
});