Handle srsName better
This commit is contained in:
@@ -163,6 +163,7 @@ ol.format.GML.readFeature_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readPoint_ = function(node, objectStack) {
|
ol.format.GML.readPoint_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'Point');
|
goog.asserts.assert(node.localName == 'Point');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var flatCoordinates =
|
var flatCoordinates =
|
||||||
ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack);
|
ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack);
|
||||||
if (goog.isDefAndNotNull(flatCoordinates)) {
|
if (goog.isDefAndNotNull(flatCoordinates)) {
|
||||||
@@ -185,6 +186,7 @@ ol.format.GML.readPoint_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readMultiPoint_ = function(node, objectStack) {
|
ol.format.GML.readMultiPoint_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'MultiPoint');
|
goog.asserts.assert(node.localName == 'MultiPoint');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var coordinates = ol.xml.pushParseAndPop(
|
var coordinates = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<Array.<number>>} */ ([]),
|
/** @type {Array.<Array.<number>>} */ ([]),
|
||||||
ol.format.GML.MULTIPOINT_PARSERS_, node, objectStack);
|
ol.format.GML.MULTIPOINT_PARSERS_, node, objectStack);
|
||||||
@@ -205,6 +207,7 @@ ol.format.GML.readMultiPoint_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readMultiLineString_ = function(node, objectStack) {
|
ol.format.GML.readMultiLineString_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'MultiLineString');
|
goog.asserts.assert(node.localName == 'MultiLineString');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var lineStrings = ol.xml.pushParseAndPop(
|
var lineStrings = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<ol.geom.LineString>} */ ([]),
|
/** @type {Array.<ol.geom.LineString>} */ ([]),
|
||||||
ol.format.GML.MULTILINESTRING_PARSERS_, node, objectStack);
|
ol.format.GML.MULTILINESTRING_PARSERS_, node, objectStack);
|
||||||
@@ -227,6 +230,7 @@ ol.format.GML.readMultiLineString_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readMultiCurve_ = function(node, objectStack) {
|
ol.format.GML.readMultiCurve_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'MultiCurve');
|
goog.asserts.assert(node.localName == 'MultiCurve');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var lineStrings = ol.xml.pushParseAndPop(
|
var lineStrings = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<ol.geom.LineString>} */ ([]),
|
/** @type {Array.<ol.geom.LineString>} */ ([]),
|
||||||
ol.format.GML.MULTICURVE_PARSERS_, node, objectStack);
|
ol.format.GML.MULTICURVE_PARSERS_, node, objectStack);
|
||||||
@@ -249,6 +253,7 @@ ol.format.GML.readMultiCurve_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readMultiSurface_ = function(node, objectStack) {
|
ol.format.GML.readMultiSurface_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'MultiSurface');
|
goog.asserts.assert(node.localName == 'MultiSurface');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var polygons = ol.xml.pushParseAndPop(
|
var polygons = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<ol.geom.Polygon>} */ ([]),
|
/** @type {Array.<ol.geom.Polygon>} */ ([]),
|
||||||
ol.format.GML.MULTISURFACE_PARSERS_, node, objectStack);
|
ol.format.GML.MULTISURFACE_PARSERS_, node, objectStack);
|
||||||
@@ -271,6 +276,7 @@ ol.format.GML.readMultiSurface_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readMultiPolygon_ = function(node, objectStack) {
|
ol.format.GML.readMultiPolygon_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'MultiPolygon');
|
goog.asserts.assert(node.localName == 'MultiPolygon');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var polygons = ol.xml.pushParseAndPop(
|
var polygons = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<ol.geom.Polygon>} */ ([]),
|
/** @type {Array.<ol.geom.Polygon>} */ ([]),
|
||||||
ol.format.GML.MULTIPOLYGON_PARSERS_, node, objectStack);
|
ol.format.GML.MULTIPOLYGON_PARSERS_, node, objectStack);
|
||||||
@@ -349,6 +355,18 @@ ol.format.GML.polygonMemberParser_ = function(node, objectStack) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Node} node Node.
|
||||||
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.format.GML.injectSrsName_ = function(node, objectStack) {
|
||||||
|
if (node.getAttribute('srsName') !== null) {
|
||||||
|
objectStack.push({srsName: node.getAttribute('srsName')});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
* @param {Array.<*>} objectStack Object stack.
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
@@ -358,6 +376,7 @@ ol.format.GML.polygonMemberParser_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readLineString_ = function(node, objectStack) {
|
ol.format.GML.readLineString_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'LineString');
|
goog.asserts.assert(node.localName == 'LineString');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var flatCoordinates =
|
var flatCoordinates =
|
||||||
ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack);
|
ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack);
|
||||||
if (goog.isDefAndNotNull(flatCoordinates)) {
|
if (goog.isDefAndNotNull(flatCoordinates)) {
|
||||||
@@ -515,6 +534,7 @@ ol.format.GML.readFlatLinearRing_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readLinearRing_ = function(node, objectStack) {
|
ol.format.GML.readLinearRing_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'LinearRing');
|
goog.asserts.assert(node.localName == 'LinearRing');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var flatCoordinates =
|
var flatCoordinates =
|
||||||
ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack);
|
ol.format.GML.readFlatCoordinatesFromNode_(node, objectStack);
|
||||||
if (goog.isDef(flatCoordinates)) {
|
if (goog.isDef(flatCoordinates)) {
|
||||||
@@ -537,6 +557,7 @@ ol.format.GML.readLinearRing_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readPolygon_ = function(node, objectStack) {
|
ol.format.GML.readPolygon_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'Polygon');
|
goog.asserts.assert(node.localName == 'Polygon');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var flatLinearRings = ol.xml.pushParseAndPop(
|
var flatLinearRings = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<Array.<number>>} */ ([null]),
|
/** @type {Array.<Array.<number>>} */ ([null]),
|
||||||
ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack);
|
ol.format.GML.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack);
|
||||||
@@ -568,6 +589,7 @@ ol.format.GML.readPolygon_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readSurface_ = function(node, objectStack) {
|
ol.format.GML.readSurface_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'Surface');
|
goog.asserts.assert(node.localName == 'Surface');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var flatLinearRings = ol.xml.pushParseAndPop(
|
var flatLinearRings = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<Array.<number>>} */ ([null]),
|
/** @type {Array.<Array.<number>>} */ ([null]),
|
||||||
ol.format.GML.SURFACE_PARSERS_, node, objectStack);
|
ol.format.GML.SURFACE_PARSERS_, node, objectStack);
|
||||||
@@ -599,6 +621,7 @@ ol.format.GML.readSurface_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readCurve_ = function(node, objectStack) {
|
ol.format.GML.readCurve_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'Curve');
|
goog.asserts.assert(node.localName == 'Curve');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var flatCoordinates = ol.xml.pushParseAndPop(
|
var flatCoordinates = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<number>} */ ([null]),
|
/** @type {Array.<number>} */ ([null]),
|
||||||
ol.format.GML.CURVE_PARSERS_, node, objectStack);
|
ol.format.GML.CURVE_PARSERS_, node, objectStack);
|
||||||
@@ -621,6 +644,7 @@ ol.format.GML.readCurve_ = function(node, objectStack) {
|
|||||||
ol.format.GML.readEnvelope_ = function(node, objectStack) {
|
ol.format.GML.readEnvelope_ = function(node, objectStack) {
|
||||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||||
goog.asserts.assert(node.localName == 'Envelope');
|
goog.asserts.assert(node.localName == 'Envelope');
|
||||||
|
ol.format.GML.injectSrsName_(node, objectStack);
|
||||||
var flatCoordinates = ol.xml.pushParseAndPop(
|
var flatCoordinates = ol.xml.pushParseAndPop(
|
||||||
/** @type {Array.<number>} */ ([null]),
|
/** @type {Array.<number>} */ ([null]),
|
||||||
ol.format.GML.ENVELOPE_PARSERS_, node, objectStack);
|
ol.format.GML.ENVELOPE_PARSERS_, node, objectStack);
|
||||||
@@ -646,13 +670,22 @@ ol.format.GML.readFlatCoordinatesFromNode_ = function(node, objectStack) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node Node.
|
* @param {Node} node Node.
|
||||||
|
* @param {Array.<*>} objectStack Object stack.
|
||||||
* @private
|
* @private
|
||||||
* @return {Array.<number>|undefined} Flat coordinates.
|
* @return {Array.<number>|undefined} Flat coordinates.
|
||||||
*/
|
*/
|
||||||
ol.format.GML.readFlatPos_ = function(node) {
|
ol.format.GML.readFlatPos_ = function(node, objectStack) {
|
||||||
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
|
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
|
||||||
var flatCoordinates = goog.array.map(s.split(/\s+/), parseFloat);
|
var flatCoordinates = goog.array.map(s.split(/\s+/), parseFloat);
|
||||||
var containerSrs = node.parentNode.getAttribute('srsName');
|
var containerSrs = null;
|
||||||
|
for (var i = 0, ii = objectStack.length; i < ii; ++i) {
|
||||||
|
if (goog.isObject(objectStack[i]) &&
|
||||||
|
goog.object.get(/** @type {Object} */(objectStack[i]), 'srsName')) {
|
||||||
|
containerSrs = objectStack[i].srsName;
|
||||||
|
goog.array.removeAt(objectStack, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
var axisOrientation = 'enu';
|
var axisOrientation = 'enu';
|
||||||
if (containerSrs !== null) {
|
if (containerSrs !== null) {
|
||||||
var proj = ol.proj.get(containerSrs);
|
var proj = ol.proj.get(containerSrs);
|
||||||
@@ -680,8 +713,16 @@ ol.format.GML.readFlatPos_ = function(node) {
|
|||||||
*/
|
*/
|
||||||
ol.format.GML.readFlatPosList_ = function(node, objectStack) {
|
ol.format.GML.readFlatPosList_ = function(node, objectStack) {
|
||||||
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
|
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
|
||||||
|
var containerSrs = null;
|
||||||
|
for (var i = 0, ii = objectStack.length; i < ii; ++i) {
|
||||||
|
if (goog.isObject(objectStack[i]) &&
|
||||||
|
goog.object.get(/** @type {Object} */ (objectStack[i]), 'srsName')) {
|
||||||
|
containerSrs = objectStack[i].srsName;
|
||||||
|
goog.array.removeAt(objectStack, i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
var containerDimension = node.parentNode.getAttribute('srsDimension');
|
var containerDimension = node.parentNode.getAttribute('srsDimension');
|
||||||
var containerSrs = node.parentNode.getAttribute('srsName');
|
|
||||||
var axisOrientation = 'enu';
|
var axisOrientation = 'enu';
|
||||||
if (containerSrs !== null) {
|
if (containerSrs !== null) {
|
||||||
var proj = ol.proj.get(containerSrs);
|
var proj = ol.proj.get(containerSrs);
|
||||||
|
|||||||
@@ -71,6 +71,29 @@ describe('ol.format.GML', function() {
|
|||||||
expect(g.getCoordinates()).to.eql([-180, -90, 0]);
|
expect(g.getCoordinates()).to.eql([-180, -90, 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can read multi surface geometry with right axis order', function() {
|
||||||
|
var text =
|
||||||
|
'<gml:MultiSurface xmlns:gml="http://www.opengis.net/gml" ' +
|
||||||
|
' srsName="urn:x-ogc:def:crs:EPSG:4326">' +
|
||||||
|
' <gml:surfaceMember>' +
|
||||||
|
' <gml:Polygon>' +
|
||||||
|
' <gml:exterior>' +
|
||||||
|
' <gml:LinearRing>' +
|
||||||
|
' <gml:posList>38.9661 -77.0081 38.9931 -77.0421 ' +
|
||||||
|
' 38.9321 -77.1221 38.9151 -77.0781 38.8861 -77.0671 ' +
|
||||||
|
' 38.8621 -77.0391 38.8381 -77.0401 38.8291 -77.0451 ' +
|
||||||
|
' 38.8131 -77.0351 38.7881 -77.0451' +
|
||||||
|
' 38.8891 -76.9111 38.9661 -77.0081</gml:posList>' +
|
||||||
|
' </gml:LinearRing>' +
|
||||||
|
' </gml:exterior>' +
|
||||||
|
' </gml:Polygon>' +
|
||||||
|
' </gml:surfaceMember>' +
|
||||||
|
'</gml:MultiSurface>';
|
||||||
|
var g = readGeometry(format, text);
|
||||||
|
expect(g.getCoordinates()[0][0][0][0]).to.equal(-77.0081);
|
||||||
|
expect(g.getCoordinates()[0][0][0][1]).to.equal(38.9661);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('linestring 3D', function() {
|
describe('linestring 3D', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user