Add GML2 serializer for Point
This commit is contained in:
@@ -498,6 +498,16 @@ ol.format.GML2.prototype.writeMultiCurveOrLineString_ = function(node, geometry,
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GML2.prototype.writePoint_ = function(node, geometry, objectStack) {
|
ol.format.GML2.prototype.writePoint_ = function(node, geometry, objectStack) {
|
||||||
|
var context = objectStack[objectStack.length - 1];
|
||||||
|
var srsName = context['srsName'];
|
||||||
|
if (srsName) {
|
||||||
|
node.setAttribute('srsName', srsName);
|
||||||
|
}
|
||||||
|
var coordinates = this.createCoordinatesNode_(node.namespaceURI);
|
||||||
|
node.appendChild(coordinates);
|
||||||
|
var point = geometry.getCoordinates();
|
||||||
|
var coord = this.getCoords_(point, srsName);
|
||||||
|
ol.format.XSD.writeStringTextNode(coordinates, coord);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -196,6 +196,33 @@ describe('ol.format.GML2', function() {
|
|||||||
|
|
||||||
expect(node).to.xmleql(ol.xml.parse(expected));
|
expect(node).to.xmleql(ol.xml.parse(expected));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can serialize a Point', function() {
|
||||||
|
var expected =
|
||||||
|
'<layer xmlns="http://www.openlayers.org/" fid="1">' +
|
||||||
|
' <geometry>' +
|
||||||
|
' <Point xmlns="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="EPSG:4326">' +
|
||||||
|
' <coordinates ' +
|
||||||
|
' decimal="." cs="," ts=" ">' +
|
||||||
|
' 2,1.1' +
|
||||||
|
' </coordinates>' +
|
||||||
|
' </Point>' +
|
||||||
|
' </geometry>' +
|
||||||
|
' </layer>';
|
||||||
|
|
||||||
|
var feature = new ol.Feature({
|
||||||
|
geometry: new ol.geom.Point([1.1, 2])
|
||||||
|
});
|
||||||
|
feature.setId(1);
|
||||||
|
var objectStack = [{
|
||||||
|
featureNS: featureNS,
|
||||||
|
srsName: 'EPSG:4326'
|
||||||
|
}];
|
||||||
|
format.writeFeatureElement(node, feature, objectStack);
|
||||||
|
|
||||||
|
expect(node).to.xmleql(ol.xml.parse(expected));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user