diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 05fcd09388..9b52a4541a 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -876,6 +876,7 @@ describe('ol.format.GML', function() { }); it('writes back features as GML', function() { + this.timeout(4000); var serialized = gmlFormat.writeFeatures(features); expect(serialized).to.xmleql(ol.xml.load(text)); }); diff --git a/test/spec/ol/format/kmlformat.test.js b/test/spec/ol/format/kmlformat.test.js index 6f49b449a4..d476ca2ebd 100644 --- a/test/spec/ol/format/kmlformat.test.js +++ b/test/spec/ol/format/kmlformat.test.js @@ -230,12 +230,21 @@ describe('ol.format.KML', function() { }); it('can transform and write XYZ Point geometries', function() { + ol.proj.addProjection(new ol.proj.Projection({code: 'double'})); + ol.proj.addCoordinateTransforms('EPSG:4326', 'double', + function(coordinate) { + return [2 * coordinate[0], 2 * coordinate[1]]; + }, + function(coordinate) { + return [coordinate[0] / 2, coordinate[1] / 2]; + }); + var layout = ol.geom.GeometryLayout.XYZ; var point = new ol.geom.Point([1, 2, 3], layout).transform( - 'EPSG:4326', 'EPSG:3857'); + 'EPSG:4326', 'double'); var features = [new ol.Feature(point)]; var node = format.writeFeatures(features, { - featureProjection: 'EPSG:3857' + featureProjection: 'double' }); var text = '' + ''; expect(node).to.xmleql(ol.xml.load(text)); + + ol.proj.removeTransform( + ol.proj.get('EPSG:4326'), ol.proj.get('double')); + ol.proj.removeTransform( + ol.proj.get('double'), ol.proj.get('EPSG:4326')); }); it('can write XYM Point geometries', function() { @@ -2433,6 +2447,7 @@ goog.require('ol.style.Fill'); goog.require('ol.style.Icon'); goog.require('ol.style.IconOrigin'); goog.require('ol.proj'); +goog.require('ol.proj.Projection'); goog.require('ol.style.Stroke'); goog.require('ol.style.Style'); goog.require('ol.style.Text'); diff --git a/test/spec/ol/format/wktformat.test.js b/test/spec/ol/format/wktformat.test.js index 66f9e84088..0012023aa5 100644 --- a/test/spec/ol/format/wktformat.test.js +++ b/test/spec/ol/format/wktformat.test.js @@ -4,6 +4,116 @@ describe('ol.format.WKT', function() { var format = new ol.format.WKT(); + describe('#readGeometry()', function() { + + it('transforms with dataProjection and featureProjection', function() { + var wkt = 'POINT(1 2)'; + var geom = format.readGeometry(wkt, { + dataProjection: 'EPSG:4326', + featureProjection: 'EPSG:3857' + }); + expect(geom.getCoordinates()).to.eql( + ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857')); + }); + + }); + + describe('#writeGeometry()', function() { + + it('transforms with dataProjection and featureProjection', function() { + var geom = new ol.geom.Point([1, 2]).transform('EPSG:4326', 'EPSG:3857'); + var wkt = format.writeGeometry(geom, { + dataProjection: 'EPSG:4326', + featureProjection: 'EPSG:3857' + }); + var got = format.readGeometry(wkt).getCoordinates(); + expect(got[0]).to.roughlyEqual(1, 1e-6); + expect(got[1]).to.roughlyEqual(2, 1e-6); + }); + + }); + + describe('#readFeature()', function() { + + it('transforms with dataProjection and featureProjection', function() { + var wkt = 'POINT(1 2)'; + var feature = format.readFeature(wkt, { + dataProjection: 'EPSG:4326', + featureProjection: 'EPSG:3857' + }); + var geom = feature.getGeometry(); + expect(geom.getCoordinates()).to.eql( + ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857')); + }); + + }); + + describe('#writeFeature()', function() { + + it('transforms with dataProjection and featureProjection', function() { + var feature = new ol.Feature( + new ol.geom.Point([1, 2]).transform('EPSG:4326', 'EPSG:3857')); + var wkt = format.writeFeature(feature, { + dataProjection: 'EPSG:4326', + featureProjection: 'EPSG:3857' + }); + var gotFeature = format.readFeature(wkt); + expect(gotFeature).to.be.a(ol.Feature); + var got = gotFeature.getGeometry().getCoordinates(); + expect(got[0]).to.roughlyEqual(1, 1e-6); + expect(got[1]).to.roughlyEqual(2, 1e-6); + }); + + }); + + describe('#readFeatures()', function() { + + it('transforms with dataProjection and featureProjection', function() { + var wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(4 5))'; + var features = format.readFeatures(wkt, { + dataProjection: 'EPSG:4326', + featureProjection: 'EPSG:3857' + }); + expect(features.length).to.eql(2); + var point1 = features[0].getGeometry(); + var point2 = features[1].getGeometry(); + expect(point1.getType()).to.eql(ol.geom.GeometryType.POINT); + expect(point2.getType()).to.eql(ol.geom.GeometryType.POINT); + expect(point1.getCoordinates()).to.eql( + ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857')); + expect(point2.getCoordinates()).to.eql( + ol.proj.transform([4, 5], 'EPSG:4326', 'EPSG:3857')); + }); + }); + + describe('#writeFeatures()', function() { + + it('transforms with dataProjection and featureProjection', function() { + var features = [ + new ol.Feature( + new ol.geom.Point([1, 2]).transform('EPSG:4326', 'EPSG:3857')), + new ol.Feature( + new ol.geom.Point([4, 5]).transform('EPSG:4326', 'EPSG:3857')) + ]; + var wkt = format.writeFeatures(features, { + dataProjection: 'EPSG:4326', + featureProjection: 'EPSG:3857' + }); + var gotFeatures = format.readFeatures(wkt); + expect(gotFeatures).to.have.length(2); + expect(gotFeatures[0].getGeometry().getCoordinates()[0]) + .to.roughlyEqual(1, 1e-6); + expect(gotFeatures[0].getGeometry().getCoordinates()[1]) + .to.roughlyEqual(2, 1e-6); + expect(gotFeatures[1].getGeometry().getCoordinates()[0]) + .to.roughlyEqual(4, 1e-6); + expect(gotFeatures[1].getGeometry().getCoordinates()[1]) + .to.roughlyEqual(5, 1e-6); + }); + + }); + + it('Point read / written correctly', function() { var wkt = 'POINT(30 10)'; var geom = format.readGeometry(wkt); @@ -15,21 +125,6 @@ describe('ol.format.WKT', function() { expect(geom.getCoordinates()).to.eql([30, 10]); }); - it('Point transformed / read / written correctly', function() { - var wkt = 'POINT(1 2)'; - var geom = format.readGeometry(wkt, { - dataProjection: 'EPSG:4326', - featureProjection: 'EPSG:3857' - }); - expect(geom.getCoordinates()).to.eql( - ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857')); - var newWkt = format.writeGeometry(geom, { - dataProjection: 'EPSG:4326', - featureProjection: 'EPSG:3857' - }); - expect(newWkt).to.eql(wkt); - }); - it('MultiPoint read / written correctly', function() { // there are two forms to test var wkt = 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))'; @@ -254,22 +349,6 @@ describe('ol.format.WKT', function() { expect(format.writeFeature(feature)).to.eql(wkt); }); - it('Point feature transformed / read / written correctly', function() { - var wkt = 'POINT(1 2)'; - var feature = format.readFeature(wkt, { - dataProjection: 'EPSG:4326', - featureProjection: 'EPSG:3857' - }); - var geom = feature.getGeometry(); - expect(geom.getCoordinates()).to.eql( - ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857')); - var newWkt = format.writeFeature(feature, { - dataProjection: 'EPSG:4326', - featureProjection: 'EPSG:3857' - }); - expect(newWkt).to.eql(wkt); - }); - it('Features read / written correctly', function() { var wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(3 4))'; var features = format.readFeatures(wkt); @@ -283,30 +362,10 @@ describe('ol.format.WKT', function() { expect(format.writeFeatures(features)).to.eql(wkt); }); - it('Features transformed / read / written correctly', function() { - var wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(4 5))'; - var features = format.readFeatures(wkt, { - dataProjection: 'EPSG:4326', - featureProjection: 'EPSG:3857' - }); - expect(features.length).to.eql(2); - var point1 = features[0].getGeometry(); - var point2 = features[1].getGeometry(); - expect(point1.getType()).to.eql(ol.geom.GeometryType.POINT); - expect(point2.getType()).to.eql(ol.geom.GeometryType.POINT); - expect(point1.getCoordinates()).to.eql( - ol.proj.transform([1, 2], 'EPSG:4326', 'EPSG:3857')); - expect(point2.getCoordinates()).to.eql( - ol.proj.transform([4, 5], 'EPSG:4326', 'EPSG:3857')); - var newWkt = format.writeFeatures(features, { - dataProjection: 'EPSG:4326', - featureProjection: 'EPSG:3857' - }); - expect(newWkt).to.eql(wkt); - }); - }); +goog.require('ol.Feature'); goog.require('ol.geom.GeometryType'); +goog.require('ol.geom.Point'); goog.require('ol.format.WKT'); goog.require('ol.proj');