From 7383371d588f9d569a24056b13728ac7d62902db Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 11 Feb 2018 09:08:55 -0700 Subject: [PATCH 1/8] Remove private static members from MVT format --- src/ol/format/MVT.js | 158 +++++++++++++++++--------------- test/spec/ol/format/mvt.test.js | 16 +--- 2 files changed, 89 insertions(+), 85 deletions(-) diff --git a/src/ol/format/MVT.js b/src/ol/format/MVT.js index 13ea01bcd4..c4379e431e 100644 --- a/src/ol/format/MVT.js +++ b/src/ol/format/MVT.js @@ -83,81 +83,94 @@ inherits(MVT, FeatureFormat); /** - * Reader callbacks for parsing the PBF. - * @type {Object.} + * Reader callback for parsing layers. + * @param {number} tag The tag. + * @param {Object} layers The layers object. + * @param {ol.ext.PBF} pbf The PBF. */ -MVT.pbfReaders_ = { - layers: function(tag, layers, pbf) { - if (tag === 3) { - const layer = { - keys: [], - values: [], - features: [] - }; - const end = pbf.readVarint() + pbf.pos; - pbf.readFields(MVT.pbfReaders_.layer, layer, end); - layer.length = layer.features.length; - if (layer.length) { - layers[layer.name] = layer; - } - } - }, - layer: function(tag, layer, pbf) { - if (tag === 15) { - layer.version = pbf.readVarint(); - } else if (tag === 1) { - layer.name = pbf.readString(); - } else if (tag === 5) { - layer.extent = pbf.readVarint(); - } else if (tag === 2) { - layer.features.push(pbf.pos); - } else if (tag === 3) { - layer.keys.push(pbf.readString()); - } else if (tag === 4) { - let value = null; - const end = pbf.readVarint() + pbf.pos; - while (pbf.pos < end) { - tag = pbf.readVarint() >> 3; - value = tag === 1 ? pbf.readString() : - tag === 2 ? pbf.readFloat() : - tag === 3 ? pbf.readDouble() : - tag === 4 ? pbf.readVarint64() : - tag === 5 ? pbf.readVarint() : - tag === 6 ? pbf.readSVarint() : - tag === 7 ? pbf.readBoolean() : null; - } - layer.values.push(value); - } - }, - feature: function(tag, feature, pbf) { - if (tag == 1) { - feature.id = pbf.readVarint(); - } else if (tag == 2) { - const end = pbf.readVarint() + pbf.pos; - while (pbf.pos < end) { - const key = feature.layer.keys[pbf.readVarint()]; - const value = feature.layer.values[pbf.readVarint()]; - feature.properties[key] = value; - } - } else if (tag == 3) { - feature.type = pbf.readVarint(); - } else if (tag == 4) { - feature.geometry = pbf.pos; +function layersPBFReader(tag, layers, pbf) { + if (tag === 3) { + const layer = { + keys: [], + values: [], + features: [] + }; + const end = pbf.readVarint() + pbf.pos; + pbf.readFields(layerPBFReader, layer, end); + layer.length = layer.features.length; + if (layer.length) { + layers[layer.name] = layer; } } -}; +} + +/** + * Reader callback for parsing layer. + * @param {number} tag The tag. + * @param {Object} layer The layer object. + * @param {ol.ext.PBF} pbf The PBF. + */ +function layerPBFReader(tag, layer, pbf) { + if (tag === 15) { + layer.version = pbf.readVarint(); + } else if (tag === 1) { + layer.name = pbf.readString(); + } else if (tag === 5) { + layer.extent = pbf.readVarint(); + } else if (tag === 2) { + layer.features.push(pbf.pos); + } else if (tag === 3) { + layer.keys.push(pbf.readString()); + } else if (tag === 4) { + let value = null; + const end = pbf.readVarint() + pbf.pos; + while (pbf.pos < end) { + tag = pbf.readVarint() >> 3; + value = tag === 1 ? pbf.readString() : + tag === 2 ? pbf.readFloat() : + tag === 3 ? pbf.readDouble() : + tag === 4 ? pbf.readVarint64() : + tag === 5 ? pbf.readVarint() : + tag === 6 ? pbf.readSVarint() : + tag === 7 ? pbf.readBoolean() : null; + } + layer.values.push(value); + } +} + +/** + * Reader callback for parsing feature. + * @param {number} tag The tag. + * @param {Object} feature The feature object. + * @param {ol.ext.PBF} pbf The PBF. + */ +function featurePBFReader(tag, feature, pbf) { + if (tag == 1) { + feature.id = pbf.readVarint(); + } else if (tag == 2) { + const end = pbf.readVarint() + pbf.pos; + while (pbf.pos < end) { + const key = feature.layer.keys[pbf.readVarint()]; + const value = feature.layer.values[pbf.readVarint()]; + feature.properties[key] = value; + } + } else if (tag == 3) { + feature.type = pbf.readVarint(); + } else if (tag == 4) { + feature.geometry = pbf.pos; + } +} /** * Read a raw feature from the pbf offset stored at index `i` in the raw layer. * @suppress {missingProperties} - * @private * @param {ol.ext.PBF} pbf PBF. * @param {Object} layer Raw layer. * @param {number} i Index of the feature in the raw layer's `features` array. * @return {Object} Raw feature. */ -MVT.readRawFeature_ = function(pbf, layer, i) { +function readRawFeature(pbf, layer, i) { pbf.pos = layer.features[i]; const end = pbf.readVarint() + pbf.pos; @@ -166,22 +179,22 @@ MVT.readRawFeature_ = function(pbf, layer, i) { type: 0, properties: {} }; - pbf.readFields(MVT.pbfReaders_.feature, feature, end); + pbf.readFields(featurePBFReader, feature, end); return feature; -}; +} /** * Read the raw geometry from the pbf offset stored in a raw feature's geometry * proeprty. * @suppress {missingProperties} - * @private * @param {ol.ext.PBF} pbf PBF. * @param {Object} feature Raw feature. * @param {Array.} flatCoordinates Array to store flat coordinates in. * @param {Array.} ends Array to store ends in. + * @private */ -MVT.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) { +MVT.prototype.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) { pbf.pos = feature.geometry; const end = pbf.readVarint() + pbf.pos; @@ -239,13 +252,12 @@ MVT.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) { /** * @suppress {missingProperties} - * @private * @param {number} type The raw feature's geometry type * @param {number} numEnds Number of ends of the flat coordinates of the * geometry. * @return {ol.geom.GeometryType} The geometry type. */ -MVT.getGeometryType_ = function(type, numEnds) { +function getGeometryType(type, numEnds) { /** @type {ol.geom.GeometryType} */ let geometryType; if (type === 1) { @@ -261,7 +273,7 @@ MVT.getGeometryType_ = function(type, numEnds) { // outer rings of polygons. } return geometryType; -}; +} /** * @private @@ -283,9 +295,9 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) { const flatCoordinates = []; let ends = []; - MVT.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends); + this.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends); - const geometryType = MVT.getGeometryType_(type, ends.length); + const geometryType = getGeometryType(type, ends.length); if (this.featureClass_ === RenderFeature) { feature = new this.featureClass_(geometryType, flatCoordinates, ends, values, id); @@ -357,7 +369,7 @@ MVT.prototype.readFeatures = function(source, opt_options) { const layers = this.layers_; const pbf = new PBF(/** @type {ArrayBuffer} */ (source)); - const pbfLayers = pbf.readFields(MVT.pbfReaders_.layers, {}); + const pbfLayers = pbf.readFields(layersPBFReader, {}); /** @type {Array.} */ const features = []; let pbfLayer; @@ -368,7 +380,7 @@ MVT.prototype.readFeatures = function(source, opt_options) { pbfLayer = pbfLayers[name]; for (let i = 0, ii = pbfLayer.length; i < ii; ++i) { - const rawFeature = MVT.readRawFeature_(pbf, pbfLayer, i); + const rawFeature = readRawFeature(pbf, pbfLayer, i); features.push(this.createFeature_(pbf, rawFeature)); } this.extent_ = pbfLayer ? [0, 0, pbfLayer.extent, pbfLayer.extent] : null; diff --git a/test/spec/ol/format/mvt.test.js b/test/spec/ol/format/mvt.test.js index 91c71b393c..34607ebde7 100644 --- a/test/spec/ol/format/mvt.test.js +++ b/test/spec/ol/format/mvt.test.js @@ -103,13 +103,11 @@ describe('ol.format.MVT', function() { name: 'layer1' } }; - const readRawGeometry_ = MVT.readRawGeometry_; - MVT.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { + format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { flatCoordinates.push(0, 0); ends.push(2); }; const feature = format.createFeature_({}, rawFeature); - MVT.readRawGeometry_ = readRawGeometry_; const geometry = feature.getGeometry(); expect(geometry).to.be.a(Point); expect(feature.get('myGeom')).to.equal(geometry); @@ -127,14 +125,12 @@ describe('ol.format.MVT', function() { name: 'layer1' } }; - const readRawGeometry_ = MVT.readRawGeometry_; - MVT.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { + format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { flatCoordinates.push(0, 0, 3, 0, 3, 3, 3, 0, 0, 0); flatCoordinates.push(1, 1, 1, 2, 2, 2, 2, 1, 1, 1); ends.push(10, 20); }; const feature = format.createFeature_({}, rawFeature); - MVT.readRawGeometry_ = readRawGeometry_; const geometry = feature.getGeometry(); expect(geometry).to.be.a(Polygon); }); @@ -150,14 +146,12 @@ describe('ol.format.MVT', function() { name: 'layer1' } }; - const readRawGeometry_ = MVT.readRawGeometry_; - MVT.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { + format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { flatCoordinates.push(0, 0, 1, 0, 1, 1, 1, 0, 0, 0); flatCoordinates.push(1, 1, 2, 1, 2, 2, 2, 1, 1, 1); ends.push(10, 20); }; const feature = format.createFeature_({}, rawFeature); - MVT.readRawGeometry_ = readRawGeometry_; const geometry = feature.getGeometry(); expect(geometry).to.be.a(MultiPolygon); }); @@ -173,10 +167,9 @@ describe('ol.format.MVT', function() { name: 'layer1' } }; - const readRawGeometry_ = MVT.readRawGeometry_; let createdFlatCoordinates; let createdEnds; - MVT.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { + format.readRawGeometry_ = function({}, rawFeature, flatCoordinates, ends) { flatCoordinates.push(0, 0, 1, 0, 1, 1, 1, 0, 0, 0); flatCoordinates.push(1, 1, 2, 1, 2, 2, 2, 1, 1, 1); createdFlatCoordinates = flatCoordinates; @@ -184,7 +177,6 @@ describe('ol.format.MVT', function() { createdEnds = ends; }; const feature = format.createFeature_({}, rawFeature); - MVT.readRawGeometry_ = readRawGeometry_; expect(feature).to.be.a(RenderFeature); expect(feature.getType()).to.be('Polygon'); expect(feature.getFlatCoordinates()).to.equal(createdFlatCoordinates); From 434a90506d662920249e724fe8526fd9f0ec6361 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 11 Feb 2018 09:12:57 -0700 Subject: [PATCH 2/8] Remove private static members from OSMXML format --- src/ol/format/OSMXML.js | 110 ++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 60 deletions(-) diff --git a/src/ol/format/OSMXML.js b/src/ol/format/OSMXML.js index 7f6d6a5f3e..ee35408b86 100644 --- a/src/ol/format/OSMXML.js +++ b/src/ol/format/OSMXML.js @@ -36,12 +36,50 @@ const OSMXML = function() { inherits(OSMXML, XMLFeature); +/** + * @const + * @type {Array.} + */ +const NAMESPACE_URIS = [null]; + + +/** + * @const + * @type {Object.>} + */ +const WAY_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'nd': readNd, + 'tag': readTag + }); + + +/** + * @const + * @type {Object.>} + */ +const PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'node': readNode, + 'way': readWay + }); + + +/** + * @const + * @type {Object.>} + */ +const NODE_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'tag': readTag + }); + + /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private */ -OSMXML.readNode_ = function(node, objectStack) { +function readNode(node, objectStack) { const options = /** @type {olx.format.ReadOptions} */ (objectStack[0]); const state = /** @type {Object} */ (objectStack[objectStack.length - 1]); const id = node.getAttribute('id'); @@ -54,7 +92,7 @@ OSMXML.readNode_ = function(node, objectStack) { const values = pushParseAndPop({ tags: {} - }, OSMXML.NODE_PARSERS_, node, objectStack); + }, NODE_PARSERS, node, objectStack); if (!isEmpty(values.tags)) { const geometry = new Point(coordinates); transformWithOptions(geometry, false, options); @@ -63,91 +101,43 @@ OSMXML.readNode_ = function(node, objectStack) { feature.setProperties(values.tags); state.features.push(feature); } -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private */ -OSMXML.readWay_ = function(node, objectStack) { +function readWay(node, objectStack) { const id = node.getAttribute('id'); const values = pushParseAndPop({ id: id, ndrefs: [], tags: {} - }, OSMXML.WAY_PARSERS_, node, objectStack); + }, WAY_PARSERS, node, objectStack); const state = /** @type {Object} */ (objectStack[objectStack.length - 1]); state.ways.push(values); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private */ -OSMXML.readNd_ = function(node, objectStack) { +function readNd(node, objectStack) { const values = /** @type {Object} */ (objectStack[objectStack.length - 1]); values.ndrefs.push(node.getAttribute('ref')); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private */ -OSMXML.readTag_ = function(node, objectStack) { +function readTag(node, objectStack) { const values = /** @type {Object} */ (objectStack[objectStack.length - 1]); values.tags[node.getAttribute('k')] = node.getAttribute('v'); -}; - - -/** - * @const - * @private - * @type {Array.} - */ -OSMXML.NAMESPACE_URIS_ = [ - null -]; - - -/** - * @const - * @type {Object.>} - * @private - */ -OSMXML.WAY_PARSERS_ = makeStructureNS( - OSMXML.NAMESPACE_URIS_, { - 'nd': OSMXML.readNd_, - 'tag': OSMXML.readTag_ - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OSMXML.PARSERS_ = makeStructureNS( - OSMXML.NAMESPACE_URIS_, { - 'node': OSMXML.readNode_, - 'way': OSMXML.readWay_ - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OSMXML.NODE_PARSERS_ = makeStructureNS( - OSMXML.NAMESPACE_URIS_, { - 'tag': OSMXML.readTag_ - }); +} /** @@ -172,7 +162,7 @@ OSMXML.prototype.readFeaturesFromNode = function(node, opt_options) { nodes: {}, ways: [], features: [] - }, OSMXML.PARSERS_, node, [options]); + }, PARSERS, node, [options]); // parse nodes in ways for (let j = 0; j < state.ways.length; j++) { const values = /** @type {Object} */ (state.ways[j]); From 38d27534c04e0875691babfba19efd51e96791dc Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 11 Feb 2018 09:23:04 -0700 Subject: [PATCH 3/8] Remove private static members from OWS format --- src/ol/format/OWS.js | 476 ++++++++++++++++++++----------------------- 1 file changed, 223 insertions(+), 253 deletions(-) diff --git a/src/ol/format/OWS.js b/src/ol/format/OWS.js index 5b42bf601d..60c206d526 100644 --- a/src/ol/format/OWS.js +++ b/src/ol/format/OWS.js @@ -18,6 +18,187 @@ const OWS = function() { inherits(OWS, XML); +/** + * @const + * @type {Array.} + */ +const NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1']; + + +/** + * @const + * @type {Object.>} + */ +const PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'ServiceIdentification': makeObjectPropertySetter( + readServiceIdentification), + 'ServiceProvider': makeObjectPropertySetter( + readServiceProvider), + 'OperationsMetadata': makeObjectPropertySetter( + readOperationsMetadata) + }); + + +/** + * @const + * @type {Object.>} + */ +const ADDRESS_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'DeliveryPoint': makeObjectPropertySetter( + XSD.readString), + 'City': makeObjectPropertySetter(XSD.readString), + 'AdministrativeArea': makeObjectPropertySetter( + XSD.readString), + 'PostalCode': makeObjectPropertySetter(XSD.readString), + 'Country': makeObjectPropertySetter(XSD.readString), + 'ElectronicMailAddress': makeObjectPropertySetter( + XSD.readString) + }); + + +/** + * @const + * @type {Object.>} + */ +const ALLOWED_VALUES_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Value': makeObjectPropertyPusher(readValue) + }); + + +/** + * @const + * @type {Object.>} + */ +const CONSTRAINT_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'AllowedValues': makeObjectPropertySetter( + readAllowedValues) + }); + + +/** + * @const + * @type {Object.>} + */ +const CONTACT_INFO_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Phone': makeObjectPropertySetter(readPhone), + 'Address': makeObjectPropertySetter(readAddress) + }); + + +/** + * @const + * @type {Object.>} + */ +const DCP_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'HTTP': makeObjectPropertySetter(readHttp) + }); + + +/** + * @const + * @type {Object.>} + */ +const HTTP_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Get': makeObjectPropertyPusher(readGet), + 'Post': undefined // TODO + }); + + +/** + * @const + * @type {Object.>} + */ +const OPERATION_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'DCP': makeObjectPropertySetter(readDcp) + }); + + +/** + * @const + * @type {Object.>} + */ +const OPERATIONS_METADATA_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Operation': readOperation + }); + + +/** + * @const + * @type {Object.>} + */ +const PHONE_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Voice': makeObjectPropertySetter(XSD.readString), + 'Facsimile': makeObjectPropertySetter(XSD.readString) + }); + + +/** + * @const + * @type {Object.>} + */ +const REQUEST_METHOD_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Constraint': makeObjectPropertyPusher( + readConstraint) + }); + + +/** + * @const + * @type {Object.>} + */ +const SERVICE_CONTACT_PARSERS = + makeStructureNS( + NAMESPACE_URIS, { + 'IndividualName': makeObjectPropertySetter( + XSD.readString), + 'PositionName': makeObjectPropertySetter(XSD.readString), + 'ContactInfo': makeObjectPropertySetter( + readContactInfo) + }); + + +/** + * @const + * @type {Object.>} + */ +const SERVICE_IDENTIFICATION_PARSERS = + makeStructureNS( + NAMESPACE_URIS, { + 'Abstract': makeObjectPropertySetter(XSD.readString), + 'AccessConstraints': makeObjectPropertySetter(XSD.readString), + 'Fees': makeObjectPropertySetter(XSD.readString), + 'Title': makeObjectPropertySetter(XSD.readString), + 'ServiceTypeVersion': makeObjectPropertySetter( + XSD.readString), + 'ServiceType': makeObjectPropertySetter(XSD.readString) + }); + + +/** + * @const + * @type {Object.>} + */ +const SERVICE_PROVIDER_PARSERS = + makeStructureNS( + NAMESPACE_URIS, { + 'ProviderName': makeObjectPropertySetter(XSD.readString), + 'ProviderSite': makeObjectPropertySetter(XLink.readHref), + 'ServiceContact': makeObjectPropertySetter( + readServiceContact) + }); + + /** * @inheritDoc */ @@ -36,7 +217,7 @@ OWS.prototype.readFromDocument = function(doc) { */ OWS.prototype.readFromNode = function(node) { const owsObject = pushParseAndPop({}, - OWS.PARSERS_, node, []); + PARSERS, node, []); return owsObject ? owsObject : null; }; @@ -44,387 +225,176 @@ OWS.prototype.readFromNode = function(node) { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The address. */ -OWS.readAddress_ = function(node, objectStack) { +function readAddress(node, objectStack) { return pushParseAndPop({}, - OWS.ADDRESS_PARSERS_, node, objectStack); -}; + ADDRESS_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The values. */ -OWS.readAllowedValues_ = function(node, objectStack) { +function readAllowedValues(node, objectStack) { return pushParseAndPop({}, - OWS.ALLOWED_VALUES_PARSERS_, node, objectStack); -}; + ALLOWED_VALUES_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The constraint. */ -OWS.readConstraint_ = function(node, objectStack) { +function readConstraint(node, objectStack) { const name = node.getAttribute('name'); if (!name) { return undefined; } return pushParseAndPop({'name': name}, - OWS.CONSTRAINT_PARSERS_, node, + CONSTRAINT_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The contact info. */ -OWS.readContactInfo_ = function(node, objectStack) { +function readContactInfo(node, objectStack) { return pushParseAndPop({}, - OWS.CONTACT_INFO_PARSERS_, node, objectStack); -}; + CONTACT_INFO_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The DCP. */ -OWS.readDcp_ = function(node, objectStack) { +function readDcp(node, objectStack) { return pushParseAndPop({}, - OWS.DCP_PARSERS_, node, objectStack); -}; + DCP_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The GET object. */ -OWS.readGet_ = function(node, objectStack) { +function readGet(node, objectStack) { const href = XLink.readHref(node); if (!href) { return undefined; } return pushParseAndPop({'href': href}, - OWS.REQUEST_METHOD_PARSERS_, node, objectStack); -}; + REQUEST_METHOD_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The HTTP object. */ -OWS.readHttp_ = function(node, objectStack) { - return pushParseAndPop({}, OWS.HTTP_PARSERS_, +function readHttp(node, objectStack) { + return pushParseAndPop({}, HTTP_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The operation. */ -OWS.readOperation_ = function(node, objectStack) { +function readOperation(node, objectStack) { const name = node.getAttribute('name'); const value = pushParseAndPop({}, - OWS.OPERATION_PARSERS_, node, objectStack); + OPERATION_PARSERS, node, objectStack); if (!value) { return undefined; } const object = /** @type {Object} */ (objectStack[objectStack.length - 1]); object[name] = value; -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The operations metadata. */ -OWS.readOperationsMetadata_ = function(node, +function readOperationsMetadata(node, objectStack) { return pushParseAndPop({}, - OWS.OPERATIONS_METADATA_PARSERS_, node, + OPERATIONS_METADATA_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The phone. */ -OWS.readPhone_ = function(node, objectStack) { +function readPhone(node, objectStack) { return pushParseAndPop({}, - OWS.PHONE_PARSERS_, node, objectStack); -}; + PHONE_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The service identification. */ -OWS.readServiceIdentification_ = function(node, +function readServiceIdentification(node, objectStack) { return pushParseAndPop( - {}, OWS.SERVICE_IDENTIFICATION_PARSERS_, node, + {}, SERVICE_IDENTIFICATION_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The service contact. */ -OWS.readServiceContact_ = function(node, objectStack) { +function readServiceContact(node, objectStack) { return pushParseAndPop( - {}, OWS.SERVICE_CONTACT_PARSERS_, node, + {}, SERVICE_CONTACT_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} The service provider. */ -OWS.readServiceProvider_ = function(node, objectStack) { +function readServiceProvider(node, objectStack) { return pushParseAndPop( - {}, OWS.SERVICE_PROVIDER_PARSERS_, node, + {}, SERVICE_PROVIDER_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {string|undefined} The value. */ -OWS.readValue_ = function(node, objectStack) { +function readValue(node, objectStack) { return XSD.readString(node); -}; +} -/** - * @const - * @type {Array.} - * @private - */ -OWS.NAMESPACE_URIS_ = [ - null, - 'http://www.opengis.net/ows/1.1' -]; - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'ServiceIdentification': makeObjectPropertySetter( - OWS.readServiceIdentification_), - 'ServiceProvider': makeObjectPropertySetter( - OWS.readServiceProvider_), - 'OperationsMetadata': makeObjectPropertySetter( - OWS.readOperationsMetadata_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.ADDRESS_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'DeliveryPoint': makeObjectPropertySetter( - XSD.readString), - 'City': makeObjectPropertySetter(XSD.readString), - 'AdministrativeArea': makeObjectPropertySetter( - XSD.readString), - 'PostalCode': makeObjectPropertySetter(XSD.readString), - 'Country': makeObjectPropertySetter(XSD.readString), - 'ElectronicMailAddress': makeObjectPropertySetter( - XSD.readString) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.ALLOWED_VALUES_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'Value': makeObjectPropertyPusher(OWS.readValue_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.CONSTRAINT_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'AllowedValues': makeObjectPropertySetter( - OWS.readAllowedValues_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.CONTACT_INFO_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'Phone': makeObjectPropertySetter(OWS.readPhone_), - 'Address': makeObjectPropertySetter(OWS.readAddress_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.DCP_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'HTTP': makeObjectPropertySetter(OWS.readHttp_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.HTTP_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'Get': makeObjectPropertyPusher(OWS.readGet_), - 'Post': undefined // TODO - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.OPERATION_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'DCP': makeObjectPropertySetter(OWS.readDcp_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.OPERATIONS_METADATA_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'Operation': OWS.readOperation_ - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.PHONE_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'Voice': makeObjectPropertySetter(XSD.readString), - 'Facsimile': makeObjectPropertySetter(XSD.readString) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.REQUEST_METHOD_PARSERS_ = makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'Constraint': makeObjectPropertyPusher( - OWS.readConstraint_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.SERVICE_CONTACT_PARSERS_ = - makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'IndividualName': makeObjectPropertySetter( - XSD.readString), - 'PositionName': makeObjectPropertySetter(XSD.readString), - 'ContactInfo': makeObjectPropertySetter( - OWS.readContactInfo_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.SERVICE_IDENTIFICATION_PARSERS_ = - makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'Abstract': makeObjectPropertySetter(XSD.readString), - 'AccessConstraints': makeObjectPropertySetter(XSD.readString), - 'Fees': makeObjectPropertySetter(XSD.readString), - 'Title': makeObjectPropertySetter(XSD.readString), - 'ServiceTypeVersion': makeObjectPropertySetter( - XSD.readString), - 'ServiceType': makeObjectPropertySetter(XSD.readString) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -OWS.SERVICE_PROVIDER_PARSERS_ = - makeStructureNS( - OWS.NAMESPACE_URIS_, { - 'ProviderName': makeObjectPropertySetter(XSD.readString), - 'ProviderSite': makeObjectPropertySetter(XLink.readHref), - 'ServiceContact': makeObjectPropertySetter( - OWS.readServiceContact_) - }); export default OWS; From cc5b80036d1f0298c1ad97625517fbef2638d98d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 11 Feb 2018 09:24:45 -0700 Subject: [PATCH 4/8] Remove private static members from WMSGetFeatureInfo format --- src/ol/format/WMSGetFeatureInfo.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ol/format/WMSGetFeatureInfo.js b/src/ol/format/WMSGetFeatureInfo.js index 7f1b5bc6bf..79e47e3fd1 100644 --- a/src/ol/format/WMSGetFeatureInfo.js +++ b/src/ol/format/WMSGetFeatureInfo.js @@ -51,17 +51,15 @@ inherits(WMSGetFeatureInfo, XMLFeature); /** * @const * @type {string} - * @private */ -WMSGetFeatureInfo.featureIdentifier_ = '_feature'; +const featureIdentifier = '_feature'; /** * @const * @type {string} - * @private */ -WMSGetFeatureInfo.layerIdentifier_ = '_layer'; +const layerIdentifier = '_layer'; /** @@ -102,7 +100,7 @@ WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { } const context = objectStack[0]; - const toRemove = WMSGetFeatureInfo.layerIdentifier_; + const toRemove = layerIdentifier; const layerName = layer.localName.replace(toRemove, ''); if (this.layers_ && !includes(this.layers_, layerName)) { @@ -110,7 +108,7 @@ WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) { } const featureType = layerName + - WMSGetFeatureInfo.featureIdentifier_; + featureIdentifier; context['featureType'] = featureType; context['featureNS'] = this.featureNS_; From 5ee4909feb141bb28d237a43f28b59fabd625226 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 11 Feb 2018 09:36:59 -0700 Subject: [PATCH 5/8] Remove private static members from WKT format --- src/ol/format/WKT.js | 1212 +++++++++++++++++++++--------------------- 1 file changed, 600 insertions(+), 612 deletions(-) diff --git a/src/ol/format/WKT.js b/src/ol/format/WKT.js index 504e9451d2..62b90c35a9 100644 --- a/src/ol/format/WKT.js +++ b/src/ol/format/WKT.js @@ -16,6 +16,509 @@ import Point from '../geom/Point.js'; import Polygon from '../geom/Polygon.js'; import SimpleGeometry from '../geom/SimpleGeometry.js'; + +/** + * @const + * @type {string} + */ +const EMPTY = 'EMPTY'; + + +/** + * @const + * @type {string} + */ +const Z = 'Z'; + + +/** + * @const + * @type {string} + */ +const M = 'M'; + + +/** + * @const + * @type {string} + */ +const ZM = 'ZM'; + + +/** + * @const + * @enum {number} + */ +const TokenType = { + TEXT: 1, + LEFT_PAREN: 2, + RIGHT_PAREN: 3, + NUMBER: 4, + COMMA: 5, + EOF: 6 +}; + + +/** + * Class to tokenize a WKT string. + * @param {string} wkt WKT string. + * @constructor + */ +const Lexer = function(wkt) { + + /** + * @type {string} + */ + this.wkt = wkt; + + /** + * @type {number} + * @private + */ + this.index_ = -1; +}; + + +/** + * @param {string} c Character. + * @return {boolean} Whether the character is alphabetic. + * @private + */ +Lexer.prototype.isAlpha_ = function(c) { + return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'; +}; + + +/** + * @param {string} c Character. + * @param {boolean=} opt_decimal Whether the string number + * contains a dot, i.e. is a decimal number. + * @return {boolean} Whether the character is numeric. + * @private + */ +Lexer.prototype.isNumeric_ = function(c, opt_decimal) { + const decimal = opt_decimal !== undefined ? opt_decimal : false; + return c >= '0' && c <= '9' || c == '.' && !decimal; +}; + + +/** + * @param {string} c Character. + * @return {boolean} Whether the character is whitespace. + * @private + */ +Lexer.prototype.isWhiteSpace_ = function(c) { + return c == ' ' || c == '\t' || c == '\r' || c == '\n'; +}; + + +/** + * @return {string} Next string character. + * @private + */ +Lexer.prototype.nextChar_ = function() { + return this.wkt.charAt(++this.index_); +}; + + +/** + * Fetch and return the next token. + * @return {!ol.WKTToken} Next string token. + */ +Lexer.prototype.nextToken = function() { + const c = this.nextChar_(); + const token = {position: this.index_, value: c}; + + if (c == '(') { + token.type = TokenType.LEFT_PAREN; + } else if (c == ',') { + token.type = TokenType.COMMA; + } else if (c == ')') { + token.type = TokenType.RIGHT_PAREN; + } else if (this.isNumeric_(c) || c == '-') { + token.type = TokenType.NUMBER; + token.value = this.readNumber_(); + } else if (this.isAlpha_(c)) { + token.type = TokenType.TEXT; + token.value = this.readText_(); + } else if (this.isWhiteSpace_(c)) { + return this.nextToken(); + } else if (c === '') { + token.type = TokenType.EOF; + } else { + throw new Error('Unexpected character: ' + c); + } + + return token; +}; + + +/** + * @return {number} Numeric token value. + * @private + */ +Lexer.prototype.readNumber_ = function() { + let c; + const index = this.index_; + let decimal = false; + let scientificNotation = false; + do { + if (c == '.') { + decimal = true; + } else if (c == 'e' || c == 'E') { + scientificNotation = true; + } + c = this.nextChar_(); + } while ( + this.isNumeric_(c, decimal) || + // if we haven't detected a scientific number before, 'e' or 'E' + // hint that we should continue to read + !scientificNotation && (c == 'e' || c == 'E') || + // once we know that we have a scientific number, both '-' and '+' + // are allowed + scientificNotation && (c == '-' || c == '+') + ); + return parseFloat(this.wkt.substring(index, this.index_--)); +}; + + +/** + * @return {string} String token value. + * @private + */ +Lexer.prototype.readText_ = function() { + let c; + const index = this.index_; + do { + c = this.nextChar_(); + } while (this.isAlpha_(c)); + return this.wkt.substring(index, this.index_--).toUpperCase(); +}; + + +/** + * Class to parse the tokens from the WKT string. + * @param {ol.format.Lexer} lexer The lexer. + * @constructor + */ +const Parser = function(lexer) { + + /** + * @type {ol.format.Lexer} + * @private + */ + this.lexer_ = lexer; + + /** + * @type {ol.WKTToken} + * @private + */ + this.token_; + + /** + * @type {ol.geom.GeometryLayout} + * @private + */ + this.layout_ = GeometryLayout.XY; +}; + + +/** + * Fetch the next token form the lexer and replace the active token. + * @private + */ +Parser.prototype.consume_ = function() { + this.token_ = this.lexer_.nextToken(); +}; + +/** + * Tests if the given type matches the type of the current token. + * @param {ol.format.TokenType} type Token type. + * @return {boolean} Whether the token matches the given type. + */ +Parser.prototype.isTokenType = function(type) { + const isMatch = this.token_.type == type; + return isMatch; +}; + + +/** + * If the given type matches the current token, consume it. + * @param {ol.format.TokenType} type Token type. + * @return {boolean} Whether the token matches the given type. + */ +Parser.prototype.match = function(type) { + const isMatch = this.isTokenType(type); + if (isMatch) { + this.consume_(); + } + return isMatch; +}; + + +/** + * Try to parse the tokens provided by the lexer. + * @return {ol.geom.Geometry} The geometry. + */ +Parser.prototype.parse = function() { + this.consume_(); + const geometry = this.parseGeometry_(); + return geometry; +}; + + +/** + * Try to parse the dimensional info. + * @return {ol.geom.GeometryLayout} The layout. + * @private + */ +Parser.prototype.parseGeometryLayout_ = function() { + let layout = GeometryLayout.XY; + const dimToken = this.token_; + if (this.isTokenType(TokenType.TEXT)) { + const dimInfo = dimToken.value; + if (dimInfo === Z) { + layout = GeometryLayout.XYZ; + } else if (dimInfo === M) { + layout = GeometryLayout.XYM; + } else if (dimInfo === ZM) { + layout = GeometryLayout.XYZM; + } + if (layout !== GeometryLayout.XY) { + this.consume_(); + } + } + return layout; +}; + + +/** + * @return {!Array.} A collection of geometries. + * @private + */ +Parser.prototype.parseGeometryCollectionText_ = function() { + if (this.match(TokenType.LEFT_PAREN)) { + const geometries = []; + do { + geometries.push(this.parseGeometry_()); + } while (this.match(TokenType.COMMA)); + if (this.match(TokenType.RIGHT_PAREN)) { + return geometries; + } + } else if (this.isEmptyGeometry_()) { + return []; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {Array.} All values in a point. + * @private + */ +Parser.prototype.parsePointText_ = function() { + if (this.match(TokenType.LEFT_PAREN)) { + const coordinates = this.parsePoint_(); + if (this.match(TokenType.RIGHT_PAREN)) { + return coordinates; + } + } else if (this.isEmptyGeometry_()) { + return null; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {!Array.>} All points in a linestring. + * @private + */ +Parser.prototype.parseLineStringText_ = function() { + if (this.match(TokenType.LEFT_PAREN)) { + const coordinates = this.parsePointList_(); + if (this.match(TokenType.RIGHT_PAREN)) { + return coordinates; + } + } else if (this.isEmptyGeometry_()) { + return []; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {!Array.>} All points in a polygon. + * @private + */ +Parser.prototype.parsePolygonText_ = function() { + if (this.match(TokenType.LEFT_PAREN)) { + const coordinates = this.parseLineStringTextList_(); + if (this.match(TokenType.RIGHT_PAREN)) { + return coordinates; + } + } else if (this.isEmptyGeometry_()) { + return []; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {!Array.>} All points in a multipoint. + * @private + */ +Parser.prototype.parseMultiPointText_ = function() { + if (this.match(TokenType.LEFT_PAREN)) { + let coordinates; + if (this.token_.type == TokenType.LEFT_PAREN) { + coordinates = this.parsePointTextList_(); + } else { + coordinates = this.parsePointList_(); + } + if (this.match(TokenType.RIGHT_PAREN)) { + return coordinates; + } + } else if (this.isEmptyGeometry_()) { + return []; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {!Array.>} All linestring points + * in a multilinestring. + * @private + */ +Parser.prototype.parseMultiLineStringText_ = function() { + if (this.match(TokenType.LEFT_PAREN)) { + const coordinates = this.parseLineStringTextList_(); + if (this.match(TokenType.RIGHT_PAREN)) { + return coordinates; + } + } else if (this.isEmptyGeometry_()) { + return []; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {!Array.>} All polygon points in a multipolygon. + * @private + */ +Parser.prototype.parseMultiPolygonText_ = function() { + if (this.match(TokenType.LEFT_PAREN)) { + const coordinates = this.parsePolygonTextList_(); + if (this.match(TokenType.RIGHT_PAREN)) { + return coordinates; + } + } else if (this.isEmptyGeometry_()) { + return []; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {!Array.} A point. + * @private + */ +Parser.prototype.parsePoint_ = function() { + const coordinates = []; + const dimensions = this.layout_.length; + for (let i = 0; i < dimensions; ++i) { + const token = this.token_; + if (this.match(TokenType.NUMBER)) { + coordinates.push(token.value); + } else { + break; + } + } + if (coordinates.length == dimensions) { + return coordinates; + } + throw new Error(this.formatErrorMessage_()); +}; + + +/** + * @return {!Array.>} An array of points. + * @private + */ +Parser.prototype.parsePointList_ = function() { + const coordinates = [this.parsePoint_()]; + while (this.match(TokenType.COMMA)) { + coordinates.push(this.parsePoint_()); + } + return coordinates; +}; + + +/** + * @return {!Array.>} An array of points. + * @private + */ +Parser.prototype.parsePointTextList_ = function() { + const coordinates = [this.parsePointText_()]; + while (this.match(TokenType.COMMA)) { + coordinates.push(this.parsePointText_()); + } + return coordinates; +}; + + +/** + * @return {!Array.>} An array of points. + * @private + */ +Parser.prototype.parseLineStringTextList_ = function() { + const coordinates = [this.parseLineStringText_()]; + while (this.match(TokenType.COMMA)) { + coordinates.push(this.parseLineStringText_()); + } + return coordinates; +}; + + +/** + * @return {!Array.>} An array of points. + * @private + */ +Parser.prototype.parsePolygonTextList_ = function() { + const coordinates = [this.parsePolygonText_()]; + while (this.match(TokenType.COMMA)) { + coordinates.push(this.parsePolygonText_()); + } + return coordinates; +}; + + +/** + * @return {boolean} Whether the token implies an empty geometry. + * @private + */ +Parser.prototype.isEmptyGeometry_ = function() { + const isEmpty = this.isTokenType(TokenType.TEXT) && + this.token_.value == EMPTY; + if (isEmpty) { + this.consume_(); + } + return isEmpty; +}; + + +/** + * Create an error message for an unexpected token error. + * @return {string} Error message. + * @private + */ +Parser.prototype.formatErrorMessage_ = function() { + return 'Unexpected `' + this.token_.value + '` at position ' + + this.token_.position + ' in `' + this.lexer_.wkt + '`'; +}; + + /** * @classdesc * Geometry format for reading and writing data in the `WellKnownText` (WKT) @@ -45,155 +548,134 @@ const WKT = function(opt_options) { inherits(WKT, TextFeature); -/** - * @const - * @type {string} - */ -WKT.EMPTY = 'EMPTY'; - - -/** - * @const - * @type {string} - */ -WKT.Z = 'Z'; - - -/** - * @const - * @type {string} - */ -WKT.M = 'M'; - - -/** - * @const - * @type {string} - */ -WKT.ZM = 'ZM'; - - /** * @param {ol.geom.Point} geom Point geometry. * @return {string} Coordinates part of Point as WKT. - * @private */ -WKT.encodePointGeometry_ = function(geom) { +function encodePointGeometry(geom) { const coordinates = geom.getCoordinates(); if (coordinates.length === 0) { return ''; } return coordinates.join(' '); -}; +} /** * @param {ol.geom.MultiPoint} geom MultiPoint geometry. * @return {string} Coordinates part of MultiPoint as WKT. - * @private */ -WKT.encodeMultiPointGeometry_ = function(geom) { +function encodeMultiPointGeometry(geom) { const array = []; const components = geom.getPoints(); for (let i = 0, ii = components.length; i < ii; ++i) { - array.push('(' + WKT.encodePointGeometry_(components[i]) + ')'); + array.push('(' + encodePointGeometry(components[i]) + ')'); } return array.join(','); -}; +} /** * @param {ol.geom.GeometryCollection} geom GeometryCollection geometry. * @return {string} Coordinates part of GeometryCollection as WKT. - * @private */ -WKT.encodeGeometryCollectionGeometry_ = function(geom) { +function encodeGeometryCollectionGeometry(geom) { const array = []; const geoms = geom.getGeometries(); for (let i = 0, ii = geoms.length; i < ii; ++i) { - array.push(WKT.encode_(geoms[i])); + array.push(encode(geoms[i])); } return array.join(','); -}; +} /** * @param {ol.geom.LineString|ol.geom.LinearRing} geom LineString geometry. * @return {string} Coordinates part of LineString as WKT. - * @private */ -WKT.encodeLineStringGeometry_ = function(geom) { +function encodeLineStringGeometry(geom) { const coordinates = geom.getCoordinates(); const array = []; for (let i = 0, ii = coordinates.length; i < ii; ++i) { array.push(coordinates[i].join(' ')); } return array.join(','); -}; +} /** * @param {ol.geom.MultiLineString} geom MultiLineString geometry. * @return {string} Coordinates part of MultiLineString as WKT. - * @private */ -WKT.encodeMultiLineStringGeometry_ = function(geom) { +function encodeMultiLineStringGeometry(geom) { const array = []; const components = geom.getLineStrings(); for (let i = 0, ii = components.length; i < ii; ++i) { - array.push('(' + WKT.encodeLineStringGeometry_( + array.push('(' + encodeLineStringGeometry( components[i]) + ')'); } return array.join(','); -}; +} /** * @param {ol.geom.Polygon} geom Polygon geometry. * @return {string} Coordinates part of Polygon as WKT. - * @private */ -WKT.encodePolygonGeometry_ = function(geom) { +function encodePolygonGeometry(geom) { const array = []; const rings = geom.getLinearRings(); for (let i = 0, ii = rings.length; i < ii; ++i) { - array.push('(' + WKT.encodeLineStringGeometry_( + array.push('(' + encodeLineStringGeometry( rings[i]) + ')'); } return array.join(','); -}; +} /** * @param {ol.geom.MultiPolygon} geom MultiPolygon geometry. * @return {string} Coordinates part of MultiPolygon as WKT. - * @private */ -WKT.encodeMultiPolygonGeometry_ = function(geom) { +function encodeMultiPolygonGeometry(geom) { const array = []; const components = geom.getPolygons(); for (let i = 0, ii = components.length; i < ii; ++i) { - array.push('(' + WKT.encodePolygonGeometry_( + array.push('(' + encodePolygonGeometry( components[i]) + ')'); } return array.join(','); -}; +} /** * @param {ol.geom.SimpleGeometry} geom SimpleGeometry geometry. * @return {string} Potential dimensional information for WKT type. - * @private */ -WKT.encodeGeometryLayout_ = function(geom) { +function encodeGeometryLayout(geom) { const layout = geom.getLayout(); let dimInfo = ''; if (layout === GeometryLayout.XYZ || layout === GeometryLayout.XYZM) { - dimInfo += WKT.Z; + dimInfo += Z; } if (layout === GeometryLayout.XYM || layout === GeometryLayout.XYZM) { - dimInfo += WKT.M; + dimInfo += M; } return dimInfo; +} + + +/** + * @const + * @type {Object.} + */ +const GeometryEncoder = { + 'Point': encodePointGeometry, + 'LineString': encodeLineStringGeometry, + 'Polygon': encodePolygonGeometry, + 'MultiPoint': encodeMultiPointGeometry, + 'MultiLineString': encodeMultiLineStringGeometry, + 'MultiPolygon': encodeMultiPolygonGeometry, + 'GeometryCollection': encodeGeometryCollectionGeometry }; @@ -201,40 +683,23 @@ WKT.encodeGeometryLayout_ = function(geom) { * Encode a geometry as WKT. * @param {ol.geom.Geometry} geom The geometry to encode. * @return {string} WKT string for the geometry. - * @private */ -WKT.encode_ = function(geom) { +function encode(geom) { let type = geom.getType(); - const geometryEncoder = WKT.GeometryEncoder_[type]; + const geometryEncoder = GeometryEncoder[type]; const enc = geometryEncoder(geom); type = type.toUpperCase(); if (geom instanceof SimpleGeometry) { - const dimInfo = WKT.encodeGeometryLayout_(geom); + const dimInfo = encodeGeometryLayout(geom); if (dimInfo.length > 0) { type += ' ' + dimInfo; } } if (enc.length === 0) { - return type + ' ' + WKT.EMPTY; + return type + ' ' + EMPTY; } return type + '(' + enc + ')'; -}; - - -/** - * @const - * @type {Object.} - * @private - */ -WKT.GeometryEncoder_ = { - 'Point': WKT.encodePointGeometry_, - 'LineString': WKT.encodeLineStringGeometry_, - 'Polygon': WKT.encodePolygonGeometry_, - 'MultiPoint': WKT.encodeMultiPointGeometry_, - 'MultiLineString': WKT.encodeMultiLineStringGeometry_, - 'MultiPolygon': WKT.encodeMultiPolygonGeometry_, - 'GeometryCollection': WKT.encodeGeometryCollectionGeometry_ -}; +} /** @@ -245,8 +710,8 @@ WKT.GeometryEncoder_ = { * @private */ WKT.prototype.parse_ = function(wkt) { - const lexer = new WKT.Lexer(wkt); - const parser = new WKT.Parser(lexer); + const lexer = new Lexer(wkt); + const parser = new Parser(lexer); return parser.parse(); }; @@ -340,6 +805,58 @@ WKT.prototype.readGeometryFromText = function(text, opt_options) { }; +/** + * @enum {function (new:ol.geom.Geometry, Array, ol.geom.GeometryLayout)} + */ +const GeometryConstructor = { + 'POINT': Point, + 'LINESTRING': LineString, + 'POLYGON': Polygon, + 'MULTIPOINT': MultiPoint, + 'MULTILINESTRING': MultiLineString, + 'MULTIPOLYGON': MultiPolygon +}; + + +/** + * @enum {(function(): Array)} + */ +const GeometryParser = { + 'POINT': Parser.prototype.parsePointText_, + 'LINESTRING': Parser.prototype.parseLineStringText_, + 'POLYGON': Parser.prototype.parsePolygonText_, + 'MULTIPOINT': Parser.prototype.parseMultiPointText_, + 'MULTILINESTRING': Parser.prototype.parseMultiLineStringText_, + 'MULTIPOLYGON': Parser.prototype.parseMultiPolygonText_ +}; + + +/** + * @return {!ol.geom.Geometry} The geometry. + * @private + */ +Parser.prototype.parseGeometry_ = function() { + const token = this.token_; + if (this.match(TokenType.TEXT)) { + const geomType = token.value; + this.layout_ = this.parseGeometryLayout_(); + if (geomType == GeometryType.GEOMETRY_COLLECTION.toUpperCase()) { + const geometries = this.parseGeometryCollectionText_(); + return new GeometryCollection(geometries); + } else { + const parser = GeometryParser[geomType]; + const ctor = GeometryConstructor[geomType]; + if (!parser || !ctor) { + throw new Error('Invalid geometry type: ' + geomType); + } + const coordinates = parser.call(this); + return new ctor(coordinates, this.layout_); + } + } + throw new Error(this.formatErrorMessage_()); +}; + + /** * Encode a feature as a WKT string. * @@ -408,538 +925,9 @@ WKT.prototype.writeGeometry; * @inheritDoc */ WKT.prototype.writeGeometryText = function(geometry, opt_options) { - return WKT.encode_(/** @type {ol.geom.Geometry} */ ( + return encode(/** @type {ol.geom.Geometry} */ ( transformWithOptions(geometry, true, opt_options))); }; -/** - * @const - * @enum {number} - * @private - */ -WKT.TokenType_ = { - TEXT: 1, - LEFT_PAREN: 2, - RIGHT_PAREN: 3, - NUMBER: 4, - COMMA: 5, - EOF: 6 -}; - - -/** - * Class to tokenize a WKT string. - * @param {string} wkt WKT string. - * @constructor - * @protected - */ -WKT.Lexer = function(wkt) { - - /** - * @type {string} - */ - this.wkt = wkt; - - /** - * @type {number} - * @private - */ - this.index_ = -1; -}; - - -/** - * @param {string} c Character. - * @return {boolean} Whether the character is alphabetic. - * @private - */ -WKT.Lexer.prototype.isAlpha_ = function(c) { - return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'; -}; - - -/** - * @param {string} c Character. - * @param {boolean=} opt_decimal Whether the string number - * contains a dot, i.e. is a decimal number. - * @return {boolean} Whether the character is numeric. - * @private - */ -WKT.Lexer.prototype.isNumeric_ = function(c, opt_decimal) { - const decimal = opt_decimal !== undefined ? opt_decimal : false; - return c >= '0' && c <= '9' || c == '.' && !decimal; -}; - - -/** - * @param {string} c Character. - * @return {boolean} Whether the character is whitespace. - * @private - */ -WKT.Lexer.prototype.isWhiteSpace_ = function(c) { - return c == ' ' || c == '\t' || c == '\r' || c == '\n'; -}; - - -/** - * @return {string} Next string character. - * @private - */ -WKT.Lexer.prototype.nextChar_ = function() { - return this.wkt.charAt(++this.index_); -}; - - -/** - * Fetch and return the next token. - * @return {!ol.WKTToken} Next string token. - */ -WKT.Lexer.prototype.nextToken = function() { - const c = this.nextChar_(); - const token = {position: this.index_, value: c}; - - if (c == '(') { - token.type = WKT.TokenType_.LEFT_PAREN; - } else if (c == ',') { - token.type = WKT.TokenType_.COMMA; - } else if (c == ')') { - token.type = WKT.TokenType_.RIGHT_PAREN; - } else if (this.isNumeric_(c) || c == '-') { - token.type = WKT.TokenType_.NUMBER; - token.value = this.readNumber_(); - } else if (this.isAlpha_(c)) { - token.type = WKT.TokenType_.TEXT; - token.value = this.readText_(); - } else if (this.isWhiteSpace_(c)) { - return this.nextToken(); - } else if (c === '') { - token.type = WKT.TokenType_.EOF; - } else { - throw new Error('Unexpected character: ' + c); - } - - return token; -}; - - -/** - * @return {number} Numeric token value. - * @private - */ -WKT.Lexer.prototype.readNumber_ = function() { - let c; - const index = this.index_; - let decimal = false; - let scientificNotation = false; - do { - if (c == '.') { - decimal = true; - } else if (c == 'e' || c == 'E') { - scientificNotation = true; - } - c = this.nextChar_(); - } while ( - this.isNumeric_(c, decimal) || - // if we haven't detected a scientific number before, 'e' or 'E' - // hint that we should continue to read - !scientificNotation && (c == 'e' || c == 'E') || - // once we know that we have a scientific number, both '-' and '+' - // are allowed - scientificNotation && (c == '-' || c == '+') - ); - return parseFloat(this.wkt.substring(index, this.index_--)); -}; - - -/** - * @return {string} String token value. - * @private - */ -WKT.Lexer.prototype.readText_ = function() { - let c; - const index = this.index_; - do { - c = this.nextChar_(); - } while (this.isAlpha_(c)); - return this.wkt.substring(index, this.index_--).toUpperCase(); -}; - - -/** - * Class to parse the tokens from the WKT string. - * @param {ol.format.WKT.Lexer} lexer The lexer. - * @constructor - * @protected - */ -WKT.Parser = function(lexer) { - - /** - * @type {ol.format.WKT.Lexer} - * @private - */ - this.lexer_ = lexer; - - /** - * @type {ol.WKTToken} - * @private - */ - this.token_; - - /** - * @type {ol.geom.GeometryLayout} - * @private - */ - this.layout_ = GeometryLayout.XY; -}; - - -/** - * Fetch the next token form the lexer and replace the active token. - * @private - */ -WKT.Parser.prototype.consume_ = function() { - this.token_ = this.lexer_.nextToken(); -}; - -/** - * Tests if the given type matches the type of the current token. - * @param {ol.format.WKT.TokenType_} type Token type. - * @return {boolean} Whether the token matches the given type. - */ -WKT.Parser.prototype.isTokenType = function(type) { - const isMatch = this.token_.type == type; - return isMatch; -}; - - -/** - * If the given type matches the current token, consume it. - * @param {ol.format.WKT.TokenType_} type Token type. - * @return {boolean} Whether the token matches the given type. - */ -WKT.Parser.prototype.match = function(type) { - const isMatch = this.isTokenType(type); - if (isMatch) { - this.consume_(); - } - return isMatch; -}; - - -/** - * Try to parse the tokens provided by the lexer. - * @return {ol.geom.Geometry} The geometry. - */ -WKT.Parser.prototype.parse = function() { - this.consume_(); - const geometry = this.parseGeometry_(); - return geometry; -}; - - -/** - * Try to parse the dimensional info. - * @return {ol.geom.GeometryLayout} The layout. - * @private - */ -WKT.Parser.prototype.parseGeometryLayout_ = function() { - let layout = GeometryLayout.XY; - const dimToken = this.token_; - if (this.isTokenType(WKT.TokenType_.TEXT)) { - const dimInfo = dimToken.value; - if (dimInfo === WKT.Z) { - layout = GeometryLayout.XYZ; - } else if (dimInfo === WKT.M) { - layout = GeometryLayout.XYM; - } else if (dimInfo === WKT.ZM) { - layout = GeometryLayout.XYZM; - } - if (layout !== GeometryLayout.XY) { - this.consume_(); - } - } - return layout; -}; - - -/** - * @return {!ol.geom.Geometry} The geometry. - * @private - */ -WKT.Parser.prototype.parseGeometry_ = function() { - const token = this.token_; - if (this.match(WKT.TokenType_.TEXT)) { - const geomType = token.value; - this.layout_ = this.parseGeometryLayout_(); - if (geomType == GeometryType.GEOMETRY_COLLECTION.toUpperCase()) { - const geometries = this.parseGeometryCollectionText_(); - return new GeometryCollection(geometries); - } else { - const parser = WKT.Parser.GeometryParser_[geomType]; - const ctor = WKT.Parser.GeometryConstructor_[geomType]; - if (!parser || !ctor) { - throw new Error('Invalid geometry type: ' + geomType); - } - const coordinates = parser.call(this); - return new ctor(coordinates, this.layout_); - } - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.} A collection of geometries. - * @private - */ -WKT.Parser.prototype.parseGeometryCollectionText_ = function() { - if (this.match(WKT.TokenType_.LEFT_PAREN)) { - const geometries = []; - do { - geometries.push(this.parseGeometry_()); - } while (this.match(WKT.TokenType_.COMMA)); - if (this.match(WKT.TokenType_.RIGHT_PAREN)) { - return geometries; - } - } else if (this.isEmptyGeometry_()) { - return []; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {Array.} All values in a point. - * @private - */ -WKT.Parser.prototype.parsePointText_ = function() { - if (this.match(WKT.TokenType_.LEFT_PAREN)) { - const coordinates = this.parsePoint_(); - if (this.match(WKT.TokenType_.RIGHT_PAREN)) { - return coordinates; - } - } else if (this.isEmptyGeometry_()) { - return null; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.>} All points in a linestring. - * @private - */ -WKT.Parser.prototype.parseLineStringText_ = function() { - if (this.match(WKT.TokenType_.LEFT_PAREN)) { - const coordinates = this.parsePointList_(); - if (this.match(WKT.TokenType_.RIGHT_PAREN)) { - return coordinates; - } - } else if (this.isEmptyGeometry_()) { - return []; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.>} All points in a polygon. - * @private - */ -WKT.Parser.prototype.parsePolygonText_ = function() { - if (this.match(WKT.TokenType_.LEFT_PAREN)) { - const coordinates = this.parseLineStringTextList_(); - if (this.match(WKT.TokenType_.RIGHT_PAREN)) { - return coordinates; - } - } else if (this.isEmptyGeometry_()) { - return []; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.>} All points in a multipoint. - * @private - */ -WKT.Parser.prototype.parseMultiPointText_ = function() { - if (this.match(WKT.TokenType_.LEFT_PAREN)) { - let coordinates; - if (this.token_.type == WKT.TokenType_.LEFT_PAREN) { - coordinates = this.parsePointTextList_(); - } else { - coordinates = this.parsePointList_(); - } - if (this.match(WKT.TokenType_.RIGHT_PAREN)) { - return coordinates; - } - } else if (this.isEmptyGeometry_()) { - return []; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.>} All linestring points - * in a multilinestring. - * @private - */ -WKT.Parser.prototype.parseMultiLineStringText_ = function() { - if (this.match(WKT.TokenType_.LEFT_PAREN)) { - const coordinates = this.parseLineStringTextList_(); - if (this.match(WKT.TokenType_.RIGHT_PAREN)) { - return coordinates; - } - } else if (this.isEmptyGeometry_()) { - return []; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.>} All polygon points in a multipolygon. - * @private - */ -WKT.Parser.prototype.parseMultiPolygonText_ = function() { - if (this.match(WKT.TokenType_.LEFT_PAREN)) { - const coordinates = this.parsePolygonTextList_(); - if (this.match(WKT.TokenType_.RIGHT_PAREN)) { - return coordinates; - } - } else if (this.isEmptyGeometry_()) { - return []; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.} A point. - * @private - */ -WKT.Parser.prototype.parsePoint_ = function() { - const coordinates = []; - const dimensions = this.layout_.length; - for (let i = 0; i < dimensions; ++i) { - const token = this.token_; - if (this.match(WKT.TokenType_.NUMBER)) { - coordinates.push(token.value); - } else { - break; - } - } - if (coordinates.length == dimensions) { - return coordinates; - } - throw new Error(this.formatErrorMessage_()); -}; - - -/** - * @return {!Array.>} An array of points. - * @private - */ -WKT.Parser.prototype.parsePointList_ = function() { - const coordinates = [this.parsePoint_()]; - while (this.match(WKT.TokenType_.COMMA)) { - coordinates.push(this.parsePoint_()); - } - return coordinates; -}; - - -/** - * @return {!Array.>} An array of points. - * @private - */ -WKT.Parser.prototype.parsePointTextList_ = function() { - const coordinates = [this.parsePointText_()]; - while (this.match(WKT.TokenType_.COMMA)) { - coordinates.push(this.parsePointText_()); - } - return coordinates; -}; - - -/** - * @return {!Array.>} An array of points. - * @private - */ -WKT.Parser.prototype.parseLineStringTextList_ = function() { - const coordinates = [this.parseLineStringText_()]; - while (this.match(WKT.TokenType_.COMMA)) { - coordinates.push(this.parseLineStringText_()); - } - return coordinates; -}; - - -/** - * @return {!Array.>} An array of points. - * @private - */ -WKT.Parser.prototype.parsePolygonTextList_ = function() { - const coordinates = [this.parsePolygonText_()]; - while (this.match(WKT.TokenType_.COMMA)) { - coordinates.push(this.parsePolygonText_()); - } - return coordinates; -}; - - -/** - * @return {boolean} Whether the token implies an empty geometry. - * @private - */ -WKT.Parser.prototype.isEmptyGeometry_ = function() { - const isEmpty = this.isTokenType(WKT.TokenType_.TEXT) && - this.token_.value == WKT.EMPTY; - if (isEmpty) { - this.consume_(); - } - return isEmpty; -}; - - -/** - * Create an error message for an unexpected token error. - * @return {string} Error message. - * @private - */ -WKT.Parser.prototype.formatErrorMessage_ = function() { - return 'Unexpected `' + this.token_.value + '` at position ' + - this.token_.position + ' in `' + this.lexer_.wkt + '`'; -}; - - -/** - * @enum {function (new:ol.geom.Geometry, Array, ol.geom.GeometryLayout)} - * @private - */ -WKT.Parser.GeometryConstructor_ = { - 'POINT': Point, - 'LINESTRING': LineString, - 'POLYGON': Polygon, - 'MULTIPOINT': MultiPoint, - 'MULTILINESTRING': MultiLineString, - 'MULTIPOLYGON': MultiPolygon -}; - - -/** - * @enum {(function(): Array)} - * @private - */ -WKT.Parser.GeometryParser_ = { - 'POINT': WKT.Parser.prototype.parsePointText_, - 'LINESTRING': WKT.Parser.prototype.parseLineStringText_, - 'POLYGON': WKT.Parser.prototype.parsePolygonText_, - 'MULTIPOINT': WKT.Parser.prototype.parseMultiPointText_, - 'MULTILINESTRING': WKT.Parser.prototype.parseMultiLineStringText_, - 'MULTIPOLYGON': WKT.Parser.prototype.parseMultiPolygonText_ -}; export default WKT; From 70648165a86659638d69e586850b7e8d3636aa8e Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 11 Feb 2018 10:51:03 -0700 Subject: [PATCH 6/8] Remove private static members from WFS format --- src/ol/format/WFS.js | 312 +++++++++++++++++++------------------------ 1 file changed, 138 insertions(+), 174 deletions(-) diff --git a/src/ol/format/WFS.js b/src/ol/format/WFS.js index 438dc1da20..7afa513ac0 100644 --- a/src/ol/format/WFS.js +++ b/src/ol/format/WFS.js @@ -234,9 +234,8 @@ WFS.prototype.readFeatureCollectionMetadataFromDocument = function(doc) { /** * @const * @type {Object.>} - * @private */ -WFS.FEATURE_COLLECTION_PARSERS_ = { +const FEATURE_COLLECTION_PARSERS = { 'http://www.opengis.net/gml': { 'boundedBy': makeObjectPropertySetter( GMLBase.prototype.readGeometryElement, 'bounds') @@ -256,16 +255,15 @@ WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) { result['numberOfFeatures'] = value; return pushParseAndPop( /** @type {ol.WFSFeatureCollectionMetadata} */ (result), - WFS.FEATURE_COLLECTION_PARSERS_, node, [], this.gmlFormat_); + FEATURE_COLLECTION_PARSERS, node, [], this.gmlFormat_); }; /** * @const * @type {Object.>} - * @private */ -WFS.TRANSACTION_SUMMARY_PARSERS_ = { +const TRANSACTION_SUMMARY_PARSERS = { 'http://www.opengis.net/wfs': { 'totalInserted': makeObjectPropertySetter( XSD.readNonNegativeInteger), @@ -281,20 +279,18 @@ WFS.TRANSACTION_SUMMARY_PARSERS_ = { * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Transaction Summary. - * @private */ -WFS.readTransactionSummary_ = function(node, objectStack) { +function readTransactionSummary(node, objectStack) { return pushParseAndPop( - {}, WFS.TRANSACTION_SUMMARY_PARSERS_, node, objectStack); -}; + {}, TRANSACTION_SUMMARY_PARSERS, node, objectStack); +} /** * @const * @type {Object.>} - * @private */ -WFS.OGC_FID_PARSERS_ = { +const OGC_FID_PARSERS = { 'http://www.opengis.net/ogc': { 'FeatureId': makeArrayPusher(function(node, objectStack) { return node.getAttribute('fid'); @@ -306,21 +302,19 @@ WFS.OGC_FID_PARSERS_ = { /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private */ -WFS.fidParser_ = function(node, objectStack) { - parseNode(WFS.OGC_FID_PARSERS_, node, objectStack); -}; +function fidParser(node, objectStack) { + parseNode(OGC_FID_PARSERS, node, objectStack); +} /** * @const * @type {Object.>} - * @private */ -WFS.INSERT_RESULTS_PARSERS_ = { +const INSERT_RESULTS_PARSERS = { 'http://www.opengis.net/wfs': { - 'Feature': WFS.fidParser_ + 'Feature': fidParser } }; @@ -329,25 +323,23 @@ WFS.INSERT_RESULTS_PARSERS_ = { * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Array.|undefined} Insert results. - * @private */ -WFS.readInsertResults_ = function(node, objectStack) { +function readInsertResults(node, objectStack) { return pushParseAndPop( - [], WFS.INSERT_RESULTS_PARSERS_, node, objectStack); -}; + [], INSERT_RESULTS_PARSERS, node, objectStack); +} /** * @const * @type {Object.>} - * @private */ -WFS.TRANSACTION_RESPONSE_PARSERS_ = { +const TRANSACTION_RESPONSE_PARSERS = { 'http://www.opengis.net/wfs': { 'TransactionSummary': makeObjectPropertySetter( - WFS.readTransactionSummary_, 'transactionSummary'), + readTransactionSummary, 'transactionSummary'), 'InsertResults': makeObjectPropertySetter( - WFS.readInsertResults_, 'insertIds') + readInsertResults, 'insertIds') } }; @@ -373,15 +365,14 @@ WFS.prototype.readTransactionResponseFromDocument = function(doc) { WFS.prototype.readTransactionResponseFromNode = function(node) { return pushParseAndPop( /** @type {ol.WFSTransactionResponse} */({}), - WFS.TRANSACTION_RESPONSE_PARSERS_, node, []); + TRANSACTION_RESPONSE_PARSERS, node, []); }; /** * @type {Object.>} - * @private */ -WFS.QUERY_SERIALIZERS_ = { +const QUERY_SERIALIZERS = { 'http://www.opengis.net/wfs': { 'PropertyName': makeChildAppender(XSD.writeStringTextNode) } @@ -392,9 +383,8 @@ WFS.QUERY_SERIALIZERS_ = { * @param {Node} node Node. * @param {ol.Feature} feature Feature. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeFeature_ = function(node, feature, objectStack) { +function writeFeature(node, feature, objectStack) { const context = objectStack[objectStack.length - 1]; const featureType = context['featureType']; const featureNS = context['featureNS']; @@ -406,31 +396,29 @@ WFS.writeFeature_ = function(node, feature, objectStack) { } else { GML3.prototype.writeFeatureElement(child, feature, objectStack); } -}; +} /** * @param {Node} node Node. * @param {number|string} fid Feature identifier. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeOgcFidFilter_ = function(node, fid, objectStack) { +function writeOgcFidFilter(node, fid, objectStack) { const filter = createElementNS(WFS.OGCNS, 'Filter'); const child = createElementNS(WFS.OGCNS, 'FeatureId'); filter.appendChild(child); child.setAttribute('fid', fid); node.appendChild(filter); -}; +} /** * @param {string|undefined} featurePrefix The prefix of the feature. * @param {string} featureType The type of the feature. * @returns {string} The value of the typeName property. - * @private */ -WFS.getTypeName_ = function(featurePrefix, featureType) { +function getTypeName(featurePrefix, featureType) { featurePrefix = featurePrefix ? featurePrefix : WFS.FEATURE_PREFIX; const prefix = featurePrefix + ':'; @@ -440,28 +428,41 @@ WFS.getTypeName_ = function(featurePrefix, featureType) { } else { return prefix + featureType; } -}; +} /** * @param {Node} node Node. * @param {ol.Feature} feature Feature. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeDelete_ = function(node, feature, objectStack) { +function writeDelete(node, feature, objectStack) { const context = objectStack[objectStack.length - 1]; assert(feature.getId() !== undefined, 26); // Features must have an id set const featureType = context['featureType']; const featurePrefix = context['featurePrefix']; const featureNS = context['featureNS']; - const typeName = WFS.getTypeName_(featurePrefix, featureType); + const typeName = getTypeName(featurePrefix, featureType); node.setAttribute('typeName', typeName); setAttributeNS(node, WFS.XMLNS, 'xmlns:' + featurePrefix, featureNS); const fid = feature.getId(); if (fid !== undefined) { - WFS.writeOgcFidFilter_(node, fid, objectStack); + writeOgcFidFilter(node, fid, objectStack); + } +} + + +/** + * @type {Object.>} + */ +const TRANSACTION_SERIALIZERS = { + 'http://www.opengis.net/wfs': { + 'Insert': makeChildAppender(writeFeature), + 'Update': makeChildAppender(writeUpdate), + 'Delete': makeChildAppender(writeDelete), + 'Property': makeChildAppender(writeProperty), + 'Native': makeChildAppender(writeNative) } }; @@ -470,15 +471,14 @@ WFS.writeDelete_ = function(node, feature, objectStack) { * @param {Node} node Node. * @param {ol.Feature} feature Feature. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeUpdate_ = function(node, feature, objectStack) { +function writeUpdate(node, feature, objectStack) { const context = objectStack[objectStack.length - 1]; assert(feature.getId() !== undefined, 27); // Features must have an id set const featureType = context['featureType']; const featurePrefix = context['featurePrefix']; const featureNS = context['featureNS']; - const typeName = WFS.getTypeName_(featurePrefix, featureType); + const typeName = getTypeName(featurePrefix, featureType); const geometryName = feature.getGeometryName(); node.setAttribute('typeName', typeName); setAttributeNS(node, WFS.XMLNS, 'xmlns:' + featurePrefix, @@ -500,21 +500,20 @@ WFS.writeUpdate_ = function(node, feature, objectStack) { pushSerializeAndPop(/** @type {ol.XmlNodeStackItem} */ ( {'gmlVersion': context['gmlVersion'], node: node, 'hasZ': context['hasZ'], 'srsName': context['srsName']}), - WFS.TRANSACTION_SERIALIZERS_, + TRANSACTION_SERIALIZERS, makeSimpleNodeFactory('Property'), values, objectStack); - WFS.writeOgcFidFilter_(node, fid, objectStack); + writeOgcFidFilter(node, fid, objectStack); } -}; +} /** * @param {Node} node Node. * @param {Object} pair Property name and value. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeProperty_ = function(node, pair, objectStack) { +function writeProperty(node, pair, objectStack) { const name = createElementNS(WFS.WFSNS, 'Name'); const context = objectStack[objectStack.length - 1]; const gmlVersion = context['gmlVersion']; @@ -535,7 +534,7 @@ WFS.writeProperty_ = function(node, pair, objectStack) { XSD.writeStringTextNode(value, pair.value); } } -}; +} /** @@ -543,9 +542,8 @@ WFS.writeProperty_ = function(node, pair, objectStack) { * @param {{vendorId: string, safeToIgnore: boolean, value: string}} * nativeElement The native element. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeNative_ = function(node, nativeElement, objectStack) { +function writeNative(node, nativeElement, objectStack) { if (nativeElement.vendorId) { node.setAttribute('vendorId', nativeElement.vendorId); } @@ -555,20 +553,34 @@ WFS.writeNative_ = function(node, nativeElement, objectStack) { if (nativeElement.value !== undefined) { XSD.writeStringTextNode(node, nativeElement.value); } -}; +} /** * @type {Object.>} - * @private */ -WFS.TRANSACTION_SERIALIZERS_ = { +const GETFEATURE_SERIALIZERS = { 'http://www.opengis.net/wfs': { - 'Insert': makeChildAppender(WFS.writeFeature_), - 'Update': makeChildAppender(WFS.writeUpdate_), - 'Delete': makeChildAppender(WFS.writeDelete_), - 'Property': makeChildAppender(WFS.writeProperty_), - 'Native': makeChildAppender(WFS.writeNative_) + 'Query': makeChildAppender(writeQuery) + }, + 'http://www.opengis.net/ogc': { + 'During': makeChildAppender(writeDuringFilter), + 'And': makeChildAppender(writeLogicalFilter), + 'Or': makeChildAppender(writeLogicalFilter), + 'Not': makeChildAppender(writeNotFilter), + 'BBOX': makeChildAppender(writeBboxFilter), + 'Contains': makeChildAppender(writeContainsFilter), + 'Intersects': makeChildAppender(writeIntersectsFilter), + 'Within': makeChildAppender(writeWithinFilter), + 'PropertyIsEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsNotEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsLessThan': makeChildAppender(writeComparisonFilter), + 'PropertyIsLessThanOrEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsGreaterThan': makeChildAppender(writeComparisonFilter), + 'PropertyIsGreaterThanOrEqualTo': makeChildAppender(writeComparisonFilter), + 'PropertyIsNull': makeChildAppender(writeIsNullFilter), + 'PropertyIsBetween': makeChildAppender(writeIsBetweenFilter), + 'PropertyIsLike': makeChildAppender(writeIsLikeFilter) } }; @@ -577,9 +589,8 @@ WFS.TRANSACTION_SERIALIZERS_ = { * @param {Node} node Node. * @param {string} featureType Feature type. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeQuery_ = function(node, featureType, objectStack) { +function writeQuery(node, featureType, objectStack) { const context = /** @type {Object} */ (objectStack[objectStack.length - 1]); const featurePrefix = context['featurePrefix']; const featureNS = context['featureNS']; @@ -588,7 +599,7 @@ WFS.writeQuery_ = function(node, featureType, objectStack) { let typeName; // If feature prefix is not defined, we must not use the default prefix. if (featurePrefix) { - typeName = WFS.getTypeName_(featurePrefix, featureType); + typeName = getTypeName(featurePrefix, featureType); } else { typeName = featureType; } @@ -603,101 +614,95 @@ WFS.writeQuery_ = function(node, featureType, objectStack) { const item = /** @type {ol.XmlNodeStackItem} */ (assign({}, context)); item.node = node; pushSerializeAndPop(item, - WFS.QUERY_SERIALIZERS_, + QUERY_SERIALIZERS, makeSimpleNodeFactory('PropertyName'), propertyNames, objectStack); const filter = context['filter']; if (filter) { const child = createElementNS(WFS.OGCNS, 'Filter'); node.appendChild(child); - WFS.writeFilterCondition_(child, filter, objectStack); + writeFilterCondition(child, filter, objectStack); } -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.Filter} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeFilterCondition_ = function(node, filter, objectStack) { +function writeFilterCondition(node, filter, objectStack) { /** @type {ol.XmlNodeStackItem} */ const item = {node: node}; pushSerializeAndPop(item, - WFS.GETFEATURE_SERIALIZERS_, + GETFEATURE_SERIALIZERS, makeSimpleNodeFactory(filter.getTagName()), [filter], objectStack); -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.Bbox} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeBboxFilter_ = function(node, filter, objectStack) { +function writeBboxFilter(node, filter, objectStack) { const context = objectStack[objectStack.length - 1]; context['srsName'] = filter.srsName; - WFS.writeOgcPropertyName_(node, filter.geometryName); + writeOgcPropertyName(node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.extent, objectStack); -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.Contains} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeContainsFilter_ = function(node, filter, objectStack) { +function writeContainsFilter(node, filter, objectStack) { const context = objectStack[objectStack.length - 1]; context['srsName'] = filter.srsName; - WFS.writeOgcPropertyName_(node, filter.geometryName); + writeOgcPropertyName(node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.Intersects} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeIntersectsFilter_ = function(node, filter, objectStack) { +function writeIntersectsFilter(node, filter, objectStack) { const context = objectStack[objectStack.length - 1]; context['srsName'] = filter.srsName; - WFS.writeOgcPropertyName_(node, filter.geometryName); + writeOgcPropertyName(node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.Within} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeWithinFilter_ = function(node, filter, objectStack) { +function writeWithinFilter(node, filter, objectStack) { const context = objectStack[objectStack.length - 1]; context['srsName'] = filter.srsName; - WFS.writeOgcPropertyName_(node, filter.geometryName); + writeOgcPropertyName(node, filter.geometryName); GML3.prototype.writeGeometryElement(node, filter.geometry, objectStack); -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.During} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeDuringFilter_ = function(node, filter, objectStack) { +function writeDuringFilter(node, filter, objectStack) { const valueReference = createElementNS(WFS.FESNS, 'ValueReference'); XSD.writeStringTextNode(valueReference, filter.propertyName); @@ -709,190 +714,150 @@ WFS.writeDuringFilter_ = function(node, filter, objectStack) { const begin = createElementNS(GMLBase.GMLNS, 'begin'); timePeriod.appendChild(begin); - WFS.writeTimeInstant_(begin, filter.begin); + writeTimeInstant(begin, filter.begin); const end = createElementNS(GMLBase.GMLNS, 'end'); timePeriod.appendChild(end); - WFS.writeTimeInstant_(end, filter.end); -}; + writeTimeInstant(end, filter.end); +} /** * @param {Node} node Node. * @param {ol.format.filter.LogicalNary} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeLogicalFilter_ = function(node, filter, objectStack) { +function writeLogicalFilter(node, filter, objectStack) { /** @type {ol.XmlNodeStackItem} */ const item = {node: node}; const conditions = filter.conditions; for (let i = 0, ii = conditions.length; i < ii; ++i) { const condition = conditions[i]; pushSerializeAndPop(item, - WFS.GETFEATURE_SERIALIZERS_, + GETFEATURE_SERIALIZERS, makeSimpleNodeFactory(condition.getTagName()), [condition], objectStack); } -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.Not} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeNotFilter_ = function(node, filter, objectStack) { +function writeNotFilter(node, filter, objectStack) { /** @type {ol.XmlNodeStackItem} */ const item = {node: node}; const condition = filter.condition; pushSerializeAndPop(item, - WFS.GETFEATURE_SERIALIZERS_, + GETFEATURE_SERIALIZERS, makeSimpleNodeFactory(condition.getTagName()), [condition], objectStack); -}; +} /** * @param {Node} node Node. * @param {ol.format.filter.ComparisonBinary} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeComparisonFilter_ = function(node, filter, objectStack) { +function writeComparisonFilter(node, filter, objectStack) { if (filter.matchCase !== undefined) { node.setAttribute('matchCase', filter.matchCase.toString()); } - WFS.writeOgcPropertyName_(node, filter.propertyName); - WFS.writeOgcLiteral_(node, '' + filter.expression); -}; + writeOgcPropertyName(node, filter.propertyName); + writeOgcLiteral(node, '' + filter.expression); +} /** * @param {Node} node Node. * @param {ol.format.filter.IsNull} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeIsNullFilter_ = function(node, filter, objectStack) { - WFS.writeOgcPropertyName_(node, filter.propertyName); -}; +function writeIsNullFilter(node, filter, objectStack) { + writeOgcPropertyName(node, filter.propertyName); +} /** * @param {Node} node Node. * @param {ol.format.filter.IsBetween} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeIsBetweenFilter_ = function(node, filter, objectStack) { - WFS.writeOgcPropertyName_(node, filter.propertyName); +function writeIsBetweenFilter(node, filter, objectStack) { + writeOgcPropertyName(node, filter.propertyName); const lowerBoundary = createElementNS(WFS.OGCNS, 'LowerBoundary'); node.appendChild(lowerBoundary); - WFS.writeOgcLiteral_(lowerBoundary, '' + filter.lowerBoundary); + writeOgcLiteral(lowerBoundary, '' + filter.lowerBoundary); const upperBoundary = createElementNS(WFS.OGCNS, 'UpperBoundary'); node.appendChild(upperBoundary); - WFS.writeOgcLiteral_(upperBoundary, '' + filter.upperBoundary); -}; + writeOgcLiteral(upperBoundary, '' + filter.upperBoundary); +} /** * @param {Node} node Node. * @param {ol.format.filter.IsLike} filter Filter. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeIsLikeFilter_ = function(node, filter, objectStack) { +function writeIsLikeFilter(node, filter, objectStack) { node.setAttribute('wildCard', filter.wildCard); node.setAttribute('singleChar', filter.singleChar); node.setAttribute('escapeChar', filter.escapeChar); if (filter.matchCase !== undefined) { node.setAttribute('matchCase', filter.matchCase.toString()); } - WFS.writeOgcPropertyName_(node, filter.propertyName); - WFS.writeOgcLiteral_(node, '' + filter.pattern); -}; + writeOgcPropertyName(node, filter.propertyName); + writeOgcLiteral(node, '' + filter.pattern); +} /** * @param {string} tagName Tag name. * @param {Node} node Node. * @param {string} value Value. - * @private */ -WFS.writeOgcExpression_ = function(tagName, node, value) { +function writeOgcExpression(tagName, node, value) { const property = createElementNS(WFS.OGCNS, tagName); XSD.writeStringTextNode(property, value); node.appendChild(property); -}; +} /** * @param {Node} node Node. * @param {string} value PropertyName value. - * @private */ -WFS.writeOgcPropertyName_ = function(node, value) { - WFS.writeOgcExpression_('PropertyName', node, value); -}; +function writeOgcPropertyName(node, value) { + writeOgcExpression('PropertyName', node, value); +} /** * @param {Node} node Node. * @param {string} value PropertyName value. - * @private */ -WFS.writeOgcLiteral_ = function(node, value) { - WFS.writeOgcExpression_('Literal', node, value); -}; +function writeOgcLiteral(node, value) { + writeOgcExpression('Literal', node, value); +} /** * @param {Node} node Node. * @param {string} time PropertyName value. - * @private */ -WFS.writeTimeInstant_ = function(node, time) { +function writeTimeInstant(node, time) { const timeInstant = createElementNS(GMLBase.GMLNS, 'TimeInstant'); node.appendChild(timeInstant); const timePosition = createElementNS(GMLBase.GMLNS, 'timePosition'); timeInstant.appendChild(timePosition); XSD.writeStringTextNode(timePosition, time); -}; - - -/** - * @type {Object.>} - * @private - */ -WFS.GETFEATURE_SERIALIZERS_ = { - 'http://www.opengis.net/wfs': { - 'Query': makeChildAppender(WFS.writeQuery_) - }, - 'http://www.opengis.net/ogc': { - 'During': makeChildAppender(WFS.writeDuringFilter_), - 'And': makeChildAppender(WFS.writeLogicalFilter_), - 'Or': makeChildAppender(WFS.writeLogicalFilter_), - 'Not': makeChildAppender(WFS.writeNotFilter_), - 'BBOX': makeChildAppender(WFS.writeBboxFilter_), - 'Contains': makeChildAppender(WFS.writeContainsFilter_), - 'Intersects': makeChildAppender(WFS.writeIntersectsFilter_), - 'Within': makeChildAppender(WFS.writeWithinFilter_), - 'PropertyIsEqualTo': makeChildAppender(WFS.writeComparisonFilter_), - 'PropertyIsNotEqualTo': makeChildAppender(WFS.writeComparisonFilter_), - 'PropertyIsLessThan': makeChildAppender(WFS.writeComparisonFilter_), - 'PropertyIsLessThanOrEqualTo': makeChildAppender(WFS.writeComparisonFilter_), - 'PropertyIsGreaterThan': makeChildAppender(WFS.writeComparisonFilter_), - 'PropertyIsGreaterThanOrEqualTo': makeChildAppender(WFS.writeComparisonFilter_), - 'PropertyIsNull': makeChildAppender(WFS.writeIsNullFilter_), - 'PropertyIsBetween': makeChildAppender(WFS.writeIsBetweenFilter_), - 'PropertyIsLike': makeChildAppender(WFS.writeIsLikeFilter_) - } -}; +} /** @@ -904,7 +869,7 @@ WFS.GETFEATURE_SERIALIZERS_ = { */ WFS.writeFilter = function(filter) { const child = createElementNS(WFS.OGCNS, 'Filter'); - WFS.writeFilterCondition_(child, filter, []); + writeFilterCondition(child, filter, []); return child; }; @@ -913,17 +878,16 @@ WFS.writeFilter = function(filter) { * @param {Node} node Node. * @param {Array.} featureTypes Feature types. * @param {Array.<*>} objectStack Node stack. - * @private */ -WFS.writeGetFeature_ = function(node, featureTypes, objectStack) { +function writeGetFeature(node, featureTypes, objectStack) { const context = /** @type {Object} */ (objectStack[objectStack.length - 1]); const item = /** @type {ol.XmlNodeStackItem} */ (assign({}, context)); item.node = node; pushSerializeAndPop(item, - WFS.GETFEATURE_SERIALIZERS_, + GETFEATURE_SERIALIZERS, makeSimpleNodeFactory('Query'), featureTypes, objectStack); -}; +} /** @@ -985,7 +949,7 @@ WFS.prototype.writeGetFeature = function(options) { }; assert(Array.isArray(options.featureTypes), 11); // `options.featureTypes` should be an Array - WFS.writeGetFeature_(node, /** @type {!Array.} */ (options.featureTypes), [context]); + writeGetFeature(node, /** @type {!Array.} */ (options.featureTypes), [context]); return node; }; @@ -1028,7 +992,7 @@ WFS.prototype.writeTransaction = function(inserts, updates, deletes, 'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName}; assign(obj, baseObj); pushSerializeAndPop(obj, - WFS.TRANSACTION_SERIALIZERS_, + TRANSACTION_SERIALIZERS, makeSimpleNodeFactory('Insert'), inserts, objectStack); } @@ -1038,7 +1002,7 @@ WFS.prototype.writeTransaction = function(inserts, updates, deletes, 'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName}; assign(obj, baseObj); pushSerializeAndPop(obj, - WFS.TRANSACTION_SERIALIZERS_, + TRANSACTION_SERIALIZERS, makeSimpleNodeFactory('Update'), updates, objectStack); } @@ -1046,7 +1010,7 @@ WFS.prototype.writeTransaction = function(inserts, updates, deletes, pushSerializeAndPop({node: node, 'featureNS': options.featureNS, 'featureType': options.featureType, 'featurePrefix': featurePrefix, 'gmlVersion': gmlVersion, 'srsName': options.srsName}, - WFS.TRANSACTION_SERIALIZERS_, + TRANSACTION_SERIALIZERS, makeSimpleNodeFactory('Delete'), deletes, objectStack); } @@ -1054,7 +1018,7 @@ WFS.prototype.writeTransaction = function(inserts, updates, deletes, pushSerializeAndPop({node: node, 'featureNS': options.featureNS, 'featureType': options.featureType, 'featurePrefix': featurePrefix, 'gmlVersion': gmlVersion, 'srsName': options.srsName}, - WFS.TRANSACTION_SERIALIZERS_, + TRANSACTION_SERIALIZERS, makeSimpleNodeFactory('Native'), options.nativeElements, objectStack); } From d4a6dc6ec6458a7c78d457a9935ba3bc3334bd70 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 11 Feb 2018 20:32:30 -0700 Subject: [PATCH 7/8] Remove private static members from WMSCapabilities format --- src/ol/format/WMSCapabilities.js | 692 ++++++++++++++----------------- 1 file changed, 302 insertions(+), 390 deletions(-) diff --git a/src/ol/format/WMSCapabilities.js b/src/ol/format/WMSCapabilities.js index a9e7dcd015..b1b0f94e76 100644 --- a/src/ol/format/WMSCapabilities.js +++ b/src/ol/format/WMSCapabilities.js @@ -8,6 +8,7 @@ import XSD from '../format/XSD.js'; import {makeArrayPusher, makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js'; + /** * @classdesc * Format for reading WMS capabilities data @@ -29,6 +30,242 @@ const WMSCapabilities = function() { inherits(WMSCapabilities, XML); +/** + * @const + * @type {Array.} + */ +const NAMESPACE_URIS = [ + null, + 'http://www.opengis.net/wms' +]; + + +/** + * @const + * @type {Object.>} + */ +const PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Service': makeObjectPropertySetter(readService), + 'Capability': makeObjectPropertySetter(readCapability) + }); + + +/** + * @const + * @type {Object.>} + */ +const CAPABILITY_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Request': makeObjectPropertySetter(readRequest), + 'Exception': makeObjectPropertySetter(readException), + 'Layer': makeObjectPropertySetter(readCapabilityLayer) + }); + + +/** + * @const + * @type {Object.>} + */ +const SERVICE_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Name': makeObjectPropertySetter(XSD.readString), + 'Title': makeObjectPropertySetter(XSD.readString), + 'Abstract': makeObjectPropertySetter(XSD.readString), + 'KeywordList': makeObjectPropertySetter(readKeywordList), + 'OnlineResource': makeObjectPropertySetter(XLink.readHref), + 'ContactInformation': makeObjectPropertySetter(readContactInformation), + 'Fees': makeObjectPropertySetter(XSD.readString), + 'AccessConstraints': makeObjectPropertySetter(XSD.readString), + 'LayerLimit': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'MaxWidth': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'MaxHeight': makeObjectPropertySetter(XSD.readNonNegativeInteger) + }); + + +/** + * @const + * @type {Object.>} + */ +const CONTACT_INFORMATION_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'ContactPersonPrimary': makeObjectPropertySetter(readContactPersonPrimary), + 'ContactPosition': makeObjectPropertySetter(XSD.readString), + 'ContactAddress': makeObjectPropertySetter(readContactAddress), + 'ContactVoiceTelephone': makeObjectPropertySetter(XSD.readString), + 'ContactFacsimileTelephone': makeObjectPropertySetter(XSD.readString), + 'ContactElectronicMailAddress': makeObjectPropertySetter(XSD.readString) + }); + + +/** + * @const + * @type {Object.>} + */ +const CONTACT_PERSON_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'ContactPerson': makeObjectPropertySetter(XSD.readString), + 'ContactOrganization': makeObjectPropertySetter(XSD.readString) + }); + + +/** + * @const + * @type {Object.>} + */ +const CONTACT_ADDRESS_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'AddressType': makeObjectPropertySetter(XSD.readString), + 'Address': makeObjectPropertySetter(XSD.readString), + 'City': makeObjectPropertySetter(XSD.readString), + 'StateOrProvince': makeObjectPropertySetter(XSD.readString), + 'PostCode': makeObjectPropertySetter(XSD.readString), + 'Country': makeObjectPropertySetter(XSD.readString) + }); + + +/** + * @const + * @type {Object.>} + */ +const EXCEPTION_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Format': makeArrayPusher(XSD.readString) + }); + + +/** + * @const + * @type {Object.>} + */ +const LAYER_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Name': makeObjectPropertySetter(XSD.readString), + 'Title': makeObjectPropertySetter(XSD.readString), + 'Abstract': makeObjectPropertySetter(XSD.readString), + 'KeywordList': makeObjectPropertySetter(readKeywordList), + 'CRS': makeObjectPropertyPusher(XSD.readString), + 'EX_GeographicBoundingBox': makeObjectPropertySetter(readEXGeographicBoundingBox), + 'BoundingBox': makeObjectPropertyPusher(readBoundingBox), + 'Dimension': makeObjectPropertyPusher(readDimension), + 'Attribution': makeObjectPropertySetter(readAttribution), + 'AuthorityURL': makeObjectPropertyPusher(readAuthorityURL), + 'Identifier': makeObjectPropertyPusher(XSD.readString), + 'MetadataURL': makeObjectPropertyPusher(readMetadataURL), + 'DataURL': makeObjectPropertyPusher(readFormatOnlineresource), + 'FeatureListURL': makeObjectPropertyPusher(readFormatOnlineresource), + 'Style': makeObjectPropertyPusher(readStyle), + 'MinScaleDenominator': makeObjectPropertySetter(XSD.readDecimal), + 'MaxScaleDenominator': makeObjectPropertySetter(XSD.readDecimal), + 'Layer': makeObjectPropertyPusher(readLayer) + }); + + +/** + * @const + * @type {Object.>} + */ +const ATTRIBUTION_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Title': makeObjectPropertySetter(XSD.readString), + 'OnlineResource': makeObjectPropertySetter(XLink.readHref), + 'LogoURL': makeObjectPropertySetter(readSizedFormatOnlineresource) + }); + + +/** + * @const + * @type {Object.>} + */ +const EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS = + makeStructureNS(NAMESPACE_URIS, { + 'westBoundLongitude': makeObjectPropertySetter(XSD.readDecimal), + 'eastBoundLongitude': makeObjectPropertySetter(XSD.readDecimal), + 'southBoundLatitude': makeObjectPropertySetter(XSD.readDecimal), + 'northBoundLatitude': makeObjectPropertySetter(XSD.readDecimal) + }); + + +/** + * @const + * @type {Object.>} + */ +const REQUEST_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'GetCapabilities': makeObjectPropertySetter(readOperationType), + 'GetMap': makeObjectPropertySetter(readOperationType), + 'GetFeatureInfo': makeObjectPropertySetter(readOperationType) + }); + + +/** + * @const + * @type {Object.>} + */ +const OPERATIONTYPE_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Format': makeObjectPropertyPusher(XSD.readString), + 'DCPType': makeObjectPropertyPusher(readDCPType) + }); + + +/** + * @const + * @type {Object.>} + */ +const DCPTYPE_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'HTTP': makeObjectPropertySetter(readHTTP) + }); + + +/** + * @const + * @type {Object.>} + */ +const HTTP_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Get': makeObjectPropertySetter(readFormatOnlineresource), + 'Post': makeObjectPropertySetter(readFormatOnlineresource) + }); + + +/** + * @const + * @type {Object.>} + */ +const STYLE_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Name': makeObjectPropertySetter(XSD.readString), + 'Title': makeObjectPropertySetter(XSD.readString), + 'Abstract': makeObjectPropertySetter(XSD.readString), + 'LegendURL': makeObjectPropertyPusher(readSizedFormatOnlineresource), + 'StyleSheetURL': makeObjectPropertySetter(readFormatOnlineresource), + 'StyleURL': makeObjectPropertySetter(readFormatOnlineresource) + }); + + +/** + * @const + * @type {Object.>} + */ +const FORMAT_ONLINERESOURCE_PARSERS = + makeStructureNS(NAMESPACE_URIS, { + 'Format': makeObjectPropertySetter(XSD.readString), + 'OnlineResource': makeObjectPropertySetter(XLink.readHref) + }); + + +/** + * @const + * @type {Object.>} + */ +const KEYWORDLIST_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Keyword': makeArrayPusher(XSD.readString) + }); + + /** * Read a WMS capabilities document. * @@ -60,30 +297,28 @@ WMSCapabilities.prototype.readFromNode = function(node) { this.version = node.getAttribute('version').trim(); const wmsCapabilityObject = pushParseAndPop({ 'version': this.version - }, WMSCapabilities.PARSERS_, node, []); + }, PARSERS, node, []); return wmsCapabilityObject ? wmsCapabilityObject : null; }; /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Attribution object. */ -WMSCapabilities.readAttribution_ = function(node, objectStack) { +function readAttribution(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.ATTRIBUTION_PARSERS_, node, objectStack); -}; + {}, ATTRIBUTION_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object} Bounding box object. */ -WMSCapabilities.readBoundingBox_ = function(node, objectStack) { +function readBoundingBox(node, objectStack) { const extent = [ XSD.readDecimalString(node.getAttribute('minx')), XSD.readDecimalString(node.getAttribute('miny')), @@ -101,19 +336,18 @@ WMSCapabilities.readBoundingBox_ = function(node, objectStack) { 'extent': extent, 'res': resolutions }; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {ol.Extent|undefined} Bounding box object. */ -WMSCapabilities.readEXGeographicBoundingBox_ = function(node, objectStack) { +function readEXGeographicBoundingBox(node, objectStack) { const geographicBoundingBox = pushParseAndPop( {}, - WMSCapabilities.EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS_, + EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS, node, objectStack); if (!geographicBoundingBox) { return undefined; @@ -134,108 +368,100 @@ WMSCapabilities.readEXGeographicBoundingBox_ = function(node, objectStack) { westBoundLongitude, southBoundLatitude, eastBoundLongitude, northBoundLatitude ]; -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} Capability object. */ -WMSCapabilities.readCapability_ = function(node, objectStack) { +function readCapability(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.CAPABILITY_PARSERS_, node, objectStack); -}; + {}, CAPABILITY_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} Service object. */ -WMSCapabilities.readService_ = function(node, objectStack) { +function readService(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.SERVICE_PARSERS_, node, objectStack); -}; + {}, SERVICE_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} Contact information object. */ -WMSCapabilities.readContactInformation_ = function(node, objectStack) { +function readContactInformation(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.CONTACT_INFORMATION_PARSERS_, + {}, CONTACT_INFORMATION_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} Contact person object. */ -WMSCapabilities.readContactPersonPrimary_ = function(node, objectStack) { +function readContactPersonPrimary(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.CONTACT_PERSON_PARSERS_, + {}, CONTACT_PERSON_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} Contact address object. */ -WMSCapabilities.readContactAddress_ = function(node, objectStack) { +function readContactAddress(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.CONTACT_ADDRESS_PARSERS_, + {}, CONTACT_ADDRESS_PARSERS, node, objectStack); -}; +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Array.|undefined} Format array. */ -WMSCapabilities.readException_ = function(node, objectStack) { +function readException(node, objectStack) { return pushParseAndPop( - [], WMSCapabilities.EXCEPTION_PARSERS_, node, objectStack); -}; + [], EXCEPTION_PARSERS, node, objectStack); +} /** * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. - * @private * @return {Object|undefined} Layer object. */ -WMSCapabilities.readCapabilityLayer_ = function(node, objectStack) { +function readCapabilityLayer(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.LAYER_PARSERS_, node, objectStack); -}; + {}, LAYER_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Layer object. */ -WMSCapabilities.readLayer_ = function(node, objectStack) { +function readLayer(node, objectStack) { const parentLayerObject = /** @type {Object.} */ (objectStack[objectStack.length - 1]); const layerObject = pushParseAndPop( - {}, WMSCapabilities.LAYER_PARSERS_, node, objectStack); + {}, LAYER_PARSERS, node, objectStack); if (!layerObject) { return undefined; @@ -300,16 +526,15 @@ WMSCapabilities.readLayer_ = function(node, objectStack) { }); return layerObject; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object} Dimension object. */ -WMSCapabilities.readDimension_ = function(node, objectStack) { +function readDimension(node, objectStack) { const dimensionObject = { 'name': node.getAttribute('name'), 'units': node.getAttribute('units'), @@ -323,79 +548,73 @@ WMSCapabilities.readDimension_ = function(node, objectStack) { 'values': XSD.readString(node) }; return dimensionObject; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Online resource object. */ -WMSCapabilities.readFormatOnlineresource_ = function(node, objectStack) { +function readFormatOnlineresource(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.FORMAT_ONLINERESOURCE_PARSERS_, + {}, FORMAT_ONLINERESOURCE_PARSERS, node, objectStack); -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Request object. */ -WMSCapabilities.readRequest_ = function(node, objectStack) { +function readRequest(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.REQUEST_PARSERS_, node, objectStack); -}; + {}, REQUEST_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} DCP type object. */ -WMSCapabilities.readDCPType_ = function(node, objectStack) { +function readDCPType(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.DCPTYPE_PARSERS_, node, objectStack); -}; + {}, DCPTYPE_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} HTTP object. */ -WMSCapabilities.readHTTP_ = function(node, objectStack) { +function readHTTP(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.HTTP_PARSERS_, node, objectStack); -}; + {}, HTTP_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Operation type object. */ -WMSCapabilities.readOperationType_ = function(node, objectStack) { +function readOperationType(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.OPERATIONTYPE_PARSERS_, node, objectStack); -}; + {}, OPERATIONTYPE_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Online resource object. */ -WMSCapabilities.readSizedFormatOnlineresource_ = function(node, objectStack) { +function readSizedFormatOnlineresource(node, objectStack) { const formatOnlineresource = - WMSCapabilities.readFormatOnlineresource_(node, objectStack); + readFormatOnlineresource(node, objectStack); if (formatOnlineresource) { const size = [ XSD.readNonNegativeIntegerString(node.getAttribute('width')), @@ -405,368 +624,61 @@ WMSCapabilities.readSizedFormatOnlineresource_ = function(node, objectStack) { return formatOnlineresource; } return undefined; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Authority URL object. */ -WMSCapabilities.readAuthorityURL_ = function(node, objectStack) { +function readAuthorityURL(node, objectStack) { const authorityObject = - WMSCapabilities.readFormatOnlineresource_(node, objectStack); + readFormatOnlineresource(node, objectStack); if (authorityObject) { authorityObject['name'] = node.getAttribute('name'); return authorityObject; } return undefined; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Metadata URL object. */ -WMSCapabilities.readMetadataURL_ = function(node, objectStack) { +function readMetadataURL(node, objectStack) { const metadataObject = - WMSCapabilities.readFormatOnlineresource_(node, objectStack); + readFormatOnlineresource(node, objectStack); if (metadataObject) { metadataObject['type'] = node.getAttribute('type'); return metadataObject; } return undefined; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Style object. */ -WMSCapabilities.readStyle_ = function(node, objectStack) { +function readStyle(node, objectStack) { return pushParseAndPop( - {}, WMSCapabilities.STYLE_PARSERS_, node, objectStack); -}; + {}, STYLE_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Array.|undefined} Keyword list. */ -WMSCapabilities.readKeywordList_ = function(node, objectStack) { +function readKeywordList(node, objectStack) { return pushParseAndPop( - [], WMSCapabilities.KEYWORDLIST_PARSERS_, node, objectStack); -}; + [], KEYWORDLIST_PARSERS, node, objectStack); +} -/** - * @const - * @private - * @type {Array.} - */ -WMSCapabilities.NAMESPACE_URIS_ = [ - null, - 'http://www.opengis.net/wms' -]; - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Service': makeObjectPropertySetter( - WMSCapabilities.readService_), - 'Capability': makeObjectPropertySetter( - WMSCapabilities.readCapability_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.CAPABILITY_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Request': makeObjectPropertySetter( - WMSCapabilities.readRequest_), - 'Exception': makeObjectPropertySetter( - WMSCapabilities.readException_), - 'Layer': makeObjectPropertySetter( - WMSCapabilities.readCapabilityLayer_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.SERVICE_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Name': makeObjectPropertySetter(XSD.readString), - 'Title': makeObjectPropertySetter(XSD.readString), - 'Abstract': makeObjectPropertySetter(XSD.readString), - 'KeywordList': makeObjectPropertySetter( - WMSCapabilities.readKeywordList_), - 'OnlineResource': makeObjectPropertySetter( - XLink.readHref), - 'ContactInformation': makeObjectPropertySetter( - WMSCapabilities.readContactInformation_), - 'Fees': makeObjectPropertySetter(XSD.readString), - 'AccessConstraints': makeObjectPropertySetter( - XSD.readString), - 'LayerLimit': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'MaxWidth': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'MaxHeight': makeObjectPropertySetter( - XSD.readNonNegativeInteger) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.CONTACT_INFORMATION_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'ContactPersonPrimary': makeObjectPropertySetter( - WMSCapabilities.readContactPersonPrimary_), - 'ContactPosition': makeObjectPropertySetter( - XSD.readString), - 'ContactAddress': makeObjectPropertySetter( - WMSCapabilities.readContactAddress_), - 'ContactVoiceTelephone': makeObjectPropertySetter( - XSD.readString), - 'ContactFacsimileTelephone': makeObjectPropertySetter( - XSD.readString), - 'ContactElectronicMailAddress': makeObjectPropertySetter( - XSD.readString) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.CONTACT_PERSON_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'ContactPerson': makeObjectPropertySetter( - XSD.readString), - 'ContactOrganization': makeObjectPropertySetter( - XSD.readString) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.CONTACT_ADDRESS_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'AddressType': makeObjectPropertySetter(XSD.readString), - 'Address': makeObjectPropertySetter(XSD.readString), - 'City': makeObjectPropertySetter(XSD.readString), - 'StateOrProvince': makeObjectPropertySetter( - XSD.readString), - 'PostCode': makeObjectPropertySetter(XSD.readString), - 'Country': makeObjectPropertySetter(XSD.readString) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.EXCEPTION_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Format': makeArrayPusher(XSD.readString) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.LAYER_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Name': makeObjectPropertySetter(XSD.readString), - 'Title': makeObjectPropertySetter(XSD.readString), - 'Abstract': makeObjectPropertySetter(XSD.readString), - 'KeywordList': makeObjectPropertySetter( - WMSCapabilities.readKeywordList_), - 'CRS': makeObjectPropertyPusher(XSD.readString), - 'EX_GeographicBoundingBox': makeObjectPropertySetter( - WMSCapabilities.readEXGeographicBoundingBox_), - 'BoundingBox': makeObjectPropertyPusher( - WMSCapabilities.readBoundingBox_), - 'Dimension': makeObjectPropertyPusher( - WMSCapabilities.readDimension_), - 'Attribution': makeObjectPropertySetter( - WMSCapabilities.readAttribution_), - 'AuthorityURL': makeObjectPropertyPusher( - WMSCapabilities.readAuthorityURL_), - 'Identifier': makeObjectPropertyPusher(XSD.readString), - 'MetadataURL': makeObjectPropertyPusher( - WMSCapabilities.readMetadataURL_), - 'DataURL': makeObjectPropertyPusher( - WMSCapabilities.readFormatOnlineresource_), - 'FeatureListURL': makeObjectPropertyPusher( - WMSCapabilities.readFormatOnlineresource_), - 'Style': makeObjectPropertyPusher( - WMSCapabilities.readStyle_), - 'MinScaleDenominator': makeObjectPropertySetter( - XSD.readDecimal), - 'MaxScaleDenominator': makeObjectPropertySetter( - XSD.readDecimal), - 'Layer': makeObjectPropertyPusher( - WMSCapabilities.readLayer_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.ATTRIBUTION_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Title': makeObjectPropertySetter(XSD.readString), - 'OnlineResource': makeObjectPropertySetter( - XLink.readHref), - 'LogoURL': makeObjectPropertySetter( - WMSCapabilities.readSizedFormatOnlineresource_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.EX_GEOGRAPHIC_BOUNDING_BOX_PARSERS_ = - makeStructureNS(WMSCapabilities.NAMESPACE_URIS_, { - 'westBoundLongitude': makeObjectPropertySetter( - XSD.readDecimal), - 'eastBoundLongitude': makeObjectPropertySetter( - XSD.readDecimal), - 'southBoundLatitude': makeObjectPropertySetter( - XSD.readDecimal), - 'northBoundLatitude': makeObjectPropertySetter( - XSD.readDecimal) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.REQUEST_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'GetCapabilities': makeObjectPropertySetter( - WMSCapabilities.readOperationType_), - 'GetMap': makeObjectPropertySetter( - WMSCapabilities.readOperationType_), - 'GetFeatureInfo': makeObjectPropertySetter( - WMSCapabilities.readOperationType_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.OPERATIONTYPE_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Format': makeObjectPropertyPusher(XSD.readString), - 'DCPType': makeObjectPropertyPusher( - WMSCapabilities.readDCPType_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.DCPTYPE_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'HTTP': makeObjectPropertySetter( - WMSCapabilities.readHTTP_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.HTTP_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Get': makeObjectPropertySetter( - WMSCapabilities.readFormatOnlineresource_), - 'Post': makeObjectPropertySetter( - WMSCapabilities.readFormatOnlineresource_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.STYLE_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Name': makeObjectPropertySetter(XSD.readString), - 'Title': makeObjectPropertySetter(XSD.readString), - 'Abstract': makeObjectPropertySetter(XSD.readString), - 'LegendURL': makeObjectPropertyPusher( - WMSCapabilities.readSizedFormatOnlineresource_), - 'StyleSheetURL': makeObjectPropertySetter( - WMSCapabilities.readFormatOnlineresource_), - 'StyleURL': makeObjectPropertySetter( - WMSCapabilities.readFormatOnlineresource_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.FORMAT_ONLINERESOURCE_PARSERS_ = - makeStructureNS(WMSCapabilities.NAMESPACE_URIS_, { - 'Format': makeObjectPropertySetter(XSD.readString), - 'OnlineResource': makeObjectPropertySetter( - XLink.readHref) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMSCapabilities.KEYWORDLIST_PARSERS_ = makeStructureNS( - WMSCapabilities.NAMESPACE_URIS_, { - 'Keyword': makeArrayPusher(XSD.readString) - }); export default WMSCapabilities; From 2316d02f9f17d81802fd39dfba3074162ad2a05e Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Mon, 12 Feb 2018 05:50:26 -0700 Subject: [PATCH 8/8] Remove private static members from WMTSCapabilities format --- src/ol/format/WMTSCapabilities.js | 461 +++++++++++++----------------- 1 file changed, 199 insertions(+), 262 deletions(-) diff --git a/src/ol/format/WMTSCapabilities.js b/src/ol/format/WMTSCapabilities.js index 85c1776295..6e230c2893 100644 --- a/src/ol/format/WMTSCapabilities.js +++ b/src/ol/format/WMTSCapabilities.js @@ -31,6 +31,168 @@ const WMTSCapabilities = function() { inherits(WMTSCapabilities, XML); +/** + * @const + * @type {Array.} + */ +const NAMESPACE_URIS = [ + null, + 'http://www.opengis.net/wmts/1.0' +]; + + +/** + * @const + * @type {Array.} + */ +const OWS_NAMESPACE_URIS = [ + null, + 'http://www.opengis.net/ows/1.1' +]; + + +/** + * @const + * @type {Object.>} + */ +const PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Contents': makeObjectPropertySetter(readContents) + }); + + +/** + * @const + * @type {Object.>} + */ +const CONTENTS_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Layer': makeObjectPropertyPusher(readLayer), + 'TileMatrixSet': makeObjectPropertyPusher(readTileMatrixSet) + }); + + +/** + * @const + * @type {Object.>} + */ +const LAYER_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Style': makeObjectPropertyPusher(readStyle), + 'Format': makeObjectPropertyPusher(XSD.readString), + 'TileMatrixSetLink': makeObjectPropertyPusher(readTileMatrixSetLink), + 'Dimension': makeObjectPropertyPusher(readDimensions), + 'ResourceURL': makeObjectPropertyPusher(readResourceUrl) + }, makeStructureNS(OWS_NAMESPACE_URIS, { + 'Title': makeObjectPropertySetter(XSD.readString), + 'Abstract': makeObjectPropertySetter(XSD.readString), + 'WGS84BoundingBox': makeObjectPropertySetter(readWgs84BoundingBox), + 'Identifier': makeObjectPropertySetter(XSD.readString) + })); + + +/** + * @const + * @type {Object.>} + */ +const STYLE_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'LegendURL': makeObjectPropertyPusher(readLegendUrl) + }, makeStructureNS(OWS_NAMESPACE_URIS, { + 'Title': makeObjectPropertySetter(XSD.readString), + 'Identifier': makeObjectPropertySetter(XSD.readString) + })); + + +/** + * @const + * @type {Object.>} + */ +const TMS_LINKS_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'TileMatrixSet': makeObjectPropertySetter(XSD.readString), + 'TileMatrixSetLimits': makeObjectPropertySetter(readTileMatrixLimitsList) + }); + +/** + * @const + * @type {Object.>} + */ +const TMS_LIMITS_LIST_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'TileMatrixLimits': makeArrayPusher(readTileMatrixLimits) + }); + + +/** + * @const + * @type {Object.>} + */ +const TMS_LIMITS_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'TileMatrix': makeObjectPropertySetter(XSD.readString), + 'MinTileRow': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'MaxTileRow': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'MinTileCol': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'MaxTileCol': makeObjectPropertySetter(XSD.readNonNegativeInteger) + }); + + +/** + * @const + * @type {Object.>} + */ +const DIMENSION_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'Default': makeObjectPropertySetter(XSD.readString), + 'Value': makeObjectPropertyPusher(XSD.readString) + }, makeStructureNS(OWS_NAMESPACE_URIS, { + 'Identifier': makeObjectPropertySetter(XSD.readString) + })); + + +/** + * @const + * @type {Object.>} + */ +const WGS84_BBOX_READERS = makeStructureNS( + OWS_NAMESPACE_URIS, { + 'LowerCorner': makeArrayPusher(readCoordinates), + 'UpperCorner': makeArrayPusher(readCoordinates) + }); + + +/** + * @const + * @type {Object.>} + */ +const TMS_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'WellKnownScaleSet': makeObjectPropertySetter(XSD.readString), + 'TileMatrix': makeObjectPropertyPusher(readTileMatrix) + }, makeStructureNS(OWS_NAMESPACE_URIS, { + 'SupportedCRS': makeObjectPropertySetter(XSD.readString), + 'Identifier': makeObjectPropertySetter(XSD.readString) + })); + + +/** + * @const + * @type {Object.>} + */ +const TM_PARSERS = makeStructureNS( + NAMESPACE_URIS, { + 'TopLeftCorner': makeObjectPropertySetter(readCoordinates), + 'ScaleDenominator': makeObjectPropertySetter(XSD.readDecimal), + 'TileWidth': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'TileHeight': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'MatrixWidth': makeObjectPropertySetter(XSD.readNonNegativeInteger), + 'MatrixHeight': makeObjectPropertySetter(XSD.readNonNegativeInteger) + }, makeStructureNS(OWS_NAMESPACE_URIS, { + 'Identifier': makeObjectPropertySetter(XSD.readString) + })); + + /** * Read a WMTS capabilities document. * @@ -66,56 +228,52 @@ WMTSCapabilities.prototype.readFromNode = function(node) { } WMTSCapabilityObject['version'] = version; WMTSCapabilityObject = pushParseAndPop(WMTSCapabilityObject, - WMTSCapabilities.PARSERS_, node, []); + PARSERS, node, []); return WMTSCapabilityObject ? WMTSCapabilityObject : null; }; /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Attribution object. */ -WMTSCapabilities.readContents_ = function(node, objectStack) { +function readContents(node, objectStack) { return pushParseAndPop({}, - WMTSCapabilities.CONTENTS_PARSERS_, node, objectStack); -}; + CONTENTS_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Layers object. */ -WMTSCapabilities.readLayer_ = function(node, objectStack) { +function readLayer(node, objectStack) { return pushParseAndPop({}, - WMTSCapabilities.LAYER_PARSERS_, node, objectStack); -}; + LAYER_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Tile Matrix Set object. */ -WMTSCapabilities.readTileMatrixSet_ = function(node, objectStack) { +function readTileMatrixSet(node, objectStack) { return pushParseAndPop({}, - WMTSCapabilities.TMS_PARSERS_, node, objectStack); -}; + TMS_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Style object. */ -WMTSCapabilities.readStyle_ = function(node, objectStack) { +function readStyle(node, objectStack) { const style = pushParseAndPop({}, - WMTSCapabilities.STYLE_PARSERS_, node, objectStack); + STYLE_PARSERS, node, objectStack); if (!style) { return undefined; } @@ -123,41 +281,38 @@ WMTSCapabilities.readStyle_ = function(node, objectStack) { style['isDefault'] = isDefault; return style; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Tile Matrix Set Link object. */ -WMTSCapabilities.readTileMatrixSetLink_ = function(node, +function readTileMatrixSetLink(node, objectStack) { return pushParseAndPop({}, - WMTSCapabilities.TMS_LINKS_PARSERS_, node, objectStack); -}; + TMS_LINKS_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Dimension object. */ -WMTSCapabilities.readDimensions_ = function(node, objectStack) { +function readDimensions(node, objectStack) { return pushParseAndPop({}, - WMTSCapabilities.DIMENSION_PARSERS_, node, objectStack); -}; + DIMENSION_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Resource URL object. */ -WMTSCapabilities.readResourceUrl_ = function(node, objectStack) { +function readResourceUrl(node, objectStack) { const format = node.getAttribute('format'); const template = node.getAttribute('template'); const resourceType = node.getAttribute('resourceType'); @@ -172,46 +327,43 @@ WMTSCapabilities.readResourceUrl_ = function(node, objectStack) { resource['resourceType'] = resourceType; } return resource; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} WGS84 BBox object. */ -WMTSCapabilities.readWgs84BoundingBox_ = function(node, objectStack) { +function readWgs84BoundingBox(node, objectStack) { const coordinates = pushParseAndPop([], - WMTSCapabilities.WGS84_BBOX_READERS_, node, objectStack); + WGS84_BBOX_READERS, node, objectStack); if (coordinates.length != 2) { return undefined; } return boundingExtent(coordinates); -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Legend object. */ -WMTSCapabilities.readLegendUrl_ = function(node, objectStack) { +function readLegendUrl(node, objectStack) { const legend = {}; legend['format'] = node.getAttribute('format'); legend['href'] = XLink.readHref(node); return legend; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} Coordinates object. */ -WMTSCapabilities.readCoordinates_ = function(node, objectStack) { +function readCoordinates(node, objectStack) { const coordinates = XSD.readString(node).split(' '); if (!coordinates || coordinates.length != 2) { return undefined; @@ -222,257 +374,42 @@ WMTSCapabilities.readCoordinates_ = function(node, objectStack) { return undefined; } return [x, y]; -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} TileMatrix object. */ -WMTSCapabilities.readTileMatrix_ = function(node, objectStack) { +function readTileMatrix(node, objectStack) { return pushParseAndPop({}, - WMTSCapabilities.TM_PARSERS_, node, objectStack); -}; + TM_PARSERS, node, objectStack); +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} TileMatrixSetLimits Object. */ -WMTSCapabilities.readTileMatrixLimitsList_ = function(node, +function readTileMatrixLimitsList(node, objectStack) { return pushParseAndPop([], - WMTSCapabilities.TMS_LIMITS_LIST_PARSERS_, node, + TMS_LIMITS_LIST_PARSERS, node, objectStack); -}; +} /** - * @private * @param {Node} node Node. * @param {Array.<*>} objectStack Object stack. * @return {Object|undefined} TileMatrixLimits Array. */ -WMTSCapabilities.readTileMatrixLimits_ = function(node, objectStack) { +function readTileMatrixLimits(node, objectStack) { return pushParseAndPop({}, - WMTSCapabilities.TMS_LIMITS_PARSERS_, node, objectStack); -}; + TMS_LIMITS_PARSERS, node, objectStack); +} -/** - * @const - * @private - * @type {Array.} - */ -WMTSCapabilities.NAMESPACE_URIS_ = [ - null, - 'http://www.opengis.net/wmts/1.0' -]; - - -/** - * @const - * @private - * @type {Array.} - */ -WMTSCapabilities.OWS_NAMESPACE_URIS_ = [ - null, - 'http://www.opengis.net/ows/1.1' -]; - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'Contents': makeObjectPropertySetter( - WMTSCapabilities.readContents_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.CONTENTS_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'Layer': makeObjectPropertyPusher( - WMTSCapabilities.readLayer_), - 'TileMatrixSet': makeObjectPropertyPusher( - WMTSCapabilities.readTileMatrixSet_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.LAYER_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'Style': makeObjectPropertyPusher( - WMTSCapabilities.readStyle_), - 'Format': makeObjectPropertyPusher( - XSD.readString), - 'TileMatrixSetLink': makeObjectPropertyPusher( - WMTSCapabilities.readTileMatrixSetLink_), - 'Dimension': makeObjectPropertyPusher( - WMTSCapabilities.readDimensions_), - 'ResourceURL': makeObjectPropertyPusher( - WMTSCapabilities.readResourceUrl_) - }, makeStructureNS(WMTSCapabilities.OWS_NAMESPACE_URIS_, { - 'Title': makeObjectPropertySetter( - XSD.readString), - 'Abstract': makeObjectPropertySetter( - XSD.readString), - 'WGS84BoundingBox': makeObjectPropertySetter( - WMTSCapabilities.readWgs84BoundingBox_), - 'Identifier': makeObjectPropertySetter( - XSD.readString) - })); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.STYLE_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'LegendURL': makeObjectPropertyPusher( - WMTSCapabilities.readLegendUrl_) - }, makeStructureNS(WMTSCapabilities.OWS_NAMESPACE_URIS_, { - 'Title': makeObjectPropertySetter( - XSD.readString), - 'Identifier': makeObjectPropertySetter( - XSD.readString) - })); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.TMS_LINKS_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'TileMatrixSet': makeObjectPropertySetter( - XSD.readString), - 'TileMatrixSetLimits': makeObjectPropertySetter( - WMTSCapabilities.readTileMatrixLimitsList_) - }); - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.TMS_LIMITS_LIST_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'TileMatrixLimits': makeArrayPusher( - WMTSCapabilities.readTileMatrixLimits_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.TMS_LIMITS_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'TileMatrix': makeObjectPropertySetter( - XSD.readString), - 'MinTileRow': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'MaxTileRow': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'MinTileCol': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'MaxTileCol': makeObjectPropertySetter( - XSD.readNonNegativeInteger) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.DIMENSION_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'Default': makeObjectPropertySetter( - XSD.readString), - 'Value': makeObjectPropertyPusher( - XSD.readString) - }, makeStructureNS(WMTSCapabilities.OWS_NAMESPACE_URIS_, { - 'Identifier': makeObjectPropertySetter( - XSD.readString) - })); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.WGS84_BBOX_READERS_ = makeStructureNS( - WMTSCapabilities.OWS_NAMESPACE_URIS_, { - 'LowerCorner': makeArrayPusher( - WMTSCapabilities.readCoordinates_), - 'UpperCorner': makeArrayPusher( - WMTSCapabilities.readCoordinates_) - }); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.TMS_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'WellKnownScaleSet': makeObjectPropertySetter( - XSD.readString), - 'TileMatrix': makeObjectPropertyPusher( - WMTSCapabilities.readTileMatrix_) - }, makeStructureNS(WMTSCapabilities.OWS_NAMESPACE_URIS_, { - 'SupportedCRS': makeObjectPropertySetter( - XSD.readString), - 'Identifier': makeObjectPropertySetter( - XSD.readString) - })); - - -/** - * @const - * @type {Object.>} - * @private - */ -WMTSCapabilities.TM_PARSERS_ = makeStructureNS( - WMTSCapabilities.NAMESPACE_URIS_, { - 'TopLeftCorner': makeObjectPropertySetter( - WMTSCapabilities.readCoordinates_), - 'ScaleDenominator': makeObjectPropertySetter( - XSD.readDecimal), - 'TileWidth': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'TileHeight': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'MatrixWidth': makeObjectPropertySetter( - XSD.readNonNegativeInteger), - 'MatrixHeight': makeObjectPropertySetter( - XSD.readNonNegativeInteger) - }, makeStructureNS(WMTSCapabilities.OWS_NAMESPACE_URIS_, { - 'Identifier': makeObjectPropertySetter( - XSD.readString) - })); export default WMTSCapabilities;