Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -2,12 +2,9 @@
* @module ol/format/EsriJSON
*/
import Feature from '../Feature.js';
import {assert} from '../asserts.js';
import {containsExtent} from '../extent.js';
import {transformGeometryWithOptions} from './Feature.js';
import JSONFeature from './JSONFeature.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';
import MultiLineString from '../geom/MultiLineString.js';
@@ -15,10 +12,13 @@ import MultiPoint from '../geom/MultiPoint.js';
import MultiPolygon from '../geom/MultiPolygon.js';
import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js';
import {assert} from '../asserts.js';
import {containsExtent} from '../extent.js';
import {deflateCoordinates} from '../geom/flat/deflate.js';
import {linearRingIsClockwise} from '../geom/flat/orient.js';
import {isEmpty} from '../obj.js';
import {get as getProjection} from '../proj.js';
import {isEmpty} from '../obj.js';
import {linearRingIsClockwise} from '../geom/flat/orient.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @typedef {import("arcgis-rest-api").Feature} EsriJSONFeature
@@ -33,7 +33,6 @@ import {get as getProjection} from '../proj.js';
* @typedef {import("arcgis-rest-api").SpatialReferenceWkid} EsriJSONSpatialReferenceWkid
*/
/**
* @typedef {Object} EsriJSONMultiPolygon
* @property {Array<Array<Array<Array<number>>>>} rings Rings for the MultiPolygon.
@@ -42,7 +41,6 @@ import {get as getProjection} from '../proj.js';
* @property {EsriJSONSpatialReferenceWkid} [spatialReference] The coordinate reference system.
*/
/**
* @const
* @type {Object<import("../geom/GeometryType.js").default, function(EsriJSONGeometry): import("../geom/Geometry.js").default>}
@@ -55,7 +53,6 @@ GEOMETRY_READERS[GeometryType.MULTI_POINT] = readMultiPointGeometry;
GEOMETRY_READERS[GeometryType.MULTI_LINE_STRING] = readMultiLineStringGeometry;
GEOMETRY_READERS[GeometryType.MULTI_POLYGON] = readMultiPolygonGeometry;
/**
* @const
* @type {Object<string, function(import("../geom/Geometry.js").default, import("./Feature.js").WriteOptions=): (EsriJSONGeometry)>}
@@ -68,13 +65,11 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POINT] = writeMultiPointGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_LINE_STRING] = writeMultiLineStringGeometry;
GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
/**
* @typedef {Object} Options
* @property {string} [geometryName] Geometry name to use when creating features.
*/
/**
* @classdesc
* Feature format for reading and writing data in the EsriJSON format.
@@ -82,12 +77,10 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
* @api
*/
class EsriJSON extends JSONFeature {
/**
* @param {Options=} opt_options Options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
super();
@@ -98,7 +91,6 @@ class EsriJSON extends JSONFeature {
* @private
*/
this.geometryName_ = options.geometryName;
}
/**
@@ -120,7 +112,7 @@ class EsriJSON extends JSONFeature {
feature.setProperties(esriJSONFeature.attributes, true);
const id = esriJSONFeature.attributes[opt_idField];
if (id !== undefined) {
feature.setId(/** @type {number} */(id));
feature.setId(/** @type {number} */ (id));
}
}
return feature;
@@ -140,7 +132,13 @@ class EsriJSON extends JSONFeature {
const features = [];
const esriJSONFeatures = esriJSONFeatureSet.features;
for (let i = 0, ii = esriJSONFeatures.length; i < ii; ++i) {
features.push(this.readFeatureFromObject(esriJSONFeatures[i], options, object.objectIdFieldName));
features.push(
this.readFeatureFromObject(
esriJSONFeatures[i],
options,
object.objectIdFieldName
)
);
}
return features;
} else {
@@ -164,8 +162,13 @@ class EsriJSON extends JSONFeature {
* @return {import("../proj/Projection.js").default} Projection.
*/
readProjectionFromObject(object) {
if (object['spatialReference'] && object['spatialReference']['wkid'] !== undefined) {
const spatialReference = /** @type {EsriJSONSpatialReferenceWkid} */ (object['spatialReference']);
if (
object['spatialReference'] &&
object['spatialReference']['wkid'] !== undefined
) {
const spatialReference = /** @type {EsriJSONSpatialReferenceWkid} */ (object[
'spatialReference'
]);
const crs = spatialReference.wkid;
return getProjection('EPSG:' + crs);
} else {
@@ -200,8 +203,15 @@ class EsriJSON extends JSONFeature {
if (geometry) {
object['geometry'] = writeGeometry(geometry, opt_options);
if (opt_options && opt_options.featureProjection) {
object['geometry']['spatialReference'] = /** @type {EsriJSONSpatialReferenceWkid} */({
wkid: Number(getProjection(opt_options.featureProjection).getCode().split(':').pop())
object['geometry'][
'spatialReference'
] = /** @type {EsriJSONSpatialReferenceWkid} */ ({
wkid: Number(
getProjection(opt_options.featureProjection)
.getCode()
.split(':')
.pop()
),
});
}
}
@@ -230,12 +240,11 @@ class EsriJSON extends JSONFeature {
objects.push(this.writeFeatureObject(features[i], opt_options));
}
return {
'features': objects
'features': objects,
};
}
}
/**
* @param {EsriJSONGeometry} object Object.
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
@@ -271,10 +280,13 @@ function readGeometry(object, opt_options) {
}
}
const geometryReader = GEOMETRY_READERS[type];
return transformGeometryWithOptions(geometryReader(object), false, opt_options);
return transformGeometryWithOptions(
geometryReader(object),
false,
opt_options
);
}
/**
* Determines inner and outer rings.
* Checks if any polygons in this array contain any other polygons in this
@@ -293,8 +305,12 @@ function convertRings(rings, layout) {
flatRing.length = 0;
deflateCoordinates(flatRing, 0, rings[i], layout.length);
// is this ring an outer ring? is it clockwise?
const clockwise = linearRingIsClockwise(flatRing, 0,
flatRing.length, layout.length);
const clockwise = linearRingIsClockwise(
flatRing,
0,
flatRing.length,
layout.length
);
if (clockwise) {
outerRings.push([rings[i]]);
} else {
@@ -327,7 +343,6 @@ function convertRings(rings, layout) {
return outerRings;
}
/**
* @param {EsriJSONPoint} object Object.
* @return {import("../geom/Geometry.js").default} Point.
@@ -335,21 +350,20 @@ 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],
GeometryLayout.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], GeometryLayout.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], GeometryLayout.XYM);
} else {
point = new Point([object.x, object.y]);
}
return point;
}
/**
* @param {EsriJSONPolyline} object Object.
* @return {import("../geom/Geometry.js").default} LineString.
@@ -359,7 +373,6 @@ function readLineStringGeometry(object) {
return new LineString(object.paths[0], layout);
}
/**
* @param {EsriJSONPolyline} object Object.
* @return {import("../geom/Geometry.js").default} MultiLineString.
@@ -369,7 +382,6 @@ function readMultiLineStringGeometry(object) {
return new MultiLineString(object.paths, layout);
}
/**
* @param {EsriJSONHasZM} object Object.
* @return {import("../geom/GeometryLayout.js").default} The geometry layout to use.
@@ -386,7 +398,6 @@ function getGeometryLayout(object) {
return layout;
}
/**
* @param {EsriJSONMultipoint} object Object.
* @return {import("../geom/Geometry.js").default} MultiPoint.
@@ -396,7 +407,6 @@ function readMultiPointGeometry(object) {
return new MultiPoint(object.points, layout);
}
/**
* @param {EsriJSONMultiPolygon} object Object.
* @return {import("../geom/Geometry.js").default} MultiPolygon.
@@ -406,7 +416,6 @@ function readMultiPolygonGeometry(object) {
return new MultiPolygon(object.rings, layout);
}
/**
* @param {EsriJSONPolygon} object Object.
* @return {import("../geom/Geometry.js").default} Polygon.
@@ -416,7 +425,6 @@ function readPolygonGeometry(object) {
return new Polygon(object.rings, layout);
}
/**
* @param {import("../geom/Point.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -431,25 +439,25 @@ function writePointGeometry(geometry, opt_options) {
esriJSON = {
x: coordinates[0],
y: coordinates[1],
z: coordinates[2]
z: coordinates[2],
};
} else if (layout === GeometryLayout.XYM) {
esriJSON = {
x: coordinates[0],
y: coordinates[1],
m: coordinates[2]
m: coordinates[2],
};
} else if (layout === GeometryLayout.XYZM) {
esriJSON = {
x: coordinates[0],
y: coordinates[1],
z: coordinates[2],
m: coordinates[3]
m: coordinates[3],
};
} else if (layout === GeometryLayout.XY) {
esriJSON = {
x: coordinates[0],
y: coordinates[1]
y: coordinates[1],
};
} else {
assert(false, 34); // Invalid geometry layout
@@ -457,7 +465,6 @@ function writePointGeometry(geometry, opt_options) {
return esriJSON;
}
/**
* @param {import("../geom/SimpleGeometry.js").default} geometry Geometry.
* @return {Object} Object with boolean hasZ and hasM keys.
@@ -465,14 +472,11 @@ 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 === GeometryLayout.XYZ || layout === GeometryLayout.XYZM,
hasM: layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM,
};
}
/**
* @param {import("../geom/LineString.js").default} lineString Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -484,12 +488,11 @@ function writeLineStringGeometry(lineString, opt_options) {
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
paths: [
/** @type {Array<EsriJSONPosition>} */ (lineString.getCoordinates())
]
/** @type {Array<EsriJSONPosition>} */ (lineString.getCoordinates()),
],
};
}
/**
* @param {import("../geom/Polygon.js").default} polygon Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -501,11 +504,12 @@ function writePolygonGeometry(polygon, opt_options) {
return {
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (polygon.getCoordinates(false))
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (polygon.getCoordinates(
false
)),
};
}
/**
* @param {import("../geom/MultiLineString.js").default} multiLineString Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -516,11 +520,10 @@ function writeMultiLineStringGeometry(multiLineString, opt_options) {
return {
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
paths: /** @type {Array<Array<EsriJSONPosition>>} */ (multiLineString.getCoordinates())
paths: /** @type {Array<Array<EsriJSONPosition>>} */ (multiLineString.getCoordinates()),
};
}
/**
* @param {import("../geom/MultiPoint.js").default} multiPoint Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -531,11 +534,10 @@ function writeMultiPointGeometry(multiPoint, opt_options) {
return {
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
points: /** @type {Array<EsriJSONPosition>} */ (multiPoint.getCoordinates())
points: /** @type {Array<EsriJSONPosition>} */ (multiPoint.getCoordinates()),
};
}
/**
* @param {import("../geom/MultiPolygon.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -553,11 +555,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
return {
hasZ: hasZM.hasZ,
hasM: hasZM.hasM,
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (output)
rings: /** @type {Array<Array<EsriJSONPosition>>} */ (output),
};
}
/**
* @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -565,8 +566,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
*/
function writeGeometry(geometry, opt_options) {
const geometryWriter = GEOMETRY_WRITERS[geometry.getType()];
return geometryWriter(transformGeometryWithOptions(geometry, true, opt_options), opt_options);
return geometryWriter(
transformGeometryWithOptions(geometry, true, opt_options),
opt_options
);
}
export default EsriJSON;

View File

