ol 9.0.0-dev.1706533843703 → 9.0.0-dev.1706603894900
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ol.js +2 -2
- package/dist/ol.js.map +1 -1
- package/format/GPX.d.ts +95 -0
- package/format/GPX.d.ts.map +1 -1
- package/format/GPX.js +199 -0
- package/package.json +1 -1
- package/util.js +1 -1
package/format/GPX.d.ts
CHANGED
|
@@ -1,4 +1,76 @@
|
|
|
1
1
|
export default GPX;
|
|
2
|
+
export type GPXLink = {
|
|
3
|
+
/**
|
|
4
|
+
* text
|
|
5
|
+
*/
|
|
6
|
+
text?: string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* type
|
|
9
|
+
*/
|
|
10
|
+
type?: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
export type GPXAuthor = {
|
|
13
|
+
/**
|
|
14
|
+
* name
|
|
15
|
+
*/
|
|
16
|
+
name?: string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* email
|
|
19
|
+
*/
|
|
20
|
+
email?: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* link
|
|
23
|
+
*/
|
|
24
|
+
link?: GPXLink | undefined;
|
|
25
|
+
};
|
|
26
|
+
export type GPXMetadata = {
|
|
27
|
+
/**
|
|
28
|
+
* name
|
|
29
|
+
*/
|
|
30
|
+
name?: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* desc
|
|
33
|
+
*/
|
|
34
|
+
desc?: string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* author
|
|
37
|
+
*/
|
|
38
|
+
author?: GPXAuthor | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* link
|
|
41
|
+
*/
|
|
42
|
+
link?: GPXLink | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* time
|
|
45
|
+
*/
|
|
46
|
+
time?: number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* keywords
|
|
49
|
+
*/
|
|
50
|
+
keywords?: string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* bounds
|
|
53
|
+
*/
|
|
54
|
+
bounds?: number[] | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* extensions
|
|
57
|
+
*/
|
|
58
|
+
extensions?: any;
|
|
59
|
+
};
|
|
60
|
+
export type GPXCopyright = {
|
|
61
|
+
/**
|
|
62
|
+
* author
|
|
63
|
+
*/
|
|
64
|
+
author?: string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* year
|
|
67
|
+
*/
|
|
68
|
+
year?: number | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* license
|
|
71
|
+
*/
|
|
72
|
+
license?: string | undefined;
|
|
73
|
+
};
|
|
2
74
|
export type Options = {
|
|
3
75
|
/**
|
|
4
76
|
* Callback function
|
|
@@ -65,6 +137,29 @@ declare class GPX extends XMLFeature {
|
|
|
65
137
|
* @private
|
|
66
138
|
*/
|
|
67
139
|
private handleReadExtensions_;
|
|
140
|
+
/**
|
|
141
|
+
* Reads a GPX file's metadata tag, reading among other things:
|
|
142
|
+
* - the name and description of this GPX
|
|
143
|
+
* - its author
|
|
144
|
+
* - the copyright associated with this GPX file
|
|
145
|
+
*
|
|
146
|
+
* Will return null if no metadata tag is present (or no valid source is given).
|
|
147
|
+
*
|
|
148
|
+
* @param {Document|Element|Object|string} source Source.
|
|
149
|
+
* @return {GPXMetadata | null} Metadata
|
|
150
|
+
* @api
|
|
151
|
+
*/
|
|
152
|
+
readMetadata(source: Document | Element | any | string): GPXMetadata | null;
|
|
153
|
+
/**
|
|
154
|
+
* @param {Document} doc Document.
|
|
155
|
+
* @return {GPXMetadata | null} Metadata
|
|
156
|
+
*/
|
|
157
|
+
readMetadataFromDocument(doc: Document): GPXMetadata | null;
|
|
158
|
+
/**
|
|
159
|
+
* @param {Element} node Node.
|
|
160
|
+
* @return {Object} Metadata
|
|
161
|
+
*/
|
|
162
|
+
readMetadataFromNode(node: Element): any;
|
|
68
163
|
}
|
|
69
164
|
import Feature from '../Feature.js';
|
|
70
165
|
import XMLFeature from './XMLFeature.js';
|
package/format/GPX.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GPX.d.ts","sourceRoot":"","sources":["GPX.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GPX.d.ts","sourceRoot":"","sources":["GPX.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA2KuB,OAAO,QAAE,IAAI,KAAE,IAAI;;;;;;;;;;;;AAF1C;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;GAeG;AACH;IACE;;OAEG;IACH,2CAeC;IALC;;;OAGG;IACH,wBAA6C;IAG/C;;;OAGG;IACH,8BAYC;IAED;;;;;;;;;;;OAWG;IACH,qBAJW,QAAQ,GAAC,OAAO,SAAQ,MAAM,GAC7B,WAAW,GAAG,IAAI,CAc7B;IAED;;;OAGG;IACH,8BAHW,QAAQ,GACP,WAAW,GAAG,IAAI,CAY7B;IAED;;;OAGG;IACH,2BAHW,OAAO,OAgBjB;CAgFF;oBAvXmB,eAAe;uBAIZ,iBAAiB"}
|
package/format/GPX.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
OBJECT_PROPERTY_NODE_FACTORY,
|
|
11
11
|
XML_SCHEMA_INSTANCE_URI,
|
|
12
12
|
createElementNS,
|
|
13
|
+
isDocument,
|
|
13
14
|
makeArrayPusher,
|
|
14
15
|
makeArraySerializer,
|
|
15
16
|
makeChildAppender,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
makeSequence,
|
|
18
19
|
makeSimpleNodeFactory,
|
|
19
20
|
makeStructureNS,
|
|
21
|
+
parse,
|
|
20
22
|
parseNode,
|
|
21
23
|
pushParseAndPop,
|
|
22
24
|
pushSerializeAndPop,
|
|
@@ -73,6 +75,12 @@ const GPX_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
|
|
73
75
|
'wpt': makeArrayPusher(readWpt),
|
|
74
76
|
});
|
|
75
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @typedef {Object} GPXLink
|
|
80
|
+
* @property {string} [text] text
|
|
81
|
+
* @property {string} [type] type
|
|
82
|
+
*/
|
|
83
|
+
|
|
76
84
|
/**
|
|
77
85
|
* @const
|
|
78
86
|
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
|
@@ -83,6 +91,71 @@ const LINK_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
|
|
83
91
|
'type': makeObjectPropertySetter(readString, 'linkType'),
|
|
84
92
|
});
|
|
85
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {Object} GPXAuthor
|
|
96
|
+
* @property {string} [name] name
|
|
97
|
+
* @property {string} [email] email
|
|
98
|
+
* @property {GPXLink} [link] link
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @const
|
|
103
|
+
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
|
104
|
+
*/
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
const AUTHOR_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
|
107
|
+
'name': makeObjectPropertySetter(readString),
|
|
108
|
+
'email': parseEmail,
|
|
109
|
+
'link': parseLink,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @typedef {Object} GPXMetadata
|
|
114
|
+
* @property {string} [name] name
|
|
115
|
+
* @property {string} [desc] desc
|
|
116
|
+
* @property {GPXAuthor} [author] author
|
|
117
|
+
* @property {GPXLink} [link] link
|
|
118
|
+
* @property {number} [time] time
|
|
119
|
+
* @property {string} [keywords] keywords
|
|
120
|
+
* @property {Array<number>} [bounds] bounds
|
|
121
|
+
* @property {Object} [extensions] extensions
|
|
122
|
+
*
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @const
|
|
127
|
+
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
|
128
|
+
*/
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
const METADATA_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
|
131
|
+
'name': makeObjectPropertySetter(readString),
|
|
132
|
+
'desc': makeObjectPropertySetter(readString),
|
|
133
|
+
'author': makeObjectPropertySetter(readAuthor),
|
|
134
|
+
'copyright': makeObjectPropertySetter(readCopyright),
|
|
135
|
+
'link': parseLink,
|
|
136
|
+
'time': makeObjectPropertySetter(readDateTime),
|
|
137
|
+
'keywords': makeObjectPropertySetter(readString),
|
|
138
|
+
'bounds': parseBounds,
|
|
139
|
+
'extensions': parseExtensions,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @typedef {Object} GPXCopyright
|
|
144
|
+
* @property {string} [author] author
|
|
145
|
+
* @property {number} [year] year
|
|
146
|
+
* @property {string} [license] license
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @const
|
|
151
|
+
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
|
152
|
+
*/
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
const COPYRIGHT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
|
155
|
+
'year': makeObjectPropertySetter(readPositiveInteger),
|
|
156
|
+
'license': makeObjectPropertySetter(readString),
|
|
157
|
+
});
|
|
158
|
+
|
|
86
159
|
/**
|
|
87
160
|
* @const
|
|
88
161
|
* @type {Object<string, Object<string, import("../xml.js").Serializer>>}
|
|
@@ -165,6 +238,66 @@ class GPX extends XMLFeature {
|
|
|
165
238
|
}
|
|
166
239
|
}
|
|
167
240
|
|
|
241
|
+
/**
|
|
242
|
+
* Reads a GPX file's metadata tag, reading among other things:
|
|
243
|
+
* - the name and description of this GPX
|
|
244
|
+
* - its author
|
|
245
|
+
* - the copyright associated with this GPX file
|
|
246
|
+
*
|
|
247
|
+
* Will return null if no metadata tag is present (or no valid source is given).
|
|
248
|
+
*
|
|
249
|
+
* @param {Document|Element|Object|string} source Source.
|
|
250
|
+
* @return {GPXMetadata | null} Metadata
|
|
251
|
+
* @api
|
|
252
|
+
*/
|
|
253
|
+
readMetadata(source) {
|
|
254
|
+
if (!source) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
if (typeof source === 'string') {
|
|
258
|
+
return this.readMetadataFromDocument(parse(source));
|
|
259
|
+
}
|
|
260
|
+
if (isDocument(source)) {
|
|
261
|
+
return this.readMetadataFromDocument(/** @type {Document} */ (source));
|
|
262
|
+
}
|
|
263
|
+
return this.readMetadataFromNode(source);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @param {Document} doc Document.
|
|
268
|
+
* @return {GPXMetadata | null} Metadata
|
|
269
|
+
*/
|
|
270
|
+
readMetadataFromDocument(doc) {
|
|
271
|
+
for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
|
|
272
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
273
|
+
const metadata = this.readMetadataFromNode(/** @type {Element} */ (n));
|
|
274
|
+
if (metadata) {
|
|
275
|
+
return metadata;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @param {Element} node Node.
|
|
284
|
+
* @return {Object} Metadata
|
|
285
|
+
*/
|
|
286
|
+
readMetadataFromNode(node) {
|
|
287
|
+
if (!NAMESPACE_URIS.includes(node.namespaceURI)) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
|
291
|
+
if (
|
|
292
|
+
NAMESPACE_URIS.includes(n.namespaceURI) &&
|
|
293
|
+
n.localName === 'metadata'
|
|
294
|
+
) {
|
|
295
|
+
return pushParseAndPop({}, METADATA_PARSERS, n, []);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
168
301
|
/**
|
|
169
302
|
* @param {Element} node Node.
|
|
170
303
|
* @param {import("./Feature.js").ReadOptions} [options] Options.
|
|
@@ -589,6 +722,72 @@ function applyLayoutOptions(layoutOptions, flatCoordinates, ends) {
|
|
|
589
722
|
return layout;
|
|
590
723
|
}
|
|
591
724
|
|
|
725
|
+
/**
|
|
726
|
+
* @param {Element} node Node.
|
|
727
|
+
* @param {Array<any>} objectStack Object stack.
|
|
728
|
+
* @return {GPXAuthor | undefined} Person object.
|
|
729
|
+
*/
|
|
730
|
+
function readAuthor(node, objectStack) {
|
|
731
|
+
const values = pushParseAndPop({}, AUTHOR_PARSERS, node, objectStack);
|
|
732
|
+
if (values) {
|
|
733
|
+
return values;
|
|
734
|
+
}
|
|
735
|
+
return undefined;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* @param {Element} node Node.
|
|
740
|
+
* @param {Array<any>} objectStack Object stack.
|
|
741
|
+
* @return {GPXCopyright | undefined} Person object.
|
|
742
|
+
*/
|
|
743
|
+
function readCopyright(node, objectStack) {
|
|
744
|
+
const values = pushParseAndPop({}, COPYRIGHT_PARSERS, node, objectStack);
|
|
745
|
+
if (values) {
|
|
746
|
+
const author = node.getAttribute('author');
|
|
747
|
+
if (author !== null) {
|
|
748
|
+
values['author'] = author;
|
|
749
|
+
}
|
|
750
|
+
return values;
|
|
751
|
+
}
|
|
752
|
+
return undefined;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* @param {Element} node Node.
|
|
757
|
+
* @param {Array<*>} objectStack Object stack.
|
|
758
|
+
*/
|
|
759
|
+
function parseBounds(node, objectStack) {
|
|
760
|
+
const values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
|
761
|
+
const minlat = node.getAttribute('minlat');
|
|
762
|
+
const minlon = node.getAttribute('minlon');
|
|
763
|
+
const maxlat = node.getAttribute('maxlat');
|
|
764
|
+
const maxlon = node.getAttribute('maxlon');
|
|
765
|
+
if (
|
|
766
|
+
minlon !== null &&
|
|
767
|
+
minlat !== null &&
|
|
768
|
+
maxlon !== null &&
|
|
769
|
+
maxlat !== null
|
|
770
|
+
) {
|
|
771
|
+
values['bounds'] = [
|
|
772
|
+
[parseFloat(minlon), parseFloat(minlat)],
|
|
773
|
+
[parseFloat(maxlon), parseFloat(maxlat)],
|
|
774
|
+
];
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* @param {Element} node Node.
|
|
780
|
+
* @param {Array<*>} objectStack Object stack.
|
|
781
|
+
*/
|
|
782
|
+
function parseEmail(node, objectStack) {
|
|
783
|
+
const values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
|
784
|
+
const id = node.getAttribute('id');
|
|
785
|
+
const domain = node.getAttribute('domain');
|
|
786
|
+
if (id !== null && domain !== null) {
|
|
787
|
+
values['email'] = `${id}@${domain}`;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
592
791
|
/**
|
|
593
792
|
* @param {Element} node Node.
|
|
594
793
|
* @param {Array<*>} objectStack Object stack.
|
package/package.json
CHANGED
package/util.js
CHANGED