I am trying to write out my geometry in gml format after it is drawn in OpenLayers. Actually it is working fine, I get the gml like this:
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates decimal="." cs="," ts=" ">8.62975388121127,46.34818691143132 8.761589818711352,46.590322794368646 9.124138646836665,46.43911409951752 8.805535131211348,46.24951148519901 8.62975388121127,46.34818691143132</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
But unfortunately I need it to have the coordinate system (srsName) defined in it, like this:
<gml:Polygon srsName="EPSG:4326" >
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates decimal="." cs="," ts=" ">8.62975388121127,46.34818691143132 8.761589818711352,46.590322794368646 9.124138646836665,46.43911409951752 8.805535131211348,46.24951148519901 8.62975388121127,46.34818691143132</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
Here is my code:
draw.events.register('featureadded', this, function(evt) {
var feat1 = vectors.features;
var gml = new OpenLayers.Format.GML({
format: OpenLayers.Format.GML.v3,
formatOptions: {
srsName: "urn:x-ogc:def:crs:EPSG:4326",
}
});
for (var i=0; i<feat1.length; i++) {
var geomtransformed = feat1[i].geometry.transform(new OpenLayers.Projection("EPSG:3857"), new OpenLayers.Projection("EPSG:4326"));
geomout = gml.buildGeometry.polygon.apply(gml,[geomtransformed]);
console.log(geomout)
}
});
This is working but the srsName does not appear in the gml.
So could you please advise me if it is possible to transform vector feature to gml with writing the srsName into the gml, and if yes, how?