Sensible axisOrientation and srsName defaults

This commit is contained in:
ahocevar
2013-07-29 16:20:14 +02:00
parent 023d3faf3c
commit 6f3fa14c53
6 changed files with 45 additions and 56 deletions

View File

@@ -357,9 +357,9 @@
/**
* @typedef {Object} ol.parser.GMLOptions
* @property {string|undefined} axisOrientation The axis orientation as
* specified in Proj4. If this is not provided, 'enu' will be used for GML2,
* and the projection's axis orientation for GML3, with a fallback to 'enu'
* if `projection` was not configured and is not provided by the data.
* specified in Proj4. If this is not provided, the projection's axis
* orientation will be used if `projection` is not overridden (i.e. the
* projection defined in the data is used). Otherwise the default is 'enu'.
* @property {boolean|undefined} curve Write gml:Curve instead of
* gml:LineString elements. This also affects the elements in multi-part
* geometries. Default is `false´. This only applies to GML version 3.

View File

@@ -29,7 +29,7 @@ ol.parser.ogc.GML = function(opt_options) {
var options = /** @type {ol.parser.GMLOptions} */
(goog.isDef(opt_options) ? opt_options : {});
this.axisOrientation = goog.isDef(options.axisOrientation) ?
options.axisOrientation : 'enu';
options.axisOrientation : null;
this.extractAttributes = goog.isDef(options.extractAttributes) ?
options.extractAttributes : true;
this.surface = goog.isDef(options.surface) ?
@@ -47,14 +47,13 @@ ol.parser.ogc.GML = function(opt_options) {
* @private
* @type {string|undefined}
*/
this.srsName_ = goog.isNull(this.srsName) ? undefined : this.srsName;
this.srsName_;
/**
* @private
* @type {string|undefined}
*/
this.axisOrientation_ = goog.isNull(this.srsName) ? undefined :
ol.proj.get(this.srsName).getAxisOrientation();
this.axisOrientation_;
if (goog.isDef(options.schemaLocation)) {
this.schemaLocation = options.schemaLocation;
@@ -319,25 +318,24 @@ ol.parser.ogc.GML = function(opt_options) {
}
// TODO: Deal with GML documents that do not have the same SRS for all
// geometries.
var srsName;
if (!goog.isDef(this.srsName_)) {
for (var i = node.childNodes.length - 1; i >= 0; --i) {
var child = node.childNodes[i];
if (child.nodeType == 1) {
var srsName = child.getAttribute('srsName');
srsName = child.getAttribute('srsName');
if (goog.isDef(srsName)) {
this.srsName_ = srsName.replace(ol.parser.ogc.GML.regExes.epsg,
'EPSG:');
if (!goog.isDef(this.axisOrientation_)) {
var projection = ol.proj.get(this.srsName_);
if (!goog.isNull(projection)) {
this.axisOrientation_ = projection.getAxisOrientation();
}
}
this.srsName_ = srsName;
}
break;
}
}
}
if (!goog.isDef(this.axisOrientation_)) {
if (goog.isDef(srsName)) {
this.axisOrientation_ = ol.proj.get(srsName).getAxisOrientation();
}
}
this.readChildNodes(node, obj);
},
'_attribute': function(node, obj) {
@@ -516,12 +514,13 @@ ol.parser.ogc.GML.prototype.read = function(data) {
if (data && data.nodeType == 9) {
data = data.documentElement;
}
this.srsName_ = goog.isNull(this.srsName) ? undefined : this.srsName;
this.axisOrientation_ = goog.isNull(this.axisOrientation) ?
undefined : this.axisOrientation;
var obj = /** @type {ol.parser.ReadFeaturesResult} */
({features: [], metadata: {}});
this.readNode(data, obj, true);
obj.metadata.projection = this.srsName_;
this.srsName_ = goog.isNull(this.srsName) ? undefined : this.srsName;
delete this.axisOrientation_;
return obj;
};

View File

@@ -45,7 +45,7 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
for (var i = 0; i < numCoordinates; ++i) {
var coord = coordinates[i];
var part = goog.array.concat(coord);
if (this.axisOrientation.substr(0, 2) !== 'en') {
if (this.getAxisOrientation().substr(0, 2) !== 'en') {
part[0] = coord[1];
part[1] = coord[0];
}
@@ -101,8 +101,8 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
this.writeNode('coordinates', [[extent.minX, extent.minY],
[extent.maxX, extent.maxY]], null, node);
// srsName attribute is optional for gml:Box
if (goog.isDef(this.srsName)) {
node.setAttribute('srsName', this.srsName);
if (goog.isDef(this.getSrsName())) {
node.setAttribute('srsName', this.getSrsName());
}
return node;
}
@@ -111,14 +111,6 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
goog.inherits(ol.parser.ogc.GML_v2, ol.parser.ogc.GML);
/**
* @return {string?} Axis orientation that was configured with this instance.
*/
ol.parser.ogc.GML_v2.prototype.getAxisOrientation = function() {
return this.axisOrientation;
};
/**
* @param {Object} obj Object structure to write out as XML.
* @return {string} An string representing the XML document.
@@ -129,5 +121,8 @@ ol.parser.ogc.GML_v2.prototype.write = function(obj) {
this.setAttributeNS(
root, 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation', this.schemaLocation);
this.srsName_ = goog.isNull(this.srsName) ? undefined : this.srsName;
this.axisOrientation_ = goog.isNull(this.axisOrientation) ?
undefined : this.axisOrientation;
return this.serialize(root);
};

View File

@@ -55,8 +55,8 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
} else if (type === ol.geom.GeometryType.GEOMETRYCOLLECTION) {
child = this.writeNode('MultiGeometry', geometry, null, node);
}
if (goog.isDef(this.srsName)) {
this.setAttributeNS(child, null, 'srsName', this.srsName);
if (goog.isDef(this.getSrsName())) {
this.setAttributeNS(child, null, 'srsName', this.getSrsName());
}
return node;
};
@@ -238,7 +238,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
'pos': function(point) {
// only 2d for simple features profile
var pos;
if (this.axisOrientation.substr(0, 2) === 'en') {
if (this.getAxisOrientation().substr(0, 2) === 'en') {
pos = (point[0] + ' ' + point[1]);
} else {
pos = (point[1] + ' ' + point[0]);
@@ -274,7 +274,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
var point;
for (var i = 0; i < len; ++i) {
point = points[i];
if (this.axisOrientation.substr(0, 2) === 'en') {
if (this.getAxisOrientation().substr(0, 2) === 'en') {
parts[i] = point[0] + ' ' + point[1];
} else {
parts[i] = point[1] + ' ' + point[0];
@@ -373,15 +373,15 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
this.writeNode('lowerCorner', bounds, null, node);
this.writeNode('upperCorner', bounds, null, node);
// srsName attribute is required for gml:Envelope
if (this.srsName) {
node.setAttribute('srsName', this.srsName);
if (this.getSrsName()) {
node.setAttribute('srsName', this.getSrsName());
}
return node;
},
'lowerCorner': function(bounds) {
// only 2d for simple features profile
var pos;
if (this.axisOrientation.substr(0, 2) === 'en') {
if (this.getAxisOrientation().substr(0, 2) === 'en') {
pos = (bounds.left + ' ' + bounds.bottom);
} else {
pos = (bounds.bottom + ' ' + bounds.left);
@@ -416,5 +416,8 @@ ol.parser.ogc.GML_v3.prototype.write = function(obj) {
this.setAttributeNS(
root, 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation', this.schemaLocation);
this.srsName_ = goog.isNull(this.srsName) ? undefined : this.srsName;
this.axisOrientation_ = goog.isNull(this.axisOrientation) ?
undefined : this.axisOrientation;
return this.serialize(root);
};