@@ -876,6 +876,7 @@ describe('ol.format.GML', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('writes back features as GML', function() {
|
it('writes back features as GML', function() {
|
||||||
|
this.timeout(4000);
|
||||||
var serialized = gmlFormat.writeFeatures(features);
|
var serialized = gmlFormat.writeFeatures(features);
|
||||||
expect(serialized).to.xmleql(ol.xml.load(text));
|
expect(serialized).to.xmleql(ol.xml.load(text));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -230,12 +230,21 @@ describe('ol.format.KML', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can transform and write XYZ Point geometries', 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 layout = ol.geom.GeometryLayout.XYZ;
|
||||||
var point = new ol.geom.Point([1, 2, 3], layout).transform(
|
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 features = [new ol.Feature(point)];
|
||||||
var node = format.writeFeatures(features, {
|
var node = format.writeFeatures(features, {
|
||||||
featureProjection: 'EPSG:3857'
|
featureProjection: 'double'
|
||||||
});
|
});
|
||||||
var text =
|
var text =
|
||||||
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||||
@@ -250,6 +259,11 @@ describe('ol.format.KML', function() {
|
|||||||
' </Placemark>' +
|
' </Placemark>' +
|
||||||
'</kml>';
|
'</kml>';
|
||||||
expect(node).to.xmleql(ol.xml.load(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() {
|
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.Icon');
|
||||||
goog.require('ol.style.IconOrigin');
|
goog.require('ol.style.IconOrigin');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.proj.Projection');
|
||||||
goog.require('ol.style.Stroke');
|
goog.require('ol.style.Stroke');
|
||||||
goog.require('ol.style.Style');
|
goog.require('ol.style.Style');
|
||||||
goog.require('ol.style.Text');
|
goog.require('ol.style.Text');
|
||||||
|
|||||||
@@ -4,6 +4,116 @@ describe('ol.format.WKT', function() {
|
|||||||
|
|
||||||
var format = new ol.format.WKT();
|
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() {
|
it('Point read / written correctly', function() {
|
||||||
var wkt = 'POINT(30 10)';
|
var wkt = 'POINT(30 10)';
|
||||||
var geom = format.readGeometry(wkt);
|
var geom = format.readGeometry(wkt);
|
||||||
@@ -15,21 +125,6 @@ describe('ol.format.WKT', function() {
|
|||||||
expect(geom.getCoordinates()).to.eql([30, 10]);
|
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() {
|
it('MultiPoint read / written correctly', function() {
|
||||||
// there are two forms to test
|
// there are two forms to test
|
||||||
var wkt = 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))';
|
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);
|
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() {
|
it('Features read / written correctly', function() {
|
||||||
var wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(3 4))';
|
var wkt = 'GEOMETRYCOLLECTION(POINT(1 2),POINT(3 4))';
|
||||||
var features = format.readFeatures(wkt);
|
var features = format.readFeatures(wkt);
|
||||||
@@ -283,30 +362,10 @@ describe('ol.format.WKT', function() {
|
|||||||
expect(format.writeFeatures(features)).to.eql(wkt);
|
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.GeometryType');
|
||||||
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.format.WKT');
|
goog.require('ol.format.WKT');
|
||||||
goog.require('ol.proj');
|
goog.require('ol.proj');
|
||||||
|
|||||||
Reference in New Issue
Block a user