incorporate review from @ahocevar

This commit is contained in:
Bart van den Eijnden
2013-05-15 14:50:37 +02:00
parent 5ad4734c24
commit 2ad3ee6f99
7 changed files with 34 additions and 31 deletions

View File

@@ -314,8 +314,8 @@
* @property {Array.<string>|string|undefined} featureType The local
* (without prefix) feature typeName(s).
* @property {string|undefined} geometryName Geometry element name.
* @property {boolean|undefined} xy Order of the GML coordinate true:(x,y) or
* false:(y,x). Default is `true`.
* @property {string|undefined} axisOrientation The axis orientation as
* specified in Proj4. The default is 'enu'.
*/
/**
@@ -327,8 +327,8 @@
* @property {Array.<string>|string|undefined} featureType The local
* (without prefix) feature typeName(s).
* @property {string|undefined} geometryName Geometry element name.
* @property {boolean|undefined} xy Order of the GML coordinate true:(x,y) or
* false:(y,x). Default is `true`.
* @property {string|undefined} axisOrientation The axis orientation as
* specified in Proj4. The default is 'enu'.
* @property {boolean|undefined} surface Write gml:Surface instead of
* gml:Polygon elements. This also affects the elements in multi-part
* geometries. Default is `false´.

View File

@@ -349,24 +349,26 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
this.addFeatures(features);
};
var options = {callback: callback, projection:
this.getSource().getProjection()};
if (goog.isString(data)) {
if (goog.isFunction(parser.readFeaturesFromStringAsync)) {
parser.readFeaturesFromStringAsync(data, goog.bind(addFeatures, this),
{callback: callback});
options);
} else {
goog.asserts.assert(goog.isFunction(parser.readFeaturesFromString),
'Expected a parser with readFeaturesFromString method.');
features = parser.readFeaturesFromString(data, {callback: callback});
features = parser.readFeaturesFromString(data, options);
addFeatures.call(this, features);
}
} else if (goog.isObject(data)) {
if (goog.isFunction(parser.readFeaturesFromObjectAsync)) {
parser.readFeaturesFromObjectAsync(data, goog.bind(addFeatures, this),
{callback: callback});
options);
} else {
goog.asserts.assert(goog.isFunction(parser.readFeaturesFromObject),
'Expected a parser with a readFeaturesFromObject method.');
features = parser.readFeaturesFromObject(data, {callback: callback});
features = parser.readFeaturesFromObject(data, options);
addFeatures.call(this, features);
}
} else {

View File

@@ -97,6 +97,7 @@ ol.parser.ReadFeaturesCallback;
/**
* @typedef {{callback: ol.parser.ReadFeaturesCallback}}
* @typedef {{callback: ol.parser.ReadFeaturesCallback,
* projection: ol.Projection}}
*/
ol.parser.ReadFeaturesOptions;

View File

@@ -29,8 +29,8 @@ ol.parser.ogc.GML = function(opt_options) {
if (goog.isDef(opt_options)) {
goog.object.extend(this, opt_options);
}
if (!goog.isDef(this.xy)) {
this.xy = true;
if (!goog.isDef(this.axisOrientation)) {
this.axisOrientation = 'enu';
}
if (!goog.isDef(this.extractAttributes)) {
this.extractAttributes = true;
@@ -182,7 +182,7 @@ ol.parser.ogc.GML = function(opt_options) {
var points = new Array(numPoints);
for (var i = 0; i < numPoints; ++i) {
coords = pointList[i].split(cs).map(parseFloat);
if (this.xy) {
if (this.axisOrientation.substr(0, 2) === 'en') {
points[i] = coords;
} else {
if (coords.length === 2) {
@@ -552,5 +552,8 @@ ol.parser.ogc.GML.prototype.createGeometry_ = function(container,
ol.parser.ogc.GML.prototype.readFeaturesFromString =
function(str, opt_options) {
this.readFeaturesOptions_ = opt_options;
if (goog.isDef(opt_options) && goog.isDef(opt_options.projection)) {
this.axisOrientation = opt_options.projection.getAxisOrientation();
}
return this.read(str).features;
};

View File

@@ -1,6 +1,6 @@
goog.provide('ol.parser.ogc.GML_v2');
goog.require('goog.dom.xml');
goog.require('goog.array');
goog.require('goog.object');
goog.require('ol.parser.ogc.GML');
@@ -44,18 +44,14 @@ ol.parser.ogc.GML_v2 = function(opt_options) {
var parts = new Array(numCoordinates);
for (var i = 0; i < numCoordinates; ++i) {
var coord = coordinates[i];
var str = '';
if (this.xy) {
str += coord[0] + ',' + coord[1];
} else {
str += coord[1] + ',' + coord[0];
var part = goog.array.concat(coord);
if (this.axisOrientation.substr(0, 2) !== 'en') {
part[0] = coord[1];
part[1] = coord[0];
}
if (coord.length === 3) {
str += ',' + coord[2];
}
parts[i] = str;
parts[i] = part.join(',');
}
var value = (numCoordinates === 1) ? parts[0] : parts.join(' ');
var value = parts.join(' ');
var node = this.createElementNS('gml:coordinates');
this.setAttributeNS(node, null, 'decimal', '.');
this.setAttributeNS(node, null, 'cs', ',');

View File

@@ -112,7 +112,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
var str = this.getChildValue(node).replace(
this.regExes.trimSpace, '');
var coords = str.split(this.regExes.splitSpace).map(parseFloat);
if (this.xy) {
if (this.axisOrientation.substr(0, 2) === 'en') {
obj.push([coords]);
} else {
if (coords.length === 2) {
@@ -136,14 +136,15 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
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 (this.xy) {
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 (this.xy) {
if (xy) {
points[i / dim] = [x, y];
} else {
points[i / dim] = [y, x];
@@ -248,7 +249,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
'pos': function(point) {
// only 2d for simple features profile
var pos;
if (this.xy) {
if (this.axisOrientation.substr(0, 2) === 'en') {
pos = (point[0] + ' ' + point[1]);
} else {
pos = (point[1] + ' ' + point[0]);
@@ -284,7 +285,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
var point;
for (var i = 0; i < len; ++i) {
point = points[i];
if (this.xy) {
if (this.axisOrientation.substr(0, 2) === 'en') {
parts[i] = point[0] + ' ' + point[1];
} else {
parts[i] = point[1] + ' ' + point[0];
@@ -383,7 +384,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
'lowerCorner': function(bounds) {
// only 2d for simple features profile
var pos;
if (this.xy) {
if (this.axisOrientation.substr(0, 2) === 'en') {
pos = (bounds.left + ' ' + bounds.bottom);
} else {
pos = (bounds.bottom + ' ' + bounds.left);
@@ -395,7 +396,7 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
'upperCorner': function(bounds) {
// only 2d for simple features profile
var pos;
if (this.xy) {
if (this.axisOrientation.substr(0, 2) === 'en') {
pos = (bounds.right + ' ' + bounds.top);
} else {
pos = (bounds.top + ' ' + bounds.right);