Implement GML.readProjectionFromNode()

This commit is contained in:
tsauerwein
2014-08-08 10:54:40 +02:00
parent 65346d716d
commit 281fd3c6a9
2 changed files with 20 additions and 5 deletions

View File

@@ -1,5 +1,3 @@
//FIXME Implement readProjectionFrom*
goog.provide('ol.format.GML');
goog.require('goog.asserts');
@@ -1077,8 +1075,8 @@ ol.format.GML.prototype.readFeaturesFromNode = function(node, opt_options) {
* @inheritDoc
*/
ol.format.GML.prototype.readProjectionFromNode = function(node) {
//TODO read this from data
return ol.proj.get(this.srsName_);
return goog.isDef(this.srsName_) ? this.srsName_ :
node.firstElementChild.getAttribute('srsName');
};

View File

@@ -10,10 +10,11 @@ var readGeometry = function(format, text, opt_options) {
describe('ol.format.GML', function() {
var format, formatWGS84;
var format, formatWGS84, formatNoSrs;
beforeEach(function() {
format = new ol.format.GML({srsName: 'CRS:84'});
formatWGS84 = new ol.format.GML({srsName: 'urn:x-ogc:def:crs:EPSG:4326'});
formatNoSrs = new ol.format.GML();
});
describe('#readGeometry', function() {
@@ -55,6 +56,22 @@ describe('ol.format.GML', function() {
expect(coordinate[1]).to.roughlyEqual(2, 1e-9);
});
it('can detect SRS, read and transform a point geometry', function() {
var config = {
featureProjection: 'EPSG:3857'
};
var text =
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +
' srsName="CRS:84">' +
' <gml:pos>1 2</gml:pos>' +
'</gml:Point>';
var g = readGeometry(formatNoSrs, text, config);
expect(g).to.be.an(ol.geom.Point);
var coordinates = g.getCoordinates();
expect(coordinates.splice(0, 2)).to.eql(
ol.proj.transform([1, 2], 'CRS:84', 'EPSG:3857'));
});
it('can read and write a point geometry in EPSG:4326', function() {
var text =
'<gml:Point xmlns:gml="http://www.opengis.net/gml" ' +