From 44bea898b8884442cbf5cde85581ff6e3128d8ab Mon Sep 17 00:00:00 2001 From: ahocevar Date: Tue, 17 Jul 2018 16:10:11 +0200 Subject: [PATCH] Use extends and super for format/JSONFeature --- src/ol/format/EsriJSON.js | 93 +----------------------------------- src/ol/format/JSONFeature.js | 50 ++++++++++++++++--- 2 files changed, 45 insertions(+), 98 deletions(-) diff --git a/src/ol/format/EsriJSON.js b/src/ol/format/EsriJSON.js index 0f388a10b2..7c5e4fc080 100644 --- a/src/ol/format/EsriJSON.js +++ b/src/ol/format/EsriJSON.js @@ -1,7 +1,6 @@ /** * @module ol/format/EsriJSON */ -import {inherits} from '../util.js'; import Feature from '../Feature.js'; import {assert} from '../asserts.js'; import {containsExtent} from '../extent.js'; @@ -58,10 +57,9 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry; * @classdesc * Feature format for reading and writing data in the EsriJSON format. * - * @extends {module:ol/format/JSONFeature} * @api */ -class EsriJSON { +class EsriJSON extends JSONFeature { /** * @param {module:ol/format/EsriJSON~Options=} opt_options Options. @@ -70,7 +68,7 @@ class EsriJSON { const options = opt_options ? opt_options : {}; - JSONFeature.call(this); + super(); /** * Name of the geometry attribute for features. @@ -208,8 +206,6 @@ class EsriJSON { } } -inherits(EsriJSON, JSONFeature); - /** * @param {EsriJSONGeometry} object Object. @@ -543,55 +539,6 @@ function writeMultiPolygonGeometry(geometry, opt_options) { } -/** - * Read a feature from a EsriJSON Feature source. Only works for Feature, - * use `readFeatures` to read FeatureCollection source. - * - * @function - * @param {ArrayBuffer|Document|Node|Object|string} source Source. - * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. - * @return {module:ol/Feature} Feature. - * @api - */ -EsriJSON.prototype.readFeature; - - -/** - * Read all features from a EsriJSON source. Works with both Feature and - * FeatureCollection sources. - * - * @function - * @param {ArrayBuffer|Document|Node|Object|string} source Source. - * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. - * @return {Array.} Features. - * @api - */ -EsriJSON.prototype.readFeatures; - - -/** - * Read a geometry from a EsriJSON source. - * - * @function - * @param {ArrayBuffer|Document|Node|Object|string} source Source. - * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. - * @return {module:ol/geom/Geometry} Geometry. - * @api - */ -EsriJSON.prototype.readGeometry; - - -/** - * Read the projection from a EsriJSON source. - * - * @function - * @param {ArrayBuffer|Document|Node|Object|string} source Source. - * @return {module:ol/proj/Projection} Projection. - * @api - */ -EsriJSON.prototype.readProjection; - - /** * @param {module:ol/geom/Geometry} geometry Geometry. * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. @@ -604,40 +551,4 @@ function writeGeometry(geometry, opt_options) { } -/** - * Encode a geometry as a EsriJSON string. - * - * @function - * @param {module:ol/geom/Geometry} geometry Geometry. - * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. - * @return {string} EsriJSON. - * @api - */ -EsriJSON.prototype.writeGeometry; - - -/** - * Encode a feature as a EsriJSON Feature string. - * - * @function - * @param {module:ol/Feature} feature Feature. - * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. - * @return {string} EsriJSON. - * @api - */ -EsriJSON.prototype.writeFeature; - - -/** - * Encode an array of features as EsriJSON. - * - * @function - * @param {Array.} features Features. - * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. - * @return {string} EsriJSON. - * @api - */ -EsriJSON.prototype.writeFeatures; - - export default EsriJSON; diff --git a/src/ol/format/JSONFeature.js b/src/ol/format/JSONFeature.js index 682bdc87e5..dfdc63c041 100644 --- a/src/ol/format/JSONFeature.js +++ b/src/ol/format/JSONFeature.js @@ -27,7 +27,13 @@ class JSONFeature { } /** - * @inheritDoc + * Read a feature. Only works for a single feature. Use `readFeatures` to + * read a feature collection. + * + * @param {ArrayBuffer|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) { return this.readFeatureFromObject( @@ -35,7 +41,13 @@ class JSONFeature { } /** - * @inheritDoc + * Read all features. Works with both a single feature and a feature + * collection. + * + * @param {ArrayBuffer|Document|Node|Object|string} source Source. + * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. + * @return {Array.} Features. + * @api */ readFeatures(source, opt_options) { return this.readFeaturesFromObject( @@ -61,7 +73,12 @@ class JSONFeature { readFeaturesFromObject(object, opt_options) {} /** - * @inheritDoc + * Read a geometry. + * + * @param {ArrayBuffer|Document|Node|Object|string} source Source. + * @param {module:ol/format/Feature~ReadOptions=} opt_options Read options. + * @return {module:ol/geom/Geometry} Geometry. + * @api */ readGeometry(source, opt_options) { return this.readGeometryFromObject( @@ -78,7 +95,11 @@ class JSONFeature { readGeometryFromObject(object, opt_options) {} /** - * @inheritDoc + * Read the projection. + * + * @param {ArrayBuffer|Document|Node|Object|string} source Source. + * @return {module:ol/proj/Projection} Projection. + * @api */ readProjection(source) { return this.readProjectionFromObject(getObject(source)); @@ -93,7 +114,12 @@ class JSONFeature { readProjectionFromObject(object) {} /** - * @inheritDoc + * Encode a feature as string. + * + * @param {module:ol/Feature} feature Feature. + * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. + * @return {string} Encoded feature. + * @api */ writeFeature(feature, opt_options) { return JSON.stringify(this.writeFeatureObject(feature, opt_options)); @@ -108,7 +134,12 @@ class JSONFeature { writeFeatureObject(feature, opt_options) {} /** - * @inheritDoc + * Encode an array of features as string. + * + * @param {Array.} features Features. + * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. + * @return {string} Encoded features. + * @api */ writeFeatures(features, opt_options) { return JSON.stringify(this.writeFeaturesObject(features, opt_options)); @@ -123,7 +154,12 @@ class JSONFeature { writeFeaturesObject(features, opt_options) {} /** - * @inheritDoc + * Encode a geometry as string. + * + * @param {module:ol/geom/Geometry} geometry Geometry. + * @param {module:ol/format/Feature~WriteOptions=} opt_options Write options. + * @return {string} Encoded geometry. + * @api */ writeGeometry(geometry, opt_options) { return JSON.stringify(this.writeGeometryObject(geometry, opt_options));