Replace GeometryLayout enum with typedef
This commit is contained in:
+16
-19
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/EsriJSON
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import JSONFeature from './JSONFeature.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import LinearRing from '../geom/LinearRing.js';
|
||||
@@ -295,7 +294,7 @@ function readGeometry(object, opt_options) {
|
||||
* array. It is used for checking for holes.
|
||||
* Logic inspired by: https://github.com/Esri/terraformer-arcgis-parser
|
||||
* @param {Array<!Array<!Array<number>>>} rings Rings.
|
||||
* @param {import("../geom/GeometryLayout.js").default} layout Geometry layout.
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} layout Geometry layout.
|
||||
* @return {Array<!Array<!Array<!Array<number>>>>} Transformed rings.
|
||||
*/
|
||||
function convertRings(rings, layout) {
|
||||
@@ -352,14 +351,11 @@ function convertRings(rings, layout) {
|
||||
function readPointGeometry(object) {
|
||||
let point;
|
||||
if (object.m !== undefined && object.z !== undefined) {
|
||||
point = new Point(
|
||||
[object.x, object.y, object.z, object.m],
|
||||
GeometryLayout.XYZM
|
||||
);
|
||||
point = new Point([object.x, object.y, object.z, object.m], 'XYZM');
|
||||
} else if (object.z !== undefined) {
|
||||
point = new Point([object.x, object.y, object.z], GeometryLayout.XYZ);
|
||||
point = new Point([object.x, object.y, object.z], 'XYZ');
|
||||
} else if (object.m !== undefined) {
|
||||
point = new Point([object.x, object.y, object.m], GeometryLayout.XYM);
|
||||
point = new Point([object.x, object.y, object.m], 'XYM');
|
||||
} else {
|
||||
point = new Point([object.x, object.y]);
|
||||
}
|
||||
@@ -386,16 +382,17 @@ function readMultiLineStringGeometry(object) {
|
||||
|
||||
/**
|
||||
* @param {EsriJSONHasZM} object Object.
|
||||
* @return {import("../geom/GeometryLayout.js").default} The geometry layout to use.
|
||||
* @return {import("../geom/Geometry.js").GeometryLayout} The geometry layout to use.
|
||||
*/
|
||||
function getGeometryLayout(object) {
|
||||
let layout = GeometryLayout.XY;
|
||||
/** @type {import("../geom/Geometry.js").GeometryLayout} */
|
||||
let layout = 'XY';
|
||||
if (object.hasZ === true && object.hasM === true) {
|
||||
layout = GeometryLayout.XYZM;
|
||||
layout = 'XYZM';
|
||||
} else if (object.hasZ === true) {
|
||||
layout = GeometryLayout.XYZ;
|
||||
layout = 'XYZ';
|
||||
} else if (object.hasM === true) {
|
||||
layout = GeometryLayout.XYM;
|
||||
layout = 'XYM';
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
@@ -437,26 +434,26 @@ function writePointGeometry(geometry, opt_options) {
|
||||
/** @type {EsriJSONPoint} */
|
||||
let esriJSON;
|
||||
const layout = geometry.getLayout();
|
||||
if (layout === GeometryLayout.XYZ) {
|
||||
if (layout === 'XYZ') {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
z: coordinates[2],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XYM) {
|
||||
} else if (layout === 'XYM') {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
m: coordinates[2],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XYZM) {
|
||||
} else if (layout === 'XYZM') {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
z: coordinates[2],
|
||||
m: coordinates[3],
|
||||
};
|
||||
} else if (layout === GeometryLayout.XY) {
|
||||
} else if (layout === 'XY') {
|
||||
esriJSON = {
|
||||
x: coordinates[0],
|
||||
y: coordinates[1],
|
||||
@@ -474,8 +471,8 @@ function writePointGeometry(geometry, opt_options) {
|
||||
function getHasZM(geometry) {
|
||||
const layout = geometry.getLayout();
|
||||
return {
|
||||
hasZ: layout === GeometryLayout.XYZ || layout === GeometryLayout.XYZM,
|
||||
hasM: layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM,
|
||||
hasZ: layout === 'XYZ' || layout === 'XYZM',
|
||||
hasM: layout === 'XYM' || layout === 'XYZM',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import GML2 from './GML2.js';
|
||||
import GMLBase, {GMLNS} from './GMLBase.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPolygon from '../geom/MultiPolygon.js';
|
||||
@@ -308,7 +307,7 @@ class GML3 extends GMLBase {
|
||||
extend(flatCoordinates, flatLinearRings[i]);
|
||||
ends.push(flatCoordinates.length);
|
||||
}
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
|
||||
return new Polygon(flatCoordinates, 'XYZ', ends);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
@@ -329,7 +328,7 @@ class GML3 extends GMLBase {
|
||||
this
|
||||
);
|
||||
if (flatCoordinates) {
|
||||
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
|
||||
const lineString = new LineString(flatCoordinates, 'XYZ');
|
||||
return lineString;
|
||||
} else {
|
||||
return undefined;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
// of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
|
||||
// envelopes/extents, only geometries!
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import LinearRing from '../geom/LinearRing.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
@@ -370,7 +369,7 @@ class GMLBase extends XMLFeature {
|
||||
readPoint(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
return new Point(flatCoordinates, GeometryLayout.XYZ);
|
||||
return new Point(flatCoordinates, 'XYZ');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,7 +464,7 @@ class GMLBase extends XMLFeature {
|
||||
readLineString(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
|
||||
const lineString = new LineString(flatCoordinates, 'XYZ');
|
||||
return lineString;
|
||||
} else {
|
||||
return undefined;
|
||||
@@ -500,7 +499,7 @@ class GMLBase extends XMLFeature {
|
||||
readLinearRing(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
|
||||
return new LinearRing(flatCoordinates, 'XYZ');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -526,7 +525,7 @@ class GMLBase extends XMLFeature {
|
||||
extend(flatCoordinates, flatLinearRings[i]);
|
||||
ends.push(flatCoordinates.length);
|
||||
}
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
|
||||
return new Polygon(flatCoordinates, 'XYZ', ends);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/GPX
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import Point from '../geom/Point.js';
|
||||
@@ -557,19 +556,20 @@ function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
|
||||
* @param {LayoutOptions} layoutOptions Layout options.
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {Array<number>} [ends] Ends.
|
||||
* @return {import("../geom/GeometryLayout.js").default} Layout.
|
||||
* @return {import("../geom/Geometry.js").GeometryLayout} Layout.
|
||||
*/
|
||||
function applyLayoutOptions(layoutOptions, flatCoordinates, ends) {
|
||||
let layout = GeometryLayout.XY;
|
||||
/** @type {import("../geom/Geometry.js").GeometryLayout} */
|
||||
let layout = 'XY';
|
||||
let stride = 2;
|
||||
if (layoutOptions.hasZ && layoutOptions.hasM) {
|
||||
layout = GeometryLayout.XYZM;
|
||||
layout = 'XYZM';
|
||||
stride = 4;
|
||||
} else if (layoutOptions.hasZ) {
|
||||
layout = GeometryLayout.XYZ;
|
||||
layout = 'XYZ';
|
||||
stride = 3;
|
||||
} else if (layoutOptions.hasM) {
|
||||
layout = GeometryLayout.XYM;
|
||||
layout = 'XYM';
|
||||
stride = 3;
|
||||
}
|
||||
if (stride !== 4) {
|
||||
@@ -800,17 +800,17 @@ function writeWptType(node, coordinate, objectStack) {
|
||||
node.setAttributeNS(null, 'lon', String(coordinate[0]));
|
||||
const geometryLayout = context['geometryLayout'];
|
||||
switch (geometryLayout) {
|
||||
case GeometryLayout.XYZM:
|
||||
case 'XYZM':
|
||||
if (coordinate[3] !== 0) {
|
||||
properties['time'] = coordinate[3];
|
||||
}
|
||||
// fall through
|
||||
case GeometryLayout.XYZ:
|
||||
case 'XYZ':
|
||||
if (coordinate[2] !== 0) {
|
||||
properties['ele'] = coordinate[2];
|
||||
}
|
||||
break;
|
||||
case GeometryLayout.XYM:
|
||||
case 'XYM':
|
||||
if (coordinate[2] !== 0) {
|
||||
properties['time'] = coordinate[2];
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/IGC
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import TextFeature from './TextFeature.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
@@ -148,8 +147,7 @@ class IGC extends TextFeature {
|
||||
if (flatCoordinates.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const layout =
|
||||
altitudeMode == 'none' ? GeometryLayout.XYM : GeometryLayout.XYZM;
|
||||
const layout = altitudeMode == 'none' ? 'XYM' : 'XYZM';
|
||||
const lineString = new LineString(flatCoordinates, layout);
|
||||
const feature = new Feature(
|
||||
transformGeometryWithOptions(lineString, false, opt_options)
|
||||
|
||||
@@ -4,7 +4,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 Icon from '../style/Icon.js';
|
||||
import IconAnchorUnits from '../style/IconAnchorUnits.js';
|
||||
import IconOrigin from '../style/IconOrigin.js';
|
||||
@@ -1594,7 +1593,7 @@ function readGxTrack(node, objectStack) {
|
||||
);
|
||||
}
|
||||
}
|
||||
return new LineString(flatCoordinates, GeometryLayout.XYZM);
|
||||
return new LineString(flatCoordinates, 'XYZM');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1677,7 +1676,7 @@ function readLineString(node, objectStack) {
|
||||
);
|
||||
const flatCoordinates = readFlatCoordinatesFromNode(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
|
||||
const lineString = new LineString(flatCoordinates, 'XYZ');
|
||||
lineString.setProperties(properties, true);
|
||||
return lineString;
|
||||
} else {
|
||||
@@ -1699,7 +1698,7 @@ function readLinearRing(node, objectStack) {
|
||||
);
|
||||
const flatCoordinates = readFlatCoordinatesFromNode(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
const polygon = new Polygon(flatCoordinates, GeometryLayout.XYZ, [
|
||||
const polygon = new Polygon(flatCoordinates, 'XYZ', [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
polygon.setProperties(properties, true);
|
||||
@@ -1795,7 +1794,7 @@ function readPoint(node, objectStack) {
|
||||
);
|
||||
const flatCoordinates = readFlatCoordinatesFromNode(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
const point = new Point(flatCoordinates, GeometryLayout.XYZ);
|
||||
const point = new Point(flatCoordinates, 'XYZ');
|
||||
point.setProperties(properties, true);
|
||||
return point;
|
||||
} else {
|
||||
@@ -1838,7 +1837,7 @@ function readPolygon(node, objectStack) {
|
||||
extend(flatCoordinates, flatLinearRings[i]);
|
||||
ends.push(flatCoordinates.length);
|
||||
}
|
||||
const polygon = new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
|
||||
const polygon = new Polygon(flatCoordinates, 'XYZ', ends);
|
||||
polygon.setProperties(properties, true);
|
||||
return polygon;
|
||||
} else {
|
||||
@@ -2338,9 +2337,9 @@ function writeCoordinatesTextNode(node, coordinates, objectStack) {
|
||||
const stride = context['stride'];
|
||||
|
||||
let dimension;
|
||||
if (layout == GeometryLayout.XY || layout == GeometryLayout.XYM) {
|
||||
if (layout == 'XY' || layout == 'XYM') {
|
||||
dimension = 2;
|
||||
} else if (layout == GeometryLayout.XYZ || layout == GeometryLayout.XYZM) {
|
||||
} else if (layout == 'XYZ' || layout == 'XYZM') {
|
||||
dimension = 3;
|
||||
} else {
|
||||
assert(false, 34); // Invalid geometry layout
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
//FIXME Implement projection handling
|
||||
|
||||
import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
@@ -204,18 +203,18 @@ class MVT extends FeatureFormat {
|
||||
const endss = inflateEnds(flatCoordinates, ends);
|
||||
geom =
|
||||
endss.length > 1
|
||||
? new MultiPolygon(flatCoordinates, GeometryLayout.XY, endss)
|
||||
: new Polygon(flatCoordinates, GeometryLayout.XY, ends);
|
||||
? new MultiPolygon(flatCoordinates, 'XY', endss)
|
||||
: new Polygon(flatCoordinates, 'XY', ends);
|
||||
} else {
|
||||
geom =
|
||||
geometryType === 'Point'
|
||||
? new Point(flatCoordinates, GeometryLayout.XY)
|
||||
? new Point(flatCoordinates, 'XY')
|
||||
: geometryType === 'LineString'
|
||||
? new LineString(flatCoordinates, GeometryLayout.XY)
|
||||
? new LineString(flatCoordinates, 'XY')
|
||||
: geometryType === 'MultiPoint'
|
||||
? new MultiPoint(flatCoordinates, GeometryLayout.XY)
|
||||
? new MultiPoint(flatCoordinates, 'XY')
|
||||
: geometryType === 'MultiLineString'
|
||||
? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends)
|
||||
? new MultiLineString(flatCoordinates, 'XY', ends)
|
||||
: null;
|
||||
}
|
||||
const ctor = /** @type {typeof import("../Feature.js").default} */ (
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
// FIXME add typedef for stack state objects
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import Point from '../geom/Point.js';
|
||||
import Polygon from '../geom/Polygon.js';
|
||||
@@ -88,11 +87,11 @@ class OSMXML extends XMLFeature {
|
||||
let geometry;
|
||||
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
|
||||
// closed way
|
||||
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [
|
||||
geometry = new Polygon(flatCoordinates, 'XY', [
|
||||
flatCoordinates.length,
|
||||
]);
|
||||
} else {
|
||||
geometry = new LineString(flatCoordinates, GeometryLayout.XY);
|
||||
geometry = new LineString(flatCoordinates, 'XY');
|
||||
}
|
||||
transformGeometryWithOptions(geometry, false, options);
|
||||
const feature = new Feature(geometry);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/Polyline
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import TextFeature from './TextFeature.js';
|
||||
import {assert} from '../asserts.js';
|
||||
@@ -15,7 +14,7 @@ import {transformGeometryWithOptions} from './Feature.js';
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {number} [factor=1e5] The factor by which the coordinates values will be scaled.
|
||||
* @property {GeometryLayout} [geometryLayout='XY'] Layout of the
|
||||
* @property {import("../geom/Geometry.js").GeometryLayout} [geometryLayout='XY'] Layout of the
|
||||
* feature geometries created by the format reader.
|
||||
*/
|
||||
|
||||
@@ -55,11 +54,11 @@ class Polyline extends TextFeature {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../geom/GeometryLayout").default}
|
||||
* @type {import("../geom/Geometry.js").GeometryLayout}
|
||||
*/
|
||||
this.geometryLayout_ = options.geometryLayout
|
||||
? options.geometryLayout
|
||||
: GeometryLayout.XY;
|
||||
: 'XY';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+55
-21
@@ -4,7 +4,6 @@
|
||||
import Feature from '../Feature.js';
|
||||
import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
|
||||
import GeometryCollection from '../geom/GeometryCollection.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
@@ -53,17 +52,50 @@ class WkbReader {
|
||||
* @param {DataView} view source to read
|
||||
*/
|
||||
constructor(view) {
|
||||
/** @private */
|
||||
this.view_ = view;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.pos_ = 0;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.initialized_ = false;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.isLittleEndian_ = false;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.hasZ_ = false;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.hasM_ = false;
|
||||
/** @type {number|null} */
|
||||
|
||||
/**
|
||||
* @type {number|null}
|
||||
* @private
|
||||
*/
|
||||
this.srid_ = null;
|
||||
|
||||
this.layout_ = GeometryLayout.XY;
|
||||
/**
|
||||
* @type {import("../geom/Geometry.js").GeometryLayout}
|
||||
* @private
|
||||
*/
|
||||
this.layout_ = 'XY';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +196,9 @@ class WkbReader {
|
||||
wkbTypeThousandth === 3;
|
||||
const hasSRID = Boolean(wkbType & 0x20000000);
|
||||
const typeId = (wkbType & 0x0fffffff) % 1000; // Assume 1000 is an upper limit for type ID
|
||||
const layout = ['XY', hasZ ? 'Z' : '', hasM ? 'M' : ''].join('');
|
||||
const layout = /** @type {import("../geom/Geometry.js").GeometryLayout} */ (
|
||||
['XY', hasZ ? 'Z' : '', hasM ? 'M' : ''].join('')
|
||||
);
|
||||
|
||||
const srid = hasSRID ? this.readUint32(isLittleEndian) : null;
|
||||
|
||||
@@ -415,7 +449,7 @@ class WkbWriter {
|
||||
|
||||
/**
|
||||
* @param {import('../coordinate.js').Coordinate} coords coords
|
||||
* @param {import("../geom/GeometryLayout").default} layout layout
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} layout layout
|
||||
*/
|
||||
writePoint(coords, layout) {
|
||||
/**
|
||||
@@ -439,7 +473,7 @@ class WkbWriter {
|
||||
|
||||
/**
|
||||
* @param {Array<import('../coordinate.js').Coordinate>} coords coords
|
||||
* @param {import("../geom/GeometryLayout").default} layout layout
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} layout layout
|
||||
*/
|
||||
writeLineString(coords, layout) {
|
||||
this.writeUint32(coords.length); // numPoints
|
||||
@@ -450,7 +484,7 @@ class WkbWriter {
|
||||
|
||||
/**
|
||||
* @param {Array<Array<import('../coordinate.js').Coordinate>>} rings rings
|
||||
* @param {import("../geom/GeometryLayout").default} layout layout
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} layout layout
|
||||
*/
|
||||
writePolygon(rings, layout) {
|
||||
this.writeUint32(rings.length); // numRings
|
||||
@@ -484,7 +518,7 @@ class WkbWriter {
|
||||
|
||||
/**
|
||||
* @param {Array<import('../coordinate.js').Coordinate>} coords coords
|
||||
* @param {string} layout layout
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} layout layout
|
||||
*/
|
||||
writeMultiPoint(coords, layout) {
|
||||
this.writeUint32(coords.length); // numItems
|
||||
@@ -496,7 +530,7 @@ class WkbWriter {
|
||||
|
||||
/**
|
||||
* @param {Array<Array<import('../coordinate.js').Coordinate>>} coords coords
|
||||
* @param {string} layout layout
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} layout layout
|
||||
*/
|
||||
writeMultiLineString(coords, layout) {
|
||||
this.writeUint32(coords.length); // numItems
|
||||
@@ -508,7 +542,7 @@ class WkbWriter {
|
||||
|
||||
/**
|
||||
* @param {Array<Array<Array<import('../coordinate.js').Coordinate>>>} coords coords
|
||||
* @param {string} layout layout
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} layout layout
|
||||
*/
|
||||
writeMultiPolygon(coords, layout) {
|
||||
this.writeUint32(coords.length); // numItems
|
||||
@@ -531,31 +565,31 @@ class WkbWriter {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geom geometry
|
||||
* @param {import("../geom/GeometryLayout.js").default} [layout] layout
|
||||
* @return {import("../geom/GeometryLayout.js").default} minumum layout made by common axes
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} [layout] layout
|
||||
* @return {import("../geom/Geometry.js").GeometryLayout} minumum layout made by common axes
|
||||
*/
|
||||
findMinimumLayout(geom, layout = GeometryLayout.XYZM) {
|
||||
findMinimumLayout(geom, layout = 'XYZM') {
|
||||
/**
|
||||
* @param {import("../geom/GeometryLayout.js").default} a A
|
||||
* @param {import("../geom/GeometryLayout.js").default} b B
|
||||
* @return {import("../geom/GeometryLayout.js").default} minumum layout made by common axes
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} a A
|
||||
* @param {import("../geom/Geometry.js").GeometryLayout} b B
|
||||
* @return {import("../geom/Geometry.js").GeometryLayout} minumum layout made by common axes
|
||||
*/
|
||||
const GeometryLayout_min = (a, b) => {
|
||||
if (a === b) {
|
||||
return a;
|
||||
}
|
||||
|
||||
if (a === GeometryLayout.XYZM) {
|
||||
if (a === 'XYZM') {
|
||||
// anything `b` is minimum
|
||||
return b;
|
||||
}
|
||||
if (b === GeometryLayout.XYZM) {
|
||||
if (b === 'XYZM') {
|
||||
// anything `a` is minimum
|
||||
return a;
|
||||
}
|
||||
|
||||
// otherwise, incompatible
|
||||
return GeometryLayout.XY;
|
||||
return 'XY';
|
||||
};
|
||||
|
||||
if (geom instanceof SimpleGeometry) {
|
||||
@@ -564,7 +598,7 @@ class WkbWriter {
|
||||
|
||||
if (geom instanceof GeometryCollection) {
|
||||
const geoms = geom.getGeometriesArray();
|
||||
for (let i = 0; i < geoms.length && layout !== GeometryLayout.XY; i++) {
|
||||
for (let i = 0; i < geoms.length && layout !== 'XY'; i++) {
|
||||
layout = this.findMinimumLayout(geoms[i], layout);
|
||||
}
|
||||
}
|
||||
@@ -652,7 +686,7 @@ class WkbWriter {
|
||||
* @property {boolean} [hex=true] Returns hex string instead of ArrayBuffer for output. This also is used as a hint internally whether it should load contents as text or ArrayBuffer on reading.
|
||||
* @property {boolean} [littleEndian=true] Use littleEndian for output.
|
||||
* @property {boolean} [ewkb=true] Use EWKB format for output.
|
||||
* @property {import("../geom/GeometryLayout").default} [geometryLayout=null] Use specific coordinate layout for output features (null: auto detect)
|
||||
* @property {import("../geom/Geometry.js").GeometryLayout} [geometryLayout=null] Use specific coordinate layout for output features (null: auto detect)
|
||||
* @property {number} [nodataZ=0] If the `geometryLayout` doesn't match with geometry to be output, this value is used to fill missing coordinate value of Z.
|
||||
* @property {number} [nodataM=0] If the `geometryLayout` doesn't match with geometry to be output, this value is used to fill missing coordinate value of M.
|
||||
* @property {number|boolean} [srid=true] SRID for output. Specify integer value to enforce the value as a SRID. Specify `true` to extract from `dataProjection`. `false` to suppress the output. This option only takes effect when `ewkb` is `true`.
|
||||
|
||||
+12
-12
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import GeometryCollection from '../geom/GeometryCollection.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
import MultiPoint from '../geom/MultiPoint.js';
|
||||
@@ -15,7 +14,7 @@ import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* Geometry constructors
|
||||
* @enum {function (new:import("../geom/Geometry.js").default, Array, import("../geom/GeometryLayout.js").default)}
|
||||
* @enum {function (new:import("../geom/Geometry.js").default, Array, import("../geom/Geometry.js").GeometryLayout)}
|
||||
*/
|
||||
const GeometryConstructor = {
|
||||
'POINT': Point,
|
||||
@@ -249,10 +248,10 @@ class Parser {
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {import("../geom/GeometryLayout.js").default}
|
||||
* @type {import("../geom/Geometry.js").GeometryLayout}
|
||||
* @private
|
||||
*/
|
||||
this.layout_ = GeometryLayout.XY;
|
||||
this.layout_ = 'XY';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,22 +295,23 @@ class Parser {
|
||||
|
||||
/**
|
||||
* Try to parse the dimensional info.
|
||||
* @return {import("../geom/GeometryLayout.js").default} The layout.
|
||||
* @return {import("../geom/Geometry.js").GeometryLayout} The layout.
|
||||
* @private
|
||||
*/
|
||||
parseGeometryLayout_() {
|
||||
let layout = GeometryLayout.XY;
|
||||
/** @type {import("../geom/Geometry.js").GeometryLayout} */
|
||||
let layout = 'XY';
|
||||
const dimToken = this.token_;
|
||||
if (this.isTokenType(TokenType.TEXT)) {
|
||||
const dimInfo = dimToken.value;
|
||||
if (dimInfo === Z) {
|
||||
layout = GeometryLayout.XYZ;
|
||||
layout = 'XYZ';
|
||||
} else if (dimInfo === M) {
|
||||
layout = GeometryLayout.XYM;
|
||||
layout = 'XYM';
|
||||
} else if (dimInfo === ZM) {
|
||||
layout = GeometryLayout.XYZM;
|
||||
layout = 'XYZM';
|
||||
}
|
||||
if (layout !== GeometryLayout.XY) {
|
||||
if (layout !== 'XY') {
|
||||
this.consume_();
|
||||
}
|
||||
}
|
||||
@@ -819,10 +819,10 @@ function encodeMultiPolygonGeometry(geom) {
|
||||
function encodeGeometryLayout(geom) {
|
||||
const layout = geom.getLayout();
|
||||
let dimInfo = '';
|
||||
if (layout === GeometryLayout.XYZ || layout === GeometryLayout.XYZM) {
|
||||
if (layout === 'XYZ' || layout === 'XYZM') {
|
||||
dimInfo += Z;
|
||||
}
|
||||
if (layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM) {
|
||||
if (layout === 'XYM' || layout === 'XYZM') {
|
||||
dimInfo += M;
|
||||
}
|
||||
return dimInfo;
|
||||
|
||||
Reference in New Issue
Block a user