From 9492c95539d486cbf05d9e14179e8b0871ddc299 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Wed, 12 Mar 2014 13:42:56 +0100 Subject: [PATCH] Remove old GML parser --- old/src/ol/parser/ogc/gmlparser.exports | 6 - old/src/ol/parser/ogc/gmlparser.js | 667 ------------------------ old/src/ol/parser/ogc/gmlparser_v2.js | 145 ------ old/src/ol/parser/ogc/gmlparser_v3.js | 442 ---------------- 4 files changed, 1260 deletions(-) delete mode 100644 old/src/ol/parser/ogc/gmlparser.exports delete mode 100644 old/src/ol/parser/ogc/gmlparser.js delete mode 100644 old/src/ol/parser/ogc/gmlparser_v2.js delete mode 100644 old/src/ol/parser/ogc/gmlparser_v3.js diff --git a/old/src/ol/parser/ogc/gmlparser.exports b/old/src/ol/parser/ogc/gmlparser.exports deleted file mode 100644 index ee6aaaefd8..0000000000 --- a/old/src/ol/parser/ogc/gmlparser.exports +++ /dev/null @@ -1,6 +0,0 @@ -@exportSymbol ol.parser.ogc.GML_v2 -@exportProperty ol.parser.ogc.GML_v2.prototype.read -@exportProperty ol.parser.ogc.GML_v2.prototype.write -@exportSymbol ol.parser.ogc.GML_v3 -@exportProperty ol.parser.ogc.GML_v3.prototype.read -@exportProperty ol.parser.ogc.GML_v3.prototype.write diff --git a/old/src/ol/parser/ogc/gmlparser.js b/old/src/ol/parser/ogc/gmlparser.js deleted file mode 100644 index 28c36e0f1a..0000000000 --- a/old/src/ol/parser/ogc/gmlparser.js +++ /dev/null @@ -1,667 +0,0 @@ -goog.provide('ol.parser.ogc.GML'); -goog.require('goog.array'); -goog.require('goog.asserts'); -goog.require('goog.dom.xml'); -goog.require('ol.Feature'); -goog.require('ol.geom.Geometry'); -goog.require('ol.geom.GeometryCollection'); -goog.require('ol.geom.GeometryType'); -goog.require('ol.geom.LineString'); -goog.require('ol.geom.LinearRing'); -goog.require('ol.geom.MultiLineString'); -goog.require('ol.geom.MultiPoint'); -goog.require('ol.geom.MultiPolygon'); -goog.require('ol.geom.Point'); -goog.require('ol.geom.Polygon'); -goog.require('ol.parser.StringFeatureParser'); -goog.require('ol.parser.XML'); -goog.require('ol.proj'); - - - -/** - * @constructor - * @implements {ol.parser.StringFeatureParser} - * @param {olx.parser.GMLOptions=} opt_options - * Optional configuration object. - * @extends {ol.parser.XML} - */ -ol.parser.ogc.GML = function(opt_options) { - var options = /** @type {olx.parser.GMLOptions} */ - (goog.isDef(opt_options) ? opt_options : {}); - this.extractAttributes = goog.isDef(options.extractAttributes) ? - options.extractAttributes : true; - this.surface = goog.isDef(options.surface) ? - options.surface : false; - this.curve = goog.isDef(options.curve) ? - options.curve : false; - this.multiCurve = goog.isDef(options.multiCurve) ? - options.multiCurve : true; - this.multiSurface = goog.isDef(options.multiSurface) ? - options.multiSurface : true; - this.readOptions = options.readOptions; - this.writeOptions = options.writeOptions; - - /** - * @protected - * @type {string|undefined} - */ - this.srsName; - - /** - * @protected - * @type {string|undefined} - */ - this.axisOrientation; - - if (goog.isDef(options.schemaLocation)) { - this.schemaLocation = options.schemaLocation; - } - if (goog.isDef(options.featureNS)) { - this.featureNS = options.featureNS; - } - if (goog.isDef(options.featureType)) { - this.featureType = options.featureType; - } - this.singleFeatureType = !goog.isDef(opt_options) || - goog.isString(opt_options.featureType); - this.defaultNamespaceURI = 'http://www.opengis.net/gml'; - this.readers = { - 'http://www.opengis.net/wfs': { - 'FeatureCollection': function(node, obj) { - this.readChildNodes(node, obj); - } - }, - 'http://www.opengis.net/gml': { - '_inherit': function(node, obj, container) { - // Version specific parsers extend this with goog.functions.sequence - var srsName; - if (!goog.isDef(this.srsName)) { - srsName = this.srsName = node.getAttribute('srsName'); - } - if (!goog.isDef(this.axisOrientation)) { - if (goog.isDefAndNotNull(srsName)) { - this.axisOrientation = ol.proj.get(srsName).getAxisOrientation(); - } else { - this.axisOrientation = 'enu'; - } - } - }, - 'name': function(node, obj) { - obj.name = this.getChildValue(node); - }, - 'featureMember': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'featureMembers': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'GeometryCollection': function(node, container) { - var parts = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, parts, container]); - this.readChildNodes(node, parts); - container.geometry = { - type: ol.geom.GeometryType.GEOMETRY_COLLECTION, - parts: parts - }; - }, - 'geometryMember': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'MultiPoint': function(node, container) { - var parts = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, parts, container]); - this.readChildNodes(node, parts); - container.geometry = { - type: ol.geom.GeometryType.MULTI_POINT, - parts: parts - }; - }, - 'pointMember': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'MultiLineString': function(node, container) { - var parts = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, parts, container]); - this.readChildNodes(node, parts); - container.geometry = { - type: ol.geom.GeometryType.MULTI_LINE_STRING, - parts: parts - }; - }, - 'lineStringMember': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'MultiPolygon': function(node, container) { - var parts = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, parts, container]); - this.readChildNodes(node, parts); - container.geometry = { - type: ol.geom.GeometryType.MULTI_POLYGON, - parts: parts - }; - }, - 'polygonMember': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'boundedBy': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'Point': function(node, container) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, coordinates, container]); - this.readChildNodes(node, coordinates); - var point = { - type: ol.geom.GeometryType.POINT, - coordinates: coordinates[0][0] - }; - // in the case of a multi geometry this is parts - if (goog.isArray(container)) { - container.push(point); - } else { - container.geometry = point; - } - }, - 'LineString': function(node, container) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, coordinates, container]); - this.readChildNodes(node, coordinates); - var linestring = { - type: ol.geom.GeometryType.LINE_STRING, - coordinates: coordinates[0] - }; - // in the case of a multi geometry this is parts - if (goog.isArray(container)) { - container.push(linestring); - } else { - container.geometry = linestring; - } - }, - 'Polygon': function(node, container) { - var obj = {outer: null, inner: []}; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, obj, container]); - this.readChildNodes(node, obj); - obj.inner.unshift(obj.outer); - var polygon = { - type: ol.geom.GeometryType.POLYGON, - coordinates: obj.inner - }; - // in the case of a multi geometry this is parts - if (goog.isArray(container)) { - container.push(polygon); - } else { - container.geometry = polygon; - } - }, - 'LinearRing': function(node, container) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, coordinates, container]); - this.readChildNodes(node, coordinates); - if (goog.isArray(container)) { - container.push(coordinates); - } else { - container.geometry = { - type: ol.geom.GeometryType.LINEAR_RING, - coordinates: coordinates[0] - }; - } - }, - 'coordinates': function(node, coordinates) { - var str = this.getChildValue(node).replace( - this.regExes.trimSpace, ''); - str = str.replace(this.regExes.trimComma, ','); - var coords; - var cs = node.getAttribute('cs') || ','; - var ts = node.getAttribute('ts') || this.regExes.splitSpace; - var pointList = str.split(ts); - var numPoints = pointList.length; - var points = new Array(numPoints); - for (var i = 0; i < numPoints; ++i) { - coords = goog.array.map(pointList[i].split(cs), parseFloat); - if (this.axisOrientation.substr(0, 2) === 'en') { - points[i] = coords; - } else { - if (coords.length === 2) { - points[i] = coords.reverse(); - } else if (coords.length === 3) { - points[i] = [coords[1], coords[0], coords[2]]; - } - } - } - coordinates.push(points); - }, - 'coord': function(node, coordinates) { - var coord = {}; - if (coordinates.length === 0) { - coordinates.push([]); - } - this.readChildNodes(node, coord); - if (goog.isDef(coord.z)) { - coordinates.push([coord.x, coord.y, coord.z]); - } else { - coordinates[0].push([coord.x, coord.y]); - } - }, - 'X': function(node, coord) { - coord.x = parseFloat(this.getChildValue(node)); - }, - 'Y': function(node, coord) { - coord.y = parseFloat(this.getChildValue(node)); - }, - 'Z': function(node, coord) { - coord.z = parseFloat(this.getChildValue(node)); - } - } - }; - this.featureNSReaders_ = { - '*': function(node, obj) { - // The node can either be named like the featureType, or it - // can be a child of the feature:featureType. Children can be - // geometry or attributes. - var name; - var local = node.localName || node.nodeName.split(':').pop(); - // Since an attribute can have the same name as the feature type - // we only want to read the node as a feature if the parent - // node can have feature nodes as children. In this case, the - // obj.features property is set. - if (obj.features) { - if (!this.singleFeatureType && - (goog.array.indexOf(this.featureType, local) !== -1)) { - name = '_typeName'; - } else if (local === this.featureType) { - name = '_typeName'; - } - } else { - // Assume attribute elements have one child node and that the child - // is a text node. Otherwise assume it is a geometry node. - if (node.childNodes.length === 0 || - (node.childNodes.length === 1 && - node.firstChild.nodeType === 3)) { - if (this.extractAttributes) { - name = '_attribute'; - } - } else { - name = '_geometry'; - } - } - if (name) { - this.readers[this.featureNS][name].apply(this, [node, obj]); - } - }, - '_typeName': function(node, obj) { - var container = {properties: {}}; - this.readChildNodes(node, container); - // look for common gml namespaced elements - if (container.name) { - container.properties.name = container.name; - } - var feature = new ol.Feature(container.properties); - var geom = container.geometry; - if (geom) { - var geometry = this.createGeometry({geometry: geom}); - if (goog.isDef(geometry)) { - feature.setGeometry(geometry); - } - } - // TODO set feature.type and feature.namespace - var fid = node.getAttribute('fid') || - this.getAttributeNS(node, this.defaultNamespaceURI, 'id'); - if (!goog.isNull(fid)) { - feature.setId(fid); - } - obj.features.push(feature); - }, - '_geometry': function(node, obj) { - var local = node.localName || node.nodeName.split(':').pop(); - this.readChildNodes(node, obj); - obj.properties[local] = this.createGeometry({geometry: obj.geometry}); - delete obj.geometry; - }, - '_attribute': function(node, obj) { - var local = node.localName || node.nodeName.split(':').pop(); - var value = this.getChildValue(node); - obj.properties[local] = value; - } - }; - if (goog.isDef(this.featureNS)) { - this.readers[this.featureNS] = this.featureNSReaders_; - } - this.writers = { - 'http://www.opengis.net/gml': { - 'featureMember': function(obj) { - var node = this.createElementNS('gml:featureMember'); - this.writeNode('_typeName', obj, this.featureNS, node); - return node; - }, - 'MultiPoint': function(geometry) { - var node = this.createElementNS('gml:MultiPoint'); - var components = geometry.getComponents(); - for (var i = 0, ii = components.length; i < ii; ++i) { - this.writeNode('pointMember', components[i], null, node); - } - return node; - }, - 'pointMember': function(geometry) { - var node = this.createElementNS('gml:pointMember'); - this.writeNode('Point', geometry, null, node); - return node; - }, - 'MultiLineString': function(geometry) { - var node = this.createElementNS('gml:MultiLineString'); - var components = geometry.getComponents(); - for (var i = 0, ii = components.length; i < ii; ++i) { - this.writeNode('lineStringMember', components[i], null, node); - } - return node; - }, - 'lineStringMember': function(geometry) { - var node = this.createElementNS('gml:lineStringMember'); - this.writeNode('LineString', geometry, null, node); - return node; - }, - 'MultiPolygon': function(geometry) { - var node = this.createElementNS('gml:MultiPolygon'); - var components = geometry.getComponents(); - for (var i = 0, ii = components.length; i < ii; ++i) { - this.writeNode('polygonMember', components[i], null, node); - } - return node; - }, - 'polygonMember': function(geometry) { - var node = this.createElementNS('gml:polygonMember'); - this.writeNode('Polygon', geometry, null, node); - return node; - }, - 'GeometryCollection': function(geometry) { - var node = this.createElementNS('gml:GeometryCollection'); - var components = geometry.getComponents(); - for (var i = 0, ii = components.length; i < ii; ++i) { - this.writeNode('geometryMember', components[i], null, node); - } - return node; - }, - 'geometryMember': function(geometry) { - var node = this.createElementNS('gml:geometryMember'); - var child = this.writeNode('_geometry', {value: geometry}, - this.featureNS); - node.appendChild(child.firstChild); - return node; - } - }, - 'http://www.opengis.net/wfs': { - 'FeatureCollection': function(features) { - /** - * This is only here because GML2 only describes abstract - * feature collections. Typically, you would not be using - * the GML format to write wfs elements. This just provides - * some way to write out lists of features. GML3 defines the - * featureMembers element, so that is used by default instead. - */ - var node = this.createElementNS('wfs:FeatureCollection', - 'http://www.opengis.net/wfs'); - for (var i = 0, ii = features.length; i < ii; ++i) { - this.writeNode('featureMember', features[i], null, node); - } - return node; - } - } - }; - this.featureNSWriters_ = { - '_typeName': function(feature) { - var node = this.createElementNS('feature:' + this.featureType, - this.featureNS); - var fid = feature.getId(); - if (goog.isDef(fid)) { - this.setAttributeNS(node, this.defaultNamespaceURI, 'fid', fid); - } - var attributes = feature.getAttributes(); - for (var name in attributes) { - var value = attributes[name]; - if (goog.isDefAndNotNull(value)) { - if (value instanceof ol.geom.Geometry) { - this.writeNode('_geometry', {name: name, value: value}, - this.featureNS, node); - } else { - this.writeNode('_attribute', {name: name, value: value}, - this.featureNS, node); - } - } - } - return node; - }, - '_geometry': function(obj) { - var node = this.createElementNS('feature:' + obj.name, - this.featureNS); - var geometry = obj.value; - var type = geometry.getType(), child; - if (type === ol.geom.GeometryType.POINT) { - child = this.writeNode('Point', geometry, null, node); - } else if (type === ol.geom.GeometryType.MULTI_POINT) { - child = this.writeNode('MultiPoint', geometry, null, node); - } else if (type === ol.geom.GeometryType.LINEAR_RING) { - child = this.writeNode('LinearRing', geometry.getCoordinates(), null, - node); - } else if (type === ol.geom.GeometryType.LINE_STRING) { - child = this.writeNode('LineString', geometry, null, node); - } else if (type === ol.geom.GeometryType.MULTI_LINE_STRING) { - child = this.writeNode('MultiLineString', geometry, null, node); - } else if (type === ol.geom.GeometryType.POLYGON) { - child = this.writeNode('Polygon', geometry, null, node); - } else if (type === ol.geom.GeometryType.MULTI_POLYGON) { - child = this.writeNode('MultiPolygon', geometry, null, node); - } else if (type === ol.geom.GeometryType.GEOMETRY_COLLECTION) { - child = this.writeNode('GeometryCollection', geometry, null, node); - } - if (goog.isDefAndNotNull(this.srsName)) { - this.setAttributeNS(child, null, 'srsName', this.srsName); - } - return node; - }, - '_attribute': function(obj) { - var node = this.createElementNS('feature:' + obj.name, this.featureNS); - node.appendChild(this.createTextNode(obj.value)); - return node; - } - }; - if (goog.isDef(this.featureNS)) { - this.writers[this.featureNS] = this.featureNSWriters_; - } - goog.base(this); -}; -goog.inherits(ol.parser.ogc.GML, ol.parser.XML); - - -/** - * @param {ol.geom.Geometry} geometry Geometry. - * @return {Element} XML node representing the geometry. - */ -ol.parser.ogc.GML.prototype.writeGeometry = function(geometry) { - return this.featureNSWriters_['_geometry'].call(this, {value: geometry}) - .firstChild; -}; - - -/** - * @param {string|Document|Element|Object} data Data to read. - * @param {olx.parser.GMLReadOptions=} opt_options Read options. - * @return {ol.parser.ReadFeaturesResult} An object representing the document. - */ -ol.parser.ogc.GML.prototype.read = function(data, opt_options) { - var srsName; - if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) { - srsName = opt_options.srsName; - } else if (goog.isDef(this.readOptions) && - goog.isDef(this.readOptions.srsName)) { - srsName = this.readOptions.srsName; - } - if (goog.isDef(srsName)) { - this.srsName = goog.isString(srsName) ? srsName : srsName.getCode(); - } - if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) { - this.axisOrientation = opt_options.axisOrientation; - } else if (goog.isDef(this.readOptions) && - goog.isDef(this.readOptions.axisOrientation)) { - this.axisOrientation = this.readOptions.axisOrientation; - } - if (typeof data == 'string') { - data = goog.dom.xml.loadXml(data); - } - if (data && data.nodeType == 9) { - data = data.documentElement; - } - var obj = /** @type {ol.parser.ReadFeaturesResult} */ - ({features: [], metadata: {}}); - this.readNode(data, obj, true); - obj.metadata.projection = this.srsName; - delete this.srsName; - delete this.axisOrientation; - return obj; -}; - - -/** - * @param {Element|Document} node The node to be read. - * @param {Object} obj The object to be modified. - * @param {boolean=} opt_first Should be set to true for the first node read. - * This is usually the readNode call in the read method. Without this being - * set, auto-configured properties will stick on subsequent reads. - * @return {Object} The input object, modified (or a new one if none was - * provided). - */ -ol.parser.ogc.GML.prototype.readNode = function(node, obj, opt_first) { - // on subsequent calls of this.read(), we want to reset auto- - // configured properties and auto-configure again. - if (opt_first === true && this.autoConfig === true) { - this.featureType = null; - delete this.readers[this.featureNS]; - delete this.writers[this.featureNS]; - this.featureNS = null; - } - // featureType auto-configuration - if (!this.featureNS && (!(node.namespaceURI in this.readers) && - node.parentNode.namespaceURI == this.defaultNamespaceURI && - (/^(.*:)?featureMembers?$/).test(node.parentNode.nodeName))) { - this.featureType = node.nodeName.split(':').pop(); - this.readers[node.namespaceURI] = this.featureNSReaders_; - this.writers[node.namespaceURI] = this.featureNSWriters_; - this.featureNS = node.namespaceURI; - this.autoConfig = true; - } - return ol.parser.XML.prototype.readNode.apply(this, [node, obj]); -}; - - -/** - * @param {Object} container Geometry container. - * @return {ol.geom.Geometry} The geometry created. - */ -// TODO use a mixin since this is also used in the KML parser -ol.parser.ogc.GML.prototype.createGeometry = function(container) { - var geometry = null, coordinates, i, ii; - switch (container.geometry.type) { - case ol.geom.GeometryType.POINT: - geometry = new ol.geom.Point(container.geometry.coordinates); - break; - case ol.geom.GeometryType.LINEAR_RING: - geometry = new ol.geom.LinearRing(container.geometry.coordinates); - break; - case ol.geom.GeometryType.LINE_STRING: - geometry = new ol.geom.LineString(container.geometry.coordinates); - break; - case ol.geom.GeometryType.POLYGON: - geometry = new ol.geom.Polygon(container.geometry.coordinates); - break; - case ol.geom.GeometryType.MULTI_POINT: - coordinates = []; - for (i = 0, ii = container.geometry.parts.length; i < ii; i++) { - coordinates.push(container.geometry.parts[i].coordinates); - } - geometry = new ol.geom.MultiPoint(coordinates); - break; - case ol.geom.GeometryType.MULTI_LINE_STRING: - coordinates = []; - for (i = 0, ii = container.geometry.parts.length; i < ii; i++) { - coordinates.push(container.geometry.parts[i].coordinates); - } - geometry = new ol.geom.MultiLineString(coordinates); - break; - case ol.geom.GeometryType.MULTI_POLYGON: - coordinates = []; - for (i = 0, ii = container.geometry.parts.length; i < ii; i++) { - coordinates.push(container.geometry.parts[i].coordinates); - } - geometry = new ol.geom.MultiPolygon(coordinates); - break; - case ol.geom.GeometryType.GEOMETRY_COLLECTION: - var geometries = []; - for (i = 0, ii = container.geometry.parts.length; i < ii; i++) { - geometries.push(this.createGeometry({ - geometry: container.geometry.parts[i] - })); - } - geometry = new ol.geom.GeometryCollection(geometries); - break; - default: - break; - } - return geometry; -}; - - -/** - * Parse a GML document provided as a string. - * @param {string} str GML document. - * @return {ol.parser.ReadFeaturesResult} Features and metadata. - */ -ol.parser.ogc.GML.prototype.readFeaturesFromString = function(str) { - return this.read(str); -}; - - -/** - * Applies the writeOptions passed into the write function. - * @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as - * GML. - * @param {olx.parser.GMLWriteOptions=} opt_options Write options. - */ -ol.parser.ogc.GML.prototype.applyWriteOptions = function(obj, opt_options) { - // srsName handling: opt_options -> this.writeOptions -> obj.metadata - var srsName; - if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) { - srsName = opt_options.srsName; - } else if (goog.isDef(this.writeOptions) && - goog.isDef(this.writeOptions.srsName)) { - srsName = this.writeOptions.srsName; - } else if (goog.isDef(obj.metadata)) { - srsName = obj.metadata.projection; - } - goog.asserts.assert(goog.isDef(srsName), 'srsName required for writing GML'); - this.srsName = goog.isString(srsName) ? srsName : srsName.getCode(); - // axisOrientation handling: opt_options -> this.writeOptions - if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) { - this.axisOrientation = opt_options.axisOrientation; - } else if (goog.isDef(this.writeOptions) && - goog.isDef(this.writeOptions.axisOrientation)) { - this.axisOrientation = this.writeOptions.axisOrientation; - } else { - this.axisOrientation = ol.proj.get(this.srsName).getAxisOrientation(); - } -}; - - -/** - * @param {string} featureNS Feature namespace. - */ -ol.parser.ogc.GML.prototype.setFeatureNS = function(featureNS) { - this.featureNS = featureNS; - this.readers[featureNS] = this.featureNSReaders_; - this.writers[featureNS] = this.featureNSWriters_; -}; diff --git a/old/src/ol/parser/ogc/gmlparser_v2.js b/old/src/ol/parser/ogc/gmlparser_v2.js deleted file mode 100644 index a6aaa73c52..0000000000 --- a/old/src/ol/parser/ogc/gmlparser_v2.js +++ /dev/null @@ -1,145 +0,0 @@ -goog.provide('ol.parser.ogc.GML_v2'); - -goog.require('goog.array'); -goog.require('goog.object'); -goog.require('ol.parser.ogc.GML'); - - - -/** - * Read and write [GML](http://www.opengeospatial.org/standards/gml) - * version 2.1.2 - * - * @constructor - * @param {olx.parser.GMLOptions=} opt_options Optional configuration object. - * @extends {ol.parser.ogc.GML} - * @todo stability experimental - */ -ol.parser.ogc.GML_v2 = function(opt_options) { - this.schemaLocation = 'http://www.opengis.net/gml ' + - 'http://schemas.opengis.net/gml/2.1.2/feature.xsd'; - goog.base(this, opt_options); - goog.object.extend(this.readers['http://www.opengis.net/gml'], { - 'outerBoundaryIs': function(node, container) { - var coordinates = []; - this.readChildNodes(node, coordinates); - container['outer'] = coordinates[0][0]; - }, - 'innerBoundaryIs': function(node, container) { - var coordinates = []; - this.readChildNodes(node, coordinates); - container.inner.push(coordinates[0][0]); - }, - 'Box': function(node, container) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, coordinates, container]); - this.readChildNodes(node, coordinates); - container.projection = node.getAttribute('srsName'); - container.bounds = [ - coordinates[0][0][0], coordinates[0][0][1], - coordinates[0][1][0], coordinates[0][1][1] - ]; - } - }); - goog.object.extend(this.writers['http://www.opengis.net/gml'], { - 'Point': function(geometry) { - var node = this.createElementNS('gml:Point'); - this.writeNode('coordinates', [geometry.getCoordinates()], null, node); - return node; - }, - 'coordinates': function(coordinates) { - var numCoordinates = coordinates.length; - var parts = new Array(numCoordinates); - for (var i = 0; i < numCoordinates; ++i) { - var coord = coordinates[i]; - var part = goog.array.concat(coord); - if (goog.isDef(this.axisOrientation) && - this.axisOrientation.substr(0, 2) !== 'en') { - part[0] = coord[1]; - part[1] = coord[0]; - } - parts[i] = part.join(','); - } - var value = parts.join(' '); - var node = this.createElementNS('gml:coordinates'); - this.setAttributeNS(node, null, 'decimal', '.'); - this.setAttributeNS(node, null, 'cs', ','); - this.setAttributeNS(node, null, 'ts', ' '); - node.appendChild(this.createTextNode(value)); - return node; - }, - 'LineString': function(geometry) { - var node = this.createElementNS('gml:LineString'); - this.writeNode('coordinates', geometry.getCoordinates(), null, node); - return node; - }, - 'Polygon': function(geometry) { - var node = this.createElementNS('gml:Polygon'); - var coordinates = geometry.getCoordinates(); - /** - * Though there continues to be ambiguity around this, GML references - * ISO 19107, which says polygons have counter-clockwise exterior rings - * and clockwise interior rings. The ambiguity comes because the - * the Simple Feature Access - SQL spec (ISO 19125-2) says that no - * winding order is enforced. Anyway, we write out counter-clockwise - * exterior and clockwise interior here but accept either when reading. - */ - this.writeNode('outerBoundaryIs', coordinates[0].reverse(), null, node); - for (var i = 1; i < coordinates.length; ++i) { - this.writeNode('innerBoundaryIs', coordinates[i].reverse(), null, node); - } - return node; - }, - 'outerBoundaryIs': function(ring) { - var node = this.createElementNS('gml:outerBoundaryIs'); - this.writeNode('LinearRing', ring, null, node); - return node; - }, - 'innerBoundaryIs': function(ring) { - var node = this.createElementNS('gml:innerBoundaryIs'); - this.writeNode('LinearRing', ring, null, node); - return node; - }, - 'LinearRing': function(ring) { - var node = this.createElementNS('gml:LinearRing'); - this.writeNode('coordinates', ring, null, node); - return node; - }, - 'Box': function(extent) { - var node = this.createElementNS('gml:Box'); - var coordinates = [ - [extent[0], extent[1]], - [extent[2], extent[3]] - ]; - this.writeNode('coordinates', coordinates, null, node); - // srsName attribute is optional for gml:Box - if (goog.isDefAndNotNull(this.srsName)) { - node.setAttribute('srsName', this.srsName); - } - return node; - } - }); -}; -goog.inherits(ol.parser.ogc.GML_v2, ol.parser.ogc.GML); - - -/** - * @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as - * GML. - * @param {olx.parser.GMLWriteOptions=} opt_options Write options. - * @return {string} A string representing the GML document. - * @todo stability experimental - */ -ol.parser.ogc.GML_v2.prototype.write = function(obj, opt_options) { - this.applyWriteOptions(obj, opt_options); - var root = this.writeNode('FeatureCollection', obj.features, - 'http://www.opengis.net/wfs'); - this.setAttributeNS( - root, 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation', this.schemaLocation); - var gml = this.serialize(root); - delete this.srsName; - delete this.axisOrientation; - return gml; -}; diff --git a/old/src/ol/parser/ogc/gmlparser_v3.js b/old/src/ol/parser/ogc/gmlparser_v3.js deleted file mode 100644 index b22f755e3e..0000000000 --- a/old/src/ol/parser/ogc/gmlparser_v3.js +++ /dev/null @@ -1,442 +0,0 @@ -goog.provide('ol.parser.ogc.GML_v3'); - -goog.require('goog.array'); -goog.require('goog.functions'); -goog.require('goog.object'); -goog.require('ol.geom.GeometryType'); -goog.require('ol.parser.ogc.GML'); - - - -/** - * Read and write [GML](http://www.opengeospatial.org/standards/gml) - * version 3.1.1 - * - * @constructor - * @param {olx.parser.GMLOptions=} opt_options Optional configuration object. - * @extends {ol.parser.ogc.GML} - * @todo stability experimental - */ -ol.parser.ogc.GML_v3 = function(opt_options) { - this.schemaLocation = 'http://www.opengis.net/gml ' + - 'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' + - '1.0.0/gmlsf.xsd'; - goog.base(this, opt_options); - this.featureNSWriters_['_geometry'] = function(obj) { - var node = this.createElementNS('feature:' + obj.name, - this.featureNS); - var geometry = obj.value; - var type = geometry.getType(), child; - if (type === ol.geom.GeometryType.POINT) { - child = this.writeNode('Point', geometry, null, node); - } else if (type === ol.geom.GeometryType.MULTI_POINT) { - child = this.writeNode('MultiPoint', geometry, null, node); - } else if (type === ol.geom.GeometryType.LINE_STRING) { - if (this.curve === true) { - child = this.writeNode('Curve', geometry, null, node); - } else { - child = this.writeNode('LineString', geometry, null, node); - } - } else if (type === ol.geom.GeometryType.LINEAR_RING) { - child = this.writeNode('LinearRing', geometry.getCoordinates(), null, - node); - } else if (type === ol.geom.GeometryType.MULTI_LINE_STRING) { - if (this.multiCurve === false) { - child = this.writeNode('MultiLineString', geometry, null, node); - } else { - child = this.writeNode('MultiCurve', geometry, null, node); - } - } else if (type === ol.geom.GeometryType.POLYGON) { - if (this.surface === true) { - child = this.writeNode('Surface', geometry, null, node); - } else { - child = this.writeNode('Polygon', geometry, null, node); - } - } else if (type === ol.geom.GeometryType.MULTI_POLYGON) { - if (this.multiSurface === false) { - child = this.writeNode('MultiPolygon', geometry, null, node); - } else { - child = this.writeNode('MultiSurface', geometry, null, node); - } - } else if (type === ol.geom.GeometryType.GEOMETRY_COLLECTION) { - child = this.writeNode('MultiGeometry', geometry, null, node); - } - if (goog.isDefAndNotNull(this.srsName)) { - this.setAttributeNS(child, null, 'srsName', this.srsName); - } - return node; - }; - goog.object.extend(this.readers['http://www.opengis.net/gml'], { - '_inherit': goog.functions.sequence( - this.readers['http://www.opengis.net/gml']['_inherit'], - function(node, obj, container) { - // SRSReferenceGroup attributes - var dim = parseInt(node.getAttribute('srsDimension'), 10) || - (container && container.srsDimension); - if (dim) { - obj.srsDimension = dim; - } - }), - 'featureMembers': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'Curve': function(node, container) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, coordinates, container]); - this.readChildNodes(node, coordinates); - var linestring = { - type: ol.geom.GeometryType.LINE_STRING, - coordinates: coordinates[0] - }; - // in the case of a multi geometry this is parts - if (goog.isArray(container)) { - container.push(linestring); - } else { - container.geometry = linestring; - } - }, - 'segments': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'LineStringSegment': function(node, container) { - var coordinates = []; - this.readChildNodes(node, coordinates); - container.push(coordinates[0]); - }, - 'pos': function(node, obj) { - var str = this.getChildValue(node).replace( - this.regExes.trimSpace, ''); - var coords = goog.array.map(str.split(this.regExes.splitSpace), - parseFloat); - if (this.axisOrientation.substr(0, 2) === 'en') { - obj.push([coords]); - } else { - if (coords.length === 2) { - obj.push([coords.reverse()]); - } else if (coords.length === 3) { - obj.push([[coords[1], coords[0], coords[2]]]); - } - } - }, - 'posList': function(node, obj) { - var str = this.getChildValue(node).replace( - this.regExes.trimSpace, ''); - var coords = str.split(this.regExes.splitSpace); - // The "dimension" attribute is from the GML 3.0.1 spec. - var dim = obj.srsDimension || - parseInt(node.getAttribute('srsDimension') || - node.getAttribute('dimension'), 10) || 2; - var x, y, z; - var numPoints = coords.length / dim; - var points = new Array(numPoints); - for (var i = 0, ii = coords.length; i < ii; i += dim) { - x = parseFloat(coords[i]); - y = parseFloat(coords[i + 1]); - var xy = this.axisOrientation.substr(0, 2) === 'en'; - if (dim === 3) { - if (xy) { - points[i / dim] = [x, y, parseFloat(coords[i + 2])]; - } else { - points[i / dim] = [y, x, parseFloat(coords[i + 2])]; - } - } else if (dim === 2) { - if (xy) { - points[i / dim] = [x, y]; - } else { - points[i / dim] = [y, x]; - } - } - } - obj.push(points); - }, - 'Surface': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'patches': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'PolygonPatch': function(node, obj) { - this.readers[this.defaultNamespaceURI]['Polygon'].apply(this, - [node, obj]); - }, - 'exterior': function(node, container) { - var coordinates = []; - this.readChildNodes(node, coordinates); - container.outer = coordinates[0][0]; - }, - 'interior': function(node, container) { - var coordinates = []; - this.readChildNodes(node, coordinates); - container.inner.push(coordinates[0][0]); - }, - 'MultiCurve': function(node, container) { - var parts = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, parts, container]); - this.readChildNodes(node, parts); - container.geometry = { - type: ol.geom.GeometryType.MULTI_LINE_STRING, - parts: parts - }; - }, - 'curveMember': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'MultiSurface': function(node, container) { - var parts = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, parts, container]); - this.readChildNodes(node, parts); - container.geometry = { - type: ol.geom.GeometryType.MULTI_POLYGON, - parts: parts - }; - }, - 'surfaceMember': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'surfaceMembers': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'pointMembers': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'lineStringMembers': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'polygonMembers': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'geometryMembers': function(node, obj) { - this.readChildNodes(node, obj); - }, - 'Envelope': function(node, container) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['_inherit'].apply(this, - [node, coordinates, container]); - this.readChildNodes(node, coordinates); - container.projection = node.getAttribute('srsName'); - container.bounds = [ - coordinates[0][0], coordinates[0][1], - coordinates[1][0], coordinates[1][1] - ]; - }, - 'lowerCorner': function(node, envelope) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['pos'].apply(this, - [node, coordinates]); - envelope.push(coordinates[0][0]); - }, - 'upperCorner': function(node, envelope) { - var coordinates = []; - this.readers[this.defaultNamespaceURI]['pos'].apply(this, - [node, coordinates]); - envelope.push(coordinates[0][0]); - } - }); - goog.object.extend(this.writers['http://www.opengis.net/gml'], { - 'featureMembers': function(features) { - var node = this.createElementNS('gml:featureMembers'); - for (var i = 0, ii = features.length; i < ii; ++i) { - this.writeNode('_typeName', features[i], this.featureNS, node); - } - return node; - }, - 'Point': function(geometry) { - var node = this.createElementNS('gml:Point'); - this.writeNode('pos', geometry.getCoordinates(), null, node); - return node; - }, - 'pos': function(point) { - // only 2d for simple features profile - var pos; - if (this.axisOrientation.substr(0, 2) === 'en') { - pos = (point[0] + ' ' + point[1]); - } else { - pos = (point[1] + ' ' + point[0]); - } - var node = this.createElementNS('gml:pos'); - node.appendChild(this.createTextNode(pos)); - return node; - }, - 'LineString': function(geometry) { - var node = this.createElementNS('gml:LineString'); - this.writeNode('posList', geometry.getCoordinates(), null, node); - return node; - }, - 'Curve': function(geometry) { - var node = this.createElementNS('gml:Curve'); - this.writeNode('segments', geometry, null, node); - return node; - }, - 'segments': function(geometry) { - var node = this.createElementNS('gml:segments'); - this.writeNode('LineStringSegment', geometry, null, node); - return node; - }, - 'LineStringSegment': function(geometry) { - var node = this.createElementNS('gml:LineStringSegment'); - this.writeNode('posList', geometry.getCoordinates(), null, node); - return node; - }, - 'posList': function(points) { - // only 2d for simple features profile - var len = points.length; - var parts = new Array(len); - var point; - for (var i = 0; i < len; ++i) { - point = points[i]; - if (this.axisOrientation.substr(0, 2) === 'en') { - parts[i] = point[0] + ' ' + point[1]; - } else { - parts[i] = point[1] + ' ' + point[0]; - } - } - var node = this.createElementNS('gml:posList'); - node.appendChild(this.createTextNode(parts.join(' '))); - return node; - }, - 'Surface': function(geometry) { - var node = this.createElementNS('gml:Surface'); - this.writeNode('patches', geometry, null, node); - return node; - }, - 'patches': function(geometry) { - var node = this.createElementNS('gml:patches'); - this.writeNode('PolygonPatch', geometry, null, node); - return node; - }, - 'PolygonPatch': function(geometry) { - var node = this.createElementNS('gml:PolygonPatch'); - node.setAttribute('interpolation', 'planar'); - var coordinates = geometry.getCoordinates(); - this.writeNode('exterior', coordinates[0].reverse(), null, node); - for (var i = 1, len = coordinates.length; i < len; ++i) { - this.writeNode('interior', coordinates[i].reverse(), null, node); - } - return node; - }, - 'Polygon': function(geometry) { - var node = this.createElementNS('gml:Polygon'); - var coordinates = geometry.getCoordinates(); - /** - * Though there continues to be ambiguity around this, GML references - * ISO 19107, which says polygons have counter-clockwise exterior rings - * and clockwise interior rings. The ambiguity comes because the - * the Simple Feature Access - SQL spec (ISO 19125-2) says that no - * winding order is enforced. Anyway, we write out counter-clockwise - * exterior and clockwise interior here but accept either when reading. - */ - this.writeNode('exterior', coordinates[0].reverse(), null, node); - for (var i = 1, len = coordinates.length; i < len; ++i) { - this.writeNode('interior', coordinates[i].reverse(), null, node); - } - return node; - }, - 'exterior': function(ring) { - var node = this.createElementNS('gml:exterior'); - this.writeNode('LinearRing', ring, null, node); - return node; - }, - 'interior': function(ring) { - var node = this.createElementNS('gml:interior'); - this.writeNode('LinearRing', ring, null, node); - return node; - }, - 'LinearRing': function(ring) { - var node = this.createElementNS('gml:LinearRing'); - this.writeNode('posList', ring, null, node); - return node; - }, - 'MultiCurve': function(geometry) { - var node = this.createElementNS('gml:MultiCurve'); - var components = geometry.getComponents(); - for (var i = 0, len = components.length; i < len; ++i) { - this.writeNode('curveMember', components[i], null, node); - } - return node; - }, - 'curveMember': function(geometry) { - var node = this.createElementNS('gml:curveMember'); - if (this.curve) { - this.writeNode('Curve', geometry, null, node); - } else { - this.writeNode('LineString', geometry, null, node); - } - return node; - }, - 'MultiSurface': function(geometry) { - var node = this.createElementNS('gml:MultiSurface'); - var components = geometry.getComponents(); - for (var i = 0, len = components.length; i < len; ++i) { - this.writeNode('surfaceMember', components[i], null, node); - } - return node; - }, - 'surfaceMember': function(polygon) { - var node = this.createElementNS('gml:surfaceMember'); - if (this.surface) { - this.writeNode('Surface', polygon, null, node); - } else { - this.writeNode('Polygon', polygon, null, node); - } - return node; - }, - 'Envelope': function(bounds) { - var node = this.createElementNS('gml:Envelope'); - this.writeNode('lowerCorner', bounds, null, node); - this.writeNode('upperCorner', bounds, null, node); - // srsName attribute is required for gml:Envelope - if (goog.isDef(this.srsName)) { - node.setAttribute('srsName', this.srsName); - } - return node; - }, - 'lowerCorner': function(bounds) { - // only 2d for simple features profile - var pos; - if (this.axisOrientation.substr(0, 2) === 'en') { - pos = (bounds[0] + ' ' + bounds[1]); - } else { - pos = (bounds[1] + ' ' + bounds[0]); - } - var node = this.createElementNS('gml:lowerCorner'); - node.appendChild(this.createTextNode(pos)); - return node; - }, - 'upperCorner': function(bounds) { - // only 2d for simple features profile - var pos; - if (this.axisOrientation.substr(0, 2) === 'en') { - pos = (bounds[2] + ' ' + bounds[3]); - } else { - pos = (bounds[3] + ' ' + bounds[2]); - } - var node = this.createElementNS('gml:upperCorner'); - node.appendChild(this.createTextNode(pos)); - return node; - } - }); -}; -goog.inherits(ol.parser.ogc.GML_v3, ol.parser.ogc.GML); - - -/** - * @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as - * XML. - * @param {olx.parser.GMLWriteOptions=} opt_options Write options. - * @return {string} An string representing the XML document. - * @todo stability experimental - */ -ol.parser.ogc.GML_v3.prototype.write = function(obj, opt_options) { - this.applyWriteOptions(obj, opt_options); - var root = this.writeNode('featureMembers', obj.features); - this.setAttributeNS( - root, 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation', this.schemaLocation); - var gml = this.serialize(root); - delete this.srsName; - delete this.axisOrientation; - return gml; -};