Use extends and super for format/GPX

This commit is contained in:
ahocevar
2018-07-17 16:43:28 +02:00
parent 9a28af76ca
commit e1e5e54d74
2 changed files with 29 additions and 62 deletions
+12 -59
View File
@@ -1,7 +1,6 @@
/** /**
* @module ol/format/GPX * @module ol/format/GPX
*/ */
import {inherits} from '../util.js';
import Feature from '../Feature.js'; import Feature from '../Feature.js';
import {includes} from '../array.js'; import {includes} from '../array.js';
import {transformWithOptions} from '../format/Feature.js'; import {transformWithOptions} from '../format/Feature.js';
@@ -103,19 +102,28 @@ const GPX_SERIALIZERS = makeStructureNS(
* @classdesc * @classdesc
* Feature format for reading and writing data in the GPX format. * Feature format for reading and writing data in the GPX format.
* *
* @extends {module:ol/format/XMLFeature} * Note that {@link module:ol/format/GPX~GPX#readFeature} only reads the first
* feature of the source.
*
* When reading, routes (`<rte>`) are converted into LineString geometries, and
* tracks (`<trk>`) into MultiLineString. Any properties on route and track
* waypoints are ignored.
*
* When writing, LineString geometries are output as routes (`<rte>`), and
* MultiLineString as tracks (`<trk>`).
*
* @api * @api
*/ */
class GPX { class GPX extends XMLFeature {
/** /**
* @param {module:ol/format/GPX~Options=} opt_options Options. * @param {module:ol/format/GPX~Options=} opt_options Options.
*/ */
constructor(opt_options) { constructor(opt_options) {
super();
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
XMLFeature.call(this);
/** /**
* @inheritDoc * @inheritDoc
@@ -214,8 +222,6 @@ class GPX {
} }
} }
inherits(GPX, XMLFeature);
/** /**
* @const * @const
@@ -702,45 +708,6 @@ function readWpt(node, objectStack) {
} }
/**
* Read the first feature from a GPX source.
* Routes (`<rte>`) are converted into LineString geometries, and tracks (`<trk>`)
* into MultiLineString. Any properties on route and track waypoints are ignored.
*
* @function
* @param {Document|Node|Object|string} source Source.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @return {module:ol/Feature} Feature.
* @api
*/
GPX.prototype.readFeature;
/**
* Read all features from a GPX source.
* Routes (`<rte>`) are converted into LineString geometries, and tracks (`<trk>`)
* into MultiLineString. Any properties on route and track waypoints are ignored.
*
* @function
* @param {Document|Node|Object|string} source Source.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @return {Array.<module:ol/Feature>} Features.
* @api
*/
GPX.prototype.readFeatures;
/**
* Read the projection from a GPX source.
*
* @function
* @param {Document|Node|Object|string} source Source.
* @return {module:ol/proj/Projection} Projection.
* @api
*/
GPX.prototype.readProjection;
/** /**
* @param {Node} node Node. * @param {Node} node Node.
* @param {string} value Value for the link's `href` attribute. * @param {string} value Value for the link's `href` attribute.
@@ -887,18 +854,4 @@ function writeWpt(node, feature, objectStack) {
} }
/**
* Encode an array of features in the GPX format.
* LineString geometries are output as routes (`<rte>`), and MultiLineString
* as tracks (`<trk>`).
*
* @function
* @param {Array.<module:ol/Feature>} features Features.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {string} Result.
* @api
*/
GPX.prototype.writeFeatures;
export default GPX; export default GPX;
+17 -3
View File
@@ -36,7 +36,12 @@ class XMLFeature {
} }
/** /**
* @inheritDoc * Read a single feature.
*
* @param {Document|Node|Object|string} source Source.
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
* @return {module:ol/Feature} Feature.
* @api
*/ */
readFeature(source, opt_options) { readFeature(source, opt_options) {
if (isDocument(source)) { if (isDocument(source)) {
@@ -161,7 +166,11 @@ class XMLFeature {
} }
/** /**
* @inheritDoc * Read the projection from the source.
*
* @param {Document|Node|Object|string} source Source.
* @return {module:ol/proj/Projection} Projection.
* @api
*/ */
readProjection(source) { readProjection(source) {
if (isDocument(source)) { if (isDocument(source)) {
@@ -213,7 +222,12 @@ class XMLFeature {
} }
/** /**
* @inheritDoc * Encode an array of features as string.
*
* @param {Array.<module:ol/Feature>} features Features.
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
* @return {string} Result.
* @api
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, opt_options) {
const node = this.writeFeaturesNode(features, opt_options); const node = this.writeFeaturesNode(features, opt_options);