@@ -1,11 +1,14 @@
/**
* @module ol/format/Feature
*/
import {assign} from '../obj.js';
import {abstract} from '../util.js';
import {get as getProjection, equivalent as equivalentProjection, transformExtent} from '../proj.js';
import Units from '../proj/Units.js';
import {abstract} from '../util.js';
import {assign} from '../obj.js';
import {
equivalent as equivalentProjection,
get as getProjection,
transformExtent,
} from '../proj.js';
/**
* @typedef {Object} ReadOptions
@@ -23,7 +26,6 @@ import Units from '../proj/Units.js';
* `dataProjection`.
*/
/**
* @typedef {Object} WriteOptions
* @property {import("../proj.js").ProjectionLike} [dataProjection] Projection of the data we are writing.
@@ -49,7 +51,6 @@ import Units from '../proj/Units.js';
* Default is no rounding.
*/
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
@@ -64,7 +65,6 @@ import Units from '../proj/Units.js';
*/
class FeatureFormat {
constructor() {
/**
* @protected
* @type {import("../proj/Projection.js").default}
@@ -76,7 +76,6 @@ class FeatureFormat {
* @type {import("../proj/Projection.js").default}
*/
this.defaultFeatureProjection = null;
}
/**
@@ -89,16 +88,20 @@ class FeatureFormat {
getReadOptions(source, opt_options) {
let options;
if (opt_options) {
let dataProjection = opt_options.dataProjection ?
getProjection(opt_options.dataProjection) : this.readProjection(source);
if (opt_options.extent &&
dataProjection && dataProjection.getUnits() === Units.TILE_PIXELS) {
let dataProjection = opt_options.dataProjection
? getProjection(opt_options.dataProjection)
: this.readProjection(source);
if (
opt_options.extent &&
dataProjection &&
dataProjection.getUnits() === Units.TILE_PIXELS
) {
dataProjection = getProjection(dataProjection);
dataProjection.setWorldExtent(opt_options.extent);
}
options = {
dataProjection: dataProjection,
featureProjection: opt_options.featureProjection
featureProjection: opt_options.featureProjection,
};
}
return this.adaptOptions(options);
@@ -114,10 +117,13 @@ class FeatureFormat {
* Updated options.
*/
adaptOptions(options) {
return assign({
dataProjection: this.dataProjection,
featureProjection: this.defaultFeatureProjection
}, options);
return assign(
{
dataProjection: this.dataProjection,
featureProjection: this.defaultFeatureProjection,
},
options
);
}
/**
@@ -221,25 +227,41 @@ export default FeatureFormat;
* @return {import("../geom/Geometry.js").default} Transformed geometry.
*/
export function transformGeometryWithOptions(geometry, write, opt_options) {
const featureProjection = opt_options ? getProjection(opt_options.featureProjection) : null;
const dataProjection = opt_options ? getProjection(opt_options.dataProjection) : null;
const featureProjection = opt_options
? getProjection(opt_options.featureProjection)
: null;
const dataProjection = opt_options
? getProjection(opt_options.dataProjection)
: null;
let transformed;
if (featureProjection && dataProjection && !equivalentProjection(featureProjection, dataProjection)) {
if (
featureProjection &&
dataProjection &&
!equivalentProjection(featureProjection, dataProjection)
) {
transformed = (write ? geometry.clone() : geometry).transform(
write ? featureProjection : dataProjection,
write ? dataProjection : featureProjection);
write ? dataProjection : featureProjection
);
} else {
transformed = geometry;
}
if (write && opt_options && /** @type {WriteOptions} */ (opt_options).decimals !== undefined) {
const power = Math.pow(10, /** @type {WriteOptions} */ (opt_options).decimals);
if (
write &&
opt_options &&
/** @type {WriteOptions} */ (opt_options).decimals !== undefined
) {
const power = Math.pow(
10,
/** @type {WriteOptions} */ (opt_options).decimals
);
// if decimals option on write, round each coordinate appropriately
/**
* @param {Array<number>} coordinates Coordinates.
* @return {Array<number>} Transformed coordinates.
*/
const transform = function(coordinates) {
const transform = function (coordinates) {
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
coordinates[i] = Math.round(coordinates[i] * power) / power;
}
@@ -253,17 +275,24 @@ export function transformGeometryWithOptions(geometry, write, opt_options) {
return transformed;
}
/**
* @param {import("../extent.js").Extent} extent Extent.
* @param {ReadOptions=} opt_options Read options.
* @return {import("../extent.js").Extent} Transformed extent.
*/
export function transformExtentWithOptions(extent, opt_options) {
const featureProjection = opt_options ? getProjection(opt_options.featureProjection) : null;
const dataProjection = opt_options ? getProjection(opt_options.dataProjection) : null;
const featureProjection = opt_options
? getProjection(opt_options.featureProjection)
: null;
const dataProjection = opt_options
? getProjection(opt_options.dataProjection)
: null;
if (featureProjection && dataProjection && !equivalentProjection(featureProjection, dataProjection)) {
if (
featureProjection &&
dataProjection &&
!equivalentProjection(featureProjection, dataProjection)
) {
return transformExtent(extent, dataProjection, featureProjection);
} else {
return extent;

View File

@@ -9,5 +9,5 @@ export default {
ARRAY_BUFFER: 'arraybuffer',
JSON: 'json',
TEXT: 'text',
XML: 'xml'
XML: 'xml',
};

View File

@@ -15,7 +15,6 @@ import GML3 from './GML3.js';
*/
const GML = GML3;
/**
* Encode an array of features in GML 3.1.1 Simple Features.
*
@@ -27,7 +26,6 @@ const GML = GML3;
*/
GML.prototype.writeFeatures;
/**
* Encode an array of features in the GML 3.1.1 format as an XML node.
*

View File

@@ -1,22 +1,33 @@
/**
* @module ol/format/GML2
*/
import {createOrUpdate} from '../extent.js';
import {transformExtentWithOptions, transformGeometryWithOptions} from './Feature.js';
import GMLBase, {GMLNS} from './GMLBase.js';
import {writeStringTextNode} from './xsd.js';
import {
OBJECT_PROPERTY_NODE_FACTORY,
createElementNS,
getAllTextContent,
makeArrayPusher,
makeChildAppender,
makeReplacer,
makeSimpleNodeFactory,
pushParseAndPop,
pushSerializeAndPop,
} from '../xml.js';
import {assign} from '../obj.js';
import {createOrUpdate} from '../extent.js';
import {get as getProjection} from '../proj.js';
import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender,
makeReplacer, makeSimpleNodeFactory, OBJECT_PROPERTY_NODE_FACTORY, pushParseAndPop, pushSerializeAndPop} from '../xml.js';
import {
transformExtentWithOptions,
transformGeometryWithOptions,
} from './Feature.js';
import {writeStringTextNode} from './xsd.js';
/**
* @const
* @type {string}
*/
const schemaLocation = GMLNS + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
const schemaLocation =
GMLNS + ' http://schemas.opengis.net/gml/2.1.2/feature.xsd';
/**
* @const
@@ -26,10 +37,9 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
'MultiLineString': 'lineStringMember',
'MultiCurve': 'curveMember',
'MultiPolygon': 'polygonMember',
'MultiSurface': 'surfaceMember'
'MultiSurface': 'surfaceMember',
};
/**
* @classdesc
* Feature format for reading and writing data in the GML format,
@@ -38,26 +48,26 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
* @api
*/
class GML2 extends GMLBase {
/**
* @param {import("./GMLBase.js").Options=} opt_options Optional configuration object.
*/
constructor(opt_options) {
const options = /** @type {import("./GMLBase.js").Options} */
(opt_options ? opt_options : {});
const options =
/** @type {import("./GMLBase.js").Options} */
(opt_options ? opt_options : {});
super(options);
this.FEATURE_COLLECTION_PARSERS[GMLNS][
'featureMember'] =
makeArrayPusher(this.readFeaturesInternal);
this.FEATURE_COLLECTION_PARSERS[GMLNS]['featureMember'] = makeArrayPusher(
this.readFeaturesInternal
);
/**
* @type {string}
*/
this.schemaLocation = options.schemaLocation ?
options.schemaLocation : schemaLocation;
this.schemaLocation = options.schemaLocation
? options.schemaLocation
: schemaLocation;
}
/**
@@ -83,7 +93,7 @@ class GML2 extends GMLBase {
const coords = coordsGroups[i].split(/,+/);
const x = parseFloat(coords[0]);
const y = parseFloat(coords[1]);
const z = (coords.length === 3) ? parseFloat(coords[2]) : 0;
const z = coords.length === 3 ? parseFloat(coords[2]) : 0;
if (axisOrientation.substr(0, 2) === 'en') {
flatCoordinates.push(x, y, z);
} else {
@@ -101,11 +111,19 @@ class GML2 extends GMLBase {
*/
readBox_(node, objectStack) {
/** @type {Array<number>} */
const flatCoordinates = pushParseAndPop([null],
this.BOX_PARSERS_, node, objectStack, this);
return createOrUpdate(flatCoordinates[1][0],
flatCoordinates[1][1], flatCoordinates[1][3],
flatCoordinates[1][4]);
const flatCoordinates = pushParseAndPop(
[null],
this.BOX_PARSERS_,
node,
objectStack,
this
);
return createOrUpdate(
flatCoordinates[1][0],
flatCoordinates[1][1],
flatCoordinates[1][3],
flatCoordinates[1][4]
);
}
/**
@@ -115,11 +133,17 @@ class GML2 extends GMLBase {
*/
innerBoundaryIsParser_(node, objectStack) {
/** @type {Array<number>|undefined} */
const flatLinearRing = pushParseAndPop(undefined,
this.RING_PARSERS, node, objectStack, this);
const flatLinearRing = pushParseAndPop(
undefined,
this.RING_PARSERS,
node,
objectStack,
this
);
if (flatLinearRing) {
const flatLinearRings = /** @type {Array<Array<number>>} */
(objectStack[objectStack.length - 1]);
const flatLinearRings =
/** @type {Array<Array<number>>} */
(objectStack[objectStack.length - 1]);
flatLinearRings.push(flatLinearRing);
}
}
@@ -131,11 +155,17 @@ class GML2 extends GMLBase {
*/
outerBoundaryIsParser_(node, objectStack) {
/** @type {Array<number>|undefined} */
const flatLinearRing = pushParseAndPop(undefined,
this.RING_PARSERS, node, objectStack, this);
const flatLinearRing = pushParseAndPop(
undefined,
this.RING_PARSERS,
node,
objectStack,
this
);
if (flatLinearRing) {
const flatLinearRings = /** @type {Array<Array<number>>} */
(objectStack[objectStack.length - 1]);
const flatLinearRings =
/** @type {Array<Array<number>>} */
(objectStack[objectStack.length - 1]);
flatLinearRings[0] = flatLinearRing;
}
}
@@ -166,8 +196,7 @@ class GML2 extends GMLBase {
} else {
nodeName = 'Envelope';
}
return createElementNS('http://www.opengis.net/gml',
nodeName);
return createElementNS('http://www.opengis.net/gml', nodeName);
}
/**
@@ -195,25 +224,36 @@ class GML2 extends GMLBase {
if (value !== null) {
keys.push(key);
values.push(value);
if (key == geometryName || typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
if (
key == geometryName ||
typeof (/** @type {?} */ (value).getSimplifiedGeometry) === 'function'
) {
if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = makeChildAppender(
this.writeGeometryElement, this);
this.writeGeometryElement,
this
);
}
} else {
if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = makeChildAppender(writeStringTextNode);
context.serializers[featureNS][key] = makeChildAppender(
writeStringTextNode
);
}
}
}
}
const item = assign({}, context);
item.node = node;
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
(item), context.serializers,
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
(item),
context.serializers,
makeSimpleNodeFactory(undefined, featureNS),
values,
objectStack, keys);
objectStack,
keys
);
}
/**
@@ -228,16 +268,17 @@ class GML2 extends GMLBase {
if (node.nodeName !== 'LineStringSegment' && srsName) {
node.setAttribute('srsName', srsName);
}
if (node.nodeName === 'LineString' ||
node.nodeName === 'LineStringSegment') {
if (
node.nodeName === 'LineString' ||
node.nodeName === 'LineStringSegment'
) {
const coordinates = this.createCoordinatesNode_(node.namespaceURI);
node.appendChild(coordinates);
this.writeCoordinates_(coordinates, geometry, objectStack);
} else if (node.nodeName === 'Curve') {
const segments = createElementNS(node.namespaceURI, 'segments');
node.appendChild(segments);
this.writeCurveSegments_(segments,
geometry, objectStack);
this.writeCurveSegments_(segments, geometry, objectStack);
}
}
@@ -270,10 +311,15 @@ class GML2 extends GMLBase {
node.setAttribute('srsName', srsName);
}
const lines = geometry.getLineStrings();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, curve: curve},
pushSerializeAndPop(
{node: node, hasZ: hasZ, srsName: srsName, curve: curve},
this.LINESTRINGORCURVEMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, lines,
objectStack, undefined, this);
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_,
lines,
objectStack,
undefined,
this
);
}
/**
@@ -282,19 +328,34 @@ class GML2 extends GMLBase {
* @param {Array<*>} objectStack Node stack.
*/
writeGeometryElement(node, geometry, objectStack) {
const context = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[objectStack.length - 1]);
const context = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[
objectStack.length - 1
]);
const item = assign({}, context);
item['node'] = node;
let value;
if (Array.isArray(geometry)) {
value = transformExtentWithOptions(/** @type {import("../extent.js").Extent} */ (geometry), context);
value = transformExtentWithOptions(
/** @type {import("../extent.js").Extent} */ (geometry),
context
);
} else {
value = transformGeometryWithOptions(/** @type {import("../geom/Geometry.js").default} */ (geometry), true, context);
value = transformGeometryWithOptions(
/** @type {import("../geom/Geometry.js").default} */ (geometry),
true,
context
);
}
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
(item), this.GEOMETRY_SERIALIZERS_,
this.GEOMETRY_NODE_FACTORY_, [value],
objectStack, undefined, this);
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
(item),
this.GEOMETRY_SERIALIZERS_,
this.GEOMETRY_NODE_FACTORY_,
[value],
objectStack,
undefined,
this
);
}
/**
@@ -363,12 +424,15 @@ class GML2 extends GMLBase {
{node: node, hasZ: hasZ, srsName: srsName},
this.RING_SERIALIZERS_,
this.RING_NODE_FACTORY_,
rings, objectStack, undefined, this);
rings,
objectStack,
undefined,
this
);
} else if (node.nodeName === 'Surface') {
const patches = createElementNS(node.namespaceURI, 'patches');
node.appendChild(patches);
this.writeSurfacePatches_(
patches, geometry, objectStack);
this.writeSurfacePatches_(patches, geometry, objectStack);
}
}
@@ -386,8 +450,10 @@ class GML2 extends GMLBase {
if (exteriorWritten === undefined) {
context['exteriorWritten'] = true;
}
return createElementNS(parentNode.namespaceURI,
exteriorWritten !== undefined ? 'innerBoundaryIs' : 'outerBoundaryIs');
return createElementNS(
parentNode.namespaceURI,
exteriorWritten !== undefined ? 'innerBoundaryIs' : 'outerBoundaryIs'
);
}
/**
@@ -426,9 +492,10 @@ class GML2 extends GMLBase {
if (opt_srsName) {
axisOrientation = getProjection(opt_srsName).getAxisOrientation();
}
let coords = ((axisOrientation.substr(0, 2) === 'en') ?
point[0] + ',' + point[1] :
point[1] + ',' + point[0]);
let coords =
axisOrientation.substr(0, 2) === 'en'
? point[0] + ',' + point[1]
: point[1] + ',' + point[0];
if (opt_hasZ) {
// For newly created points, Z can be undefined.
const z = point[2] || 0;
@@ -472,10 +539,15 @@ class GML2 extends GMLBase {
node.setAttribute('srsName', srsName);
}
const points = geometry.getPoints();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName},
pushSerializeAndPop(
{node: node, hasZ: hasZ, srsName: srsName},
this.POINTMEMBER_SERIALIZERS_,
makeSimpleNodeFactory('pointMember'), points,
objectStack, undefined, this);
makeSimpleNodeFactory('pointMember'),
points,
objectStack,
undefined,
this
);
}
/**
@@ -522,10 +594,15 @@ class GML2 extends GMLBase {
node.setAttribute('srsName', srsName);
}
const polygons = geometry.getPolygons();
pushSerializeAndPop({node: node, hasZ: hasZ, srsName: srsName, surface: surface},
pushSerializeAndPop(
{node: node, hasZ: hasZ, srsName: srsName, surface: surface},
this.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
objectStack, undefined, this);
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_,
polygons,
objectStack,
undefined,
this
);
}
/**
@@ -535,8 +612,7 @@ class GML2 extends GMLBase {
* @private
*/
writeSurfaceOrPolygonMember_(node, polygon, objectStack) {
const child = this.GEOMETRY_NODE_FACTORY_(
polygon, objectStack);
const child = this.GEOMETRY_NODE_FACTORY_(polygon, objectStack);
if (child) {
node.appendChild(child);
this.writeSurfaceOrPolygon_(child, polygon, objectStack);
@@ -557,11 +633,16 @@ class GML2 extends GMLBase {
}
const keys = ['lowerCorner', 'upperCorner'];
const values = [extent[0] + ' ' + extent[1], extent[2] + ' ' + extent[3]];
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
({node: node}), this.ENVELOPE_SERIALIZERS_,
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
({node: node}),
this.ENVELOPE_SERIALIZERS_,
OBJECT_PROPERTY_NODE_FACTORY,
values,
objectStack, keys, this);
objectStack,
keys,
this
);
}
/**
@@ -574,8 +655,10 @@ class GML2 extends GMLBase {
*/
MULTIGEOMETRY_MEMBER_NODE_FACTORY_(value, objectStack, opt_nodeName) {
const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS('http://www.opengis.net/gml',
MULTIGEOMETRY_TO_MEMBER_NODENAME[parentNode.nodeName]);
return createElementNS(
'http://www.opengis.net/gml',
MULTIGEOMETRY_TO_MEMBER_NODENAME[parentNode.nodeName]
);
}
}
@@ -586,8 +669,8 @@ class GML2 extends GMLBase {
*/
GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
'http://www.opengis.net/gml': {
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates_)
}
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates_),
},
};
/**
@@ -598,8 +681,8 @@ GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
GML2.prototype.FLAT_LINEAR_RINGS_PARSERS = {
'http://www.opengis.net/gml': {
'innerBoundaryIs': GML2.prototype.innerBoundaryIsParser_,
'outerBoundaryIs': GML2.prototype.outerBoundaryIsParser_
}
'outerBoundaryIs': GML2.prototype.outerBoundaryIsParser_,
},
};
/**
@@ -609,9 +692,8 @@ GML2.prototype.FLAT_LINEAR_RINGS_PARSERS = {
*/
GML2.prototype.BOX_PARSERS_ = {
'http://www.opengis.net/gml': {
'coordinates': makeArrayPusher(
GML2.prototype.readFlatCoordinates_)
}
'coordinates': makeArrayPusher(GML2.prototype.readFlatCoordinates_),
},
};
/**
@@ -622,19 +704,14 @@ GML2.prototype.BOX_PARSERS_ = {
GML2.prototype.GEOMETRY_PARSERS = {
'http://www.opengis.net/gml': {
'Point': makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': makeReplacer(
GMLBase.prototype.readMultiPoint),
'LineString': makeReplacer(
GMLBase.prototype.readLineString),
'MultiLineString': makeReplacer(
GMLBase.prototype.readMultiLineString),
'LinearRing': makeReplacer(
GMLBase.prototype.readLinearRing),
'MultiPoint': makeReplacer(GMLBase.prototype.readMultiPoint),
'LineString': makeReplacer(GMLBase.prototype.readLineString),
'MultiLineString': makeReplacer(GMLBase.prototype.readMultiLineString),
'LinearRing': makeReplacer(GMLBase.prototype.readLinearRing),
'Polygon': makeReplacer(GMLBase.prototype.readPolygon),
'MultiPolygon': makeReplacer(
GMLBase.prototype.readMultiPolygon),
'Box': makeReplacer(GML2.prototype.readBox_)
}
'MultiPolygon': makeReplacer(GMLBase.prototype.readMultiPolygon),
'Box': makeReplacer(GML2.prototype.readBox_),
},
};
/**
@@ -644,30 +721,27 @@ GML2.prototype.GEOMETRY_PARSERS = {
*/
GML2.prototype.GEOMETRY_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'Curve': makeChildAppender(
GML2.prototype.writeCurveOrLineString_),
'Curve': makeChildAppender(GML2.prototype.writeCurveOrLineString_),
'MultiCurve': makeChildAppender(
GML2.prototype.writeMultiCurveOrLineString_),
GML2.prototype.writeMultiCurveOrLineString_
),
'Point': makeChildAppender(GML2.prototype.writePoint_),
'MultiPoint': makeChildAppender(
GML2.prototype.writeMultiPoint_),
'LineString': makeChildAppender(
GML2.prototype.writeCurveOrLineString_),
'MultiPoint': makeChildAppender(GML2.prototype.writeMultiPoint_),
'LineString': makeChildAppender(GML2.prototype.writeCurveOrLineString_),
'MultiLineString': makeChildAppender(
GML2.prototype.writeMultiCurveOrLineString_),
'LinearRing': makeChildAppender(
GML2.prototype.writeLinearRing_),
'Polygon': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygon_),
GML2.prototype.writeMultiCurveOrLineString_
),
'LinearRing': makeChildAppender(GML2.prototype.writeLinearRing_),
'Polygon': makeChildAppender(GML2.prototype.writeSurfaceOrPolygon_),
'MultiPolygon': makeChildAppender(
GML2.prototype.writeMultiSurfaceOrPolygon_),
'Surface': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygon_),
GML2.prototype.writeMultiSurfaceOrPolygon_
),
'Surface': makeChildAppender(GML2.prototype.writeSurfaceOrPolygon_),
'MultiSurface': makeChildAppender(
GML2.prototype.writeMultiSurfaceOrPolygon_),
'Envelope': makeChildAppender(
GML2.prototype.writeEnvelope)
}
GML2.prototype.writeMultiSurfaceOrPolygon_
),
'Envelope': makeChildAppender(GML2.prototype.writeEnvelope),
},
};
/**
@@ -677,10 +751,12 @@ GML2.prototype.GEOMETRY_SERIALIZERS_ = {
GML2.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_),
GML2.prototype.writeLineStringOrCurveMember_
),
'curveMember': makeChildAppender(
GML2.prototype.writeLineStringOrCurveMember_)
}
GML2.prototype.writeLineStringOrCurveMember_
),
},
};
/**
@@ -690,8 +766,8 @@ GML2.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
GML2.prototype.RING_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'outerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_),
'innerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_)
}
'innerBoundaryIs': makeChildAppender(GML2.prototype.writeRing_),
},
};
/**
@@ -700,9 +776,8 @@ GML2.prototype.RING_SERIALIZERS_ = {
*/
GML2.prototype.POINTMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'pointMember': makeChildAppender(
GML2.prototype.writePointMember_)
}
'pointMember': makeChildAppender(GML2.prototype.writePointMember_),
},
};
/**
@@ -713,10 +788,12 @@ GML2.prototype.POINTMEMBER_SERIALIZERS_ = {
GML2.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'surfaceMember': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygonMember_),
GML2.prototype.writeSurfaceOrPolygonMember_
),
'polygonMember': makeChildAppender(
GML2.prototype.writeSurfaceOrPolygonMember_)
}
GML2.prototype.writeSurfaceOrPolygonMember_
),
},
};
/**
@@ -726,8 +803,8 @@ GML2.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
GML2.prototype.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml': {
'lowerCorner': makeChildAppender(writeStringTextNode),
'upperCorner': makeChildAppender(writeStringTextNode)
}
'upperCorner': makeChildAppender(writeStringTextNode),
},
};
export default GML2;

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
*/
import GML3 from './GML3.js';
import GMLBase from './GMLBase.js';
import {makeArrayPusher, makeReplacer, makeChildAppender} from '../xml.js';
import {makeArrayPusher, makeChildAppender, makeReplacer} from '../xml.js';
import {writeStringTextNode} from '../format/xsd.js';
/**
@@ -12,21 +12,22 @@ import {writeStringTextNode} from '../format/xsd.js';
* @api
*/
class GML32 extends GML3 {
/**
* @param {import("./GMLBase.js").Options=} opt_options Optional configuration object.
*/
constructor(opt_options) {
const options = /** @type {import("./GMLBase.js").Options} */ (opt_options ? opt_options : {});
const options = /** @type {import("./GMLBase.js").Options} */ (opt_options
? opt_options
: {});
super(options);
/**
* @type {string}
*/
this.schemaLocation = options.schemaLocation ?
options.schemaLocation : this.namespace + ' http://schemas.opengis.net/gml/3.2.1/gml.xsd';
this.schemaLocation = options.schemaLocation
? options.schemaLocation
: this.namespace + ' http://schemas.opengis.net/gml/3.2.1/gml.xsd';
}
}
@@ -40,8 +41,8 @@ GML32.prototype.namespace = 'http://www.opengis.net/gml/3.2';
GML32.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
'http://www.opengis.net/gml/3.2': {
'pos': makeReplacer(GML3.prototype.readFlatPos_),
'posList': makeReplacer(GML3.prototype.readFlatPosList_)
}
'posList': makeReplacer(GML3.prototype.readFlatPosList_),
},
};
/**
@@ -52,8 +53,8 @@ GML32.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
GML32.prototype.FLAT_LINEAR_RINGS_PARSERS = {
'http://www.opengis.net/gml/3.2': {
'interior': GML3.prototype.interiorParser_,
'exterior': GML3.prototype.exteriorParser_
}
'exterior': GML3.prototype.exteriorParser_,
},
};
/**
@@ -64,25 +65,18 @@ GML32.prototype.FLAT_LINEAR_RINGS_PARSERS = {
GML32.prototype.GEOMETRY_PARSERS = {
'http://www.opengis.net/gml/3.2': {
'Point': makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': makeReplacer(
GMLBase.prototype.readMultiPoint),
'LineString': makeReplacer(
GMLBase.prototype.readLineString),
'MultiLineString': makeReplacer(
GMLBase.prototype.readMultiLineString),
'LinearRing': makeReplacer(
GMLBase.prototype.readLinearRing),
'MultiPoint': makeReplacer(GMLBase.prototype.readMultiPoint),
'LineString': makeReplacer(GMLBase.prototype.readLineString),
'MultiLineString': makeReplacer(GMLBase.prototype.readMultiLineString),
'LinearRing': makeReplacer(GMLBase.prototype.readLinearRing),
'Polygon': makeReplacer(GMLBase.prototype.readPolygon),
'MultiPolygon': makeReplacer(
GMLBase.prototype.readMultiPolygon),
'MultiPolygon': makeReplacer(GMLBase.prototype.readMultiPolygon),
'Surface': makeReplacer(GML32.prototype.readSurface_),
'MultiSurface': makeReplacer(
GML3.prototype.readMultiSurface_),
'MultiSurface': makeReplacer(GML3.prototype.readMultiSurface_),
'Curve': makeReplacer(GML32.prototype.readCurve_),
'MultiCurve': makeReplacer(
GML3.prototype.readMultiCurve_),
'Envelope': makeReplacer(GML32.prototype.readEnvelope_)
}
'MultiCurve': makeReplacer(GML3.prototype.readMultiCurve_),
'Envelope': makeReplacer(GML32.prototype.readEnvelope_),
},
};
/**
@@ -92,11 +86,9 @@ GML32.prototype.GEOMETRY_PARSERS = {
*/
GML32.prototype.MULTICURVE_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'curveMember': makeArrayPusher(
GML3.prototype.curveMemberParser_),
'curveMembers': makeArrayPusher(
GML3.prototype.curveMemberParser_)
}
'curveMember': makeArrayPusher(GML3.prototype.curveMemberParser_),
'curveMembers': makeArrayPusher(GML3.prototype.curveMemberParser_),
},
};
/**
@@ -106,11 +98,9 @@ GML32.prototype.MULTICURVE_PARSERS_ = {
*/
GML32.prototype.MULTISURFACE_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'surfaceMember': makeArrayPusher(
GML3.prototype.surfaceMemberParser_),
'surfaceMembers': makeArrayPusher(
GML3.prototype.surfaceMemberParser_)
}
'surfaceMember': makeArrayPusher(GML3.prototype.surfaceMemberParser_),
'surfaceMembers': makeArrayPusher(GML3.prototype.surfaceMemberParser_),
},
};
/**
@@ -120,10 +110,9 @@ GML32.prototype.MULTISURFACE_PARSERS_ = {
*/
GML32.prototype.CURVEMEMBER_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'LineString': makeArrayPusher(
GMLBase.prototype.readLineString),
'Curve': makeArrayPusher(GML3.prototype.readCurve_)
}
'LineString': makeArrayPusher(GMLBase.prototype.readLineString),
'Curve': makeArrayPusher(GML3.prototype.readCurve_),
},
};
/**
@@ -134,8 +123,8 @@ GML32.prototype.CURVEMEMBER_PARSERS_ = {
GML32.prototype.SURFACEMEMBER_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon),
'Surface': makeArrayPusher(GML3.prototype.readSurface_)
}
'Surface': makeArrayPusher(GML3.prototype.readSurface_),
},
};
/**
@@ -145,8 +134,8 @@ GML32.prototype.SURFACEMEMBER_PARSERS_ = {
*/
GML32.prototype.SURFACE_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'patches': makeReplacer(GML3.prototype.readPatch_)
}
'patches': makeReplacer(GML3.prototype.readPatch_),
},
};
/**
@@ -156,8 +145,8 @@ GML32.prototype.SURFACE_PARSERS_ = {
*/
GML32.prototype.CURVE_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'segments': makeReplacer(GML3.prototype.readSegment_)
}
'segments': makeReplacer(GML3.prototype.readSegment_),
},
};
/**
@@ -167,11 +156,9 @@ GML32.prototype.CURVE_PARSERS_ = {
*/
GML32.prototype.ENVELOPE_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'lowerCorner': makeArrayPusher(
GML3.prototype.readFlatPosList_),
'upperCorner': makeArrayPusher(
GML3.prototype.readFlatPosList_)
}
'lowerCorner': makeArrayPusher(GML3.prototype.readFlatPosList_),
'upperCorner': makeArrayPusher(GML3.prototype.readFlatPosList_),
},
};
/**
@@ -181,9 +168,8 @@ GML32.prototype.ENVELOPE_PARSERS_ = {
*/
GML32.prototype.PATCHES_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'PolygonPatch': makeReplacer(
GML3.prototype.readPolygonPatch_)
}
'PolygonPatch': makeReplacer(GML3.prototype.readPolygonPatch_),
},
};
/**
@@ -193,9 +179,8 @@ GML32.prototype.PATCHES_PARSERS_ = {
*/
GML32.prototype.SEGMENTS_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'LineStringSegment': makeReplacer(
GML3.prototype.readLineStringSegment_)
}
'LineStringSegment': makeReplacer(GML3.prototype.readLineStringSegment_),
},
};
/**
@@ -205,11 +190,9 @@ GML32.prototype.SEGMENTS_PARSERS_ = {
*/
GML32.prototype.MULTIPOINT_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'pointMember': makeArrayPusher(
GMLBase.prototype.pointMemberParser_),
'pointMembers': makeArrayPusher(
GMLBase.prototype.pointMemberParser_)
}
'pointMember': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
},
};
/**
@@ -220,10 +203,12 @@ GML32.prototype.MULTIPOINT_PARSERS_ = {
GML32.prototype.MULTILINESTRING_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'lineStringMember': makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_),
GMLBase.prototype.lineStringMemberParser_
),
'lineStringMembers': makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_)
}
GMLBase.prototype.lineStringMemberParser_
),
},
};
/**
@@ -233,11 +218,9 @@ GML32.prototype.MULTILINESTRING_PARSERS_ = {
*/
GML32.prototype.MULTIPOLYGON_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'polygonMember': makeArrayPusher(
GMLBase.prototype.polygonMemberParser_),
'polygonMembers': makeArrayPusher(
GMLBase.prototype.polygonMemberParser_)
}
'polygonMember': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
},
};
/**
@@ -247,9 +230,8 @@ GML32.prototype.MULTIPOLYGON_PARSERS_ = {
*/
GML32.prototype.POINTMEMBER_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'Point': makeArrayPusher(
GMLBase.prototype.readFlatCoordinatesFromNode_)
}
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_),
},
};
/**
@@ -259,9 +241,8 @@ GML32.prototype.POINTMEMBER_PARSERS_ = {
*/
GML32.prototype.LINESTRINGMEMBER_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'LineString': makeArrayPusher(
GMLBase.prototype.readLineString)
}
'LineString': makeArrayPusher(GMLBase.prototype.readLineString),
},
};
/**
@@ -271,9 +252,8 @@ GML32.prototype.LINESTRINGMEMBER_PARSERS_ = {
*/
GML32.prototype.POLYGONMEMBER_PARSERS_ = {
'http://www.opengis.net/gml/3.2': {
'Polygon': makeArrayPusher(
GMLBase.prototype.readPolygon)
}
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon),
},
};
/**
@@ -283,9 +263,8 @@ GML32.prototype.POLYGONMEMBER_PARSERS_ = {
*/
GML32.prototype.RING_PARSERS = {
'http://www.opengis.net/gml/3.2': {
'LinearRing': makeReplacer(
GMLBase.prototype.readFlatLinearRing_)
}
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_),
},
};
/**
@@ -295,11 +274,10 @@ GML32.prototype.RING_PARSERS = {
GML32.prototype.RING_SERIALIZERS_ = {
'http://www.opengis.net/gml/3.2': {
'exterior': makeChildAppender(GML3.prototype.writeRing_),
'interior': makeChildAppender(GML3.prototype.writeRing_)
}
'interior': makeChildAppender(GML3.prototype.writeRing_),
},
};
/**
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
* @private
@@ -307,11 +285,10 @@ GML32.prototype.RING_SERIALIZERS_ = {
GML32.prototype.ENVELOPE_SERIALIZERS_ = {
'http://www.opengis.net/gml/3.2': {
'lowerCorner': makeChildAppender(writeStringTextNode),
'upperCorner': makeChildAppender(writeStringTextNode)
}
'upperCorner': makeChildAppender(writeStringTextNode),
},
};
/**
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
* @private
@@ -319,25 +296,24 @@ GML32.prototype.ENVELOPE_SERIALIZERS_ = {
GML32.prototype.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml/3.2': {
'surfaceMember': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygonMember_),
GML3.prototype.writeSurfaceOrPolygonMember_
),
'polygonMember': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygonMember_)
}
GML3.prototype.writeSurfaceOrPolygonMember_
),
},
};
/**
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
* @private
*/
GML32.prototype.POINTMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml/3.2': {
'pointMember': makeChildAppender(
GML3.prototype.writePointMember_)
}
'pointMember': makeChildAppender(GML3.prototype.writePointMember_),
},
};
/**
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
* @private
@@ -345,10 +321,12 @@ GML32.prototype.POINTMEMBER_SERIALIZERS_ = {
GML32.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
'http://www.opengis.net/gml/3.2': {
'lineStringMember': makeChildAppender(
GML3.prototype.writeLineStringOrCurveMember_),
GML3.prototype.writeLineStringOrCurveMember_
),
'curveMember': makeChildAppender(
GML3.prototype.writeLineStringOrCurveMember_)
}
GML3.prototype.writeLineStringOrCurveMember_
),
},
};
/**
@@ -357,30 +335,27 @@ GML32.prototype.LINESTRINGORCURVEMEMBER_SERIALIZERS_ = {
*/
GML32.prototype.GEOMETRY_SERIALIZERS_ = {
'http://www.opengis.net/gml/3.2': {
'Curve': makeChildAppender(
GML3.prototype.writeCurveOrLineString_),
'Curve': makeChildAppender(GML3.prototype.writeCurveOrLineString_),
'MultiCurve': makeChildAppender(
GML3.prototype.writeMultiCurveOrLineString_),
GML3.prototype.writeMultiCurveOrLineString_
),
'Point': makeChildAppender(GML32.prototype.writePoint_),
'MultiPoint': makeChildAppender(
GML3.prototype.writeMultiPoint_),
'LineString': makeChildAppender(
GML3.prototype.writeCurveOrLineString_),
'MultiPoint': makeChildAppender(GML3.prototype.writeMultiPoint_),
'LineString': makeChildAppender(GML3.prototype.writeCurveOrLineString_),
'MultiLineString': makeChildAppender(
GML3.prototype.writeMultiCurveOrLineString_),
'LinearRing': makeChildAppender(
GML3.prototype.writeLinearRing_),
'Polygon': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygon_),
GML3.prototype.writeMultiCurveOrLineString_
),
'LinearRing': makeChildAppender(GML3.prototype.writeLinearRing_),
'Polygon': makeChildAppender(GML3.prototype.writeSurfaceOrPolygon_),
'MultiPolygon': makeChildAppender(
GML3.prototype.writeMultiSurfaceOrPolygon_),
'Surface': makeChildAppender(
GML3.prototype.writeSurfaceOrPolygon_),
GML3.prototype.writeMultiSurfaceOrPolygon_
),
'Surface': makeChildAppender(GML3.prototype.writeSurfaceOrPolygon_),
'MultiSurface': makeChildAppender(
GML3.prototype.writeMultiSurfaceOrPolygon_),
'Envelope': makeChildAppender(
GML3.prototype.writeEnvelope)
}
GML3.prototype.writeMultiSurfaceOrPolygon_
),
'Envelope': makeChildAppender(GML3.prototype.writeEnvelope),
},
};
export default GML32;

View File

