Add support for gml:MultiPolygon
This commit is contained in:
@@ -11,6 +11,7 @@ goog.require('ol.geom.GeometryCollection');
|
|||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
goog.require('ol.geom.MultiPoint');
|
goog.require('ol.geom.MultiPoint');
|
||||||
|
goog.require('ol.geom.MultiPolygon');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.xml');
|
goog.require('ol.xml');
|
||||||
@@ -136,6 +137,28 @@ ol.format.GML.readMultiLineString_ = function(node, objectStack) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.MultiPolygon|undefined} MultiPolygon.
|
||||||
|
*/
|
||||||
|
ol.format.GML.readMultiPolygon_ = function(node, objectStack) {
|
||||||
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
|
goog.asserts.assert(node.localName == 'MultiPolygon');
|
||||||
|
var polygons = ol.xml.pushParseAndPop(
|
||||||
|
/** @type {Array.<ol.geom.Polygon>} */ ([]),
|
||||||
|
ol.format.GML.MULTIPOLYGON_PARSERS_, node, objectStack);
|
||||||
|
if (goog.isDefAndNotNull(polygons)) {
|
||||||
|
var multiPolygon = new ol.geom.MultiPolygon(null);
|
||||||
|
multiPolygon.setPolygons(polygons);
|
||||||
|
return multiPolygon;
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {Array.<*>} objectStack Object stack.
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
@@ -162,6 +185,19 @@ ol.format.GML.lineStringMemberParser_ = function(node, objectStack) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.polygonMemberParser_ = function(node, objectStack) {
|
||||||
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
|
goog.asserts.assert(node.localName == 'polygonMember' ||
|
||||||
|
node.localName == 'polygonMembers');
|
||||||
|
ol.xml.parse(ol.format.GML.POLYGONMEMBER_PARSERS_, node, objectStack);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {Array.<*>} objectStack Object stack.
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
@@ -519,6 +555,7 @@ ol.format.GML.GEOMETRY_PARSERS_ = ol.xml.makeParsersNS(
|
|||||||
ol.format.GML.readMultiLineString_),
|
ol.format.GML.readMultiLineString_),
|
||||||
'LinearRing' : ol.xml.makeArrayPusher(ol.format.GML.readLinearRing_),
|
'LinearRing' : ol.xml.makeArrayPusher(ol.format.GML.readLinearRing_),
|
||||||
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
|
'Polygon': ol.xml.makeArrayPusher(ol.format.GML.readPolygon_),
|
||||||
|
'MultiPolygon': ol.xml.makeArrayPusher(ol.format.GML.readMultiPolygon_),
|
||||||
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_),
|
'Surface': ol.xml.makeArrayPusher(ol.format.GML.readSurface_),
|
||||||
'Curve': ol.xml.makeArrayPusher(ol.format.GML.readCurve_),
|
'Curve': ol.xml.makeArrayPusher(ol.format.GML.readCurve_),
|
||||||
'Envelope': ol.xml.makeArrayPusher(ol.format.GML.readEnvelope_)
|
'Envelope': ol.xml.makeArrayPusher(ol.format.GML.readEnvelope_)
|
||||||
@@ -575,6 +612,20 @@ ol.format.GML.MULTILINESTRING_PARSERS_ = ol.xml.makeParsersNS(
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.MULTIPOLYGON_PARSERS_ = ol.xml.makeParsersNS(
|
||||||
|
ol.format.GML.NAMESPACE_URIS_, {
|
||||||
|
'polygonMember': ol.xml.makeArrayPusher(
|
||||||
|
ol.format.GML.polygonMemberParser_),
|
||||||
|
'polygonMembers': ol.xml.makeArrayPusher(
|
||||||
|
ol.format.GML.polygonMemberParser_)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
@@ -599,6 +650,18 @@ ol.format.GML.LINESTRINGMEMBER_PARSERS_ = ol.xml.makeParsersNS(
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.POLYGONMEMBER_PARSERS_ = ol.xml.makeParsersNS(
|
||||||
|
ol.format.GML.NAMESPACE_URIS_, {
|
||||||
|
'Polygon': ol.xml.makeArrayPusher(
|
||||||
|
ol.format.GML.readPolygon_)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
|
||||||
|
|||||||
@@ -247,6 +247,92 @@ describe('ol.format.GML', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('multipolygon', function() {
|
||||||
|
|
||||||
|
it('can read a singular multipolygon geometry', function() {
|
||||||
|
var text =
|
||||||
|
'<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="foo">' +
|
||||||
|
' <gml:polygonMember>' +
|
||||||
|
' <gml:Polygon>' +
|
||||||
|
' <gml:exterior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:exterior>' +
|
||||||
|
' <gml:interior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>2 3 2 5 4 5 2 3</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:interior>' +
|
||||||
|
' <gml:interior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>3 4 3 6 5 6 3 4</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:interior>' +
|
||||||
|
' </gml:Polygon>' +
|
||||||
|
' </gml:polygonMember>' +
|
||||||
|
' <gml:polygonMember>' +
|
||||||
|
' <gml:Polygon>' +
|
||||||
|
' <gml:exterior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:exterior>' +
|
||||||
|
' </gml:Polygon>' +
|
||||||
|
' </gml:polygonMember>' +
|
||||||
|
'</gml:MultiPolygon>';
|
||||||
|
var g = format.readGeometry(text);
|
||||||
|
expect(g).to.be.an(ol.geom.MultiPolygon);
|
||||||
|
expect(g.getCoordinates()).to.eql([
|
||||||
|
[[[1, 2, 0], [3, 2, 0], [3, 4, 0],
|
||||||
|
[1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]],
|
||||||
|
[[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]],
|
||||||
|
[[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can read a plural multipolygon geometry', function() {
|
||||||
|
var text =
|
||||||
|
'<gml:MultiPolygon xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="foo">' +
|
||||||
|
' <gml:polygonMembers>' +
|
||||||
|
' <gml:Polygon>' +
|
||||||
|
' <gml:exterior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:exterior>' +
|
||||||
|
' <gml:interior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>2 3 2 5 4 5 2 3</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:interior>' +
|
||||||
|
' <gml:interior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>3 4 3 6 5 6 3 4</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:interior>' +
|
||||||
|
' </gml:Polygon>' +
|
||||||
|
' <gml:Polygon>' +
|
||||||
|
' <gml:exterior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>1 2 3 2 3 4 1 2</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:exterior>' +
|
||||||
|
' </gml:Polygon>' +
|
||||||
|
' </gml:polygonMembers>' +
|
||||||
|
'</gml:MultiPolygon>';
|
||||||
|
var g = format.readGeometry(text);
|
||||||
|
expect(g).to.be.an(ol.geom.MultiPolygon);
|
||||||
|
expect(g.getCoordinates()).to.eql([
|
||||||
|
[[[1, 2, 0], [3, 2, 0], [3, 4, 0],
|
||||||
|
[1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]],
|
||||||
|
[[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]],
|
||||||
|
[[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -256,5 +342,6 @@ goog.require('ol.format.GML');
|
|||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.MultiPoint');
|
goog.require('ol.geom.MultiPoint');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
|
goog.require('ol.geom.MultiPolygon');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
|
|||||||
Reference in New Issue
Block a user