Accept feature projection in GeoJSON constructor

This commit is contained in:
Tim Schaub
2016-09-26 22:56:07 -06:00
parent f8bcd725ad
commit 4b6e907f69
4 changed files with 59 additions and 14 deletions

View File

@@ -208,6 +208,24 @@ describe('ol.format.GeoJSON', function() {
ol.proj.transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
});
it('uses featureProjection passed to the constructor', function() {
var format = new ol.format.GeoJSON({featureProjection: 'EPSG:3857'});
var feature = format.readFeatures(pointGeoJSON);
expect(feature[0].getGeometry()).to.be.an(ol.geom.Point);
expect(feature[0].getGeometry().getCoordinates()).to.eql(
ol.proj.transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
});
it('gives precedence to options passed to the read method', function() {
var format = new ol.format.GeoJSON({featureProjection: 'EPSG:1234'});
var feature = format.readFeatures(pointGeoJSON, {
featureProjection: 'EPSG:3857'
});
expect(feature[0].getGeometry()).to.be.an(ol.geom.Point);
expect(feature[0].getGeometry().getCoordinates()).to.eql(
ol.proj.transform([102.0, 0.5], 'EPSG:4326', 'EPSG:3857'));
});
it('can read and transform a feature collection', function() {
var features = format.readFeatures(featureCollectionGeoJSON, {
featureProjection: 'EPSG:3857'
@@ -578,6 +596,21 @@ describe('ol.format.GeoJSON', function() {
format.readGeometry(geojson).getCoordinates());
});
it('accepts featureProjection', function() {
var point = new ol.geom.Point(ol.proj.fromLonLat([10, 20]));
var geojson = format.writeGeometry(point, {featureProjection: 'EPSG:3857'});
var obj = JSON.parse(geojson);
expect(obj.coordinates).to.eql([10, 20]);
});
it('respects featureProjection passed to constructor', function() {
var format = new ol.format.GeoJSON({featureProjection: 'EPSG:3857'});
var point = new ol.geom.Point(ol.proj.fromLonLat([10, 20]));
var geojson = format.writeGeometry(point);
var obj = JSON.parse(geojson);
expect(obj.coordinates).to.eql([10, 20]);
});
it('encodes linestring', function() {
var linestring = new ol.geom.LineString([[10, 20], [30, 40]]);
var geojson = format.writeGeometry(linestring);