@@ -4,10 +4,7 @@
// FIXME Envelopes should not be treated as geometries! readEnvelope_ is part
// of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
// envelopes/extents, only geometries!
import {extend} from '../array.js';
import Feature from '../Feature.js';
import {transformGeometryWithOptions, transformExtentWithOptions} from './Feature.js';
import XMLFeature from './XMLFeature.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js';
import LinearRing from '../geom/LinearRing.js';
@@ -16,10 +13,22 @@ import MultiPoint from '../geom/MultiPoint.js';
import MultiPolygon from '../geom/MultiPolygon.js';
import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js';
import XMLFeature from './XMLFeature.js';
import {assign} from '../obj.js';
import {extend} from '../array.js';
import {
getAllTextContent,
getAttributeNS,
makeArrayPusher,
makeReplacer,
parseNode,
pushParseAndPop,
} from '../xml.js';
import {get as getProjection} from '../proj.js';
import {getAllTextContent, getAttributeNS, makeArrayPusher, makeReplacer, parseNode, pushParseAndPop} from '../xml.js';
import {
transformExtentWithOptions,
transformGeometryWithOptions,
} from './Feature.js';
/**
* @const
@@ -27,7 +36,6 @@ import {getAllTextContent, getAttributeNS, makeArrayPusher, makeReplacer, parseN
*/
export const GMLNS = 'http://www.opengis.net/gml';
/**
* A regular expression that matches if a string only contains whitespace
* characters. It will e.g. match `''`, `' '`, `'\n'` etc. The non-breaking
@@ -41,7 +49,6 @@ export const GMLNS = 'http://www.opengis.net/gml';
*/
const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
/**
* @typedef {Object} Options
* @property {Object<string, string>|string} [featureNS] Feature
@@ -74,7 +81,6 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
* @property {boolean} [hasZ=false] If coordinates have a Z value.
*/
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
@@ -86,7 +92,6 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
* @abstract
*/
class GMLBase extends XMLFeature {
/**
* @param {Options=} opt_options Optional configuration object.
*/
@@ -125,7 +130,7 @@ class GMLBase extends XMLFeature {
this.FEATURE_COLLECTION_PARSERS = {};
this.FEATURE_COLLECTION_PARSERS[this.namespace] = {
'featureMember': makeArrayPusher(this.readFeaturesInternal),
'featureMembers': makeReplacer(this.readFeaturesInternal)
'featureMembers': makeReplacer(this.readFeaturesInternal),
};
}
@@ -138,9 +143,13 @@ class GMLBase extends XMLFeature {
const localName = node.localName;
let features = null;
if (localName == 'FeatureCollection') {
features = pushParseAndPop([],
this.FEATURE_COLLECTION_PARSERS, node,
objectStack, this);
features = pushParseAndPop(
[],
this.FEATURE_COLLECTION_PARSERS,
node,
objectStack,
this
);
} else if (localName == 'featureMembers' || localName == 'featureMember') {
const context = objectStack[0];
let featureType = context['featureType'];
@@ -148,7 +157,7 @@ class GMLBase extends XMLFeature {
const prefix = 'p';
const defaultPrefix = 'p0';
if (!featureType && node.childNodes) {
featureType = [], featureNS = {};
(featureType = []), (featureNS = {});
for (let i = 0, ii = node.childNodes.length; i < ii; ++i) {
const child = node.childNodes[i];
if (child.nodeType === 1) {
@@ -185,18 +194,22 @@ class GMLBase extends XMLFeature {
}
/** @type {Object<string, Object<string, import("../xml.js").Parser>>} */
const parsersNS = {};
const featureTypes = Array.isArray(featureType) ? featureType : [featureType];
const featureTypes = Array.isArray(featureType)
? featureType
: [featureType];
for (const p in featureNS) {
/** @type {Object<string, import("../xml.js").Parser>} */
const parsers = {};
for (let i = 0, ii = featureTypes.length; i < ii; ++i) {
const featurePrefix = featureTypes[i].indexOf(':') === -1 ?
defaultPrefix : featureTypes[i].split(':')[0];
const featurePrefix =
featureTypes[i].indexOf(':') === -1
? defaultPrefix
: featureTypes[i].split(':')[0];
if (featurePrefix === p) {
parsers[featureTypes[i].split(':').pop()] =
(localName == 'featureMembers') ?
makeArrayPusher(this.readFeatureElement, this) :
makeReplacer(this.readFeatureElement, this);
localName == 'featureMembers'
? makeArrayPusher(this.readFeatureElement, this)
: makeReplacer(this.readFeatureElement, this);
}
}
parsersNS[featureNS[p]] = parsers;
@@ -221,13 +234,28 @@ class GMLBase extends XMLFeature {
readGeometryElement(node, objectStack) {
const context = /** @type {Object} */ (objectStack[0]);
context['srsName'] = node.firstElementChild.getAttribute('srsName');
context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
const geometry = pushParseAndPop(null, this.GEOMETRY_PARSERS, node, objectStack, this);
context['srsDimension'] = node.firstElementChild.getAttribute(
'srsDimension'
);
const geometry = pushParseAndPop(
null,
this.GEOMETRY_PARSERS,
node,
objectStack,
this
);
if (geometry) {
if (Array.isArray(geometry)) {
return transformExtentWithOptions(/** @type {import("../extent.js").Extent} */ (geometry), context);
return transformExtentWithOptions(
/** @type {import("../extent.js").Extent} */ (geometry),
context
);
} else {
return transformGeometryWithOptions(/** @type {import("../geom/Geometry.js").default} */ (geometry), false, context);
return transformGeometryWithOptions(
/** @type {import("../geom/Geometry.js").default} */ (geometry),
false,
context
);
}
} else {
return undefined;
@@ -247,8 +275,11 @@ class GMLBase extends XMLFeature {
let value;
const localName = n.localName;
// first, check if it is simple attribute
if (n.childNodes.length === 0
|| (n.childNodes.length === 1 && (n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
if (
n.childNodes.length === 0 ||
(n.childNodes.length === 1 &&
(n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))
) {
value = getAllTextContent(n, false);
if (ONLY_WHITESPACE_RE.test(value)) {
value = undefined;
@@ -258,7 +289,8 @@ class GMLBase extends XMLFeature {
//if feature, try it as a geometry
value = this.readGeometryElement(n, objectStack);
}
if (!value) { //if not a geometry or not a feature, treat it as a complex attribute
if (!value) {
//if not a geometry or not a feature, treat it as a complex attribute
value = this.readFeatureElementInternal(n, objectStack, false);
} else if (localName !== 'boundedBy') {
// boundedBy is an extent and must not be considered as a geometry
@@ -291,8 +323,8 @@ class GMLBase extends XMLFeature {
if (geometryName) {
feature.setGeometryName(geometryName);
}
const fid = node.getAttribute('fid') ||
getAttributeNS(node, this.namespace, 'id');
const fid =
node.getAttribute('fid') || getAttributeNS(node, this.namespace, 'id');
if (fid) {
feature.setId(fid);
}
@@ -300,7 +332,6 @@ class GMLBase extends XMLFeature {
}
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -316,7 +347,10 @@ class GMLBase extends XMLFeature {
* @return {Point|undefined} Point.
*/
readPoint(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
const flatCoordinates = this.readFlatCoordinatesFromNode_(
node,
objectStack
);
if (flatCoordinates) {
return new Point(flatCoordinates, GeometryLayout.XYZ);
}
@@ -329,8 +363,13 @@ class GMLBase extends XMLFeature {
*/
readMultiPoint(node, objectStack) {
/** @type {Array<Array<number>>} */
const coordinates = pushParseAndPop([],
this.MULTIPOINT_PARSERS_, node, objectStack, this);
const coordinates = pushParseAndPop(
[],
this.MULTIPOINT_PARSERS_,
node,
objectStack,
this
);
if (coordinates) {
return new MultiPoint(coordinates);
} else {
@@ -345,8 +384,13 @@ class GMLBase extends XMLFeature {
*/
readMultiLineString(node, objectStack) {
/** @type {Array<LineString>} */
const lineStrings = pushParseAndPop([],
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
const lineStrings = pushParseAndPop(
[],
this.MULTILINESTRING_PARSERS_,
node,
objectStack,
this
);
if (lineStrings) {
return new MultiLineString(lineStrings);
}
@@ -359,7 +403,13 @@ class GMLBase extends XMLFeature {
*/
readMultiPolygon(node, objectStack) {
/** @type {Array<Polygon>} */
const polygons = pushParseAndPop([], this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
const polygons = pushParseAndPop(
[],
this.MULTIPOLYGON_PARSERS_,
node,
objectStack,
this
);
if (polygons) {
return new MultiPolygon(polygons);
}
@@ -398,7 +448,10 @@ class GMLBase extends XMLFeature {
* @return {LineString|undefined} LineString.
*/
readLineString(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
const flatCoordinates = this.readFlatCoordinatesFromNode_(
node,
objectStack
);
if (flatCoordinates) {
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
return lineString;
@@ -414,9 +467,13 @@ class GMLBase extends XMLFeature {
* @return {Array<number>|undefined} LinearRing flat coordinates.
*/
readFlatLinearRing_(node, objectStack) {
const ring = pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS, node,
objectStack, this);
const ring = pushParseAndPop(
null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS,
node,
objectStack,
this
);
if (ring) {
return ring;
} else {
@@ -430,7 +487,10 @@ class GMLBase extends XMLFeature {
* @return {LinearRing|undefined} LinearRing.
*/
readLinearRing(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
const flatCoordinates = this.readFlatCoordinatesFromNode_(
node,
objectStack
);
if (flatCoordinates) {
return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
}
@@ -443,8 +503,13 @@ class GMLBase extends XMLFeature {
*/
readPolygon(node, objectStack) {
/** @type {Array<Array<number>>} */
const flatLinearRings = pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS, node, objectStack, this);
const flatLinearRings = pushParseAndPop(
[null],
this.FLAT_LINEAR_RINGS_PARSERS,
node,
objectStack,
this
);
if (flatLinearRings && flatLinearRings[0]) {
const flatCoordinates = flatLinearRings[0];
const ends = [flatCoordinates.length];
@@ -466,7 +531,13 @@ class GMLBase extends XMLFeature {
* @return {Array<number>} Flat coordinates.
*/
readFlatCoordinatesFromNode_(node, objectStack) {
return pushParseAndPop(null, this.GEOMETRY_FLAT_COORDINATES_PARSERS, node, objectStack, this);
return pushParseAndPop(
null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS,
node,
objectStack,
this
);
}
/**
@@ -477,8 +548,9 @@ class GMLBase extends XMLFeature {
*/
//@ts-ignore
readGeometryFromNode(node, opt_options) {
const geometry = this.readGeometryElement(node,
[this.getReadOptions(node, opt_options ? opt_options : {})]);
const geometry = this.readGeometryElement(node, [
this.getReadOptions(node, opt_options ? opt_options : {}),
]);
return geometry ? geometry : null;
}
@@ -490,7 +562,7 @@ class GMLBase extends XMLFeature {
readFeaturesFromNode(node, opt_options) {
const options = {
featureType: this.featureType,
featureNS: this.featureNS
featureNS: this.featureNS,
};
if (opt_options) {
assign(options, this.getReadOptions(node, opt_options));
@@ -504,44 +576,43 @@ class GMLBase extends XMLFeature {
* @return {import("../proj/Projection.js").default} Projection.
*/
readProjectionFromNode(node) {
return getProjection(this.srsName ? this.srsName : node.firstElementChild.getAttribute('srsName'));
return getProjection(
this.srsName
? this.srsName
: node.firstElementChild.getAttribute('srsName')
);
}
}
GMLBase.prototype.namespace = GMLNS;
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.FLAT_LINEAR_RINGS_PARSERS = {
'http://www.opengis.net/gml': {}
'http://www.opengis.net/gml': {},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
'http://www.opengis.net/gml': {}
'http://www.opengis.net/gml': {},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.GEOMETRY_PARSERS = {
'http://www.opengis.net/gml': {}
'http://www.opengis.net/gml': {},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -550,11 +621,10 @@ GMLBase.prototype.GEOMETRY_PARSERS = {
GMLBase.prototype.MULTIPOINT_PARSERS_ = {
'http://www.opengis.net/gml': {
'pointMember': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_)
}
'pointMembers': makeArrayPusher(GMLBase.prototype.pointMemberParser_),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -562,12 +632,15 @@ GMLBase.prototype.MULTIPOINT_PARSERS_ = {
*/
GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
'http://www.opengis.net/gml': {
'lineStringMember': makeArrayPusher(GMLBase.prototype.lineStringMemberParser_),
'lineStringMembers': makeArrayPusher(GMLBase.prototype.lineStringMemberParser_)
}
'lineStringMember': makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_
),
'lineStringMembers': makeArrayPusher(
GMLBase.prototype.lineStringMemberParser_
),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -576,11 +649,10 @@ GMLBase.prototype.MULTILINESTRING_PARSERS_ = {
GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
'http://www.opengis.net/gml': {
'polygonMember': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_)
}
'polygonMembers': makeArrayPusher(GMLBase.prototype.polygonMemberParser_),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -588,11 +660,10 @@ GMLBase.prototype.MULTIPOLYGON_PARSERS_ = {
*/
GMLBase.prototype.POINTMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_)
}
'Point': makeArrayPusher(GMLBase.prototype.readFlatCoordinatesFromNode_),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -600,11 +671,10 @@ GMLBase.prototype.POINTMEMBER_PARSERS_ = {
*/
GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'LineString': makeArrayPusher(GMLBase.prototype.readLineString)
}
'LineString': makeArrayPusher(GMLBase.prototype.readLineString),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -612,11 +682,10 @@ GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = {
*/
GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
'http://www.opengis.net/gml': {
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon)
}
'Polygon': makeArrayPusher(GMLBase.prototype.readPolygon),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -624,8 +693,8 @@ GMLBase.prototype.POLYGONMEMBER_PARSERS_ = {
*/
GMLBase.prototype.RING_PARSERS = {
'http://www.opengis.net/gml': {
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_)
}
'LinearRing': makeReplacer(GMLBase.prototype.readFlatLinearRing_),
},
};
export default GMLBase;

View File

@@ -2,21 +2,40 @@
* @module ol/format/GPX
*/
import Feature from '../Feature.js';
import {includes} from '../array.js';
import {transformGeometryWithOptions} from './Feature.js';
import XMLFeature from './XMLFeature.js';
import {readString, readDecimal, readNonNegativeInteger, readDateTime, writeStringTextNode, writeNonNegativeIntegerTextNode, writeDecimalTextNode, writeDateTimeTextNode} from './xsd.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';
import XMLFeature from './XMLFeature.js';
import {
OBJECT_PROPERTY_NODE_FACTORY,
XML_SCHEMA_INSTANCE_URI,
createElementNS,
makeArrayPusher,
makeArraySerializer,
makeChildAppender,
makeObjectPropertySetter,
makeSequence,
makeSimpleNodeFactory,
makeStructureNS,
parseNode,
pushParseAndPop,
pushSerializeAndPop,
} from '../xml.js';
import {get as getProjection} from '../proj.js';
import {createElementNS, makeArrayPusher, makeArraySerializer, makeChildAppender,
makeObjectPropertySetter, makeSequence, makeSimpleNodeFactory, makeStructureNS,
OBJECT_PROPERTY_NODE_FACTORY, parseNode, pushParseAndPop, pushSerializeAndPop,
XML_SCHEMA_INSTANCE_URI} from '../xml.js';
import {includes} from '../array.js';
import {
readDateTime,
readDecimal,
readNonNegativeInteger,
readString,
writeDateTimeTextNode,
writeDecimalTextNode,
writeNonNegativeIntegerTextNode,
writeStringTextNode,
} from './xsd.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @const
@@ -25,17 +44,16 @@ import {createElementNS, makeArrayPusher, makeArraySerializer, makeChildAppender
const NAMESPACE_URIS = [
null,
'http://www.topografix.com/GPX/1/0',
'http://www.topografix.com/GPX/1/1'
'http://www.topografix.com/GPX/1/1',
];
/**
* @const
* @type {string}
*/
const SCHEMA_LOCATION = 'http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd';
const SCHEMA_LOCATION =
'http://www.topografix.com/GPX/1/1 ' +
'http://www.topografix.com/GPX/1/1/gpx.xsd';
/**
* @const
@@ -44,47 +62,40 @@ const SCHEMA_LOCATION = 'http://www.topografix.com/GPX/1/1 ' +
const FEATURE_READER = {
'rte': readRte,
'trk': readTrk,
'wpt': readWpt
'wpt': readWpt,
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const GPX_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'rte': makeArrayPusher(readRte),
'trk': makeArrayPusher(readTrk),
'wpt': makeArrayPusher(readWpt),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const GPX_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'rte': makeArrayPusher(readRte),
'trk': makeArrayPusher(readTrk),
'wpt': makeArrayPusher(readWpt)
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const LINK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'text': makeObjectPropertySetter(readString, 'linkText'),
'type': makeObjectPropertySetter(readString, 'linkType')
});
const LINK_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'text': makeObjectPropertySetter(readString, 'linkText'),
'type': makeObjectPropertySetter(readString, 'linkType'),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
// @ts-ignore
const GPX_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'rte': makeChildAppender(writeRte),
'trk': makeChildAppender(writeTrk),
'wpt': makeChildAppender(writeWpt)
});
const GPX_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
'rte': makeChildAppender(writeRte),
'trk': makeChildAppender(writeTrk),
'wpt': makeChildAppender(writeWpt),
});
/**
* @typedef {Object} Options
@@ -119,7 +130,6 @@ const GPX_SERIALIZERS = makeStructureNS(
* @api
*/
class GPX extends XMLFeature {
/**
* @param {Options=} opt_options Options.
*/
@@ -128,7 +138,6 @@ class GPX extends XMLFeature {
const options = opt_options ? opt_options : {};
/**
* @type {import("../proj/Projection.js").default}
*/
@@ -172,7 +181,9 @@ class GPX extends XMLFeature {
if (!featureReader) {
return null;
}
const feature = featureReader(node, [this.getReadOptions(node, opt_options)]);
const feature = featureReader(node, [
this.getReadOptions(node, opt_options),
]);
if (!feature) {
return null;
}
@@ -191,8 +202,9 @@ class GPX extends XMLFeature {
}
if (node.localName == 'gpx') {
/** @type {Array<Feature>} */
const features = pushParseAndPop([], GPX_PARSERS,
node, [this.getReadOptions(node, opt_options)]);
const features = pushParseAndPop([], GPX_PARSERS, node, [
this.getReadOptions(node, opt_options),
]);
if (features) {
this.handleReadExtensions_(features);
return features;
@@ -219,118 +231,115 @@ class GPX extends XMLFeature {
const gpx = createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
gpx.setAttributeNS(xmlnsUri, 'xmlns:xsi', XML_SCHEMA_INSTANCE_URI);
gpx.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION);
gpx.setAttributeNS(
XML_SCHEMA_INSTANCE_URI,
'xsi:schemaLocation',
SCHEMA_LOCATION
);
gpx.setAttribute('version', '1.1');
gpx.setAttribute('creator', 'OpenLayers');
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
({node: gpx}), GPX_SERIALIZERS, GPX_NODE_FACTORY, features, [opt_options]);
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
({node: gpx}),
GPX_SERIALIZERS,
GPX_NODE_FACTORY,
features,
[opt_options]
);
return gpx;
}
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const RTE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(readString),
'link': parseLink,
'number': makeObjectPropertySetter(readNonNegativeInteger),
'extensions': parseExtensions,
'type': makeObjectPropertySetter(readString),
'rtept': parseRtePt,
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const RTE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(readString),
'link': parseLink,
'number': makeObjectPropertySetter(readNonNegativeInteger),
'extensions': parseExtensions,
'type': makeObjectPropertySetter(readString),
'rtept': parseRtePt
});
const RTEPT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(readDateTime),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const RTEPT_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(readDateTime)
});
const TRK_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(readString),
'link': parseLink,
'number': makeObjectPropertySetter(readNonNegativeInteger),
'type': makeObjectPropertySetter(readString),
'extensions': parseExtensions,
'trkseg': parseTrkSeg,
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const TRK_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(readString),
'link': parseLink,
'number': makeObjectPropertySetter(readNonNegativeInteger),
'type': makeObjectPropertySetter(readString),
'extensions': parseExtensions,
'trkseg': parseTrkSeg
});
const TRKSEG_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'trkpt': parseTrkPt,
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const TRKSEG_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'trkpt': parseTrkPt
});
const TRKPT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(readDateTime),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const TRKPT_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(readDateTime)
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const WPT_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(readDateTime),
'magvar': makeObjectPropertySetter(readDecimal),
'geoidheight': makeObjectPropertySetter(readDecimal),
'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(readString),
'link': parseLink,
'sym': makeObjectPropertySetter(readString),
'type': makeObjectPropertySetter(readString),
'fix': makeObjectPropertySetter(readString),
'sat': makeObjectPropertySetter(readNonNegativeInteger),
'hdop': makeObjectPropertySetter(readDecimal),
'vdop': makeObjectPropertySetter(readDecimal),
'pdop': makeObjectPropertySetter(readDecimal),
'ageofdgpsdata': makeObjectPropertySetter(readDecimal),
'dgpsid': makeObjectPropertySetter(readNonNegativeInteger),
'extensions': parseExtensions
});
const WPT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'ele': makeObjectPropertySetter(readDecimal),
'time': makeObjectPropertySetter(readDateTime),
'magvar': makeObjectPropertySetter(readDecimal),
'geoidheight': makeObjectPropertySetter(readDecimal),
'name': makeObjectPropertySetter(readString),
'cmt': makeObjectPropertySetter(readString),
'desc': makeObjectPropertySetter(readString),
'src': makeObjectPropertySetter(readString),
'link': parseLink,
'sym': makeObjectPropertySetter(readString),
'type': makeObjectPropertySetter(readString),
'fix': makeObjectPropertySetter(readString),
'sat': makeObjectPropertySetter(readNonNegativeInteger),
'hdop': makeObjectPropertySetter(readDecimal),
'vdop': makeObjectPropertySetter(readDecimal),
'pdop': makeObjectPropertySetter(readDecimal),
'ageofdgpsdata': makeObjectPropertySetter(readDecimal),
'dgpsid': makeObjectPropertySetter(readNonNegativeInteger),
'extensions': parseExtensions,
});
/**
* @const
@@ -338,87 +347,86 @@ const WPT_PARSERS = makeStructureNS(
*/
const LINK_SEQUENCE = ['text', 'type'];
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
// @ts-ignore
const LINK_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'text': makeChildAppender(writeStringTextNode),
'type': makeChildAppender(writeStringTextNode)
});
const LINK_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
'text': makeChildAppender(writeStringTextNode),
'type': makeChildAppender(writeStringTextNode),
});
/**
* @const
* @type {Object<string, Array<string>>}
*/
// @ts-ignore
const RTE_SEQUENCE = makeStructureNS(
NAMESPACE_URIS, [
'name', 'cmt', 'desc', 'src', 'link', 'number', 'type', 'rtept'
]);
const RTE_SEQUENCE = makeStructureNS(NAMESPACE_URIS, [
'name',
'cmt',
'desc',
'src',
'link',
'number',
'type',
'rtept',
]);
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
// @ts-ignore
const RTE_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink),
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
'type': makeChildAppender(writeStringTextNode),
'rtept': makeArraySerializer(makeChildAppender(writeWptType))
});
const RTE_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink),
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
'type': makeChildAppender(writeStringTextNode),
'rtept': makeArraySerializer(makeChildAppender(writeWptType)),
});
/**
* @const
* @type {Object<string, Array<string>>}
*/
// @ts-ignore
const RTEPT_TYPE_SEQUENCE = makeStructureNS(
NAMESPACE_URIS, [
'ele', 'time'
]);
const RTEPT_TYPE_SEQUENCE = makeStructureNS(NAMESPACE_URIS, ['ele', 'time']);
/**
* @const
* @type {Object<string, Array<string>>}
*/
// @ts-ignore
const TRK_SEQUENCE = makeStructureNS(
NAMESPACE_URIS, [
'name', 'cmt', 'desc', 'src', 'link', 'number', 'type', 'trkseg'
]);
const TRK_SEQUENCE = makeStructureNS(NAMESPACE_URIS, [
'name',
'cmt',
'desc',
'src',
'link',
'number',
'type',
'trkseg',
]);
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
// @ts-ignore
const TRK_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink),
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
'type': makeChildAppender(writeStringTextNode),
'trkseg': makeArraySerializer(makeChildAppender(writeTrkSeg))
});
const TRK_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink),
'number': makeChildAppender(writeNonNegativeIntegerTextNode),
'type': makeChildAppender(writeStringTextNode),
'trkseg': makeArraySerializer(makeChildAppender(writeTrkSeg)),
});
/**
* @const
@@ -426,58 +434,66 @@ const TRK_SERIALIZERS = makeStructureNS(
*/
const TRKSEG_NODE_FACTORY = makeSimpleNodeFactory('trkpt');
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
// @ts-ignore
const TRKSEG_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'trkpt': makeChildAppender(writeWptType)
});
const TRKSEG_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
'trkpt': makeChildAppender(writeWptType),
});
/**
* @const
* @type {Object<string, Array<string>>}
*/
// @ts-ignore
const WPT_TYPE_SEQUENCE = makeStructureNS(
NAMESPACE_URIS, [
'ele', 'time', 'magvar', 'geoidheight', 'name', 'cmt', 'desc', 'src',
'link', 'sym', 'type', 'fix', 'sat', 'hdop', 'vdop', 'pdop',
'ageofdgpsdata', 'dgpsid'
]);
const WPT_TYPE_SEQUENCE = makeStructureNS(NAMESPACE_URIS, [
'ele',
'time',
'magvar',
'geoidheight',
'name',
'cmt',
'desc',
'src',
'link',
'sym',
'type',
'fix',
'sat',
'hdop',
'vdop',
'pdop',
'ageofdgpsdata',
'dgpsid',
]);
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
// @ts-ignore
const WPT_TYPE_SERIALIZERS = makeStructureNS(
NAMESPACE_URIS, {
'ele': makeChildAppender(writeDecimalTextNode),
'time': makeChildAppender(writeDateTimeTextNode),
'magvar': makeChildAppender(writeDecimalTextNode),
'geoidheight': makeChildAppender(writeDecimalTextNode),
'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink),
'sym': makeChildAppender(writeStringTextNode),
'type': makeChildAppender(writeStringTextNode),
'fix': makeChildAppender(writeStringTextNode),
'sat': makeChildAppender(writeNonNegativeIntegerTextNode),
'hdop': makeChildAppender(writeDecimalTextNode),
'vdop': makeChildAppender(writeDecimalTextNode),
'pdop': makeChildAppender(writeDecimalTextNode),
'ageofdgpsdata': makeChildAppender(writeDecimalTextNode),
'dgpsid': makeChildAppender(writeNonNegativeIntegerTextNode)
});
const WPT_TYPE_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
'ele': makeChildAppender(writeDecimalTextNode),
'time': makeChildAppender(writeDateTimeTextNode),
'magvar': makeChildAppender(writeDecimalTextNode),
'geoidheight': makeChildAppender(writeDecimalTextNode),
'name': makeChildAppender(writeStringTextNode),
'cmt': makeChildAppender(writeStringTextNode),
'desc': makeChildAppender(writeStringTextNode),
'src': makeChildAppender(writeStringTextNode),
'link': makeChildAppender(writeLink),
'sym': makeChildAppender(writeStringTextNode),
'type': makeChildAppender(writeStringTextNode),
'fix': makeChildAppender(writeStringTextNode),
'sat': makeChildAppender(writeNonNegativeIntegerTextNode),
'hdop': makeChildAppender(writeDecimalTextNode),
'vdop': makeChildAppender(writeDecimalTextNode),
'pdop': makeChildAppender(writeDecimalTextNode),
'ageofdgpsdata': makeChildAppender(writeDecimalTextNode),
'dgpsid': makeChildAppender(writeNonNegativeIntegerTextNode),
});
/**
* @const
@@ -486,10 +502,9 @@ const WPT_TYPE_SERIALIZERS = makeStructureNS(
const GEOMETRY_TYPE_TO_NODENAME = {
'Point': 'wpt',
'LineString': 'rte',
'MultiLineString': 'trk'
'MultiLineString': 'trk',
};
/**
* @param {*} value Value.
* @param {Array<*>} objectStack Object stack.
@@ -507,7 +522,6 @@ function GPX_NODE_FACTORY(value, objectStack, opt_nodeName) {
}
}
/**
* @param {Array<number>} flatCoordinates Flat coordinates.
* @param {LayoutOptions} layoutOptions Layout options.
@@ -518,7 +532,8 @@ function GPX_NODE_FACTORY(value, objectStack, opt_nodeName) {
function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
flatCoordinates.push(
parseFloat(node.getAttribute('lon')),
parseFloat(node.getAttribute('lat')));
parseFloat(node.getAttribute('lat'))
);
if ('ele' in values) {
flatCoordinates.push(/** @type {number} */ (values['ele']));
delete values['ele'];
@@ -536,7 +551,6 @@ function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
return flatCoordinates;
}
/**
* Choose GeometryLayout based on flags in layoutOptions and adjust flatCoordinates
* and ends arrays by shrinking them accordingly (removing unused zero entries).
@@ -570,17 +584,16 @@ function applyLayoutOptions(layoutOptions, flatCoordinates, ends) {
flatCoordinates[i * stride + 2] = flatCoordinates[i * 4 + 3];
}
}
flatCoordinates.length = flatCoordinates.length / 4 * stride;
flatCoordinates.length = (flatCoordinates.length / 4) * stride;
if (ends) {
for (let i = 0, ii = ends.length; i < ii; i++) {
ends[i] = ends[i] / 4 * stride;
ends[i] = (ends[i] / 4) * stride;
}
}
}
return layout;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -594,7 +607,6 @@ function parseLink(node, objectStack) {
parseNode(LINK_PARSERS, node, objectStack);
}
/**
* @param {Node} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -604,7 +616,6 @@ function parseExtensions(node, objectStack) {
values['extensionsNode_'] = node;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -612,14 +623,19 @@ function parseExtensions(node, objectStack) {
function parseRtePt(node, objectStack) {
const values = pushParseAndPop({}, RTEPT_PARSERS, node, objectStack);
if (values) {
const rteValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array<number>} */ (rteValues['flatCoordinates']);
const layoutOptions = /** @type {LayoutOptions} */ (rteValues['layoutOptions']);
const rteValues = /** @type {!Object} */ (objectStack[
objectStack.length - 1
]);
const flatCoordinates = /** @type {Array<number>} */ (rteValues[
'flatCoordinates'
]);
const layoutOptions = /** @type {LayoutOptions} */ (rteValues[
'layoutOptions'
]);
appendCoordinate(flatCoordinates, layoutOptions, node, values);
}
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -627,14 +643,19 @@ function parseRtePt(node, objectStack) {
function parseTrkPt(node, objectStack) {
const values = pushParseAndPop({}, TRKPT_PARSERS, node, objectStack);
if (values) {
const trkValues = /** @type {!Object} */ (objectStack[objectStack.length - 1]);
const flatCoordinates = /** @type {Array<number>} */ (trkValues['flatCoordinates']);
const layoutOptions = /** @type {LayoutOptions} */ (trkValues['layoutOptions']);
const trkValues = /** @type {!Object} */ (objectStack[
objectStack.length - 1
]);
const flatCoordinates = /** @type {Array<number>} */ (trkValues[
'flatCoordinates'
]);
const layoutOptions = /** @type {LayoutOptions} */ (trkValues[
'layoutOptions'
]);
appendCoordinate(flatCoordinates, layoutOptions, node, values);
}
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -642,13 +663,13 @@ function parseTrkPt(node, objectStack) {
function parseTrkSeg(node, objectStack) {
const values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
parseNode(TRKSEG_PARSERS, node, objectStack);
const flatCoordinates = /** @type {Array<number>} */
(values['flatCoordinates']);
const flatCoordinates =
/** @type {Array<number>} */
(values['flatCoordinates']);
const ends = /** @type {Array<number>} */ (values['ends']);
ends.push(flatCoordinates.length);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -656,15 +677,21 @@ function parseTrkSeg(node, objectStack) {
*/
function readRte(node, objectStack) {
const options = /** @type {import("./Feature.js").ReadOptions} */ (objectStack[0]);
const values = pushParseAndPop({
'flatCoordinates': [],
'layoutOptions': {}
}, RTE_PARSERS, node, objectStack);
const values = pushParseAndPop(
{
'flatCoordinates': [],
'layoutOptions': {},
},
RTE_PARSERS,
node,
objectStack
);
if (!values) {
return undefined;
}
const flatCoordinates = /** @type {Array<number>} */
(values['flatCoordinates']);
const flatCoordinates =
/** @type {Array<number>} */
(values['flatCoordinates']);
delete values['flatCoordinates'];
const layoutOptions = /** @type {LayoutOptions} */ (values['layoutOptions']);
delete values['layoutOptions'];
@@ -676,7 +703,6 @@ function readRte(node, objectStack) {
return feature;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -684,16 +710,22 @@ function readRte(node, objectStack) {
*/
function readTrk(node, objectStack) {
const options = /** @type {import("./Feature.js").ReadOptions} */ (objectStack[0]);
const values = pushParseAndPop({
'flatCoordinates': [],
'ends': [],
'layoutOptions': {}
}, TRK_PARSERS, node, objectStack);
const values = pushParseAndPop(
{
'flatCoordinates': [],
'ends': [],
'layoutOptions': {},
},
TRK_PARSERS,
node,
objectStack
);
if (!values) {
return undefined;
}
const flatCoordinates = /** @type {Array<number>} */
(values['flatCoordinates']);
const flatCoordinates =
/** @type {Array<number>} */
(values['flatCoordinates']);
delete values['flatCoordinates'];
const ends = /** @type {Array<number>} */ (values['ends']);
delete values['ends'];
@@ -707,7 +739,6 @@ function readTrk(node, objectStack) {
return feature;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -729,7 +760,6 @@ function readWpt(node, objectStack) {
return feature;
}
/**
* @param {Element} node Node.
* @param {string} value Value for the link's `href` attribute.
@@ -739,16 +769,17 @@ function writeLink(node, value, objectStack) {
node.setAttribute('href', value);
const context = objectStack[objectStack.length - 1];
const properties = context['properties'];
const link = [
properties['linkText'],
properties['linkType']
];
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */ ({node: node}),
LINK_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
link, objectStack, LINK_SEQUENCE);
const link = [properties['linkText'], properties['linkType']];
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */ ({node: node}),
LINK_SERIALIZERS,
OBJECT_PROPERTY_NODE_FACTORY,
link,
objectStack,
LINK_SEQUENCE
);
}
/**
* @param {Element} node Node.
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
@@ -768,7 +799,7 @@ function writeWptType(node, coordinate, objectStack) {
if (coordinate[3] !== 0) {
properties['time'] = coordinate[3];
}
// fall through
// fall through
case GeometryLayout.XYZ:
if (coordinate[2] !== 0) {
properties['ele'] = coordinate[2];
@@ -780,19 +811,24 @@ function writeWptType(node, coordinate, objectStack) {
}
break;
default:
// pass
// pass
}
const orderedKeys = (node.nodeName == 'rtept') ?
RTEPT_TYPE_SEQUENCE[namespaceURI] :
WPT_TYPE_SEQUENCE[namespaceURI];
const orderedKeys =
node.nodeName == 'rtept'
? RTEPT_TYPE_SEQUENCE[namespaceURI]
: WPT_TYPE_SEQUENCE[namespaceURI];
const values = makeSequence(properties, orderedKeys);
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */
({node: node, 'properties': properties}),
WPT_TYPE_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
values, objectStack, orderedKeys);
WPT_TYPE_SERIALIZERS,
OBJECT_PROPERTY_NODE_FACTORY,
values,
objectStack,
orderedKeys
);
}
/**
* @param {Node} node Node.
* @param {Feature} feature Feature.
@@ -805,19 +841,27 @@ function writeRte(node, feature, objectStack) {
context['properties'] = properties;
const geometry = feature.getGeometry();
if (geometry.getType() == GeometryType.LINE_STRING) {
const lineString = /** @type {LineString} */ (transformGeometryWithOptions(geometry, true, options));
const lineString = /** @type {LineString} */ (transformGeometryWithOptions(
geometry,
true,
options
));
context['geometryLayout'] = lineString.getLayout();
properties['rtept'] = lineString.getCoordinates();
}
const parentNode = objectStack[objectStack.length - 1].node;
const orderedKeys = RTE_SEQUENCE[parentNode.namespaceURI];
const values = makeSequence(properties, orderedKeys);
pushSerializeAndPop(context,
RTE_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
values, objectStack, orderedKeys);
pushSerializeAndPop(
context,
RTE_SERIALIZERS,
OBJECT_PROPERTY_NODE_FACTORY,
values,
objectStack,
orderedKeys
);
}
/**
* @param {Node} node Node.
* @param {Feature} feature Feature.
@@ -831,18 +875,26 @@ function writeTrk(node, feature, objectStack) {
context['properties'] = properties;
const geometry = feature.getGeometry();
if (geometry.getType() == GeometryType.MULTI_LINE_STRING) {
const multiLineString = /** @type {MultiLineString} */ (transformGeometryWithOptions(geometry, true, options));
const multiLineString = /** @type {MultiLineString} */ (transformGeometryWithOptions(
geometry,
true,
options
));
properties['trkseg'] = multiLineString.getLineStrings();
}
const parentNode = objectStack[objectStack.length - 1].node;
const orderedKeys = TRK_SEQUENCE[parentNode.namespaceURI];
const values = makeSequence(properties, orderedKeys);
pushSerializeAndPop(context,
TRK_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY,
values, objectStack, orderedKeys);
pushSerializeAndPop(
context,
TRK_SERIALIZERS,
OBJECT_PROPERTY_NODE_FACTORY,
values,
objectStack,
orderedKeys
);
}
/**
* @param {Node} node Node.
* @param {LineString} lineString LineString.
@@ -853,12 +905,15 @@ function writeTrkSeg(node, lineString, objectStack) {
const context = {node: node};
context['geometryLayout'] = lineString.getLayout();
context['properties'] = {};
pushSerializeAndPop(context,
TRKSEG_SERIALIZERS, TRKSEG_NODE_FACTORY,
lineString.getCoordinates(), objectStack);
pushSerializeAndPop(
context,
TRKSEG_SERIALIZERS,
TRKSEG_NODE_FACTORY,
lineString.getCoordinates(),
objectStack
);
}
/**
* @param {Element} node Node.
* @param {Feature} feature Feature.
@@ -870,11 +925,14 @@ function writeWpt(node, feature, objectStack) {
context['properties'] = feature.getProperties();
const geometry = feature.getGeometry();
if (geometry.getType() == GeometryType.POINT) {
const point = /** @type {Point} */ (transformGeometryWithOptions(geometry, true, options));
const point = /** @type {Point} */ (transformGeometryWithOptions(
geometry,
true,
options
));
context['geometryLayout'] = point.getLayout();
writeWptType(node, point.getCoordinates(), objectStack);
}
}
export default GPX;

View File

@@ -2,20 +2,20 @@
* @module ol/format/GeoJSON
*/
import {assert} from '../asserts.js';
import Feature from '../Feature.js';
import {transformGeometryWithOptions} from './Feature.js';
import JSONFeature from './JSONFeature.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';
import MultiPoint from '../geom/MultiPoint.js';
import MultiPolygon from '../geom/MultiPolygon.js';
import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js';
import {assert} from '../asserts.js';
import {assign, isEmpty} from '../obj.js';
import {get as getProjection} from '../proj.js';
import GeometryType from '../geom/GeometryType.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @typedef {import("geojson").GeoJSON} GeoJSONObject
@@ -31,7 +31,6 @@ import GeometryType from '../geom/GeometryType.js';
* @typedef {import("geojson").GeometryCollection} GeoJSONGeometryCollection
*/
/**
* @typedef {Object} Options
* @property {import("../proj.js").ProjectionLike} [dataProjection='EPSG:4326'] Default data projection.
@@ -44,20 +43,17 @@ import GeometryType from '../geom/GeometryType.js';
* and a `geometryName` is provided, the `geometryName` will take precedence.
*/
/**
* @classdesc
* Feature format for reading and writing data in the GeoJSON format.
*
* @api
* @api
*/
class GeoJSON extends JSONFeature {
/**
* @param {Options=} opt_options Options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
super();
@@ -66,8 +62,8 @@ class GeoJSON extends JSONFeature {
* @type {import("../proj/Projection.js").default}
*/
this.dataProjection = getProjection(
options.dataProjection ?
options.dataProjection : 'EPSG:4326');
options.dataProjection ? options.dataProjection : 'EPSG:4326'
);
if (options.featureProjection) {
this.defaultFeatureProjection = getProjection(options.featureProjection);
@@ -86,7 +82,6 @@ class GeoJSON extends JSONFeature {
* @private
*/
this.extractGeometryName_ = options.extractGeometryName;
}
/**
@@ -106,7 +101,7 @@ class GeoJSON extends JSONFeature {
geoJSONFeature = {
'type': 'Feature',
'geometry': /** @type {GeoJSONGeometry} */ (object),
'properties': null
'properties': null,
};
}
@@ -114,7 +109,10 @@ class GeoJSON extends JSONFeature {
const feature = new Feature();
if (this.geometryName_) {
feature.setGeometryName(this.geometryName_);
} else if (this.extractGeometryName_ && 'geometry_name' in geoJSONFeature !== undefined) {
} else if (
this.extractGeometryName_ &&
'geometry_name' in geoJSONFeature !== undefined
) {
feature.setGeometryName(geoJSONFeature['geometry_name']);
}
feature.setGeometry(geometry);
@@ -144,7 +142,9 @@ class GeoJSON extends JSONFeature {
features = [];
const geoJSONFeatures = geoJSONFeatureCollection['features'];
for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
features.push(this.readFeatureFromObject(geoJSONFeatures[i], opt_options));
features.push(
this.readFeatureFromObject(geoJSONFeatures[i], opt_options)
);
}
} else {
features = [this.readFeatureFromObject(object, opt_options)];
@@ -181,9 +181,7 @@ class GeoJSON extends JSONFeature {
} else {
projection = this.dataProjection;
}
return (
/** @type {import("../proj/Projection.js").default} */ (projection)
);
return /** @type {import("../proj/Projection.js").default} */ (projection);
}
/**
@@ -201,7 +199,7 @@ class GeoJSON extends JSONFeature {
const object = {
'type': 'Feature',
geometry: null,
properties: null
properties: null,
};
const id = feature.getId();
@@ -238,7 +236,7 @@ class GeoJSON extends JSONFeature {
}
return {
type: 'FeatureCollection',
features: objects
features: objects,
};
}
@@ -255,7 +253,6 @@ class GeoJSON extends JSONFeature {
}
}
/**
* @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object.
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
@@ -276,7 +273,9 @@ function readGeometry(object, opt_options) {
break;
}
case GeometryType.LINE_STRING: {
geometry = readLineStringGeometry(/** @type {GeoJSONLineString} */ (object));
geometry = readLineStringGeometry(
/** @type {GeoJSONLineString} */ (object)
);
break;
}
case GeometryType.POLYGON: {
@@ -284,19 +283,27 @@ function readGeometry(object, opt_options) {
break;
}
case GeometryType.MULTI_POINT: {
geometry = readMultiPointGeometry(/** @type {GeoJSONMultiPoint} */ (object));
geometry = readMultiPointGeometry(
/** @type {GeoJSONMultiPoint} */ (object)
);
break;
}
case GeometryType.MULTI_LINE_STRING: {
geometry = readMultiLineStringGeometry(/** @type {GeoJSONMultiLineString} */ (object));
geometry = readMultiLineStringGeometry(
/** @type {GeoJSONMultiLineString} */ (object)
);
break;
}
case GeometryType.MULTI_POLYGON: {
geometry = readMultiPolygonGeometry(/** @type {GeoJSONMultiPolygon} */ (object));
geometry = readMultiPolygonGeometry(
/** @type {GeoJSONMultiPolygon} */ (object)
);
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
geometry = readGeometryCollectionGeometry(/** @type {GeoJSONGeometryCollection} */ (object));
geometry = readGeometryCollectionGeometry(
/** @type {GeoJSONGeometryCollection} */ (object)
);
break;
}
default: {
@@ -306,7 +313,6 @@ function readGeometry(object, opt_options) {
return transformGeometryWithOptions(geometry, false, opt_options);
}
/**
* @param {GeoJSONGeometryCollection} object Object.
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
@@ -318,13 +324,13 @@ function readGeometryCollectionGeometry(object, opt_options) {
* @param {GeoJSONGeometry} geometry Geometry.
* @return {import("../geom/Geometry.js").default} geometry Geometry.
*/
function(geometry) {
function (geometry) {
return readGeometry(geometry, opt_options);
});
}
);
return new GeometryCollection(geometries);
}
/**
* @param {GeoJSONPoint} object Object.
* @return {Point} Point.
@@ -333,7 +339,6 @@ function readPointGeometry(object) {
return new Point(object['coordinates']);
}
/**
* @param {GeoJSONLineString} object Object.
* @return {LineString} LineString.
@@ -342,7 +347,6 @@ function readLineStringGeometry(object) {
return new LineString(object['coordinates']);
}
/**
* @param {GeoJSONMultiLineString} object Object.
* @return {MultiLineString} MultiLineString.
@@ -351,7 +355,6 @@ function readMultiLineStringGeometry(object) {
return new MultiLineString(object['coordinates']);
}
/**
* @param {GeoJSONMultiPoint} object Object.
* @return {MultiPoint} MultiPoint.
@@ -360,7 +363,6 @@ function readMultiPointGeometry(object) {
return new MultiPoint(object['coordinates']);
}
/**
* @param {GeoJSONMultiPolygon} object Object.
* @return {MultiPolygon} MultiPolygon.
@@ -369,7 +371,6 @@ function readMultiPolygonGeometry(object) {
return new MultiPolygon(object['coordinates']);
}
/**
* @param {GeoJSONPolygon} object Object.
* @return {Polygon} Polygon.
@@ -378,7 +379,6 @@ function readPolygonGeometry(object) {
return new Polygon(object['coordinates']);
}
/**
* @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -392,37 +392,58 @@ function writeGeometry(geometry, opt_options) {
let geoJSON;
switch (type) {
case GeometryType.POINT: {
geoJSON = writePointGeometry(/** @type {Point} */ (geometry), opt_options);
geoJSON = writePointGeometry(
/** @type {Point} */ (geometry),
opt_options
);
break;
}
case GeometryType.LINE_STRING: {
geoJSON = writeLineStringGeometry(/** @type {LineString} */ (geometry), opt_options);
geoJSON = writeLineStringGeometry(
/** @type {LineString} */ (geometry),
opt_options
);
break;
}
case GeometryType.POLYGON: {
geoJSON = writePolygonGeometry(/** @type {Polygon} */ (geometry), opt_options);
geoJSON = writePolygonGeometry(
/** @type {Polygon} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_POINT: {
geoJSON = writeMultiPointGeometry(/** @type {MultiPoint} */ (geometry), opt_options);
geoJSON = writeMultiPointGeometry(
/** @type {MultiPoint} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_LINE_STRING: {
geoJSON = writeMultiLineStringGeometry(/** @type {MultiLineString} */ (geometry), opt_options);
geoJSON = writeMultiLineStringGeometry(
/** @type {MultiLineString} */ (geometry),
opt_options
);
break;
}
case GeometryType.MULTI_POLYGON: {
geoJSON = writeMultiPolygonGeometry(/** @type {MultiPolygon} */ (geometry), opt_options);
geoJSON = writeMultiPolygonGeometry(
/** @type {MultiPolygon} */ (geometry),
opt_options
);
break;
}
case GeometryType.GEOMETRY_COLLECTION: {
geoJSON = writeGeometryCollectionGeometry(/** @type {GeometryCollection} */ (geometry), opt_options);
geoJSON = writeGeometryCollectionGeometry(
/** @type {GeometryCollection} */ (geometry),
opt_options
);
break;
}
case GeometryType.CIRCLE: {
geoJSON = {
type: 'GeometryCollection',
geometries: []
geometries: [],
};
break;
}
@@ -433,25 +454,23 @@ function writeGeometry(geometry, opt_options) {
return geoJSON;
}
/**
* @param {GeometryCollection} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
*/
function writeGeometryCollectionGeometry(geometry, opt_options) {
const geometries = geometry.getGeometriesArray().map(function(geometry) {
const geometries = geometry.getGeometriesArray().map(function (geometry) {
const options = assign({}, opt_options);
delete options.featureProjection;
return writeGeometry(geometry, options);
});
return {
type: 'GeometryCollection',
geometries: geometries
geometries: geometries,
};
}
/**
* @param {LineString} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -460,11 +479,10 @@ function writeGeometryCollectionGeometry(geometry, opt_options) {
function writeLineStringGeometry(geometry, opt_options) {
return {
type: 'LineString',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {MultiLineString} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -473,11 +491,10 @@ function writeLineStringGeometry(geometry, opt_options) {
function writeMultiLineStringGeometry(geometry, opt_options) {
return {
type: 'MultiLineString',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {MultiPoint} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -486,11 +503,10 @@ function writeMultiLineStringGeometry(geometry, opt_options) {
function writeMultiPointGeometry(geometry, opt_options) {
return {
type: 'MultiPoint',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {MultiPolygon} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -503,11 +519,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
}
return {
type: 'MultiPolygon',
coordinates: geometry.getCoordinates(right)
coordinates: geometry.getCoordinates(right),
};
}
/**
* @param {Point} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -516,11 +531,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
function writePointGeometry(geometry, opt_options) {
return {
type: 'Point',
coordinates: geometry.getCoordinates()
coordinates: geometry.getCoordinates(),
};
}
/**
* @param {Polygon} geometry Geometry.
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
@@ -533,9 +547,8 @@ function writePolygonGeometry(geometry, opt_options) {
}
return {
type: 'Polygon',
coordinates: geometry.getCoordinates(right)
coordinates: geometry.getCoordinates(right),
};
}
export default GeoJSON;

View File

@@ -2,11 +2,11 @@
* @module ol/format/IGC
*/
import Feature from '../Feature.js';
import {transformGeometryWithOptions} from './Feature.js';
import TextFeature from './TextFeature.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';
import {transformGeometryWithOptions} from './Feature.js';
/**
* IGC altitude/z. One of 'barometric', 'gps', 'none'.
@@ -15,16 +15,14 @@ import {get as getProjection} from '../proj.js';
const IGCZ = {
BAROMETRIC: 'barometric',
GPS: 'gps',
NONE: 'none'
NONE: 'none',
};
/**
* @const
* @type {RegExp}
*/
const B_RECORD_RE =
/^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(\d{5})(\d{5})/;
const B_RECORD_RE = /^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{5})([NS])(\d{3})(\d{5})([EW])([AV])(\d{5})(\d{5})/;
/**
* @const
@@ -32,14 +30,12 @@ const B_RECORD_RE =
*/
const H_RECORD_RE = /^H.([A-Z]{3}).*?:(.*)/;
/**
* @const
* @type {RegExp}
*/
const HFDTE_RECORD_RE = /^HFDTE(\d{2})(\d{2})(\d{2})/;
/**
* A regular expression matching the newline characters `\r\n`, `\r` and `\n`.
*
@@ -48,14 +44,12 @@ const HFDTE_RECORD_RE = /^HFDTE(\d{2})(\d{2})(\d{2})/;
*/
const NEWLINE_RE = /\r\n|\r|\n/;
/**
* @typedef {Object} Options
* @property {IGCZ|string} [altitudeMode='none'] Altitude mode. Possible
* values are `'barometric'`, `'gps'`, and `'none'`.
*/
/**
* @classdesc
* Feature format for `*.igc` flight recording files.
@@ -67,7 +61,6 @@ const NEWLINE_RE = /\r\n|\r|\n/;
* @api
*/
class IGC extends TextFeature {
/**
* @param {Options=} opt_options Options.
*/
@@ -85,7 +78,9 @@ class IGC extends TextFeature {
* @private
* @type {IGCZ}
*/
this.altitudeMode_ = options.altitudeMode ? options.altitudeMode : IGCZ.NONE;
this.altitudeMode_ = options.altitudeMode
? options.altitudeMode
: IGCZ.NONE;
}
/**
@@ -159,9 +154,12 @@ class IGC extends TextFeature {
if (flatCoordinates.length === 0) {
return null;
}
const layout = altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
const layout =
altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
const lineString = new LineString(flatCoordinates, layout);
const feature = new Feature(transformGeometryWithOptions(lineString, false, opt_options));
const feature = new Feature(
transformGeometryWithOptions(lineString, false, opt_options)
);
feature.setProperties(properties, true);
return feature;
}
@@ -180,7 +178,6 @@ class IGC extends TextFeature {
return [];
}
}
}
export default IGC;

View File

@@ -4,7 +4,6 @@
import {assert} from '../asserts.js';
/**
* @typedef {Object} PreferredOptions
* @property {string} [format] Preferred image format. Will be used if the image information
@@ -51,7 +50,7 @@ import {assert} from '../asserts.js';
const Versions = {
VERSION1: 'version1',
VERSION2: 'version2',
VERSION3: 'version3'
VERSION3: 'version3',
};
/**
@@ -65,67 +64,96 @@ IIIF_PROFILE_VALUES[Versions.VERSION1] = {
'level0': {
supports: [],
formats: [],
qualities: ['native']
qualities: ['native'],
},
'level1': {
supports: ['regionByPx', 'sizeByW', 'sizeByH', 'sizeByPct'],
formats: ['jpg'],
qualities: ['native']
qualities: ['native'],
},
'level2': {
supports: ['regionByPx', 'regionByPct', 'sizeByW', 'sizeByH', 'sizeByPct',
'sizeByConfinedWh', 'sizeByWh'],
supports: [
'regionByPx',
'regionByPct',
'sizeByW',
'sizeByH',
'sizeByPct',
'sizeByConfinedWh',
'sizeByWh',
],
formats: ['jpg', 'png'],
qualities: ['native', 'color', 'grey', 'bitonal']
}
qualities: ['native', 'color', 'grey', 'bitonal'],
},
};
IIIF_PROFILE_VALUES[Versions.VERSION2] = {
'level0': {
supports: [],
formats: ['jpg'],
qualities: ['default']
qualities: ['default'],
},
'level1': {
supports: ['regionByPx', 'sizeByW', 'sizeByH', 'sizeByPct'],
formats: ['jpg'],
qualities: ['default']
qualities: ['default'],
},
'level2': {
supports: ['regionByPx', 'regionByPct', 'sizeByW', 'sizeByH', 'sizeByPct',
'sizeByConfinedWh', 'sizeByDistortedWh', 'sizeByWh'],
supports: [
'regionByPx',
'regionByPct',
'sizeByW',
'sizeByH',
'sizeByPct',
'sizeByConfinedWh',
'sizeByDistortedWh',
'sizeByWh',
],
formats: ['jpg', 'png'],
qualities: ['default', 'bitonal']
}
qualities: ['default', 'bitonal'],
},
};
IIIF_PROFILE_VALUES[Versions.VERSION3] = {
'level0': {
supports: [],
formats: ['jpg'],
qualities: ['default']
qualities: ['default'],
},
'level1': {
supports: ['regionByPx', 'regionSquare', 'sizeByW', 'sizeByH', 'sizeByWh'],
formats: ['jpg'],
qualities: ['default']
qualities: ['default'],
},
'level2': {
supports: ['regionByPx', 'regionSquare', 'regionByPct',
'sizeByW', 'sizeByH', 'sizeByPct', 'sizeByConfinedWh', 'sizeByWh'],
supports: [
'regionByPx',
'regionSquare',
'regionByPct',
'sizeByW',
'sizeByH',
'sizeByPct',
'sizeByConfinedWh',
'sizeByWh',
],
formats: ['jpg', 'png'],
qualities: ['default']
}
qualities: ['default'],
},
};
IIIF_PROFILE_VALUES['none'] = {
'none': {
supports: [],
formats: [],
qualities: []
}
qualities: [],
},
};
const COMPLIANCE_VERSION1 = new RegExp('^https?\:\/\/library\.stanford\.edu\/iiif\/image-api\/(1\.1\/)?compliance\.html#level[0-2]$');
const COMPLIANCE_VERSION2 = new RegExp('^https?\:\/\/iiif\.io\/api\/image\/2\/level[0-2](\.json)?$');
const COMPLIANCE_VERSION3 = new RegExp('(^https?\:\/\/iiif\.io\/api\/image\/3\/level[0-2](\.json)?$)|(^level[0-2]$)');
const COMPLIANCE_VERSION1 = new RegExp(
'^https?://library.stanford.edu/iiif/image-api/(1.1/)?compliance.html#level[0-2]$'
);
const COMPLIANCE_VERSION2 = new RegExp(
'^https?://iiif.io/api/image/2/level[0-2](.json)?$'
);
const COMPLIANCE_VERSION3 = new RegExp(
'(^https?://iiif.io/api/image/3/level[0-2](.json)?$)|(^level[0-2]$)'
);
function generateVersion1Options(iiifInfo) {
let levelProfile = iiifInfo.getComplianceLevelSupportedFeatures();
@@ -134,84 +162,138 @@ function generateVersion1Options(iiifInfo) {
levelProfile = IIIF_PROFILE_VALUES[Versions.VERSION1]['level0'];
}
return {
url: iiifInfo.imageInfo['@id'] === undefined ? undefined : iiifInfo.imageInfo['@id'].replace(/\/?(info.json)?$/g, ''),
url:
iiifInfo.imageInfo['@id'] === undefined
? undefined
: iiifInfo.imageInfo['@id'].replace(/\/?(info.json)?$/g, ''),
supports: levelProfile.supports,
formats: [...levelProfile.formats, iiifInfo.imageInfo.formats === undefined ?
[] : iiifInfo.imageInfo.formats
formats: [
...levelProfile.formats,
iiifInfo.imageInfo.formats === undefined
? []
: iiifInfo.imageInfo.formats,
],
qualities: [...levelProfile.qualities, iiifInfo.imageInfo.qualities === undefined ?
[] : iiifInfo.imageInfo.qualities
qualities: [
...levelProfile.qualities,
iiifInfo.imageInfo.qualities === undefined
? []
: iiifInfo.imageInfo.qualities,
],
resolutions: iiifInfo.imageInfo.scale_factors,
tileSize: iiifInfo.imageInfo.tile_width !== undefined ? (iiifInfo.imageInfo.tile_height !== undefined ?
[iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_height] : [iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_width]) :
(iiifInfo.imageInfo.tile_height != undefined ? [iiifInfo.imageInfo.tile_height, iiifInfo.imageInfo.tile_height] : undefined)
tileSize:
iiifInfo.imageInfo.tile_width !== undefined
? iiifInfo.imageInfo.tile_height !== undefined
? [iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_height]
: [iiifInfo.imageInfo.tile_width, iiifInfo.imageInfo.tile_width]
: iiifInfo.imageInfo.tile_height != undefined
? [iiifInfo.imageInfo.tile_height, iiifInfo.imageInfo.tile_height]
: undefined,
};
}
function generateVersion2Options(iiifInfo) {
const levelProfile = iiifInfo.getComplianceLevelSupportedFeatures(),
additionalProfile = Array.isArray(iiifInfo.imageInfo.profile) && iiifInfo.imageInfo.profile.length > 1,
profileSupports = additionalProfile && iiifInfo.imageInfo.profile[1].supports ? iiifInfo.imageInfo.profile[1].supports : [],
profileFormats = additionalProfile && iiifInfo.imageInfo.profile[1].formats ? iiifInfo.imageInfo.profile[1].formats : [],
profileQualities = additionalProfile && iiifInfo.imageInfo.profile[1].qualities ? iiifInfo.imageInfo.profile[1].qualities : [];
additionalProfile =
Array.isArray(iiifInfo.imageInfo.profile) &&
iiifInfo.imageInfo.profile.length > 1,
profileSupports =
additionalProfile && iiifInfo.imageInfo.profile[1].supports
? iiifInfo.imageInfo.profile[1].supports
: [],
profileFormats =
additionalProfile && iiifInfo.imageInfo.profile[1].formats
? iiifInfo.imageInfo.profile[1].formats
: [],
profileQualities =
additionalProfile && iiifInfo.imageInfo.profile[1].qualities
? iiifInfo.imageInfo.profile[1].qualities
: [];
return {
url: iiifInfo.imageInfo['@id'].replace(/\/?(info.json)?$/g, ''),
sizes: iiifInfo.imageInfo.sizes === undefined ? undefined : iiifInfo.imageInfo.sizes.map(function(size) {
return [size.width, size.height];
}),
tileSize: iiifInfo.imageInfo.tiles === undefined ? undefined : [
iiifInfo.imageInfo.tiles.map(function(tile) {
return tile.width;
})[0],
iiifInfo.imageInfo.tiles.map(function(tile) {
return tile.height === undefined ? tile.width : tile.height;
})[0]
],
resolutions: iiifInfo.imageInfo.tiles === undefined ? undefined :
iiifInfo.imageInfo.tiles.map(function(tile) {
return tile.scaleFactors;
})[0],
sizes:
iiifInfo.imageInfo.sizes === undefined
? undefined
: iiifInfo.imageInfo.sizes.map(function (size) {
return [size.width, size.height];
}),
tileSize:
iiifInfo.imageInfo.tiles === undefined
? undefined
: [
iiifInfo.imageInfo.tiles.map(function (tile) {
return tile.width;
})[0],
iiifInfo.imageInfo.tiles.map(function (tile) {
return tile.height === undefined ? tile.width : tile.height;
})[0],
],
resolutions:
iiifInfo.imageInfo.tiles === undefined
? undefined
: iiifInfo.imageInfo.tiles.map(function (tile) {
return tile.scaleFactors;
})[0],
supports: [...levelProfile.supports, ...profileSupports],
formats: [...levelProfile.formats, ...profileFormats],
qualities: [...levelProfile.qualities, ...profileQualities]
qualities: [...levelProfile.qualities, ...profileQualities],
};
}
function generateVersion3Options(iiifInfo) {
const levelProfile = iiifInfo.getComplianceLevelSupportedFeatures(),
formats = iiifInfo.imageInfo.extraFormats === undefined ? levelProfile.formats :
[...levelProfile.formats, ...iiifInfo.imageInfo.extraFormats],
preferredFormat = iiifInfo.imageInfo.preferredFormats !== undefined && Array.isArray(iiifInfo.imageInfo.preferredFormats) &&
iiifInfo.imageInfo.preferredFormats.length > 0 ?
iiifInfo.imageInfo.preferredFormats.filter(function(format) {
return ['jpg', 'png', 'gif'].includes(format);
}).reduce(function(acc, format) {
return acc === undefined && formats.includes(format) ? format : acc;
}, undefined) : undefined;
formats =
iiifInfo.imageInfo.extraFormats === undefined
? levelProfile.formats
: [...levelProfile.formats, ...iiifInfo.imageInfo.extraFormats],
preferredFormat =
iiifInfo.imageInfo.preferredFormats !== undefined &&
Array.isArray(iiifInfo.imageInfo.preferredFormats) &&
iiifInfo.imageInfo.preferredFormats.length > 0
? iiifInfo.imageInfo.preferredFormats
.filter(function (format) {
return ['jpg', 'png', 'gif'].includes(format);
})
.reduce(function (acc, format) {
return acc === undefined && formats.includes(format)
? format
: acc;
}, undefined)
: undefined;
return {
url: iiifInfo.imageInfo['id'],
sizes: iiifInfo.imageInfo.sizes === undefined ? undefined : iiifInfo.imageInfo.sizes.map(function(size) {
return [size.width, size.height];
}),
tileSize: iiifInfo.imageInfo.tiles === undefined ? undefined : [
iiifInfo.imageInfo.tiles.map(function(tile) {
return tile.width;
})[0],
iiifInfo.imageInfo.tiles.map(function(tile) {
return tile.height;
})[0]
],
resolutions: iiifInfo.imageInfo.tiles === undefined ? undefined :
iiifInfo.imageInfo.tiles.map(function(tile) {
return tile.scaleFactors;
})[0],
supports: iiifInfo.imageInfo.extraFeatures === undefined ? levelProfile.supports :
[...levelProfile.supports, ...iiifInfo.imageInfo.extraFeatures],
sizes:
iiifInfo.imageInfo.sizes === undefined
? undefined
: iiifInfo.imageInfo.sizes.map(function (size) {
return [size.width, size.height];
}),
tileSize:
iiifInfo.imageInfo.tiles === undefined
? undefined
: [
iiifInfo.imageInfo.tiles.map(function (tile) {
return tile.width;
})[0],
iiifInfo.imageInfo.tiles.map(function (tile) {
return tile.height;
})[0],
],
resolutions:
iiifInfo.imageInfo.tiles === undefined
? undefined
: iiifInfo.imageInfo.tiles.map(function (tile) {
return tile.scaleFactors;
})[0],
supports:
iiifInfo.imageInfo.extraFeatures === undefined
? levelProfile.supports
: [...levelProfile.supports, ...iiifInfo.imageInfo.extraFeatures],
formats: formats,
qualities: iiifInfo.imageInfo.extraQualities === undefined ? levelProfile.qualities :
[...levelProfile.qualities, ...iiifInfo.imageInfo.extraQualities],
preferredFormat: preferredFormat
qualities:
iiifInfo.imageInfo.extraQualities === undefined
? levelProfile.qualities
: [...levelProfile.qualities, ...iiifInfo.imageInfo.extraQualities],
preferredFormat: preferredFormat,
};
}
@@ -228,7 +310,6 @@ versionFunctions[Versions.VERSION3] = generateVersion3Options;
* @api
*/
class IIIFInfo {
/**
* @param {string|ImageInformationResponse} imageInfo
* Deserialized image information JSON response object or JSON response as string
@@ -273,7 +354,10 @@ class IIIFInfo {
return Versions.VERSION3;
case 'ol-no-context':
// Image API 1.0 has no '@context'
if (this.getComplianceLevelEntryFromProfile(Versions.VERSION1) && this.imageInfo.identifier) {
if (
this.getComplianceLevelEntryFromProfile(Versions.VERSION1) &&
this.imageInfo.identifier
) {
return Versions.VERSION1;
}
break;
@@ -307,11 +391,18 @@ class IIIFInfo {
}
break;
case Versions.VERSION2:
if (typeof this.imageInfo.profile === 'string' && COMPLIANCE_VERSION2.test(this.imageInfo.profile)) {
if (
typeof this.imageInfo.profile === 'string' &&
COMPLIANCE_VERSION2.test(this.imageInfo.profile)
) {
return this.imageInfo.profile;
}
if (Array.isArray(this.imageInfo.profile) && this.imageInfo.profile.length > 0
&& typeof this.imageInfo.profile[0] === 'string' && COMPLIANCE_VERSION2.test(this.imageInfo.profile[0])) {
if (
Array.isArray(this.imageInfo.profile) &&
this.imageInfo.profile.length > 0 &&
typeof this.imageInfo.profile[0] === 'string' &&
COMPLIANCE_VERSION2.test(this.imageInfo.profile[0])
) {
return this.imageInfo.profile[0];
}
break;
@@ -355,11 +446,12 @@ class IIIFInfo {
*/
getTileSourceOptions(opt_preferredOptions) {
const options = opt_preferredOptions || {},
version = this.getImageApiVersion();
version = this.getImageApiVersion();
if (version === undefined) {
return;
}
const imageOptions = version === undefined ? undefined : versionFunctions[version](this);
const imageOptions =
version === undefined ? undefined : versionFunctions[version](this);
if (imageOptions === undefined) {
return;
}
@@ -368,18 +460,28 @@ class IIIFInfo {
version: version,
size: [this.imageInfo.width, this.imageInfo.height],
sizes: imageOptions.sizes,
format: options.format !== undefined && imageOptions.formats.includes(options.format) ? options.format :
imageOptions.preferredFormat !== undefined ? imageOptions.preferredFormat : 'jpg',
format:
options.format !== undefined &&
imageOptions.formats.includes(options.format)
? options.format
: imageOptions.preferredFormat !== undefined
? imageOptions.preferredFormat
: 'jpg',
supports: imageOptions.supports,
quality: options.quality && imageOptions.qualities.includes(options.quality) ?
options.quality : imageOptions.qualities.includes('native') ? 'native' : 'default',
resolutions: Array.isArray(imageOptions.resolutions) ? imageOptions.resolutions.sort(function(a, b) {
return b - a;
}) : undefined,
tileSize: imageOptions.tileSize
quality:
options.quality && imageOptions.qualities.includes(options.quality)
? options.quality
: imageOptions.qualities.includes('native')
? 'native'
: 'default',
resolutions: Array.isArray(imageOptions.resolutions)
? imageOptions.resolutions.sort(function (a, b) {
return b - a;
})
: undefined,
tileSize: imageOptions.tileSize,
};
}
}
export default IIIFInfo;

View File

@@ -1,9 +1,9 @@
/**
* @module ol/format/JSONFeature
*/
import {abstract} from '../util.js';
import FeatureFormat from './Feature.js';
import FormatType from './FormatType.js';
import {abstract} from '../util.js';
/**
* @classdesc
@@ -36,7 +36,9 @@ class JSONFeature extends FeatureFormat {
*/
readFeature(source, opt_options) {
return this.readFeatureFromObject(
getObject(source), this.getReadOptions(source, opt_options));
getObject(source),
this.getReadOptions(source, opt_options)
);
}
/**
@@ -50,7 +52,9 @@ class JSONFeature extends FeatureFormat {
*/
readFeatures(source, opt_options) {
return this.readFeaturesFromObject(
getObject(source), this.getReadOptions(source, opt_options));
getObject(source),
this.getReadOptions(source, opt_options)
);
}
/**
@@ -85,7 +89,9 @@ class JSONFeature extends FeatureFormat {
*/
readGeometry(source, opt_options) {
return this.readGeometryFromObject(
getObject(source), this.getReadOptions(source, opt_options));
getObject(source),
this.getReadOptions(source, opt_options)
);
}
/**
@@ -187,7 +193,6 @@ class JSONFeature extends FeatureFormat {
}
}
/**
* @param {Document|Element|Object|string} source Source.
* @return {Object} Object.
@@ -203,5 +208,4 @@ function getObject(source) {
}
}
export default JSONFeature;

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,6 @@
*/
//FIXME Implement projection handling
import {assert} from '../asserts.js';
import PBF from 'pbf';
import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
import FormatType from './FormatType.js';
import GeometryLayout from '../geom/GeometryLayout.js';
@@ -13,14 +11,15 @@ import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js';
import MultiPoint from '../geom/MultiPoint.js';
import MultiPolygon from '../geom/MultiPolygon.js';
import PBF from 'pbf';
import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js';
import {linearRingIsClockwise} from '../geom/flat/orient.js';
import Projection from '../proj/Projection.js';
import Units from '../proj/Units.js';
import RenderFeature from '../render/Feature.js';
import Units from '../proj/Units.js';
import {assert} from '../asserts.js';
import {get} from '../proj.js';
import {linearRingIsClockwise} from '../geom/flat/orient.js';
/**
* @typedef {Object} Options
@@ -35,7 +34,6 @@ import {get} from '../proj.js';
* layers.
*/
/**
* @classdesc
* Feature format for reading data in the Mapbox MVT format.
@@ -44,7 +42,6 @@ import {get} from '../proj.js';
* @api
*/
class MVT extends FeatureFormat {
/**
* @param {Options=} opt_options Options.
*/
@@ -58,14 +55,16 @@ class MVT extends FeatureFormat {
*/
this.dataProjection = new Projection({
code: '',
units: Units.TILE_PIXELS
units: Units.TILE_PIXELS,
});
/**
* @private
* @type {import("../Feature.js").FeatureClass}
*/
this.featureClass_ = options.featureClass ? options.featureClass : RenderFeature;
this.featureClass_ = options.featureClass
? options.featureClass
: RenderFeature;
/**
* @private
@@ -90,7 +89,6 @@ class MVT extends FeatureFormat {
* @type {string}
*/
this.idProperty_ = options.idProperty;
}
/**
@@ -126,7 +124,8 @@ class MVT extends FeatureFormat {
x += pbf.readSVarint();
y += pbf.readSVarint();
if (cmd === 1) { // moveTo
if (cmd === 1) {
// moveTo
if (coordsLen > currentEnd) {
ends.push(coordsLen);
currentEnd = coordsLen;
@@ -135,16 +134,15 @@ class MVT extends FeatureFormat {
flatCoordinates.push(x, y);
coordsLen += 2;
} else if (cmd === 7) {
if (coordsLen > currentEnd) {
// close polygon
flatCoordinates.push(
flatCoordinates[currentEnd], flatCoordinates[currentEnd + 1]);
flatCoordinates[currentEnd],
flatCoordinates[currentEnd + 1]
);
coordsLen += 2;
}
} else {
assert(false, 59); // Invalid command found in the PBF
}
@@ -154,7 +152,6 @@ class MVT extends FeatureFormat {
ends.push(coordsLen);
currentEnd = coordsLen;
}
}
/**
@@ -190,7 +187,13 @@ class MVT extends FeatureFormat {
const geometryType = getGeometryType(type, ends.length);
if (this.featureClass_ === RenderFeature) {
feature = new this.featureClass_(geometryType, flatCoordinates, ends, values, id);
feature = new this.featureClass_(
geometryType,
flatCoordinates,
ends,
values,
id
);
feature.transform(options.dataProjection, options.featureProjection);
} else {
let geom;
@@ -212,14 +215,21 @@ class MVT extends FeatureFormat {
geom = new Polygon(flatCoordinates, GeometryLayout.XY, ends);
}
} else {
geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
geometryType === GeometryType.LINE_STRING ? new LineString(flatCoordinates, GeometryLayout.XY) :
geometryType === GeometryType.POLYGON ? new Polygon(flatCoordinates, GeometryLayout.XY, ends) :
geometryType === GeometryType.MULTI_POINT ? new MultiPoint(flatCoordinates, GeometryLayout.XY) :
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends) :
null;
geom =
geometryType === GeometryType.POINT
? new Point(flatCoordinates, GeometryLayout.XY)
: geometryType === GeometryType.LINE_STRING
? new LineString(flatCoordinates, GeometryLayout.XY)
: geometryType === GeometryType.POLYGON
? new Polygon(flatCoordinates, GeometryLayout.XY, ends)
: geometryType === GeometryType.MULTI_POINT
? new MultiPoint(flatCoordinates, GeometryLayout.XY)
: geometryType === GeometryType.MULTI_LINE_STRING
? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends)
: null;
}
const ctor = /** @type {typeof import("../Feature.js").default} */ (this.featureClass_);
const ctor = /** @type {typeof import("../Feature.js").default} */ (this
.featureClass_);
feature = new ctor();
if (this.geometryName_) {
feature.setGeometryName(this.geometryName_);
@@ -250,7 +260,9 @@ class MVT extends FeatureFormat {
*/
readFeatures(source, opt_options) {
const layers = this.layers_;
const options = /** @type {import("./Feature.js").ReadOptions} */ (this.adaptOptions(opt_options));
const options = /** @type {import("./Feature.js").ReadOptions} */ (this.adaptOptions(
opt_options
));
const dataProjection = get(options.dataProjection);
dataProjection.setWorldExtent(options.extent);
options.dataProjection = dataProjection;
@@ -295,10 +307,8 @@ class MVT extends FeatureFormat {
setLayers(layers) {
this.layers_ = layers;
}
}
/**
* Reader callback for parsing layers.
* @param {number} tag The tag.
@@ -310,7 +320,7 @@ function layersPBFReader(tag, layers, pbf) {
const layer = {
keys: [],
values: [],
features: []
features: [],
};
const end = pbf.readVarint() + pbf.pos;
pbf.readFields(layerPBFReader, layer, end);
@@ -343,13 +353,22 @@ function layerPBFReader(tag, layer, pbf) {
const end = pbf.readVarint() + pbf.pos;
while (pbf.pos < end) {
tag = pbf.readVarint() >> 3;
value = tag === 1 ? pbf.readString() :
tag === 2 ? pbf.readFloat() :
tag === 3 ? pbf.readDouble() :
tag === 4 ? pbf.readVarint64() :
tag === 5 ? pbf.readVarint() :
tag === 6 ? pbf.readSVarint() :
tag === 7 ? pbf.readBoolean() : null;
value =
tag === 1
? pbf.readString()
: tag === 2
? pbf.readFloat()
: tag === 3
? pbf.readDouble()
: tag === 4
? pbf.readVarint64()
: tag === 5
? pbf.readVarint()
: tag === 6
? pbf.readSVarint()
: tag === 7
? pbf.readBoolean()
: null;
}
layer.values.push(value);
}
@@ -378,7 +397,6 @@ function featurePBFReader(tag, feature, pbf) {
}
}
/**
* Read a raw feature from the pbf offset stored at index `i` in the raw layer.
* @param {PBF} pbf PBF.
@@ -393,13 +411,12 @@ function readRawFeature(pbf, layer, i) {
const feature = {
layer: layer,
type: 0,
properties: {}
properties: {},
};
pbf.readFields(featurePBFReader, feature, end);
return feature;
}
/**
* @param {number} type The raw feature's geometry type
* @param {number} numEnds Number of ends of the flat coordinates of the
@@ -410,12 +427,11 @@ function getGeometryType(type, numEnds) {
/** @type {GeometryType} */
let geometryType;
if (type === 1) {
geometryType = numEnds === 1 ?
GeometryType.POINT : GeometryType.MULTI_POINT;
geometryType =
numEnds === 1 ? GeometryType.POINT : GeometryType.MULTI_POINT;
} else if (type === 2) {
geometryType = numEnds === 1 ?
GeometryType.LINE_STRING :
GeometryType.MULTI_LINE_STRING;
geometryType =
numEnds === 1 ? GeometryType.LINE_STRING : GeometryType.MULTI_LINE_STRING;
} else if (type === 3) {
geometryType = GeometryType.POLYGON;
// MultiPolygon not relevant for rendering - winding order determines

View File

@@ -2,18 +2,17 @@
* @module ol/format/OSMXML
*/
// FIXME add typedef for stack state objects
import {extend} from '../array.js';
import Feature from '../Feature.js';
import {transformGeometryWithOptions} from './Feature.js';
import XMLFeature from './XMLFeature.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';
import {isEmpty} from '../obj.js';
import XMLFeature from './XMLFeature.js';
import {extend} from '../array.js';
import {get as getProjection} from '../proj.js';
import {pushParseAndPop, makeStructureNS} from '../xml.js';
import {isEmpty} from '../obj.js';
import {makeStructureNS, pushParseAndPop} from '../xml.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @const
@@ -21,30 +20,25 @@ import {pushParseAndPop, makeStructureNS} from '../xml.js';
*/
const NAMESPACE_URIS = [null];
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const WAY_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'nd': readNd,
'tag': readTag,
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const WAY_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'nd': readNd,
'tag': readTag
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'node': readNode,
'way': readWay
});
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
'node': readNode,
'way': readWay,
});
/**
* @classdesc
@@ -72,11 +66,16 @@ class OSMXML extends XMLFeature {
readFeaturesFromNode(node, opt_options) {
const options = this.getReadOptions(node, opt_options);
if (node.localName == 'osm') {
const state = pushParseAndPop({
nodes: {},
ways: [],
features: []
}, PARSERS, node, [options]);
const state = pushParseAndPop(
{
nodes: {},
ways: [],
features: [],
},
PARSERS,
node,
[options]
);
// parse nodes in ways
for (let j = 0; j < state.ways.length; j++) {
const values = /** @type {Object} */ (state.ways[j]);
@@ -89,7 +88,9 @@ class OSMXML extends XMLFeature {
let geometry;
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
// closed way
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [
flatCoordinates.length,
]);
} else {
geometry = new LineString(flatCoordinates, GeometryLayout.XY);
}
@@ -105,20 +106,16 @@ class OSMXML extends XMLFeature {
}
return [];
}
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const NODE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'tag': readTag
});
const NODE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'tag': readTag,
});
/**
* @param {Element} node Node.
@@ -131,13 +128,18 @@ function readNode(node, objectStack) {
/** @type {import("../coordinate.js").Coordinate} */
const coordinates = [
parseFloat(node.getAttribute('lon')),
parseFloat(node.getAttribute('lat'))
parseFloat(node.getAttribute('lat')),
];
state.nodes[id] = coordinates;
const values = pushParseAndPop({
tags: {}
}, NODE_PARSERS, node, objectStack);
const values = pushParseAndPop(
{
tags: {},
},
NODE_PARSERS,
node,
objectStack
);
if (!isEmpty(values.tags)) {
const geometry = new Point(coordinates);
transformGeometryWithOptions(geometry, false, options);
@@ -148,23 +150,26 @@ function readNode(node, objectStack) {
}
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
*/
function readWay(node, objectStack) {
const id = node.getAttribute('id');
const values = pushParseAndPop({
id: id,
ndrefs: [],
tags: {}
}, WAY_PARSERS, node, objectStack);
const values = pushParseAndPop(
{
id: id,
ndrefs: [],
tags: {},
},
WAY_PARSERS,
node,
objectStack
);
const state = /** @type {Object} */ (objectStack[objectStack.length - 1]);
state.ways.push(values);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -174,7 +179,6 @@ function readNd(node, objectStack) {
values.ndrefs.push(node.getAttribute('ref'));
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -184,5 +188,4 @@ function readTag(node, objectStack) {
values.tags[node.getAttribute('k')] = node.getAttribute('v');
}
export default OSMXML;

View File

@@ -1,11 +1,15 @@
/**
* @module ol/format/OWS
*/
import {readHref} from './XLink.js';
import XML from './XML.js';
import {
makeObjectPropertyPusher,
makeObjectPropertySetter,
makeStructureNS,
pushParseAndPop,
} from '../xml.js';
import {readHref} from './XLink.js';
import {readString} from './xsd.js';
import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js';
/**
* @const
@@ -13,19 +17,16 @@ import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pus
*/
const NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata)
});
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata),
});
class OWS extends XML {
constructor() {
@@ -50,175 +51,144 @@ class OWS extends XML {
* @return {Object} Object
*/
readFromNode(node) {
const owsObject = pushParseAndPop({},
PARSERS, node, []);
const owsObject = pushParseAndPop({}, PARSERS, node, []);
return owsObject ? owsObject : null;
}
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const ADDRESS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'DeliveryPoint': makeObjectPropertySetter(readString),
'City': makeObjectPropertySetter(readString),
'AdministrativeArea': makeObjectPropertySetter(readString),
'PostalCode': makeObjectPropertySetter(readString),
'Country': makeObjectPropertySetter(readString),
'ElectronicMailAddress': makeObjectPropertySetter(readString),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const ADDRESS_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'DeliveryPoint': makeObjectPropertySetter(readString),
'City': makeObjectPropertySetter(readString),
'AdministrativeArea': makeObjectPropertySetter(readString),
'PostalCode': makeObjectPropertySetter(readString),
'Country': makeObjectPropertySetter(readString),
'ElectronicMailAddress': makeObjectPropertySetter(readString)
});
const ALLOWED_VALUES_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Value': makeObjectPropertyPusher(readValue),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const ALLOWED_VALUES_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Value': makeObjectPropertyPusher(readValue)
});
const CONSTRAINT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'AllowedValues': makeObjectPropertySetter(readAllowedValues),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const CONSTRAINT_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'AllowedValues': makeObjectPropertySetter(readAllowedValues)
});
const CONTACT_INFO_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Phone': makeObjectPropertySetter(readPhone),
'Address': makeObjectPropertySetter(readAddress),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const CONTACT_INFO_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Phone': makeObjectPropertySetter(readPhone),
'Address': makeObjectPropertySetter(readAddress)
});
const DCP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'HTTP': makeObjectPropertySetter(readHttp),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const DCP_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'HTTP': makeObjectPropertySetter(readHttp)
});
const HTTP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Get': makeObjectPropertyPusher(readGet),
'Post': undefined, // TODO
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const HTTP_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Get': makeObjectPropertyPusher(readGet),
'Post': undefined // TODO
});
const OPERATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'DCP': makeObjectPropertySetter(readDcp),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const OPERATION_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'DCP': makeObjectPropertySetter(readDcp)
});
const OPERATIONS_METADATA_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Operation': readOperation,
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const OPERATIONS_METADATA_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Operation': readOperation
});
const PHONE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Voice': makeObjectPropertySetter(readString),
'Facsimile': makeObjectPropertySetter(readString),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const PHONE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Voice': makeObjectPropertySetter(readString),
'Facsimile': makeObjectPropertySetter(readString)
});
const REQUEST_METHOD_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Constraint': makeObjectPropertyPusher(readConstraint),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const REQUEST_METHOD_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Constraint': makeObjectPropertyPusher(readConstraint)
});
const SERVICE_CONTACT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'IndividualName': makeObjectPropertySetter(readString),
'PositionName': makeObjectPropertySetter(readString),
'ContactInfo': makeObjectPropertySetter(readContactInfo),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const SERVICE_CONTACT_PARSERS =
makeStructureNS(
NAMESPACE_URIS, {
'IndividualName': makeObjectPropertySetter(readString),
'PositionName': makeObjectPropertySetter(readString),
'ContactInfo': makeObjectPropertySetter(readContactInfo)
});
const SERVICE_IDENTIFICATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Abstract': makeObjectPropertySetter(readString),
'AccessConstraints': makeObjectPropertySetter(readString),
'Fees': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'ServiceTypeVersion': makeObjectPropertySetter(readString),
'ServiceType': makeObjectPropertySetter(readString),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const SERVICE_IDENTIFICATION_PARSERS =
makeStructureNS(
NAMESPACE_URIS, {
'Abstract': makeObjectPropertySetter(readString),
'AccessConstraints': makeObjectPropertySetter(readString),
'Fees': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'ServiceTypeVersion': makeObjectPropertySetter(readString),
'ServiceType': makeObjectPropertySetter(readString)
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const SERVICE_PROVIDER_PARSERS =
makeStructureNS(
NAMESPACE_URIS, {
'ProviderName': makeObjectPropertySetter(readString),
'ProviderSite': makeObjectPropertySetter(readHref),
'ServiceContact': makeObjectPropertySetter(readServiceContact)
});
const SERVICE_PROVIDER_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'ProviderName': makeObjectPropertySetter(readString),
'ProviderSite': makeObjectPropertySetter(readHref),
'ServiceContact': makeObjectPropertySetter(readServiceContact),
});
/**
* @param {Element} node Node.
@@ -226,22 +196,18 @@ const SERVICE_PROVIDER_PARSERS =
* @return {Object|undefined} The address.
*/
function readAddress(node, objectStack) {
return pushParseAndPop({},
ADDRESS_PARSERS, node, objectStack);
return pushParseAndPop({}, ADDRESS_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The values.
*/
function readAllowedValues(node, objectStack) {
return pushParseAndPop({},
ALLOWED_VALUES_PARSERS, node, objectStack);
return pushParseAndPop({}, ALLOWED_VALUES_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -252,34 +218,27 @@ function readConstraint(node, objectStack) {
if (!name) {
return undefined;
}
return pushParseAndPop({'name': name},
CONSTRAINT_PARSERS, node,
objectStack);
return pushParseAndPop({'name': name}, CONSTRAINT_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The contact info.
*/
function readContactInfo(node, objectStack) {
return pushParseAndPop({},
CONTACT_INFO_PARSERS, node, objectStack);
return pushParseAndPop({}, CONTACT_INFO_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The DCP.
*/
function readDcp(node, objectStack) {
return pushParseAndPop({},
DCP_PARSERS, node, objectStack);
return pushParseAndPop({}, DCP_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -290,11 +249,14 @@ function readGet(node, objectStack) {
if (!href) {
return undefined;
}
return pushParseAndPop({'href': href},
REQUEST_METHOD_PARSERS, node, objectStack);
return pushParseAndPop(
{'href': href},
REQUEST_METHOD_PARSERS,
node,
objectStack
);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -304,7 +266,6 @@ function readHttp(node, objectStack) {
return pushParseAndPop({}, HTTP_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -312,76 +273,59 @@ function readHttp(node, objectStack) {
*/
function readOperation(node, objectStack) {
const name = node.getAttribute('name');
const value = pushParseAndPop({},
OPERATION_PARSERS, node, objectStack);
const value = pushParseAndPop({}, OPERATION_PARSERS, node, objectStack);
if (!value) {
return undefined;
}
const object = /** @type {Object} */
(objectStack[objectStack.length - 1]);
const object = /** @type {Object} */ (objectStack[objectStack.length - 1]);
object[name] = value;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The operations metadata.
*/
function readOperationsMetadata(node, objectStack) {
return pushParseAndPop({},
OPERATIONS_METADATA_PARSERS, node,
objectStack);
return pushParseAndPop({}, OPERATIONS_METADATA_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The phone.
*/
function readPhone(node, objectStack) {
return pushParseAndPop({},
PHONE_PARSERS, node, objectStack);
return pushParseAndPop({}, PHONE_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The service identification.
*/
function readServiceIdentification(node, objectStack) {
return pushParseAndPop(
{}, SERVICE_IDENTIFICATION_PARSERS, node,
objectStack);
return pushParseAndPop({}, SERVICE_IDENTIFICATION_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The service contact.
*/
function readServiceContact(node, objectStack) {
return pushParseAndPop(
{}, SERVICE_CONTACT_PARSERS, node,
objectStack);
return pushParseAndPop({}, SERVICE_CONTACT_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} The service provider.
*/
function readServiceProvider(node, objectStack) {
return pushParseAndPop(
{}, SERVICE_PROVIDER_PARSERS, node,
objectStack);
return pushParseAndPop({}, SERVICE_PROVIDER_PARSERS, node, objectStack);
}
/**
* @param {Node} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -391,5 +335,4 @@ function readValue(node, objectStack) {
return readString(node);
}
export default OWS;

View File

@@ -1,17 +1,16 @@
/**
* @module ol/format/Polyline
*/
import {assert} from '../asserts.js';
import Feature from '../Feature.js';
import {transformGeometryWithOptions} from './Feature.js';
import TextFeature from './TextFeature.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js';
import {getStrideForLayout} from '../geom/SimpleGeometry.js';
import TextFeature from './TextFeature.js';
import {assert} from '../asserts.js';
import {flipXY} from '../geom/flat/flip.js';
import {inflateCoordinates} from '../geom/flat/inflate.js';
import {get as getProjection} from '../proj.js';
import {getStrideForLayout} from '../geom/SimpleGeometry.js';
import {inflateCoordinates} from '../geom/flat/inflate.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @typedef {Object} Options
@@ -20,7 +19,6 @@ import {get as getProjection} from '../proj.js';
* feature geometries created by the format reader.
*/
/**
* @classdesc
* Feature format for reading and writing data in the Encoded
@@ -36,7 +34,6 @@ import {get as getProjection} from '../proj.js';
* @api
*/
class Polyline extends TextFeature {
/**
* @param {Options=} opt_options Optional configuration object.
*/
@@ -45,7 +42,6 @@ class Polyline extends TextFeature {
const options = opt_options ? opt_options : {};
/**
* @type {import("../proj/Projection.js").default}
*/
@@ -61,8 +57,9 @@ class Polyline extends TextFeature {
* @private
* @type {GeometryLayout}
*/
this.geometryLayout_ = options.geometryLayout ?
options.geometryLayout : GeometryLayout.XY;
this.geometryLayout_ = options.geometryLayout
? options.geometryLayout
: GeometryLayout.XY;
}
/**
@@ -97,10 +94,19 @@ class Polyline extends TextFeature {
const stride = getStrideForLayout(this.geometryLayout_);
const flatCoordinates = decodeDeltas(text, stride, this.factor_);
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
const coordinates = inflateCoordinates(flatCoordinates, 0, flatCoordinates.length, stride);
const coordinates = inflateCoordinates(
flatCoordinates,
0,
flatCoordinates.length,
stride
);
const lineString = new LineString(coordinates, this.geometryLayout_);
return transformGeometryWithOptions(lineString, false, this.adaptOptions(opt_options));
return transformGeometryWithOptions(
lineString,
false,
this.adaptOptions(opt_options)
);
}
/**
@@ -136,8 +142,13 @@ class Polyline extends TextFeature {
* @return {string} Text.
*/
writeGeometryText(geometry, opt_options) {
geometry = /** @type {LineString} */
(transformGeometryWithOptions(geometry, true, this.adaptOptions(opt_options)));
geometry =
/** @type {LineString} */
(transformGeometryWithOptions(
geometry,
true,
this.adaptOptions(opt_options)
));
const flatCoordinates = geometry.getFlatCoordinates();
const stride = geometry.getStride();
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
@@ -145,7 +156,6 @@ class Polyline extends TextFeature {
}
}
/**
* Encode a list of n-dimensional points and return an encoded string
*
@@ -168,7 +178,7 @@ export function encodeDeltas(numbers, stride, opt_factor) {
lastNumbers[d] = 0;
}
for (let i = 0, ii = numbers.length; i < ii;) {
for (let i = 0, ii = numbers.length; i < ii; ) {
for (d = 0; d < stride; ++d, ++i) {
const num = numbers[i];
const delta = num - lastNumbers[d];
@@ -181,7 +191,6 @@ export function encodeDeltas(numbers, stride, opt_factor) {
return encodeFloats(numbers, factor);
}
/**
* Decode a list of n-dimensional points from an encoded string
*
@@ -205,7 +214,7 @@ export function decodeDeltas(encoded, stride, opt_factor) {
const numbers = decodeFloats(encoded, factor);
for (let i = 0, ii = numbers.length; i < ii;) {
for (let i = 0, ii = numbers.length; i < ii; ) {
for (d = 0; d < stride; ++d, ++i) {
lastNumbers[d] += numbers[i];
@@ -216,7 +225,6 @@ export function decodeDeltas(encoded, stride, opt_factor) {
return numbers;
}
/**
* Encode a list of floating point numbers and return an encoded string
*
@@ -238,7 +246,6 @@ export function encodeFloats(numbers, opt_factor) {
return encodeSignedIntegers(numbers);
}
/**
* Decode a list of floating point numbers from an encoded string
*
@@ -257,7 +264,6 @@ export function decodeFloats(encoded, opt_factor) {
return numbers;
}
/**
* Encode a list of signed integers and return an encoded string
*
@@ -269,12 +275,11 @@ export function decodeFloats(encoded, opt_factor) {
export function encodeSignedIntegers(numbers) {
for (let i = 0, ii = numbers.length; i < ii; ++i) {
const num = numbers[i];
numbers[i] = (num < 0) ? ~(num << 1) : (num << 1);
numbers[i] = num < 0 ? ~(num << 1) : num << 1;
}
return encodeUnsignedIntegers(numbers);
}
/**
* Decode a list of signed integers from an encoded string
*
@@ -285,12 +290,11 @@ export function decodeSignedIntegers(encoded) {
const numbers = decodeUnsignedIntegers(encoded);
for (let i = 0, ii = numbers.length; i < ii; ++i) {
const num = numbers[i];
numbers[i] = (num & 1) ? ~(num >> 1) : (num >> 1);
numbers[i] = num & 1 ? ~(num >> 1) : num >> 1;
}
return numbers;
}
/**
* Encode a list of unsigned integers and return an encoded string
*
@@ -305,7 +309,6 @@ export function encodeUnsignedIntegers(numbers) {
return encoded;
}
/**
* Decode a list of unsigned integers from an encoded string
*
@@ -330,7 +333,6 @@ export function decodeUnsignedIntegers(encoded) {
return numbers;
}
/**
* Encode one single unsigned integer and return an encoded string
*
@@ -338,7 +340,8 @@ export function decodeUnsignedIntegers(encoded) {
* @return {string} The encoded string.
*/
export function encodeUnsignedInteger(num) {
let value, encoded = '';
let value,
encoded = '';
while (num >= 0x20) {
value = (0x20 | (num & 0x1f)) + 63;
encoded += String.fromCharCode(value);
@@ -349,5 +352,4 @@ export function encodeUnsignedInteger(num) {
return encoded;
}
export default Polyline;

View File

@@ -1,9 +1,9 @@
/**
* @module ol/format/TextFeature
*/
import {abstract} from '../util.js';
import FeatureFormat from '../format/Feature.js';
import FormatType from '../format/FormatType.js';
import {abstract} from '../util.js';
/**
* @classdesc
@@ -34,7 +34,10 @@ class TextFeature extends FeatureFormat {
* @api
*/
readFeature(source, opt_options) {
return this.readFeatureFromText(getText(source), this.adaptOptions(opt_options));
return this.readFeatureFromText(
getText(source),
this.adaptOptions(opt_options)
);
}
/**
@@ -57,7 +60,10 @@ class TextFeature extends FeatureFormat {
* @api
*/
readFeatures(source, opt_options) {
return this.readFeaturesFromText(getText(source), this.adaptOptions(opt_options));
return this.readFeaturesFromText(
getText(source),
this.adaptOptions(opt_options)
);
}
/**
@@ -80,7 +86,10 @@ class TextFeature extends FeatureFormat {
* @api
*/
readGeometry(source, opt_options) {
return this.readGeometryFromText(getText(source), this.adaptOptions(opt_options));
return this.readGeometryFromText(
getText(source),
this.adaptOptions(opt_options)
);
}
/**
@@ -184,7 +193,6 @@ class TextFeature extends FeatureFormat {
}
}
/**
* @param {Document|Element|Object|string} source Source.
* @return {string} Text.
@@ -197,5 +205,4 @@ function getText(source) {
}
}
export default TextFeature;

View File

@@ -2,7 +2,6 @@
* @module ol/format/TopoJSON
*/
import Feature from '../Feature.js';
import {transformGeometryWithOptions} from './Feature.js';
import JSONFeature from './JSONFeature.js';
import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js';
@@ -11,6 +10,7 @@ import MultiPolygon from '../geom/MultiPolygon.js';
import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js';
import {get as getProjection} from '../proj.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* @typedef {import("topojson-specification").Topology} TopoJSONTopology
@@ -48,7 +48,6 @@ import {get as getProjection} from '../proj.js';
* be read from all children.
*/
/**
* @classdesc
* Feature format for reading data in the TopoJSON format.
@@ -56,7 +55,6 @@ import {get as getProjection} from '../proj.js';
* @api
*/
class TopoJSON extends JSONFeature {
/**
* @param {Options=} opt_options Options.
*/
@@ -81,9 +79,8 @@ class TopoJSON extends JSONFeature {
* @type {import("../proj/Projection.js").default}
*/
this.dataProjection = getProjection(
options.dataProjection ?
options.dataProjection : 'EPSG:4326');
options.dataProjection ? options.dataProjection : 'EPSG:4326'
);
}
/**
@@ -95,7 +92,9 @@ class TopoJSON extends JSONFeature {
readFeaturesFromObject(object, opt_options) {
if (object.type == 'Topology') {
const topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
let transform, scale = null, translate = null;
let transform,
scale = null,
translate = null;
if (topoJSONTopology['transform']) {
transform = topoJSONTopology['transform'];
scale = transform['scale'];
@@ -115,13 +114,36 @@ class TopoJSON extends JSONFeature {
continue;
}
if (topoJSONFeatures[objectName].type === 'GeometryCollection') {
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[objectName]);
features.push.apply(features, readFeaturesFromGeometryCollection(
feature, arcs, scale, translate, property, objectName, opt_options));
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[
objectName
]);
features.push.apply(
features,
readFeaturesFromGeometryCollection(
feature,
arcs,
scale,
translate,
property,
objectName,
opt_options
)
);
} else {
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[objectName]);
features.push(readFeatureFromGeometry(
feature, arcs, scale, translate, property, objectName, opt_options));
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[
objectName
]);
features.push(
readFeatureFromGeometry(
feature,
arcs,
scale,
translate,
property,
objectName,
opt_options
)
);
}
}
return features;
@@ -138,10 +160,8 @@ class TopoJSON extends JSONFeature {
readProjectionFromObject(object) {
return this.dataProjection;
}
}
/**
* @const
* @type {Object<string, function(TopoJSONGeometry, Array, ...Array=): import("../geom/Geometry.js").default>}
@@ -152,10 +172,9 @@ const GEOMETRY_READERS = {
'Polygon': readPolygonGeometry,
'MultiPoint': readMultiPointGeometry,
'MultiLineString': readMultiLineStringGeometry,
'MultiPolygon': readMultiPolygonGeometry
'MultiPolygon': readMultiPolygonGeometry,
};
/**
* Concatenate arcs into a coordinate array.
* @param {Array<number>} indices Indices of arcs to concatenate. Negative
@@ -190,7 +209,6 @@ function concatenateArcs(indices, arcs) {
return coordinates;
}
/**
* Create a point from a TopoJSON geometry object.
*
@@ -207,7 +225,6 @@ function readPointGeometry(object, scale, translate) {
return new Point(coordinates);
}
/**
* Create a multi-point from a TopoJSON geometry object.
*
@@ -226,7 +243,6 @@ function readMultiPointGeometry(object, scale, translate) {
return new MultiPoint(coordinates);
}
/**
* Create a linestring from a TopoJSON geometry object.
*
@@ -239,7 +255,6 @@ function readLineStringGeometry(object, arcs) {
return new LineString(coordinates);
}
/**
* Create a multi-linestring from a TopoJSON geometry object.
*
@@ -255,7 +270,6 @@ function readMultiLineStringGeometry(object, arcs) {
return new MultiLineString(coordinates);
}
/**
* Create a polygon from a TopoJSON geometry object.
*
@@ -271,7 +285,6 @@ function readPolygonGeometry(object, arcs) {
return new Polygon(coordinates);
}
/**
* Create a multi-polygon from a TopoJSON geometry object.
*
@@ -294,7 +307,6 @@ function readMultiPolygonGeometry(object, arcs) {
return new MultiPolygon(coordinates);
}
/**
* Create features from a TopoJSON GeometryCollection object.
*
@@ -309,17 +321,31 @@ function readMultiPolygonGeometry(object, arcs) {
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
* @return {Array<Feature>} Array of features.
*/
function readFeaturesFromGeometryCollection(collection, arcs, scale, translate, property, name, opt_options) {
function readFeaturesFromGeometryCollection(
collection,
arcs,
scale,
translate,
property,
name,
opt_options
) {
const geometries = collection['geometries'];
const features = [];
for (let i = 0, ii = geometries.length; i < ii; ++i) {
features[i] = readFeatureFromGeometry(
geometries[i], arcs, scale, translate, property, name, opt_options);
geometries[i],
arcs,
scale,
translate,
property,
name,
opt_options
);
}
return features;
}
/**
* Create a feature from a TopoJSON geometry object.
*
@@ -333,17 +359,27 @@ function readFeaturesFromGeometryCollection(collection, arcs, scale, translate,
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
* @return {Feature} Feature.
*/
function readFeatureFromGeometry(object, arcs, scale, translate, property, name, opt_options) {
function readFeatureFromGeometry(
object,
arcs,
scale,
translate,
property,
name,
opt_options
) {
let geometry;
const type = object.type;
const geometryReader = GEOMETRY_READERS[type];
if ((type === 'Point') || (type === 'MultiPoint')) {
if (type === 'Point' || type === 'MultiPoint') {
geometry = geometryReader(object, scale, translate);
} else {
geometry = geometryReader(object, arcs);
}
const feature = new Feature();
feature.setGeometry(transformGeometryWithOptions(geometry, false, opt_options));
feature.setGeometry(
transformGeometryWithOptions(geometry, false, opt_options)
);
if (object.id !== undefined) {
feature.setId(object.id);
}
@@ -360,7 +396,6 @@ function readFeatureFromGeometry(object, arcs, scale, translate, property, name,
return feature;
}
/**
* Apply a linear transform to array of arcs. The provided array of arcs is
* modified in place.
@@ -375,7 +410,6 @@ function transformArcs(arcs, scale, translate) {
}
}
/**
* Apply a linear transform to an arc. The provided arc is modified in place.
*
@@ -396,7 +430,6 @@ function transformArc(arc, scale, translate) {
}
}
/**
* Apply a linear transform to a vertex. The provided vertex is modified in
* place.
@@ -410,5 +443,4 @@ function transformVertex(vertex, scale, translate) {
vertex[1] = vertex[1] * scale[1] + translate[1];
}
export default TopoJSON;

View File

@@ -1,19 +1,32 @@
/**
* @module ol/format/WFS
*/
import {assert} from '../asserts.js';
import GML2 from './GML2.js';
import GML3 from './GML3.js';
import GMLBase, {GMLNS} from './GMLBase.js';
import {and as andFilter, bbox as bboxFilter} from './filter.js';
import XMLFeature from './XMLFeature.js';
import {readNonNegativeIntegerString, readNonNegativeInteger, writeStringTextNode} from './xsd.js';
import {
XML_SCHEMA_INSTANCE_URI,
createElementNS,
isDocument,
makeArrayPusher,
makeChildAppender,
makeObjectPropertySetter,
makeSimpleNodeFactory,
parse,
parseNode,
pushParseAndPop,
pushSerializeAndPop,
} from '../xml.js';
import {and as andFilter, bbox as bboxFilter} from './filter.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {get as getProjection} from '../proj.js';
import {createElementNS, isDocument, makeArrayPusher, makeChildAppender,
makeObjectPropertySetter, makeSimpleNodeFactory, parse, parseNode,
pushParseAndPop, pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js';
import {
readNonNegativeInteger,
readNonNegativeIntegerString,
writeStringTextNode,
} from './xsd.js';
/**
* @const
@@ -22,11 +35,12 @@ import {createElementNS, isDocument, makeArrayPusher, makeChildAppender,
const FEATURE_COLLECTION_PARSERS = {
'http://www.opengis.net/gml': {
'boundedBy': makeObjectPropertySetter(
GMLBase.prototype.readGeometryElement, 'bounds')
}
GMLBase.prototype.readGeometryElement,
'bounds'
),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -35,11 +49,10 @@ const TRANSACTION_SUMMARY_PARSERS = {
'http://www.opengis.net/wfs': {
'totalInserted': makeObjectPropertySetter(readNonNegativeInteger),
'totalUpdated': makeObjectPropertySetter(readNonNegativeInteger),
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger)
}
'totalDeleted': makeObjectPropertySetter(readNonNegativeInteger),
},
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
@@ -47,23 +60,22 @@ const TRANSACTION_SUMMARY_PARSERS = {
const TRANSACTION_RESPONSE_PARSERS = {
'http://www.opengis.net/wfs': {
'TransactionSummary': makeObjectPropertySetter(
readTransactionSummary, 'transactionSummary'),
'InsertResults': makeObjectPropertySetter(
readInsertResults, 'insertIds')
}
readTransactionSummary,
'transactionSummary'
),
'InsertResults': makeObjectPropertySetter(readInsertResults, 'insertIds'),
},
};
/**
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
const QUERY_SERIALIZERS = {
'http://www.opengis.net/wfs': {
'PropertyName': makeChildAppender(writeStringTextNode)
}
'PropertyName': makeChildAppender(writeStringTextNode),
},
};
/**
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
@@ -73,11 +85,10 @@ const TRANSACTION_SERIALIZERS = {
'Update': makeChildAppender(writeUpdate),
'Delete': makeChildAppender(writeDelete),
'Property': makeChildAppender(writeProperty),
'Native': makeChildAppender(writeNative)
}
'Native': makeChildAppender(writeNative),
},
};
/**
* @typedef {Object} Options
* @property {Object<string, string>|string} [featureNS] The namespace URI used for features.
@@ -86,7 +97,6 @@ const TRANSACTION_SERIALIZERS = {
* @property {string} [schemaLocation] Optional schemaLocation to use for serialization, this will override the default.
*/
/**
* @typedef {Object} WriteGetFeatureOptions
* @property {string} featureNS The namespace URI used for features.
@@ -112,7 +122,6 @@ const TRANSACTION_SERIALIZERS = {
* E.g. `hits` only includes the `numberOfFeatures` attribute in the response and no features.
*/
/**
* @typedef {Object} WriteTransactionOptions
* @property {string} featureNS The namespace URI used for features.
@@ -128,7 +137,6 @@ const TRANSACTION_SERIALIZERS = {
* @property {string} [version='1.1.0'] WFS version to use for the transaction. Can be either `1.0.0` or `1.1.0`.
*/
/**
* Number of features; bounds/extent.
* @typedef {Object} FeatureCollectionMetadata
@@ -136,7 +144,6 @@ const TRANSACTION_SERIALIZERS = {
* @property {import("../extent.js").Extent} bounds
*/
/**
* Total deleted; total inserted; total updated; array of insert ids.
* @typedef {Object} TransactionResponse
@@ -146,53 +153,47 @@ const TRANSACTION_SERIALIZERS = {
* @property {Array<string>} insertIds
*/
/**
* @type {string}
*/
const FEATURE_PREFIX = 'feature';
/**
* @type {string}
*/
const XMLNS = 'http://www.w3.org/2000/xmlns/';
/**
* @type {string}
*/
const OGCNS = 'http://www.opengis.net/ogc';
/**
* @type {string}
*/
const WFSNS = 'http://www.opengis.net/wfs';
/**
* @type {string}
*/
const FESNS = 'http://www.opengis.net/fes';
/**
* @type {Object<string, string>}
*/
const SCHEMA_LOCATIONS = {
'1.1.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
'1.0.0': 'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'
'1.1.0':
'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd',
'1.0.0':
'http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd',
};
/**
* @const
* @type {string}
*/
const DEFAULT_VERSION = '1.1.0';
/**
* @classdesc
* Feature format for reading and writing data in the WFS format.
@@ -203,7 +204,6 @@ const DEFAULT_VERSION = '1.1.0';
* @api
*/
class WFS extends XMLFeature {
/**
* @param {Options=} opt_options Optional configuration object.
*/
@@ -228,15 +228,15 @@ class WFS extends XMLFeature {
* @private
* @type {GMLBase}
*/
this.gmlFormat_ = options.gmlFormat ?
options.gmlFormat : new GML3();
this.gmlFormat_ = options.gmlFormat ? options.gmlFormat : new GML3();
/**
* @private
* @type {string}
*/
this.schemaLocation_ = options.schemaLocation ?
options.schemaLocation : SCHEMA_LOCATIONS[DEFAULT_VERSION];
this.schemaLocation_ = options.schemaLocation
? options.schemaLocation
: SCHEMA_LOCATIONS[DEFAULT_VERSION];
}
/**
@@ -262,21 +262,25 @@ class WFS extends XMLFeature {
readFeaturesFromNode(node, opt_options) {
/** @type {import("../xml.js").NodeStackItem} */
const context = {
node: node
node: node,
};
assign(context, {
'featureType': this.featureType_,
'featureNS': this.featureNS_
'featureNS': this.featureNS_,
});
assign(context, this.getReadOptions(node, opt_options ? opt_options : {}));
const objectStack = [context];
this.gmlFormat_.FEATURE_COLLECTION_PARSERS[GMLNS][
'featureMember'] =
makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
let features = pushParseAndPop([],
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
objectStack, this.gmlFormat_);
'featureMember'
] = makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
let features = pushParseAndPop(
[],
this.gmlFormat_.FEATURE_COLLECTION_PARSERS,
node,
objectStack,
this.gmlFormat_
);
if (!features) {
features = [];
}
@@ -298,9 +302,12 @@ class WFS extends XMLFeature {
return this.readTransactionResponseFromDocument(doc);
} else if (isDocument(source)) {
return this.readTransactionResponseFromDocument(
/** @type {Document} */ (source));
/** @type {Document} */ (source)
);
} else {
return this.readTransactionResponseFromNode(/** @type {Element} */ (source));
return this.readTransactionResponseFromNode(
/** @type {Element} */ (source)
);
}
}
@@ -320,10 +327,12 @@ class WFS extends XMLFeature {
return this.readFeatureCollectionMetadataFromDocument(doc);
} else if (isDocument(source)) {
return this.readFeatureCollectionMetadataFromDocument(
/** @type {Document} */ (source));
/** @type {Document} */ (source)
);
} else {
return this.readFeatureCollectionMetadataFromNode(
/** @type {Element} */ (source));
/** @type {Element} */ (source)
);
}
}
@@ -335,7 +344,9 @@ class WFS extends XMLFeature {
readFeatureCollectionMetadataFromDocument(doc) {
for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
if (n.nodeType == Node.ELEMENT_NODE) {
return this.readFeatureCollectionMetadataFromNode(/** @type {Element} */ (n));
return this.readFeatureCollectionMetadataFromNode(
/** @type {Element} */ (n)
);
}
}
return undefined;
@@ -349,11 +360,16 @@ class WFS extends XMLFeature {
readFeatureCollectionMetadataFromNode(node) {
const result = {};
const value = readNonNegativeIntegerString(
node.getAttribute('numberOfFeatures'));
node.getAttribute('numberOfFeatures')
);
result['numberOfFeatures'] = value;
return pushParseAndPop(
/** @type {FeatureCollectionMetadata} */ (result),
FEATURE_COLLECTION_PARSERS, node, [], this.gmlFormat_);
FEATURE_COLLECTION_PARSERS,
node,
[],
this.gmlFormat_
);
}
/**
@@ -375,8 +391,11 @@ class WFS extends XMLFeature {
*/
readTransactionResponseFromNode(node) {
return pushParseAndPop(
/** @type {TransactionResponse} */({}),
TRANSACTION_RESPONSE_PARSERS, node, []);
/** @type {TransactionResponse} */ ({}),
TRANSACTION_RESPONSE_PARSERS,
node,
[]
);
}
/**
@@ -415,10 +434,12 @@ class WFS extends XMLFeature {
}
filter = options.filter;
if (options.bbox) {
assert(options.geometryName,
12); // `options.geometryName` must also be provided when `options.bbox` is set
assert(options.geometryName, 12); // `options.geometryName` must also be provided when `options.bbox` is set
const bbox = bboxFilter(
/** @type {string} */ (options.geometryName), options.bbox, options.srsName);
/** @type {string} */ (options.geometryName),
options.bbox,
options.srsName
);
if (filter) {
// if bbox and filter are both set, combine the two into a single filter
filter = andFilter(filter, bbox);
@@ -427,10 +448,14 @@ class WFS extends XMLFeature {
}
}
}
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', this.schemaLocation_);
node.setAttributeNS(
XML_SCHEMA_INSTANCE_URI,
'xsi:schemaLocation',
this.schemaLocation_
);
/** @type {import("../xml.js").NodeStackItem} */
const context = {
node: node
node: node,
};
assign(context, {
'srsName': options.srsName,
@@ -438,12 +463,15 @@ class WFS extends XMLFeature {
'featurePrefix': options.featurePrefix,
'geometryName': options.geometryName,
'filter': filter,
'propertyNames': options.propertyNames ? options.propertyNames : []
'propertyNames': options.propertyNames ? options.propertyNames : [],
});
assert(Array.isArray(options.featureTypes),
11); // `options.featureTypes` should be an Array
writeGetFeature(node, /** @type {!Array<string>} */ (options.featureTypes), [context]);
assert(Array.isArray(options.featureTypes), 11); // `options.featureTypes` should be an Array
writeGetFeature(
node,
/** @type {!Array<string>} */ (options.featureTypes),
[context]
);
return node;
}
@@ -474,43 +502,87 @@ class WFS extends XMLFeature {
}
}
const schemaLocation = SCHEMA_LOCATIONS[version];
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', schemaLocation);
const featurePrefix = options.featurePrefix ? options.featurePrefix : FEATURE_PREFIX;
node.setAttributeNS(
XML_SCHEMA_INSTANCE_URI,
'xsi:schemaLocation',
schemaLocation
);
const featurePrefix = options.featurePrefix
? options.featurePrefix
: FEATURE_PREFIX;
if (inserts) {
obj = assign({node: node}, {'featureNS': options.featureNS,
'featureType': options.featureType, 'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName});
obj = assign(
{node: node},
{
'featureNS': options.featureNS,
'featureType': options.featureType,
'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion,
'hasZ': options.hasZ,
'srsName': options.srsName,
}
);
assign(obj, baseObj);
pushSerializeAndPop(obj,
pushSerializeAndPop(
obj,
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Insert'), inserts,
objectStack);
makeSimpleNodeFactory('Insert'),
inserts,
objectStack
);
}
if (updates) {
obj = assign({node: node}, {'featureNS': options.featureNS,
'featureType': options.featureType, 'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName});
obj = assign(
{node: node},
{
'featureNS': options.featureNS,
'featureType': options.featureType,
'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion,
'hasZ': options.hasZ,
'srsName': options.srsName,
}
);
assign(obj, baseObj);
pushSerializeAndPop(obj,
pushSerializeAndPop(
obj,
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Update'), updates,
objectStack);
makeSimpleNodeFactory('Update'),
updates,
objectStack
);
}
if (deletes) {
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
'featureType': options.featureType, 'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion, 'srsName': options.srsName},
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Delete'), deletes,
objectStack);
pushSerializeAndPop(
{
node: node,
'featureNS': options.featureNS,
'featureType': options.featureType,
'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion,
'srsName': options.srsName,
},
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Delete'),
deletes,
objectStack
);
}
if (options.nativeElements) {
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
'featureType': options.featureType, 'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion, 'srsName': options.srsName},
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Native'), options.nativeElements,
objectStack);
pushSerializeAndPop(
{
node: node,
'featureNS': options.featureNS,
'featureType': options.featureType,
'featurePrefix': featurePrefix,
'gmlVersion': gmlVersion,
'srsName': options.srsName,
},
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Native'),
options.nativeElements,
objectStack
);
}
return node;
}
@@ -533,13 +605,15 @@ class WFS extends XMLFeature {
* @return {import("../proj/Projection.js").default} Projection.
*/
readProjectionFromNode(node) {
if (node.firstElementChild &&
node.firstElementChild.firstElementChild) {
if (node.firstElementChild && node.firstElementChild.firstElementChild) {
node = node.firstElementChild.firstElementChild;
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
if (!(n.childNodes.length === 0 ||
(n.childNodes.length === 1 &&
n.firstChild.nodeType === 3))) {
if (
!(
n.childNodes.length === 0 ||
(n.childNodes.length === 1 && n.firstChild.nodeType === 3)
)
) {
const objectStack = [{}];
this.gmlFormat_.readGeometryElement(n, objectStack);
return getProjection(objectStack.pop().srsName);
@@ -551,31 +625,27 @@ class WFS extends XMLFeature {
}
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} Transaction Summary.
*/
function readTransactionSummary(node, objectStack) {
return pushParseAndPop(
{}, TRANSACTION_SUMMARY_PARSERS, node, objectStack);
return pushParseAndPop({}, TRANSACTION_SUMMARY_PARSERS, node, objectStack);
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
const OGC_FID_PARSERS = {
'http://www.opengis.net/ogc': {
'FeatureId': makeArrayPusher(function(node, objectStack) {
'FeatureId': makeArrayPusher(function (node, objectStack) {
return node.getAttribute('fid');
})
}
}),
},
};
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -584,29 +654,25 @@ function fidParser(node, objectStack) {
parseNode(OGC_FID_PARSERS, node, objectStack);
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
const INSERT_RESULTS_PARSERS = {
'http://www.opengis.net/wfs': {
'Feature': fidParser
}
'Feature': fidParser,
},
};
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Array<string>|undefined} Insert results.
*/
function readInsertResults(node, objectStack) {
return pushParseAndPop(
[], INSERT_RESULTS_PARSERS, node, objectStack);
return pushParseAndPop([], INSERT_RESULTS_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {import("../Feature.js").default} feature Feature.
@@ -626,7 +692,6 @@ function writeFeature(node, feature, objectStack) {
}
}
/**
* @param {Node} node Node.
* @param {number|string} fid Feature identifier.
@@ -640,7 +705,6 @@ function writeOgcFidFilter(node, fid, objectStack) {
node.appendChild(filter);
}
/**
* @param {string|undefined} featurePrefix The prefix of the feature.
* @param {string} featureType The type of the feature.
@@ -657,7 +721,6 @@ function getTypeName(featurePrefix, featureType) {
}
}
/**
* @param {Element} node Node.
* @param {import("../Feature.js").default} feature Feature.
@@ -678,7 +741,6 @@ function writeDelete(node, feature, objectStack) {
}
}
/**
* @param {Element} node Node.
* @param {import("../Feature.js").default} feature Feature.
@@ -702,23 +764,31 @@ function writeUpdate(node, feature, objectStack) {
const value = feature.get(keys[i]);
if (value !== undefined) {
let name = keys[i];
if (value && typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
if (
value &&
typeof (/** @type {?} */ (value).getSimplifiedGeometry) === 'function'
) {
name = geometryName;
}
values.push({name: name, value: value});
}
}
pushSerializeAndPop(/** @type {import("../xml.js").NodeStackItem} */ (
{'gmlVersion': context['gmlVersion'], node: node,
'hasZ': context['hasZ'], 'srsName': context['srsName']}),
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Property'), values,
objectStack);
pushSerializeAndPop(
/** @type {import("../xml.js").NodeStackItem} */ ({
'gmlVersion': context['gmlVersion'],
node: node,
'hasZ': context['hasZ'],
'srsName': context['srsName'],
}),
TRANSACTION_SERIALIZERS,
makeSimpleNodeFactory('Property'),
values,
objectStack
);
writeOgcFidFilter(node, fid, objectStack);
}
}
/**
* @param {Node} node Node.
* @param {Object} pair Property name and value.
@@ -733,13 +803,15 @@ function writeProperty(node, pair, objectStack) {
if (pair.value !== undefined && pair.value !== null) {
const value = createElementNS(WFSNS, 'Value');
node.appendChild(value);
if (pair.value && typeof /** @type {?} */ (pair.value).getSimplifiedGeometry === 'function') {
if (
pair.value &&
typeof (/** @type {?} */ (pair.value).getSimplifiedGeometry) ===
'function'
) {
if (gmlVersion === 2) {
GML2.prototype.writeGeometryElement(value,
pair.value, objectStack);
GML2.prototype.writeGeometryElement(value, pair.value, objectStack);
} else {
GML3.prototype.writeGeometryElement(value,
pair.value, objectStack);
GML3.prototype.writeGeometryElement(value, pair.value, objectStack);
}
} else {
writeStringTextNode(value, pair.value);
@@ -747,7 +819,6 @@ function writeProperty(node, pair, objectStack) {
}
}
/**
* @param {Element} node Node.
* @param {{vendorId: string, safeToIgnore: boolean, value: string}} nativeElement The native element.
@@ -765,13 +836,12 @@ function writeNative(node, nativeElement, objectStack) {
}
}
/**
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
*/
const GETFEATURE_SERIALIZERS = {
'http://www.opengis.net/wfs': {
'Query': makeChildAppender(writeQuery)
'Query': makeChildAppender(writeQuery),
},
'http://www.opengis.net/ogc': {
'During': makeChildAppender(writeDuringFilter),
@@ -790,11 +860,10 @@ const GETFEATURE_SERIALIZERS = {
'PropertyIsGreaterThanOrEqualTo': makeChildAppender(writeComparisonFilter),
'PropertyIsNull': makeChildAppender(writeIsNullFilter),
'PropertyIsBetween': makeChildAppender(writeIsBetweenFilter),
'PropertyIsLike': makeChildAppender(writeIsLikeFilter)
}
'PropertyIsLike': makeChildAppender(writeIsLikeFilter),
},
};
/**
* @param {Element} node Node.
* @param {string} featureType Feature type.
@@ -820,12 +889,18 @@ function writeQuery(node, featureType, objectStack) {
if (featureNS) {
node.setAttributeNS(XMLNS, 'xmlns:' + featurePrefix, featureNS);
}
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign({}, context));
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign(
{},
context
));
item.node = node;
pushSerializeAndPop(item,
pushSerializeAndPop(
item,
QUERY_SERIALIZERS,
makeSimpleNodeFactory('PropertyName'), propertyNames,
objectStack);
makeSimpleNodeFactory('PropertyName'),
propertyNames,
objectStack
);
const filter = context['filter'];
if (filter) {
const child = createElementNS(OGCNS, 'Filter');
@@ -834,7 +909,6 @@ function writeQuery(node, featureType, objectStack) {
}
}
/**
* @param {Node} node Node.
* @param {import("./filter/Filter.js").default} filter Filter.
@@ -843,13 +917,15 @@ function writeQuery(node, featureType, objectStack) {
function writeFilterCondition(node, filter, objectStack) {
/** @type {import("../xml.js").NodeStackItem} */
const item = {node: node};
pushSerializeAndPop(item,
pushSerializeAndPop(
item,
GETFEATURE_SERIALIZERS,
makeSimpleNodeFactory(filter.getTagName()),
[filter], objectStack);
[filter],
objectStack
);
}
/**
* @param {Node} node Node.
* @param {import("./filter/Bbox.js").default} filter Filter.
@@ -863,7 +939,6 @@ function writeBboxFilter(node, filter, objectStack) {
GML3.prototype.writeGeometryElement(node, filter.extent, objectStack);
}
/**
* @param {Node} node Node.
* @param {import("./filter/Contains.js").default} filter Filter.
@@ -877,7 +952,6 @@ function writeContainsFilter(node, filter, objectStack) {
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
}
/**
* @param {Node} node Node.
* @param {import("./filter/Intersects.js").default} filter Filter.
@@ -891,7 +965,6 @@ function writeIntersectsFilter(node, filter, objectStack) {
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
}
/**
* @param {Node} node Node.
* @param {import("./filter/Within.js").default} filter Filter.
@@ -905,14 +978,12 @@ function writeWithinFilter(node, filter, objectStack) {
GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack);
}
/**
* @param {Node} node Node.
* @param {import("./filter/During.js").default} filter Filter.
* @param {Array<*>} objectStack Node stack.
*/
function writeDuringFilter(node, filter, objectStack) {
const valueReference = createElementNS(FESNS, 'ValueReference');
writeStringTextNode(valueReference, filter.propertyName);
node.appendChild(valueReference);
@@ -930,7 +1001,6 @@ function writeDuringFilter(node, filter, objectStack) {
writeTimeInstant(end, filter.end);
}
/**
* @param {Node} node Node.
* @param {import("./filter/LogicalNary.js").default} filter Filter.
@@ -942,14 +1012,16 @@ function writeLogicalFilter(node, filter, objectStack) {
const conditions = filter.conditions;
for (let i = 0, ii = conditions.length; i < ii; ++i) {
const condition = conditions[i];
pushSerializeAndPop(item,
pushSerializeAndPop(
item,
GETFEATURE_SERIALIZERS,
makeSimpleNodeFactory(condition.getTagName()),
[condition], objectStack);
[condition],
objectStack
);
}
}
/**
* @param {Node} node Node.
* @param {import("./filter/Not.js").default} filter Filter.
@@ -959,13 +1031,15 @@ function writeNotFilter(node, filter, objectStack) {
/** @type {import("../xml.js").NodeStackItem} */
const item = {node: node};
const condition = filter.condition;
pushSerializeAndPop(item,
pushSerializeAndPop(
item,
GETFEATURE_SERIALIZERS,
makeSimpleNodeFactory(condition.getTagName()),
[condition], objectStack);
[condition],
objectStack
);
}
/**
* @param {Element} node Node.
* @param {import("./filter/ComparisonBinary.js").default} filter Filter.
@@ -979,7 +1053,6 @@ function writeComparisonFilter(node, filter, objectStack) {
writeOgcLiteral(node, '' + filter.expression);
}
/**
* @param {Node} node Node.
* @param {import("./filter/IsNull.js").default} filter Filter.
@@ -989,7 +1062,6 @@ function writeIsNullFilter(node, filter, objectStack) {
writeOgcPropertyName(node, filter.propertyName);
}
/**
* @param {Node} node Node.
* @param {import("./filter/IsBetween.js").default} filter Filter.
@@ -1007,7 +1079,6 @@ function writeIsBetweenFilter(node, filter, objectStack) {
writeOgcLiteral(upperBoundary, '' + filter.upperBoundary);
}
/**
* @param {Element} node Node.
* @param {import("./filter/IsLike.js").default} filter Filter.
@@ -1024,7 +1095,6 @@ function writeIsLikeFilter(node, filter, objectStack) {
writeOgcLiteral(node, '' + filter.pattern);
}
/**
* @param {string} tagName Tag name.
* @param {Node} node Node.
@@ -1036,7 +1106,6 @@ function writeOgcExpression(tagName, node, value) {
node.appendChild(property);
}
/**
* @param {Node} node Node.
* @param {string} value PropertyName value.
@@ -1045,7 +1114,6 @@ function writeOgcPropertyName(node, value) {
writeOgcExpression('PropertyName', node, value);
}
/**
* @param {Node} node Node.
* @param {string} value PropertyName value.
@@ -1054,7 +1122,6 @@ function writeOgcLiteral(node, value) {
writeOgcExpression('Literal', node, value);
}
/**
* @param {Node} node Node.
* @param {string} time PropertyName value.
@@ -1068,7 +1135,6 @@ function writeTimeInstant(node, time) {
writeStringTextNode(timePosition, time);
}
/**
* Encode filter as WFS `Filter` and return the Node.
*
@@ -1082,7 +1148,6 @@ export function writeFilter(filter) {
return child;
}
/**
* @param {Node} node Node.
* @param {Array<string>} featureTypes Feature types.
@@ -1090,13 +1155,18 @@ export function writeFilter(filter) {
*/
function writeGetFeature(node, featureTypes, objectStack) {
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign({}, context));
const item = /** @type {import("../xml.js").NodeStackItem} */ (assign(
{},
context
));
item.node = node;
pushSerializeAndPop(item,
pushSerializeAndPop(
item,
GETFEATURE_SERIALIZERS,
makeSimpleNodeFactory('Query'), featureTypes,
objectStack);
makeSimpleNodeFactory('Query'),
featureTypes,
objectStack
);
}
export default WFS;

View File

@@ -2,18 +2,17 @@
* @module ol/format/WKT
*/
import Feature from '../Feature.js';
import {transformGeometryWithOptions} from './Feature.js';
import TextFeature from './TextFeature.js';
import GeometryCollection from '../geom/GeometryCollection.js';
import GeometryType from '../geom/GeometryType.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';
import MultiPolygon from '../geom/MultiPolygon.js';
import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js';
import TextFeature from './TextFeature.js';
import {transformGeometryWithOptions} from './Feature.js';
/**
* Geometry constructors
@@ -25,10 +24,9 @@ const GeometryConstructor = {
'POLYGON': Polygon,
'MULTIPOINT': MultiPoint,
'MULTILINESTRING': MultiLineString,
'MULTIPOLYGON': MultiPolygon
'MULTIPOLYGON': MultiPolygon,
};
/**
* @typedef {Object} Options
* @property {boolean} [splitCollection=false] Whether to split GeometryCollections into
@@ -48,28 +46,24 @@ const GeometryConstructor = {
*/
const EMPTY = 'EMPTY';
/**
* @const
* @type {string}
*/
const Z = 'Z';
/**
* @const
* @type {string}
*/
const M = 'M';
/**
* @const
* @type {string}
*/
const ZM = 'ZM';
/**
* @const
* @enum {number}
@@ -80,7 +74,7 @@ const TokenType = {
RIGHT_PAREN: 3,
NUMBER: 4,
COMMA: 5,
EOF: 6
EOF: 6,
};
/**
@@ -92,17 +86,14 @@ for (const type in GeometryType) {
WKTGeometryType[type] = GeometryType[type].toUpperCase();
}
/**
* Class to tokenize a WKT string.
*/
class Lexer {
/**
* @param {string} wkt WKT string.
*/
constructor(wkt) {
/**
* @type {string}
*/
@@ -121,7 +112,7 @@ class Lexer {
* @private
*/
isAlpha_(c) {
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z';
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
/**
@@ -133,7 +124,7 @@ class Lexer {
*/
isNumeric_(c, opt_decimal) {
const decimal = opt_decimal !== undefined ? opt_decimal : false;
return c >= '0' && c <= '9' || c == '.' && !decimal;
return (c >= '0' && c <= '9') || (c == '.' && !decimal);
}
/**
@@ -205,12 +196,12 @@ class Lexer {
c = this.nextChar_();
} while (
this.isNumeric_(c, decimal) ||
// if we haven't detected a scientific number before, 'e' or 'E'
// hint that we should continue to read
!scientificNotation && (c == 'e' || c == 'E') ||
// once we know that we have a scientific number, both '-' and '+'
// are allowed
scientificNotation && (c == '-' || c == '+')
// if we haven't detected a scientific number before, 'e' or 'E'
// hint that we should continue to read
(!scientificNotation && (c == 'e' || c == 'E')) ||
// once we know that we have a scientific number, both '-' and '+'
// are allowed
(scientificNotation && (c == '-' || c == '+'))
);
return parseFloat(this.wkt.substring(index, this.index_--));
}
@@ -233,12 +224,10 @@ class Lexer {
* Class to parse the tokens from the WKT string.
*/
class Parser {
/**
* @param {Lexer} lexer The lexer.
*/
constructor(lexer) {
/**
* @type {Lexer}
* @private
@@ -518,8 +507,8 @@ class Parser {
* @private
*/
isEmptyGeometry_() {
const isEmpty = this.isTokenType(TokenType.TEXT) &&
this.token_.value == EMPTY;
const isEmpty =
this.isTokenType(TokenType.TEXT) && this.token_.value == EMPTY;
if (isEmpty) {
this.consume_();
}
@@ -532,8 +521,15 @@ class Parser {
* @private
*/
formatErrorMessage_() {
return 'Unexpected `' + this.token_.value + '` at position ' +
this.token_.position + ' in `' + this.lexer_.wkt + '`';
return (
'Unexpected `' +
this.token_.value +
'` at position ' +
this.token_.position +
' in `' +
this.lexer_.wkt +
'`'
);
}
/**
@@ -599,7 +595,6 @@ class Parser {
}
}
/**
* @classdesc
* Geometry format for reading and writing data in the `WellKnownText` (WKT)
@@ -608,7 +603,6 @@ class Parser {
* @api
*/
class WKT extends TextFeature {
/**
* @param {Options=} opt_options Options.
*/
@@ -617,15 +611,13 @@ class WKT extends TextFeature {
const options = opt_options ? opt_options : {};
/**
* Split GeometryCollection into multiple features.
* @type {boolean}
* @private
*/
this.splitCollection_ = options.splitCollection !== undefined ?
options.splitCollection : false;
this.splitCollection_ =
options.splitCollection !== undefined ? options.splitCollection : false;
}
/**
@@ -666,10 +658,11 @@ 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) {
geometries = (/** @type {GeometryCollection} */ (geometry))
.getGeometriesArray();
if (
this.splitCollection_ &&
geometry.getType() == GeometryType.GEOMETRY_COLLECTION
) {
geometries = /** @type {GeometryCollection} */ (geometry).getGeometriesArray();
} else {
geometries = [geometry];
}
@@ -740,7 +733,6 @@ class WKT extends TextFeature {
}
}
/**
* @param {Point} geom Point geometry.
* @return {string} Coordinates part of Point as WKT.
@@ -753,7 +745,6 @@ function encodePointGeometry(geom) {
return coordinates.join(' ');
}
/**
* @param {MultiPoint} geom MultiPoint geometry.
* @return {string} Coordinates part of MultiPoint as WKT.
@@ -767,7 +758,6 @@ function encodeMultiPointGeometry(geom) {
return array.join(',');
}
/**
* @param {GeometryCollection} geom GeometryCollection geometry.
* @return {string} Coordinates part of GeometryCollection as WKT.
@@ -781,7 +771,6 @@ function encodeGeometryCollectionGeometry(geom) {
return array.join(',');
}
/**
* @param {LineString|import("../geom/LinearRing.js").default} geom LineString geometry.
* @return {string} Coordinates part of LineString as WKT.
@@ -795,7 +784,6 @@ function encodeLineStringGeometry(geom) {
return array.join(',');
}
/**
* @param {MultiLineString} geom MultiLineString geometry.
* @return {string} Coordinates part of MultiLineString as WKT.
@@ -809,7 +797,6 @@ function encodeMultiLineStringGeometry(geom) {
return array.join(',');
}
/**
* @param {Polygon} geom Polygon geometry.
* @return {string} Coordinates part of Polygon as WKT.
@@ -823,7 +810,6 @@ function encodePolygonGeometry(geom) {
return array.join(',');
}
/**
* @param {MultiPolygon} geom MultiPolygon geometry.
* @return {string} Coordinates part of MultiPolygon as WKT.
@@ -853,7 +839,6 @@ function encodeGeometryLayout(geom) {
return dimInfo;
}
/**
* @const
* @type {Object<string, function(import("../geom/Geometry.js").default): string>}
@@ -865,10 +850,9 @@ const GeometryEncoder = {
'MultiPoint': encodeMultiPointGeometry,
'MultiLineString': encodeMultiLineStringGeometry,
'MultiPolygon': encodeMultiPolygonGeometry,
'GeometryCollection': encodeGeometryCollectionGeometry
'GeometryCollection': encodeGeometryCollectionGeometry,
};
/**
* Encode a geometry as WKT.
* @param {!import("../geom/Geometry.js").default} geom The geometry to encode.
@@ -879,8 +863,10 @@ function encode(geom) {
const geometryEncoder = GeometryEncoder[type];
const enc = geometryEncoder(geom);
type = type.toUpperCase();
if (typeof /** @type {?} */ (geom).getFlatCoordinates === 'function') {
const dimInfo = encodeGeometryLayout(/** @type {import("../geom/SimpleGeometry.js").default} */ (geom));
if (typeof (/** @type {?} */ (geom).getFlatCoordinates) === 'function') {
const dimInfo = encodeGeometryLayout(
/** @type {import("../geom/SimpleGeometry.js").default} */ (geom)
);
if (dimInfo.length > 0) {
type += ' ' + dimInfo;
}
@@ -891,5 +877,4 @@ function encode(geom) {
return type + '(' + enc + ')';
}
export default WKT;

View File

@@ -1,47 +1,50 @@
/**
* @module ol/format/WMSCapabilities
*/
import {readHref} from './XLink.js';
import XML from './XML.js';
import {readDecimalString, readString, readNonNegativeInteger, readDecimal, readBooleanString, readNonNegativeIntegerString} from './xsd.js';
import {makeArrayPusher, makeObjectPropertyPusher, makeObjectPropertySetter,
makeStructureNS, pushParseAndPop} from '../xml.js';
import {
makeArrayPusher,
makeObjectPropertyPusher,
makeObjectPropertySetter,
makeStructureNS,
pushParseAndPop,
} from '../xml.js';
import {
readBooleanString,
readDecimal,
readDecimalString,
readNonNegativeInteger,
readNonNegativeIntegerString,
readString,
} from './xsd.js';
import {readHref} from './XLink.js';
/**
* @const
* @type {Array<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.opengis.net/wms'
];
const NAMESPACE_URIS = [null, 'http://www.opengis.net/wms'];
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Service': makeObjectPropertySetter(readService),
'Capability': makeObjectPropertySetter(readCapability)
});
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Service': makeObjectPropertySetter(readService),
'Capability': makeObjectPropertySetter(readCapability),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const CAPABILITY_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Request': makeObjectPropertySetter(readRequest),
'Exception': makeObjectPropertySetter(readException),
'Layer': makeObjectPropertySetter(readCapabilityLayer)
});
const CAPABILITY_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Request': makeObjectPropertySetter(readRequest),
'Exception': makeObjectPropertySetter(readException),
'Layer': makeObjectPropertySetter(readCapabilityLayer),
});
/**
* @classdesc
@@ -78,231 +81,207 @@ class WMSCapabilities extends XML {
*/
readFromNode(node) {
this.version = node.getAttribute('version').trim();
const wmsCapabilityObject = pushParseAndPop({
'version': this.version
}, PARSERS, node, []);
const wmsCapabilityObject = pushParseAndPop(
{
'version': this.version,
},
PARSERS,
node,
[]
);
return wmsCapabilityObject ? wmsCapabilityObject : null;
}
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const SERVICE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(readString),
'KeywordList': makeObjectPropertySetter(readKeywordList),
'OnlineResource': makeObjectPropertySetter(readHref),
'ContactInformation': makeObjectPropertySetter(readContactInformation),
'Fees': makeObjectPropertySetter(readString),
'AccessConstraints': makeObjectPropertySetter(readString),
'LayerLimit': makeObjectPropertySetter(readNonNegativeInteger),
'MaxWidth': makeObjectPropertySetter(readNonNegativeInteger),
'MaxHeight': makeObjectPropertySetter(readNonNegativeInteger),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const SERVICE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(readString),
'KeywordList': makeObjectPropertySetter(readKeywordList),
'OnlineResource': makeObjectPropertySetter(readHref),
'ContactInformation': makeObjectPropertySetter(readContactInformation),
'Fees': makeObjectPropertySetter(readString),
'AccessConstraints': makeObjectPropertySetter(readString),
'LayerLimit': makeObjectPropertySetter(readNonNegativeInteger),
'MaxWidth': makeObjectPropertySetter(readNonNegativeInteger),
'MaxHeight': makeObjectPropertySetter(readNonNegativeInteger)
});
const CONTACT_INFORMATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'ContactPersonPrimary': makeObjectPropertySetter(readContactPersonPrimary),
'ContactPosition': makeObjectPropertySetter(readString),
'ContactAddress': makeObjectPropertySetter(readContactAddress),
'ContactVoiceTelephone': makeObjectPropertySetter(readString),
'ContactFacsimileTelephone': makeObjectPropertySetter(readString),
'ContactElectronicMailAddress': makeObjectPropertySetter(readString),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const CONTACT_INFORMATION_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ContactPersonPrimary': makeObjectPropertySetter(readContactPersonPrimary),
'ContactPosition': makeObjectPropertySetter(readString),
'ContactAddress': makeObjectPropertySetter(readContactAddress),
'ContactVoiceTelephone': makeObjectPropertySetter(readString),
'ContactFacsimileTelephone': makeObjectPropertySetter(readString),
'ContactElectronicMailAddress': makeObjectPropertySetter(readString)
});
const CONTACT_PERSON_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'ContactPerson': makeObjectPropertySetter(readString),
'ContactOrganization': makeObjectPropertySetter(readString),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const CONTACT_PERSON_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'ContactPerson': makeObjectPropertySetter(readString),
'ContactOrganization': makeObjectPropertySetter(readString)
});
const CONTACT_ADDRESS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'AddressType': makeObjectPropertySetter(readString),
'Address': makeObjectPropertySetter(readString),
'City': makeObjectPropertySetter(readString),
'StateOrProvince': makeObjectPropertySetter(readString),
'PostCode': makeObjectPropertySetter(readString),
'Country': makeObjectPropertySetter(readString),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const CONTACT_ADDRESS_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'AddressType': makeObjectPropertySetter(readString),
'Address': makeObjectPropertySetter(readString),
'City': makeObjectPropertySetter(readString),
'StateOrProvince': makeObjectPropertySetter(readString),
'PostCode': makeObjectPropertySetter(readString),
'Country': makeObjectPropertySetter(readString)
});
const EXCEPTION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Format': makeArrayPusher(readString),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const EXCEPTION_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Format': makeArrayPusher(readString)
});
const LAYER_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(readString),
'KeywordList': makeObjectPropertySetter(readKeywordList),
'CRS': makeObjectPropertyPusher(readString),
'EX_GeographicBoundingBox': makeObjectPropertySetter(
readEXGeographicBoundingBox
),
'BoundingBox': makeObjectPropertyPusher(readBoundingBox),
'Dimension': makeObjectPropertyPusher(readDimension),
'Attribution': makeObjectPropertySetter(readAttribution),
'AuthorityURL': makeObjectPropertyPusher(readAuthorityURL),
'Identifier': makeObjectPropertyPusher(readString),
'MetadataURL': makeObjectPropertyPusher(readMetadataURL),
'DataURL': makeObjectPropertyPusher(readFormatOnlineresource),
'FeatureListURL': makeObjectPropertyPusher(readFormatOnlineresource),
'Style': makeObjectPropertyPusher(readStyle),
'MinScaleDenominator': makeObjectPropertySetter(readDecimal),
'MaxScaleDenominator': makeObjectPropertySetter(readDecimal),
'Layer': makeObjectPropertyPusher(readLayer),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const LAYER_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(readString),
'KeywordList': makeObjectPropertySetter(readKeywordList),
'CRS': makeObjectPropertyPusher(readString),
'EX_GeographicBoundingBox': makeObjectPropertySetter(readEXGeographicBoundingBox),
'BoundingBox': makeObjectPropertyPusher(readBoundingBox),
'Dimension': makeObjectPropertyPusher(readDimension),
'Attribution': makeObjectPropertySetter(readAttribution),
'AuthorityURL': makeObjectPropertyPusher(readAuthorityURL),
'Identifier': makeObjectPropertyPusher(readString),
'MetadataURL': makeObjectPropertyPusher(readMetadataURL),
'DataURL': makeObjectPropertyPusher(readFormatOnlineresource),
'FeatureListURL': makeObjectPropertyPusher(readFormatOnlineresource),
'Style': makeObjectPropertyPusher(readStyle),
'MinScaleDenominator': makeObjectPropertySetter(readDecimal),
'MaxScaleDenominator': makeObjectPropertySetter(readDecimal),
'Layer': makeObjectPropertyPusher(readLayer)
});
const ATTRIBUTION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Title': makeObjectPropertySetter(readString),
'OnlineResource': makeObjectPropertySetter(readHref),
'LogoURL': makeObjectPropertySetter(readSizedFormatOnlineresource),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const ATTRIBUTION_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Title': makeObjectPropertySetter(readString),
'OnlineResource': makeObjectPropertySetter(readHref),
'LogoURL': makeObjectPropertySetter(readSizedFormatOnlineresource)
});
const EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'westBoundLongitude': makeObjectPropertySetter(readDecimal),
'eastBoundLongitude': makeObjectPropertySetter(readDecimal),
'southBoundLatitude': makeObjectPropertySetter(readDecimal),
'northBoundLatitude': makeObjectPropertySetter(readDecimal),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS =
makeStructureNS(NAMESPACE_URIS, {
'westBoundLongitude': makeObjectPropertySetter(readDecimal),
'eastBoundLongitude': makeObjectPropertySetter(readDecimal),
'southBoundLatitude': makeObjectPropertySetter(readDecimal),
'northBoundLatitude': makeObjectPropertySetter(readDecimal)
});
const REQUEST_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'GetCapabilities': makeObjectPropertySetter(readOperationType),
'GetMap': makeObjectPropertySetter(readOperationType),
'GetFeatureInfo': makeObjectPropertySetter(readOperationType),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const REQUEST_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'GetCapabilities': makeObjectPropertySetter(readOperationType),
'GetMap': makeObjectPropertySetter(readOperationType),
'GetFeatureInfo': makeObjectPropertySetter(readOperationType)
});
const OPERATIONTYPE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Format': makeObjectPropertyPusher(readString),
'DCPType': makeObjectPropertyPusher(readDCPType),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const OPERATIONTYPE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Format': makeObjectPropertyPusher(readString),
'DCPType': makeObjectPropertyPusher(readDCPType)
});
const DCPTYPE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'HTTP': makeObjectPropertySetter(readHTTP),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const DCPTYPE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'HTTP': makeObjectPropertySetter(readHTTP)
});
const HTTP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Get': makeObjectPropertySetter(readFormatOnlineresource),
'Post': makeObjectPropertySetter(readFormatOnlineresource),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const HTTP_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Get': makeObjectPropertySetter(readFormatOnlineresource),
'Post': makeObjectPropertySetter(readFormatOnlineresource)
});
const STYLE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(readString),
'LegendURL': makeObjectPropertyPusher(readSizedFormatOnlineresource),
'StyleSheetURL': makeObjectPropertySetter(readFormatOnlineresource),
'StyleURL': makeObjectPropertySetter(readFormatOnlineresource),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const STYLE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Name': makeObjectPropertySetter(readString),
'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(readString),
'LegendURL': makeObjectPropertyPusher(readSizedFormatOnlineresource),
'StyleSheetURL': makeObjectPropertySetter(readFormatOnlineresource),
'StyleURL': makeObjectPropertySetter(readFormatOnlineresource)
});
const FORMAT_ONLINERESOURCE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Format': makeObjectPropertySetter(readString),
'OnlineResource': makeObjectPropertySetter(readHref),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const FORMAT_ONLINERESOURCE_PARSERS =
makeStructureNS(NAMESPACE_URIS, {
'Format': makeObjectPropertySetter(readString),
'OnlineResource': makeObjectPropertySetter(readHref)
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const KEYWORDLIST_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Keyword': makeArrayPusher(readString)
});
const KEYWORDLIST_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Keyword': makeArrayPusher(readString),
});
/**
* @param {Element} node Node.
@@ -313,7 +292,6 @@ function readAttribution(node, objectStack) {
return pushParseAndPop({}, ATTRIBUTION_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -324,22 +302,21 @@ function readBoundingBox(node, objectStack) {
readDecimalString(node.getAttribute('minx')),
readDecimalString(node.getAttribute('miny')),
readDecimalString(node.getAttribute('maxx')),
readDecimalString(node.getAttribute('maxy'))
readDecimalString(node.getAttribute('maxy')),
];
const resolutions = [
readDecimalString(node.getAttribute('resx')),
readDecimalString(node.getAttribute('resy'))
readDecimalString(node.getAttribute('resy')),
];
return {
'crs': node.getAttribute('CRS'),
'extent': extent,
'res': resolutions
'res': resolutions,
};
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -349,29 +326,40 @@ function readEXGeographicBoundingBox(node, objectStack) {
const geographicBoundingBox = pushParseAndPop(
{},
EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS,
node, objectStack);
node,
objectStack
);
if (!geographicBoundingBox) {
return undefined;
}
const westBoundLongitude = /** @type {number|undefined} */
(geographicBoundingBox['westBoundLongitude']);
const southBoundLatitude = /** @type {number|undefined} */
(geographicBoundingBox['southBoundLatitude']);
const eastBoundLongitude = /** @type {number|undefined} */
(geographicBoundingBox['eastBoundLongitude']);
const northBoundLatitude = /** @type {number|undefined} */
(geographicBoundingBox['northBoundLatitude']);
if (westBoundLongitude === undefined || southBoundLatitude === undefined ||
eastBoundLongitude === undefined || northBoundLatitude === undefined) {
const westBoundLongitude =
/** @type {number|undefined} */
(geographicBoundingBox['westBoundLongitude']);
const southBoundLatitude =
/** @type {number|undefined} */
(geographicBoundingBox['southBoundLatitude']);
const eastBoundLongitude =
/** @type {number|undefined} */
(geographicBoundingBox['eastBoundLongitude']);
const northBoundLatitude =
/** @type {number|undefined} */
(geographicBoundingBox['northBoundLatitude']);
if (
westBoundLongitude === undefined ||
southBoundLatitude === undefined ||
eastBoundLongitude === undefined ||
northBoundLatitude === undefined
) {
return undefined;
}
return [
westBoundLongitude, southBoundLatitude,
eastBoundLongitude, northBoundLatitude
westBoundLongitude,
southBoundLatitude,
eastBoundLongitude,
northBoundLatitude,
];
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -381,7 +369,6 @@ function readCapability(node, objectStack) {
return pushParseAndPop({}, CAPABILITY_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -391,7 +378,6 @@ function readService(node, objectStack) {
return pushParseAndPop({}, SERVICE_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -401,7 +387,6 @@ function readContactInformation(node, objectStack) {
return pushParseAndPop({}, CONTACT_INFORMATION_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -411,7 +396,6 @@ function readContactPersonPrimary(node, objectStack) {
return pushParseAndPop({}, CONTACT_PERSON_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -421,7 +405,6 @@ function readContactAddress(node, objectStack) {
return pushParseAndPop({}, CONTACT_ADDRESS_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -431,7 +414,6 @@ function readException(node, objectStack) {
return pushParseAndPop([], EXCEPTION_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -441,14 +423,15 @@ function readCapabilityLayer(node, objectStack) {
return pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} Layer object.
*/
function readLayer(node, objectStack) {
const parentLayerObject = /** @type {!Object<string,*>} */ (objectStack[objectStack.length - 1]);
const parentLayerObject = /** @type {!Object<string,*>} */ (objectStack[
objectStack.length - 1
]);
const layerObject = pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
@@ -461,8 +444,7 @@ function readLayer(node, objectStack) {
}
layerObject['queryable'] = queryable !== undefined ? queryable : false;
let cascaded = readNonNegativeIntegerString(
node.getAttribute('cascaded'));
let cascaded = readNonNegativeIntegerString(node.getAttribute('cascaded'));
if (cascaded === undefined) {
cascaded = parentLayerObject['cascaded'];
}
@@ -494,16 +476,22 @@ function readLayer(node, objectStack) {
// See 7.2.4.8
const addKeys = ['Style', 'CRS', 'AuthorityURL'];
addKeys.forEach(function(key) {
addKeys.forEach(function (key) {
if (key in parentLayerObject) {
const childValue = layerObject[key] || [];
layerObject[key] = childValue.concat(parentLayerObject[key]);
}
});
const replaceKeys = ['EX_GeographicBoundingBox', 'BoundingBox', 'Dimension',
'Attribution', 'MinScaleDenominator', 'MaxScaleDenominator'];
replaceKeys.forEach(function(key) {
const replaceKeys = [
'EX_GeographicBoundingBox',
'BoundingBox',
'Dimension',
'Attribution',
'MinScaleDenominator',
'MaxScaleDenominator',
];
replaceKeys.forEach(function (key) {
if (!(key in layerObject)) {
const parentValue = parentLayerObject[key];
layerObject[key] = parentValue;
@@ -513,7 +501,6 @@ function readLayer(node, objectStack) {
return layerObject;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -528,12 +515,11 @@ function readDimension(node, objectStack) {
'multipleValues': readBooleanString(node.getAttribute('multipleValues')),
'nearestValue': readBooleanString(node.getAttribute('nearestValue')),
'current': readBooleanString(node.getAttribute('current')),
'values': readString(node)
'values': readString(node),
};
return dimensionObject;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -543,7 +529,6 @@ function readFormatOnlineresource(node, objectStack) {
return pushParseAndPop({}, FORMAT_ONLINERESOURCE_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -553,7 +538,6 @@ function readRequest(node, objectStack) {
return pushParseAndPop({}, REQUEST_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -563,7 +547,6 @@ function readDCPType(node, objectStack) {
return pushParseAndPop({}, DCPTYPE_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -573,7 +556,6 @@ function readHTTP(node, objectStack) {
return pushParseAndPop({}, HTTP_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -583,7 +565,6 @@ function readOperationType(node, objectStack) {
return pushParseAndPop({}, OPERATIONTYPE_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -594,7 +575,7 @@ function readSizedFormatOnlineresource(node, objectStack) {
if (formatOnlineresource) {
const size = [
readNonNegativeIntegerString(node.getAttribute('width')),
readNonNegativeIntegerString(node.getAttribute('height'))
readNonNegativeIntegerString(node.getAttribute('height')),
];
formatOnlineresource['size'] = size;
return formatOnlineresource;
@@ -602,7 +583,6 @@ function readSizedFormatOnlineresource(node, objectStack) {
return undefined;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -617,7 +597,6 @@ function readAuthorityURL(node, objectStack) {
return undefined;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -632,7 +611,6 @@ function readMetadataURL(node, objectStack) {
return undefined;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -642,7 +620,6 @@ function readStyle(node, objectStack) {
return pushParseAndPop({}, STYLE_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -652,5 +629,4 @@ function readKeywordList(node, objectStack) {
return pushParseAndPop([], KEYWORDLIST_PARSERS, node, objectStack);
}
export default WMSCapabilities;

View File

@@ -1,33 +1,29 @@
/**
* @module ol/format/WMSGetFeatureInfo
*/
import {extend, includes} from '../array.js';
import GML2 from './GML2.js';
import XMLFeature from './XMLFeature.js';
import {assign} from '../obj.js';
import {extend, includes} from '../array.js';
import {makeArrayPusher, makeStructureNS, pushParseAndPop} from '../xml.js';
/**
* @typedef {Object} Options
* @property {Array<string>} [layers] If set, only features of the given layers will be returned by the format when read.
*/
/**
* @const
* @type {string}
*/
const featureIdentifier = '_feature';
/**
* @const
* @type {string}
*/
const layerIdentifier = '_layer';
/**
* @classdesc
* Format for reading WMSGetFeatureInfo format. It uses
@@ -36,7 +32,6 @@ const layerIdentifier = '_layer';
* @api
*/
class WMSGetFeatureInfo extends XMLFeature {
/**
* @param {Options=} opt_options Options.
*/
@@ -51,14 +46,12 @@ class WMSGetFeatureInfo extends XMLFeature {
*/
this.featureNS_ = 'http://mapserver.gis.umn.edu/mapserver';
/**
* @private
* @type {GML2}
*/
this.gmlFormat_ = new GML2();
/**
* @private
* @type {Array<string>}
@@ -111,8 +104,7 @@ class WMSGetFeatureInfo extends XMLFeature {
continue;
}
const featureType = layerName +
featureIdentifier;
const featureType = layerName + featureIdentifier;
context['featureType'] = featureType;
context['featureNS'] = this.featureNS_;
@@ -120,22 +112,35 @@ class WMSGetFeatureInfo extends XMLFeature {
/** @type {Object<string, import("../xml.js").Parser>} */
const parsers = {};
parsers[featureType] = makeArrayPusher(
this.gmlFormat_.readFeatureElement, this.gmlFormat_);
this.gmlFormat_.readFeatureElement,
this.gmlFormat_
);
const parsersNS = makeStructureNS(
[context['featureNS'], null], parsers);
[context['featureNS'], null],
parsers
);
layerElement.setAttribute('namespaceURI', this.featureNS_);
const layerFeatures = pushParseAndPop(
[],
// @ts-ignore
[], parsersNS, layerElement, objectStack, this.gmlFormat_);
parsersNS,
layerElement,
objectStack,
this.gmlFormat_
);
if (layerFeatures) {
extend(features, layerFeatures);
}
}
}
if (localName == 'FeatureCollection') {
const gmlFeatures = pushParseAndPop([],
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
[{}], this.gmlFormat_);
const gmlFeatures = pushParseAndPop(
[],
this.gmlFormat_.FEATURE_COLLECTION_PARSERS,
node,
[{}],
this.gmlFormat_
);
if (gmlFeatures) {
features = gmlFeatures;
}
@@ -156,8 +161,6 @@ class WMSGetFeatureInfo extends XMLFeature {
}
return this.readFeatures_(node, [options]);
}
}
export default WMSGetFeatureInfo;

View File

@@ -1,45 +1,39 @@
/**
* @module ol/format/WMTSCapabilities
*/
import {boundingExtent} from '../extent.js';
import OWS from './OWS.js';
import {readHref} from './XLink.js';
import XML from './XML.js';
import {readString, readNonNegativeInteger, readDecimal} from './xsd.js';
import {pushParseAndPop, makeStructureNS,
makeObjectPropertySetter, makeObjectPropertyPusher, makeArrayPusher} from '../xml.js';
import {boundingExtent} from '../extent.js';
import {
makeArrayPusher,
makeObjectPropertyPusher,
makeObjectPropertySetter,
makeStructureNS,
pushParseAndPop,
} from '../xml.js';
import {readDecimal, readNonNegativeInteger, readString} from './xsd.js';
import {readHref} from './XLink.js';
/**
* @const
* @type {Array<null|string>}
*/
const NAMESPACE_URIS = [
null,
'http://www.opengis.net/wmts/1.0'
];
const NAMESPACE_URIS = [null, 'http://www.opengis.net/wmts/1.0'];
/**
* @const
* @type {Array<null|string>}
*/
const OWS_NAMESPACE_URIS = [
null,
'http://www.opengis.net/ows/1.1'
];
const OWS_NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Contents': makeObjectPropertySetter(readContents)
});
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Contents': makeObjectPropertySetter(readContents),
});
/**
* @classdesc
@@ -85,23 +79,25 @@ class WMTSCapabilities extends XML {
return null;
}
WMTSCapabilityObject['version'] = version;
WMTSCapabilityObject = pushParseAndPop(WMTSCapabilityObject, PARSERS, node, []);
WMTSCapabilityObject = pushParseAndPop(
WMTSCapabilityObject,
PARSERS,
node,
[]
);
return WMTSCapabilityObject ? WMTSCapabilityObject : null;
}
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const CONTENTS_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'Layer': makeObjectPropertyPusher(readLayer),
'TileMatrixSet': makeObjectPropertyPusher(readTileMatrixSet)
});
const CONTENTS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'Layer': makeObjectPropertyPusher(readLayer),
'TileMatrixSet': makeObjectPropertyPusher(readTileMatrixSet),
});
/**
* @const
@@ -109,19 +105,21 @@ const CONTENTS_PARSERS = makeStructureNS(
*/
// @ts-ignore
const LAYER_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
NAMESPACE_URIS,
{
'Style': makeObjectPropertyPusher(readStyle),
'Format': makeObjectPropertyPusher(readString),
'TileMatrixSetLink': makeObjectPropertyPusher(readTileMatrixSetLink),
'Dimension': makeObjectPropertyPusher(readDimensions),
'ResourceURL': makeObjectPropertyPusher(readResourceUrl)
}, makeStructureNS(OWS_NAMESPACE_URIS, {
'ResourceURL': makeObjectPropertyPusher(readResourceUrl),
},
makeStructureNS(OWS_NAMESPACE_URIS, {
'Title': makeObjectPropertySetter(readString),
'Abstract': makeObjectPropertySetter(readString),
'WGS84BoundingBox': makeObjectPropertySetter(readWgs84BoundingBox),
'Identifier': makeObjectPropertySetter(readString)
}));
'Identifier': makeObjectPropertySetter(readString),
})
);
/**
* @const
@@ -129,50 +127,47 @@ const LAYER_PARSERS = makeStructureNS(
*/
// @ts-ignore
const STYLE_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'LegendURL': makeObjectPropertyPusher(readLegendUrl)
}, makeStructureNS(OWS_NAMESPACE_URIS, {
NAMESPACE_URIS,
{
'LegendURL': makeObjectPropertyPusher(readLegendUrl),
},
makeStructureNS(OWS_NAMESPACE_URIS, {
'Title': makeObjectPropertySetter(readString),
'Identifier': makeObjectPropertySetter(readString)
}));
'Identifier': makeObjectPropertySetter(readString),
})
);
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const TMS_LINKS_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'TileMatrixSet': makeObjectPropertySetter(readString),
'TileMatrixSetLimits': makeObjectPropertySetter(readTileMatrixLimitsList)
});
const TMS_LINKS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'TileMatrixSet': makeObjectPropertySetter(readString),
'TileMatrixSetLimits': makeObjectPropertySetter(readTileMatrixLimitsList),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const TMS_LIMITS_LIST_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'TileMatrixLimits': makeArrayPusher(readTileMatrixLimits)
});
const TMS_LIMITS_LIST_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'TileMatrixLimits': makeArrayPusher(readTileMatrixLimits),
});
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const TMS_LIMITS_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
'TileMatrix': makeObjectPropertySetter(readString),
'MinTileRow': makeObjectPropertySetter(readNonNegativeInteger),
'MaxTileRow': makeObjectPropertySetter(readNonNegativeInteger),
'MinTileCol': makeObjectPropertySetter(readNonNegativeInteger),
'MaxTileCol': makeObjectPropertySetter(readNonNegativeInteger)
});
const TMS_LIMITS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
'TileMatrix': makeObjectPropertySetter(readString),
'MinTileRow': makeObjectPropertySetter(readNonNegativeInteger),
'MaxTileRow': makeObjectPropertySetter(readNonNegativeInteger),
'MinTileCol': makeObjectPropertySetter(readNonNegativeInteger),
'MaxTileCol': makeObjectPropertySetter(readNonNegativeInteger),
});
/**
* @const
@@ -180,25 +175,25 @@ const TMS_LIMITS_PARSERS = makeStructureNS(
*/
// @ts-ignore
const DIMENSION_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
NAMESPACE_URIS,
{
'Default': makeObjectPropertySetter(readString),
'Value': makeObjectPropertyPusher(readString)
}, makeStructureNS(OWS_NAMESPACE_URIS, {
'Identifier': makeObjectPropertySetter(readString)
}));
'Value': makeObjectPropertyPusher(readString),
},
makeStructureNS(OWS_NAMESPACE_URIS, {
'Identifier': makeObjectPropertySetter(readString),
})
);
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
*/
// @ts-ignore
const WGS84_BBOX_READERS = makeStructureNS(
OWS_NAMESPACE_URIS, {
'LowerCorner': makeArrayPusher(readCoordinates),
'UpperCorner': makeArrayPusher(readCoordinates)
});
const WGS84_BBOX_READERS = makeStructureNS(OWS_NAMESPACE_URIS, {
'LowerCorner': makeArrayPusher(readCoordinates),
'UpperCorner': makeArrayPusher(readCoordinates),
});
/**
* @const
@@ -206,14 +201,16 @@ const WGS84_BBOX_READERS = makeStructureNS(
*/
// @ts-ignore
const TMS_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
NAMESPACE_URIS,
{
'WellKnownScaleSet': makeObjectPropertySetter(readString),
'TileMatrix': makeObjectPropertyPusher(readTileMatrix)
}, makeStructureNS(OWS_NAMESPACE_URIS, {
'TileMatrix': makeObjectPropertyPusher(readTileMatrix),
},
makeStructureNS(OWS_NAMESPACE_URIS, {
'SupportedCRS': makeObjectPropertySetter(readString),
'Identifier': makeObjectPropertySetter(readString)
}));
'Identifier': makeObjectPropertySetter(readString),
})
);
/**
* @const
@@ -221,17 +218,19 @@ const TMS_PARSERS = makeStructureNS(
*/
// @ts-ignore
const TM_PARSERS = makeStructureNS(
NAMESPACE_URIS, {
NAMESPACE_URIS,
{
'TopLeftCorner': makeObjectPropertySetter(readCoordinates),
'ScaleDenominator': makeObjectPropertySetter(readDecimal),
'TileWidth': makeObjectPropertySetter(readNonNegativeInteger),
'TileHeight': makeObjectPropertySetter(readNonNegativeInteger),
'MatrixWidth': makeObjectPropertySetter(readNonNegativeInteger),
'MatrixHeight': makeObjectPropertySetter(readNonNegativeInteger)
}, makeStructureNS(OWS_NAMESPACE_URIS, {
'Identifier': makeObjectPropertySetter(readString)
}));
'MatrixHeight': makeObjectPropertySetter(readNonNegativeInteger),
},
makeStructureNS(OWS_NAMESPACE_URIS, {
'Identifier': makeObjectPropertySetter(readString),
})
);
/**
* @param {Element} node Node.
@@ -242,7 +241,6 @@ function readContents(node, objectStack) {
return pushParseAndPop({}, CONTENTS_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -252,7 +250,6 @@ function readLayer(node, objectStack) {
return pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -262,7 +259,6 @@ function readTileMatrixSet(node, objectStack) {
return pushParseAndPop({}, TMS_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -276,10 +272,8 @@ function readStyle(node, objectStack) {
const isDefault = node.getAttribute('isDefault') === 'true';
style['isDefault'] = isDefault;
return style;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -289,7 +283,6 @@ function readTileMatrixSetLink(node, objectStack) {
return pushParseAndPop({}, TMS_LINKS_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -299,7 +292,6 @@ function readDimensions(node, objectStack) {
return pushParseAndPop({}, DIMENSION_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -322,21 +314,24 @@ function readResourceUrl(node, objectStack) {
return resource;
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
* @return {Object|undefined} WGS84 BBox object.
*/
function readWgs84BoundingBox(node, objectStack) {
const coordinates = pushParseAndPop([], WGS84_BBOX_READERS, node, objectStack);
const coordinates = pushParseAndPop(
[],
WGS84_BBOX_READERS,
node,
objectStack
);
if (coordinates.length != 2) {
return undefined;
}
return boundingExtent(coordinates);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -349,7 +344,6 @@ function readLegendUrl(node, objectStack) {
return legend;
}
/**
* @param {Node} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -368,7 +362,6 @@ function readCoordinates(node, objectStack) {
return [x, y];
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -378,7 +371,6 @@ function readTileMatrix(node, objectStack) {
return pushParseAndPop({}, TM_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -388,7 +380,6 @@ function readTileMatrixLimitsList(node, objectStack) {
return pushParseAndPop([], TMS_LIMITS_LIST_PARSERS, node, objectStack);
}
/**
* @param {Element} node Node.
* @param {Array<*>} objectStack Object stack.
@@ -398,5 +389,4 @@ function readTileMatrixLimits(node, objectStack) {
return pushParseAndPop({}, TMS_LIMITS_PARSERS, node, objectStack);
}
export default WMTSCapabilities;

View File

@@ -2,14 +2,12 @@
* @module ol/format/XLink
*/
/**
* @const
* @type {string}
*/
const NAMESPACE_URI = 'http://www.w3.org/1999/xlink';
/**
* @param {Element} node Node.
* @return {string|undefined} href.

View File

@@ -1,11 +1,11 @@
/**
* @module ol/format/XMLFeature
*/
import {abstract} from '../util.js';
import {extend} from '../array.js';
import FeatureFormat from '../format/Feature.js';
import FormatType from '../format/FormatType.js';
import {isDocument, parse, getXMLSerializer} from '../xml.js';
import {abstract} from '../util.js';
import {extend} from '../array.js';
import {getXMLSerializer, isDocument, parse} from '../xml.js';
/**
* @classdesc
@@ -48,9 +48,15 @@ class XMLFeature extends FeatureFormat {
const doc = parse(source);
return this.readFeatureFromDocument(doc, opt_options);
} else if (isDocument(source)) {
return this.readFeatureFromDocument(/** @type {Document} */ (source), opt_options);
return this.readFeatureFromDocument(
/** @type {Document} */ (source),
opt_options
);
} else {
return this.readFeatureFromNode(/** @type {Element} */ (source), opt_options);
return this.readFeatureFromNode(
/** @type {Element} */ (source),
opt_options
);
}
}
@@ -93,9 +99,14 @@ class XMLFeature extends FeatureFormat {
return this.readFeaturesFromDocument(doc, opt_options);
} else if (isDocument(source)) {
return this.readFeaturesFromDocument(
/** @type {Document} */ (source), opt_options);
/** @type {Document} */ (source),
opt_options
);
} else {
return this.readFeaturesFromNode(/** @type {Element} */ (source), opt_options);
return this.readFeaturesFromNode(
/** @type {Element} */ (source),
opt_options
);
}
}
@@ -110,7 +121,10 @@ class XMLFeature extends FeatureFormat {
const features = [];
for (let n = doc.firstChild; n; n = n.nextSibling) {
if (n.nodeType == Node.ELEMENT_NODE) {
extend(features, this.readFeaturesFromNode(/** @type {Element} */ (n), opt_options));
extend(
features,
this.readFeaturesFromNode(/** @type {Element} */ (n), opt_options)
);
}
}
return features;
@@ -142,9 +156,14 @@ class XMLFeature extends FeatureFormat {
return this.readGeometryFromDocument(doc, opt_options);
} else if (isDocument(source)) {
return this.readGeometryFromDocument(
/** @type {Document} */ (source), opt_options);
/** @type {Document} */ (source),
opt_options
);
} else {
return this.readGeometryFromNode(/** @type {Element} */ (source), opt_options);
return this.readGeometryFromNode(
/** @type {Element} */ (source),
opt_options
);
}
}
@@ -272,5 +291,4 @@ class XMLFeature extends FeatureFormat {
}
}
export default XMLFeature;

View File

@@ -19,7 +19,6 @@ import NotEqualTo from './filter/NotEqualTo.js';
import Or from './filter/Or.js';
import Within from './filter/Within.js';
/**
* Create a logical `<And>` operator between two or more filter conditions.
*
@@ -29,10 +28,9 @@ import Within from './filter/Within.js';
*/
export function and(conditions) {
const params = [null].concat(Array.prototype.slice.call(arguments));
return new (Function.prototype.bind.apply(And, params));
return new (Function.prototype.bind.apply(And, params))();
}
/**
* Create a logical `<Or>` operator between two or more filter conditions.
*
@@ -42,10 +40,9 @@ export function and(conditions) {
*/
export function or(conditions) {
const params = [null].concat(Array.prototype.slice.call(arguments));
return new (Function.prototype.bind.apply(Or, params));
return new (Function.prototype.bind.apply(Or, params))();
}
/**
* Represents a logical `<Not>` operator for a filter condition.
*
@@ -57,7 +54,6 @@ export function not(condition) {
return new Not(condition);
}
/**
* Create a `<BBOX>` operator to test whether a geometry-valued property
* intersects a fixed bounding box
@@ -118,7 +114,6 @@ export function within(geometryName, geometry, opt_srsName) {
return new Within(geometryName, geometry, opt_srsName);
}
/**
* Creates a `<PropertyIsEqualTo>` comparison operator.
*
@@ -132,7 +127,6 @@ export function equalTo(propertyName, expression, opt_matchCase) {
return new EqualTo(propertyName, expression, opt_matchCase);
}
/**
* Creates a `<PropertyIsNotEqualTo>` comparison operator.
*
@@ -146,7 +140,6 @@ export function notEqualTo(propertyName, expression, opt_matchCase) {
return new NotEqualTo(propertyName, expression, opt_matchCase);
}
/**
* Creates a `<PropertyIsLessThan>` comparison operator.
*
@@ -159,7 +152,6 @@ export function lessThan(propertyName, expression) {
return new LessThan(propertyName, expression);
}
/**
* Creates a `<PropertyIsLessThanOrEqualTo>` comparison operator.
*
@@ -172,7 +164,6 @@ export function lessThanOrEqualTo(propertyName, expression) {
return new LessThanOrEqualTo(propertyName, expression);
}
/**
* Creates a `<PropertyIsGreaterThan>` comparison operator.
*
@@ -185,7 +176,6 @@ export function greaterThan(propertyName, expression) {
return new GreaterThan(propertyName, expression);
}
/**
* Creates a `<PropertyIsGreaterThanOrEqualTo>` comparison operator.
*
@@ -198,7 +188,6 @@ export function greaterThanOrEqualTo(propertyName, expression) {
return new GreaterThanOrEqualTo(propertyName, expression);
}
/**
* Creates a `<PropertyIsNull>` comparison operator to test whether a property value
* is null.
@@ -211,7 +200,6 @@ export function isNull(propertyName) {
return new IsNull(propertyName);
}
/**
* Creates a `<PropertyIsBetween>` comparison operator to test whether an expression
* value lies within a range given by a lower and upper bound (inclusive).
@@ -226,7 +214,6 @@ export function between(propertyName, lowerBoundary, upperBoundary) {
return new IsBetween(propertyName, lowerBoundary, upperBoundary);
}
/**
* Represents a `<PropertyIsLike>` comparison operator that matches a string property
* value against a text pattern.
@@ -243,13 +230,24 @@ export function between(propertyName, lowerBoundary, upperBoundary) {
* @returns {!IsLike} `<PropertyIsLike>` operator.
* @api
*/
export function like(propertyName, pattern,
opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) {
return new IsLike(propertyName, pattern,
opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase);
export function like(
propertyName,
pattern,
opt_wildCard,
opt_singleChar,
opt_escapeChar,
opt_matchCase
) {
return new IsLike(
propertyName,
pattern,
opt_wildCard,
opt_singleChar,
opt_escapeChar,
opt_matchCase
);
}
/**
* Create a `<During>` temporal operator.
*

View File

@@ -10,14 +10,12 @@ import LogicalNary from './LogicalNary.js';
* @abstract
*/
class And extends LogicalNary {
/**
* @param {...import("./Filter.js").default} conditions Conditions.
*/
constructor(conditions) {
super('And', Array.prototype.slice.call(arguments));
}
}
export default And;

View File

@@ -11,7 +11,6 @@ import Filter from './Filter.js';
* @api
*/
class Bbox extends Filter {
/**
* @param {!string} geometryName Geometry name to use.
* @param {!import("../../extent.js").Extent} extent Extent.
@@ -19,7 +18,6 @@ class Bbox extends Filter {
* on geometries when this is not provided.
*/
constructor(geometryName, extent, opt_srsName) {
super('BBOX');
/**
@@ -32,7 +30,9 @@ class Bbox extends Filter {
*/
this.extent = extent;
if (extent.length !== 4) {
throw new Error('Expected an extent with four values ([minX, minY, maxX, maxY])');
throw new Error(
'Expected an extent with four values ([minX, minY, maxX, maxY])'
);
}
/**
@@ -40,7 +40,6 @@ class Bbox extends Filter {
*/
this.srsName = opt_srsName;
}
}
export default Bbox;

View File

@@ -11,13 +11,11 @@ import Filter from './Filter.js';
* @abstract
*/
class Comparison extends Filter {
/**
* @param {!string} tagName The XML tag name for this filter.
* @param {!string} propertyName Name of the context property to compare.
*/
constructor(tagName, propertyName) {
super(tagName);
/**
@@ -25,7 +23,6 @@ class Comparison extends Filter {
*/
this.propertyName = propertyName;
}
}
export default Comparison;

View File

@@ -11,7 +11,6 @@ import Comparison from './Comparison.js';
* @abstract
*/
class ComparisonBinary extends Comparison {
/**
* @param {!string} tagName The XML tag name for this filter.
* @param {!string} propertyName Name of the context property to compare.
@@ -19,7 +18,6 @@ class ComparisonBinary extends Comparison {
* @param {boolean=} opt_matchCase Case-sensitive?
*/
constructor(tagName, propertyName, expression, opt_matchCase) {
super(tagName, propertyName);
/**
@@ -32,7 +30,6 @@ class ComparisonBinary extends Comparison {
*/
this.matchCase = opt_matchCase;
}
}
export default ComparisonBinary;

View File

@@ -10,7 +10,6 @@ import Spatial from './Spatial.js';
* @api
*/
class Contains extends Spatial {
/**
* @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
@@ -18,11 +17,8 @@ class Contains extends Spatial {
* set on geometries when this is not provided.
*/
constructor(geometryName, geometry, opt_srsName) {
super('Contains', geometryName, geometry, opt_srsName);
}
}
export default Contains;

View File

@@ -9,7 +9,6 @@ import Comparison from './Comparison.js';
* @api
*/
class During extends Comparison {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!string} begin The begin date in ISO-8601 format.
@@ -28,7 +27,6 @@ class During extends Comparison {
*/
this.end = end;
}
}
export default During;

View File

@@ -9,7 +9,6 @@ import ComparisonBinary from './ComparisonBinary.js';
* @api
*/
class EqualTo extends ComparisonBinary {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!(string|number)} expression The value to compare.
@@ -18,7 +17,6 @@ class EqualTo extends ComparisonBinary {
constructor(propertyName, expression, opt_matchCase) {
super('PropertyIsEqualTo', propertyName, expression, opt_matchCase);
}
}
export default EqualTo;

View File

@@ -2,7 +2,6 @@
* @module ol/format/filter/Filter
*/
/**
* @classdesc
* Abstract class; normally only used for creating subclasses and not instantiated in apps.
@@ -15,7 +14,6 @@ class Filter {
* @param {!string} tagName The XML tag name for this filter.
*/
constructor(tagName) {
/**
* @private
* @type {!string}

View File

@@ -9,7 +9,6 @@ import ComparisonBinary from './ComparisonBinary.js';
* @api
*/
class GreaterThan extends ComparisonBinary {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!number} expression The value to compare.
@@ -17,7 +16,6 @@ class GreaterThan extends ComparisonBinary {
constructor(propertyName, expression) {
super('PropertyIsGreaterThan', propertyName, expression);
}
}
export default GreaterThan;

View File

@@ -9,7 +9,6 @@ import ComparisonBinary from './ComparisonBinary.js';
* @api
*/
class GreaterThanOrEqualTo extends ComparisonBinary {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!number} expression The value to compare.
@@ -17,7 +16,6 @@ class GreaterThanOrEqualTo extends ComparisonBinary {
constructor(propertyName, expression) {
super('PropertyIsGreaterThanOrEqualTo', propertyName, expression);
}
}
export default GreaterThanOrEqualTo;

View File

@@ -10,7 +10,6 @@ import Spatial from './Spatial.js';
* @api
*/
class Intersects extends Spatial {
/**
* @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
@@ -20,7 +19,6 @@ class Intersects extends Spatial {
constructor(geometryName, geometry, opt_srsName) {
super('Intersects', geometryName, geometry, opt_srsName);
}
}
export default Intersects;

View File

@@ -9,7 +9,6 @@ import Comparison from './Comparison.js';
* @api
*/
class IsBetween extends Comparison {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!number} lowerBoundary The lower bound of the range.
@@ -27,7 +26,6 @@ class IsBetween extends Comparison {
* @type {!number}
*/
this.upperBoundary = upperBoundary;
}
}

View File

@@ -9,7 +9,6 @@ import Comparison from './Comparison.js';
* @api
*/
class IsLike extends Comparison {
/**
* [constructor description]
* @param {!string} propertyName Name of the context property to compare.
@@ -22,7 +21,14 @@ class IsLike extends Comparison {
* the pattern characters. Default is '!'.
* @param {boolean=} opt_matchCase Case-sensitive?
*/
constructor(propertyName, pattern, opt_wildCard, opt_singleChar, opt_escapeChar, opt_matchCase) {
constructor(
propertyName,
pattern,
opt_wildCard,
opt_singleChar,
opt_escapeChar,
opt_matchCase
) {
super('PropertyIsLike', propertyName);
/**
@@ -33,23 +39,22 @@ class IsLike extends Comparison {
/**
* @type {!string}
*/
this.wildCard = (opt_wildCard !== undefined) ? opt_wildCard : '*';
this.wildCard = opt_wildCard !== undefined ? opt_wildCard : '*';
/**
* @type {!string}
*/
this.singleChar = (opt_singleChar !== undefined) ? opt_singleChar : '.';
this.singleChar = opt_singleChar !== undefined ? opt_singleChar : '.';
/**
* @type {!string}
*/
this.escapeChar = (opt_escapeChar !== undefined) ? opt_escapeChar : '!';
this.escapeChar = opt_escapeChar !== undefined ? opt_escapeChar : '!';
/**
* @type {boolean|undefined}
*/
this.matchCase = opt_matchCase;
}
}

View File

@@ -9,14 +9,12 @@ import Comparison from './Comparison.js';
* @api
*/
class IsNull extends Comparison {
/**
* @param {!string} propertyName Name of the context property to compare.
*/
constructor(propertyName) {
super('PropertyIsNull', propertyName);
}
}
export default IsNull;

View File

@@ -9,7 +9,6 @@ import ComparisonBinary from './ComparisonBinary.js';
* @api
*/
class LessThan extends ComparisonBinary {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!number} expression The value to compare.
@@ -17,7 +16,6 @@ class LessThan extends ComparisonBinary {
constructor(propertyName, expression) {
super('PropertyIsLessThan', propertyName, expression);
}
}
export default LessThan;

View File

@@ -9,7 +9,6 @@ import ComparisonBinary from './ComparisonBinary.js';
* @api
*/
class LessThanOrEqualTo extends ComparisonBinary {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!number} expression The value to compare.
@@ -17,7 +16,6 @@ class LessThanOrEqualTo extends ComparisonBinary {
constructor(propertyName, expression) {
super('PropertyIsLessThanOrEqualTo', propertyName, expression);
}
}
export default LessThanOrEqualTo;

View File

@@ -1,8 +1,8 @@
/**
* @module ol/format/filter/LogicalNary
*/
import {assert} from '../../asserts.js';
import Filter from './Filter.js';
import {assert} from '../../asserts.js';
/**
* @classdesc
@@ -12,13 +12,11 @@ import Filter from './Filter.js';
* @abstract
*/
class LogicalNary extends Filter {
/**
* @param {!string} tagName The XML tag name for this filter.
* @param {Array<import("./Filter.js").default>} conditions Conditions.
*/
constructor(tagName, conditions) {
super(tagName);
/**
@@ -27,7 +25,6 @@ class LogicalNary extends Filter {
this.conditions = conditions;
assert(this.conditions.length >= 2, 57); // At least 2 conditions are required.
}
}
export default LogicalNary;

View File

@@ -9,21 +9,17 @@ import Filter from './Filter.js';
* @api
*/
class Not extends Filter {
/**
* @param {!import("./Filter.js").default} condition Filter condition.
*/
constructor(condition) {
super('Not');
/**
* @type {!import("./Filter.js").default}
*/
this.condition = condition;
}
}
export default Not;

View File

@@ -9,7 +9,6 @@ import ComparisonBinary from './ComparisonBinary.js';
* @api
*/
class NotEqualTo extends ComparisonBinary {
/**
* @param {!string} propertyName Name of the context property to compare.
* @param {!(string|number)} expression The value to compare.
@@ -18,7 +17,6 @@ class NotEqualTo extends ComparisonBinary {
constructor(propertyName, expression, opt_matchCase) {
super('PropertyIsNotEqualTo', propertyName, expression, opt_matchCase);
}
}
export default NotEqualTo;

View File

@@ -9,14 +9,12 @@ import LogicalNary from './LogicalNary.js';
* @api
*/
class Or extends LogicalNary {
/**
* @param {...import("./Filter.js").default} conditions Conditions.
*/
constructor(conditions) {
super('Or', Array.prototype.slice.call(arguments));
}
}
export default Or;

View File

@@ -12,7 +12,6 @@ import Filter from './Filter.js';
* @abstract
*/
class Spatial extends Filter {
/**
* @param {!string} tagName The XML tag name for this filter.
* @param {!string} geometryName Geometry name to use.
@@ -21,7 +20,6 @@ class Spatial extends Filter {
* set on geometries when this is not provided.
*/
constructor(tagName, geometryName, geometry, opt_srsName) {
super(tagName);
/**
@@ -39,7 +37,6 @@ class Spatial extends Filter {
*/
this.srsName = opt_srsName;
}
}
export default Spatial;

View File

@@ -10,7 +10,6 @@ import Spatial from './Spatial.js';
* @api
*/
class Within extends Spatial {
/**
* @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
@@ -20,7 +19,6 @@ class Within extends Spatial {
constructor(geometryName, geometry, opt_srsName) {
super('Within', geometryName, geometry, opt_srsName);
}
}
export default Within;

View File

@@ -4,7 +4,6 @@
import {getAllTextContent, getDocument} from '../xml.js';
import {padNumber} from '../string.js';
/**
* @param {Node} node Node.
* @return {boolean|undefined} Boolean.
@@ -14,7 +13,6 @@ export function readBoolean(node) {
return readBooleanString(s);
}
/**
* @param {string} string String.
* @return {boolean|undefined} Boolean.
@@ -28,7 +26,6 @@ export function readBooleanString(string) {
}
}
/**
* @param {Node} node Node.
* @return {number|undefined} DateTime in seconds.
@@ -39,7 +36,6 @@ export function readDateTime(node) {
return isNaN(dateTime) ? undefined : dateTime / 1000;
}
/**
* @param {Node} node Node.
* @return {number|undefined} Decimal.
@@ -49,7 +45,6 @@ export function readDecimal(node) {
return readDecimalString(s);
}
/**
* @param {string} string String.
* @return {number|undefined} Decimal.
@@ -64,7 +59,6 @@ export function readDecimalString(string) {
}
}
/**
* @param {Node} node Node.
* @return {number|undefined} Non negative integer.
@@ -74,7 +68,6 @@ export function readNonNegativeInteger(node) {
return readNonNegativeIntegerString(s);
}
/**
* @param {string} string String.
* @return {number|undefined} Non negative integer.
@@ -88,7 +81,6 @@ export function readNonNegativeIntegerString(string) {
}
}
/**
* @param {Node} node Node.
* @return {string|undefined} String.
@@ -97,16 +89,14 @@ export function readString(node) {
return getAllTextContent(node, false).trim();
}
/**
* @param {Node} node Node to append a TextNode with the boolean to.
* @param {boolean} bool Boolean.
*/
export function writeBooleanTextNode(node, bool) {
writeStringTextNode(node, (bool) ? '1' : '0');
writeStringTextNode(node, bool ? '1' : '0');
}
/**
* @param {Node} node Node to append a CDATA Section with the string to.
* @param {string} string String.
@@ -115,23 +105,28 @@ export function writeCDATASection(node, string) {
node.appendChild(getDocument().createCDATASection(string));
}
/**
* @param {Node} node Node to append a TextNode with the dateTime to.
* @param {number} dateTime DateTime in seconds.
*/
export function writeDateTimeTextNode(node, dateTime) {
const date = new Date(dateTime * 1000);
const string = date.getUTCFullYear() + '-' +
padNumber(date.getUTCMonth() + 1, 2) + '-' +
padNumber(date.getUTCDate(), 2) + 'T' +
padNumber(date.getUTCHours(), 2) + ':' +
padNumber(date.getUTCMinutes(), 2) + ':' +
padNumber(date.getUTCSeconds(), 2) + 'Z';
const string =
date.getUTCFullYear() +
'-' +
padNumber(date.getUTCMonth() + 1, 2) +
'-' +
padNumber(date.getUTCDate(), 2) +
'T' +
padNumber(date.getUTCHours(), 2) +
':' +
padNumber(date.getUTCMinutes(), 2) +
':' +
padNumber(date.getUTCSeconds(), 2) +
'Z';
node.appendChild(getDocument().createTextNode(string));
}
/**
* @param {Node} node Node to append a TextNode with the decimal to.
* @param {number} decimal Decimal.
@@ -141,7 +136,6 @@ export function writeDecimalTextNode(node, decimal) {
node.appendChild(getDocument().createTextNode(string));
}
/**
* @param {Node} node Node to append a TextNode with the decimal to.
* @param {number} nonNegativeInteger Non negative integer.
@@ -151,7 +145,6 @@ export function writeNonNegativeIntegerTextNode(node, nonNegativeInteger) {
node.appendChild(getDocument().createTextNode(string));
}
/**
* @param {Node} node Node to append a TextNode with the string to.
* @param {string} string String.