-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
TextFeature.js
206 lines (188 loc) · 5.05 KB
/
TextFeature.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* @module ol/format/TextFeature
*/
import FeatureFormat from '../format/Feature.js';
import {abstract} from '../util.js';
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
* instantiated in apps.
* Base class for text feature formats.
*
* @abstract
*/
class TextFeature extends FeatureFormat {
constructor() {
super();
}
/**
* @return {import("./Feature.js").Type} Format.
*/
getType() {
return 'text';
}
/**
* Read the feature from the source.
*
* @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature.
* @api
*/
readFeature(source, options) {
return this.readFeatureFromText(
getText(source),
this.adaptOptions(options),
);
}
/**
* @abstract
* @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected
* @return {import("../Feature.js").default} Feature.
*/
readFeatureFromText(text, options) {
return abstract();
}
/**
* Read the features from the source.
*
* @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {Array<import("../Feature.js").default>} Features.
* @api
*/
readFeatures(source, options) {
return this.readFeaturesFromText(
getText(source),
this.adaptOptions(options),
);
}
/**
* @abstract
* @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected
* @return {Array<import("../Feature.js").default>} Features.
*/
readFeaturesFromText(text, options) {
return abstract();
}
/**
* Read the geometry from the source.
*
* @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry.
* @api
*/
readGeometry(source, options) {
return this.readGeometryFromText(
getText(source),
this.adaptOptions(options),
);
}
/**
* @abstract
* @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected
* @return {import("../geom/Geometry.js").default} Geometry.
*/
readGeometryFromText(text, options) {
return abstract();
}
/**
* Read the projection from the source.
*
* @param {Document|Element|Object|string} source Source.
* @return {import("../proj/Projection.js").default|undefined} Projection.
* @api
*/
readProjection(source) {
return this.readProjectionFromText(getText(source));
}
/**
* @param {string} text Text.
* @protected
* @return {import("../proj/Projection.js").default|undefined} Projection.
*/
readProjectionFromText(text) {
return this.dataProjection;
}
/**
* Encode a feature as a string.
*
* @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded feature.
* @api
*/
writeFeature(feature, options) {
return this.writeFeatureText(feature, this.adaptOptions(options));
}
/**
* @abstract
* @param {import("../Feature.js").default} feature Features.
* @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected
* @return {string} Text.
*/
writeFeatureText(feature, options) {
return abstract();
}
/**
* Encode an array of features as string.
*
* @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded features.
* @api
*/
writeFeatures(features, options) {
return this.writeFeaturesText(features, this.adaptOptions(options));
}
/**
* @abstract
* @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected
* @return {string} Text.
*/
writeFeaturesText(features, options) {
return abstract();
}
/**
* Write a single geometry.
*
* @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Geometry.
* @api
*/
writeGeometry(geometry, options) {
return this.writeGeometryText(geometry, this.adaptOptions(options));
}
/**
* @abstract
* @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected
* @return {string} Text.
*/
writeGeometryText(geometry, options) {
return abstract();
}
}
/**
* @param {Document|Element|Object|string} source Source.
* @return {string} Text.
*/
function getText(source) {
if (typeof source === 'string') {
return source;
}
return '';
}
export default TextFeature;