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:
+330
-272
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user