You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
208 lines
5.1 KiB
208 lines
5.1 KiB
/**
|
|
* @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;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
export default TextFeature;
|