Add GML2 serializer for MultiSurface and MultiPolygon
This commit is contained in:
@@ -596,6 +596,33 @@ ol.format.GML2.prototype.writeLinearRing_ = function(node, geometry, objectStack
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GML2.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStack) {
|
ol.format.GML2.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry, objectStack) {
|
||||||
|
var context = objectStack[objectStack.length - 1];
|
||||||
|
var srsName = context['srsName'];
|
||||||
|
var surface = context['surface'];
|
||||||
|
if (srsName) {
|
||||||
|
node.setAttribute('srsName', srsName);
|
||||||
|
}
|
||||||
|
var polygons = geometry.getPolygons();
|
||||||
|
ol.xml.pushSerializeAndPop({node: node, srsName: srsName, surface: surface},
|
||||||
|
ol.format.GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_,
|
||||||
|
this.MULTIGEOMETRY_MEMBER_NODE_FACTORY_, polygons,
|
||||||
|
objectStack, undefined, this);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {ol.geom.Polygon} polygon Polygon geometry.
|
||||||
|
* @param {Array.<*>} objectStack Node stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML2.prototype.writeSurfaceOrPolygonMember_ = function(node, polygon, objectStack) {
|
||||||
|
var child = this.GEOMETRY_NODE_FACTORY_(
|
||||||
|
polygon, objectStack);
|
||||||
|
if (child) {
|
||||||
|
node.appendChild(child);
|
||||||
|
this.writeSurfaceOrPolygon_(child, polygon, objectStack);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -603,6 +630,7 @@ ol.format.GML2.prototype.writeMultiSurfaceOrPolygon_ = function(node, geometry,
|
|||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {Array.<*>} objectStack Node stack.
|
* @param {Array.<*>} objectStack Node stack.
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.format.GML2.prototype.writeEnvelope = function(node, extent, objectStack) {
|
ol.format.GML2.prototype.writeEnvelope = function(node, extent, objectStack) {
|
||||||
};
|
};
|
||||||
@@ -705,3 +733,18 @@ ol.format.GML2.MULTIGEOMETRY_TO_MEMBER_NODENAME_ = {
|
|||||||
'MultiPolygon': 'polygonMember',
|
'MultiPolygon': 'polygonMember',
|
||||||
'MultiSurface': 'surfaceMember'
|
'MultiSurface': 'surfaceMember'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, Object.<string, ol.XmlSerializer>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML2.SURFACEORPOLYGONMEMBER_SERIALIZERS_ = {
|
||||||
|
'http://www.opengis.net/gml': {
|
||||||
|
'surfaceMember': ol.xml.makeChildAppender(
|
||||||
|
ol.format.GML2.prototype.writeSurfaceOrPolygonMember_),
|
||||||
|
'polygonMember': ol.xml.makeChildAppender(
|
||||||
|
ol.format.GML2.prototype.writeSurfaceOrPolygonMember_)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -285,6 +285,41 @@ 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 Multi Polygon', function() {
|
||||||
|
var expected =
|
||||||
|
'<layer xmlns="http://www.openlayers.org/" fid="1">' +
|
||||||
|
' <geometry>' +
|
||||||
|
' <MultiPolygon xmlns="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="EPSG:4326">' +
|
||||||
|
' <polygonMember>' +
|
||||||
|
' <Polygon srsName="EPSG:4326">' +
|
||||||
|
' <outerBoundaryIs>' +
|
||||||
|
' <LinearRing srsName="EPSG:4326">' +
|
||||||
|
' <coordinates ' +
|
||||||
|
' decimal="." cs="," ts=" ">' +
|
||||||
|
' 2,1.1 4.2,3 6,5.2' +
|
||||||
|
' </coordinates>' +
|
||||||
|
' </LinearRing>' +
|
||||||
|
' </outerBoundaryIs>' +
|
||||||
|
' </Polygon>' +
|
||||||
|
' </polygonMember>' +
|
||||||
|
' </MultiPolygon>' +
|
||||||
|
' </geometry>' +
|
||||||
|
' </layer>';
|
||||||
|
|
||||||
|
var feature = new ol.Feature({
|
||||||
|
geometry: new ol.geom.MultiPolygon([[[[1.1, 2], [3, 4.2], [5.2, 6]]]])
|
||||||
|
});
|
||||||
|
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