Merge pull request #8711 from schmidtk/ts-format-gml

Fix TypeScript errors in ol/format/GML
This commit is contained in:
Frédéric Junod
2018-10-16 08:25:41 +02:00
committed by GitHub
5 changed files with 64 additions and 30 deletions

View File

@@ -178,7 +178,7 @@ class GML2 extends GMLBase {
writeFeatureElement(node, feature, objectStack) {
const fid = feature.getId();
if (fid) {
node.setAttribute('fid', fid);
node.setAttribute('fid', /** @type {string} */ (fid));
}
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
const featureNS = context['featureNS'];
@@ -284,7 +284,7 @@ class GML2 extends GMLBase {
writeGeometryElement(node, geometry, objectStack) {
const context = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[objectStack.length - 1]);
const item = assign({}, context);
item.node = node;
item['node'] = node;
let value;
if (Array.isArray(geometry)) {
if (context.dataProjection) {
@@ -587,9 +587,9 @@ class GML2 extends GMLBase {
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @private
* @protected
*/
GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
'http://www.opengis.net/gml': {
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates_)
}
@@ -598,9 +598,9 @@ GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @private
* @protected
*/
GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
GML2.prototype.FLAT_LINEAR_RINGS_PARSERS = {
'http://www.opengis.net/gml': {
'innerBoundaryIs': GML2.prototype.innerBoundaryIsParser_,
'outerBoundaryIs': GML2.prototype.outerBoundaryIsParser_
@@ -622,9 +622,9 @@ GML2.prototype.BOX_PARSERS_ = {
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @private
* @protected
*/
GML2.prototype.GEOMETRY_PARSERS_ = {
GML2.prototype.GEOMETRY_PARSERS = {
'http://www.opengis.net/gml': {
'Point': makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': makeReplacer(

View File

@@ -182,7 +182,7 @@ class GML3 extends GMLBase {
*/
readPolygonPatch_(node, objectStack) {
return pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
this.FLAT_LINEAR_RINGS_PARSERS, node, objectStack, this);
}
/**
@@ -193,7 +193,7 @@ class GML3 extends GMLBase {
*/
readLineStringSegment_(node, objectStack) {
return pushParseAndPop([null],
this.GEOMETRY_FLAT_COORDINATES_PARSERS_,
this.GEOMETRY_FLAT_COORDINATES_PARSERS,
node, objectStack, this);
}
@@ -356,9 +356,9 @@ class GML3 extends GMLBase {
} else if (node.getAttribute('dimension')) {
dim = readNonNegativeIntegerString(
node.getAttribute('dimension'));
} else if (node.parentNode.getAttribute('srsDimension')) {
} else if (/** @type {Element} */ (node.parentNode).getAttribute('srsDimension')) {
dim = readNonNegativeIntegerString(
node.parentNode.getAttribute('srsDimension'));
/** @type {Element} */ (node.parentNode).getAttribute('srsDimension'));
} else if (contextDimension) {
dim = readNonNegativeIntegerString(contextDimension);
}
@@ -386,7 +386,7 @@ class GML3 extends GMLBase {
writePos_(node, value, objectStack) {
const context = objectStack[objectStack.length - 1];
const hasZ = context['hasZ'];
const srsDimension = hasZ ? 3 : 2;
const srsDimension = hasZ ? '3' : '2';
node.setAttribute('srsDimension', srsDimension);
const srsName = context['srsName'];
let axisOrientation = 'enu';
@@ -442,7 +442,7 @@ class GML3 extends GMLBase {
writePosList_(node, value, objectStack) {
const context = objectStack[objectStack.length - 1];
const hasZ = context['hasZ'];
const srsDimension = hasZ ? 3 : 2;
const srsDimension = hasZ ? '3' : '2';
node.setAttribute('srsDimension', srsDimension);
const srsName = context['srsName'];
// only 2d for simple features profile
@@ -730,7 +730,7 @@ class GML3 extends GMLBase {
writeGeometryElement(node, geometry, objectStack) {
const context = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[objectStack.length - 1]);
const item = assign({}, context);
item.node = node;
item['node'] = node;
let value;
if (Array.isArray(geometry)) {
if (context.dataProjection) {
@@ -756,7 +756,7 @@ class GML3 extends GMLBase {
writeFeatureElement(node, feature, objectStack) {
const fid = feature.getId();
if (fid) {
node.setAttribute('fid', fid);
node.setAttribute('fid', /** @type {string} */ (fid));
}
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
const featureNS = context['featureNS'];
@@ -804,6 +804,7 @@ class GML3 extends GMLBase {
const context = /** @type {Object} */ (objectStack[objectStack.length - 1]);
const featureType = context['featureType'];
const featureNS = context['featureNS'];
/** @type {Object<string, Object<string, import("../xml.js").Serializer>>} */
const serializers = {};
serializers[featureNS] = {};
serializers[featureNS][featureType] = makeChildAppender(
@@ -920,9 +921,9 @@ class GML3 extends GMLBase {
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @private
* @protected
*/
GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
'http://www.opengis.net/gml': {
'pos': makeReplacer(GML3.prototype.readFlatPos_),
'posList': makeReplacer(GML3.prototype.readFlatPosList_)
@@ -933,9 +934,9 @@ GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = {
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @private
* @protected
*/
GML3.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
GML3.prototype.FLAT_LINEAR_RINGS_PARSERS = {
'http://www.opengis.net/gml': {
'interior': GML3.prototype.interiorParser_,
'exterior': GML3.prototype.exteriorParser_
@@ -946,9 +947,9 @@ GML3.prototype.FLAT_LINEAR_RINGS_PARSERS_ = {
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @private
* @protected
*/
GML3.prototype.GEOMETRY_PARSERS_ = {
GML3.prototype.GEOMETRY_PARSERS = {
'http://www.opengis.net/gml': {
'Point': makeReplacer(GMLBase.prototype.readPoint),
'MultiPoint': makeReplacer(

View File

@@ -71,6 +71,7 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
* gml:MultiPolygon. Since the latter is deprecated in GML 3.
* @property {string} [schemaLocation] Optional schemaLocation to use when
* writing out the GML, this will override the default provided.
* @property {boolean} [hasZ=false] If coordinates have a Z value.
*/
@@ -126,7 +127,6 @@ class GMLBase extends XMLFeature {
'featureMember': makeReplacer(this.readFeaturesInternal),
'featureMembers': makeReplacer(this.readFeaturesInternal)
};
}
/**
@@ -189,9 +189,11 @@ class GMLBase extends XMLFeature {
featureNS = {};
featureNS[defaultPrefix] = ns;
}
/** @type {Object<string, Object<string, import("../xml.js").Parser>>} */
const parsersNS = {};
const featureTypes = Array.isArray(featureType) ? featureType : [featureType];
for (const p in featureNS) {
/** @type {Object<string, import("../xml.js").Parser>} */
const parsers = {};
for (let i = 0, ii = featureTypes.length; i < ii; ++i) {
const featurePrefix = featureTypes[i].indexOf(':') === -1 ?
@@ -227,7 +229,7 @@ class GMLBase extends XMLFeature {
context['srsName'] = node.firstElementChild.getAttribute('srsName');
context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
/** @type {import("../geom/Geometry.js").default} */
const geometry = pushParseAndPop(null, this.GEOMETRY_PARSERS_, node, objectStack, this);
const geometry = pushParseAndPop(null, this.GEOMETRY_PARSERS, node, objectStack, this);
if (geometry) {
return (
/** @type {import("../geom/Geometry.js").default} */ (transformWithOptions(geometry, false, context))
@@ -383,7 +385,7 @@ class GMLBase extends XMLFeature {
*/
readFlatLinearRing_(node, objectStack) {
const ring = pushParseAndPop(null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
this.GEOMETRY_FLAT_COORDINATES_PARSERS, node,
objectStack, this);
if (ring) {
return ring;
@@ -412,7 +414,7 @@ class GMLBase extends XMLFeature {
readPolygon(node, objectStack) {
/** @type {Array<Array<number>>} */
const flatLinearRings = pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
this.FLAT_LINEAR_RINGS_PARSERS, node, objectStack, this);
if (flatLinearRings && flatLinearRings[0]) {
const flatCoordinates = flatLinearRings[0];
const ends = [flatCoordinates.length];
@@ -434,7 +436,7 @@ class GMLBase extends XMLFeature {
* @return {Array<number>} Flat coordinates.
*/
readFlatCoordinatesFromNode_(node, objectStack) {
return pushParseAndPop(null, this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack, this);
return pushParseAndPop(null, this.GEOMETRY_FLAT_COORDINATES_PARSERS, node, objectStack, this);
}
/**
@@ -469,6 +471,37 @@ class GMLBase extends XMLFeature {
}
}
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.FLAT_LINEAR_RINGS_PARSERS = {
'http://www.opengis.net/gml': {}
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
'http://www.opengis.net/gml': {}
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
* @protected
*/
GMLBase.prototype.GEOMETRY_PARSERS = {
'http://www.opengis.net/gml': {}
};
/**
* @const
* @type {Object<string, Object<string, import("../xml.js").Parser>>}

View File

@@ -23,7 +23,7 @@ import {douglasPeuckerArray} from '../geom/flat/simplify.js';
class MultiLineString extends SimpleGeometry {
/**
* @param {Array<Array<import("../coordinate.js").Coordinate>|import("../geom.js").MultiLineString>|Array<number>} coordinates
* @param {Array<Array<import("../coordinate.js").Coordinate>|LineString>|Array<number>} coordinates
* Coordinates or LineString geometries. (For internal use, flat coordinates in
* combination with `opt_layout` and `opt_ends` are also accepted.)
* @param {GeometryLayout=} opt_layout Layout.
@@ -58,7 +58,7 @@ class MultiLineString extends SimpleGeometry {
this.ends_ = opt_ends;
} else {
let layout = this.getLayout();
const lineStrings = /** @type {Array<import("../geom.js").MultiLineString>} */ (coordinates);
const lineStrings = /** @type {Array<LineString>} */ (coordinates);
const flatCoordinates = [];
const ends = [];
for (let i = 0, ii = lineStrings.length; i < ii; ++i) {

View File

@@ -29,7 +29,7 @@ class MultiPolygon extends SimpleGeometry {
/**
* @param {Array<Array<Array<import("../coordinate.js").Coordinate>>|Polygon>|Array<number>} coordinates Coordinates.
* For internal use, flat coordinats in combination with `opt_layout` and `opt_endss` are also accepted.
* For internal use, flat coordinates in combination with `opt_layout` and `opt_endss` are also accepted.
* @param {GeometryLayout=} opt_layout Layout.
* @param {Array<Array<number>>=} opt_endss Array of ends for internal use with flat coordinates.
*/