Merge pull request #1294 from bartvde/gmlgeom

GML parser should write out all geometry attributes and respect their names (r=@ahocevar)
This commit is contained in:
Bart van den Eijnden
2013-11-25 00:36:51 -08:00
8 changed files with 100 additions and 42 deletions

View File

@@ -538,9 +538,6 @@
* will be automatically configured from the GML.
* @property {Array.<string>|string|undefined} featureType The local
* (without prefix) feature typeName(s).
* @property {string|undefined} geometryName Name of geometry element.
* Defaults to `geometry`. If null, it will be set on <read> when the
* first geometry is parsed.
* @property {boolean|undefined} multiCurve Write gml:MultiCurve instead of
* gml:MultiLineString. Since the latter is deprecated in GML 3, the
* default is `true`. This only applies to GML version 3.

View File

@@ -166,7 +166,7 @@ ol.parser.ogc.Filter_v1_0_0.prototype.writeSpatial_ = function(filter, name) {
} else {
var child;
if (geom !== null) {
child = this.writeNode('_geometry', geom,
child = this.writeNode('_geometry', {value: geom},
this.gml_.featureNS).firstChild;
} else if (bbox.length === 4) {
child = this.writeNode('Box', bbox,

View File

@@ -224,7 +224,7 @@ ol.parser.ogc.Filter_v1_1_0.prototype.writeSpatial_ = function(filter, name) {
} else {
var child;
if (geom !== null) {
child = this.writeNode('_geometry', geom,
child = this.writeNode('_geometry', {value: geom},
this.gml_.featureNS).firstChild;
} else if (bbox.length === 4) {
child = this.writeNode('Envelope', bbox,

View File

@@ -317,10 +317,10 @@ ol.parser.ogc.GML = function(opt_options) {
obj.features.push(feature);
},
'_geometry': function(node, obj) {
if (!this.geometryName) {
this.geometryName = node.nodeName.split(':').pop();
}
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();
@@ -387,7 +387,8 @@ ol.parser.ogc.GML = function(opt_options) {
},
'geometryMember': function(geometry) {
var node = this.createElementNS('gml:geometryMember');
var child = this.writeNode('_geometry', geometry, this.featureNS);
var child = this.writeNode('_geometry', {value: geometry},
this.featureNS);
node.appendChild(child.firstChild);
return node;
}
@@ -418,23 +419,25 @@ ol.parser.ogc.GML = function(opt_options) {
if (goog.isDef(fid)) {
this.setAttributeNS(node, this.defaultNamespaceURI, 'fid', fid);
}
if (feature.getGeometry() !== null) {
this.writeNode('_geometry', feature.getGeometry(), this.featureNS,
node);
}
var attributes = feature.getAttributes(true);
var attributes = feature.getAttributes();
for (var name in attributes) {
var value = attributes[name];
if (goog.isDefAndNotNull(value)) {
this.writeNode('_attribute', {name: name, value: value},
this.featureNS, node);
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(geometry) {
var node = this.createElementNS('feature:' + this.geometryName,
'_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);

View File

@@ -22,9 +22,10 @@ ol.parser.ogc.GML_v3 = function(opt_options) {
'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' +
'1.0.0/gmlsf.xsd';
goog.base(this, opt_options);
this.featureNSWiters_['_geometry'] = function(geometry) {
var node = this.createElementNS('feature:' + this.geometryName,
this.featureNSWiters_['_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);