Read crs from top-level object when parsing as features
This commit is contained in:
@@ -269,7 +269,7 @@ describe('ol.parser.GeoJSON', function() {
|
||||
|
||||
describe('#parseAsFeatureCollection_()', function() {
|
||||
|
||||
it('returns an array of features for FeatureCollection', function() {
|
||||
it('generates an array of features for FeatureCollection', function() {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
@@ -310,8 +310,9 @@ describe('ol.parser.GeoJSON', function() {
|
||||
}
|
||||
}]
|
||||
};
|
||||
var features = parser.parseAsFeatureCollection_(json,
|
||||
var result = parser.parseAsFeatureCollection_(json,
|
||||
{callback: callback});
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(2);
|
||||
|
||||
@@ -328,9 +329,81 @@ describe('ol.parser.GeoJSON', function() {
|
||||
expect(pointVertices.coordinates.length).to.be(2);
|
||||
expect(lineVertices.coordinates.length).to.be(4);
|
||||
expect(polygonVertices.coordinates.length).to.be(0);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('returns an array of features for Feature', function() {
|
||||
it('reads named crs from top-level object', function() {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
|
||||
var lookup = {
|
||||
'point': pointVertices,
|
||||
'linestring': lineVertices,
|
||||
'polygon': polygonVertices,
|
||||
'multipoint': pointVertices,
|
||||
'multilinstring': lineVertices,
|
||||
'multipolygon': polygonVertices
|
||||
};
|
||||
|
||||
var callback = function(feature, type) {
|
||||
return lookup[type];
|
||||
};
|
||||
|
||||
var parser = new ol.parser.GeoJSON();
|
||||
var json = {
|
||||
type: 'FeatureCollection',
|
||||
crs: {
|
||||
type: 'name',
|
||||
properties: {
|
||||
name: 'EPSG:1234'
|
||||
}
|
||||
},
|
||||
features: [{
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
foo: 'bar'
|
||||
},
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: [1, 2]
|
||||
}
|
||||
}, {
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
bam: 'baz'
|
||||
},
|
||||
geometry: {
|
||||
type: 'LineString',
|
||||
coordinates: [[1, 2], [3, 4]]
|
||||
}
|
||||
}]
|
||||
};
|
||||
var result = parser.parseAsFeatureCollection_(json,
|
||||
{callback: callback});
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(2);
|
||||
|
||||
var first = features[0];
|
||||
expect(first).to.be.a(ol.Feature);
|
||||
expect(first.get('foo')).to.be('bar');
|
||||
expect(first.getGeometry()).to.be.a(ol.geom.Point);
|
||||
|
||||
var second = features[1];
|
||||
expect(second).to.be.a(ol.Feature);
|
||||
expect(second.get('bam')).to.be('baz');
|
||||
expect(second.getGeometry()).to.be.a(ol.geom.LineString);
|
||||
|
||||
expect(pointVertices.coordinates.length).to.be(2);
|
||||
expect(lineVertices.coordinates.length).to.be(4);
|
||||
expect(polygonVertices.coordinates.length).to.be(0);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:1234');
|
||||
});
|
||||
|
||||
it('generates an array of features for Feature', function() {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
@@ -359,8 +432,9 @@ describe('ol.parser.GeoJSON', function() {
|
||||
coordinates: [[1, 2], [3, 4]]
|
||||
}
|
||||
};
|
||||
var features = parser.parseAsFeatureCollection_(json,
|
||||
var result = parser.parseAsFeatureCollection_(json,
|
||||
{callback: callback});
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
@@ -372,9 +446,11 @@ describe('ol.parser.GeoJSON', function() {
|
||||
expect(pointVertices.coordinates.length).to.be(0);
|
||||
expect(lineVertices.coordinates.length).to.be(4);
|
||||
expect(polygonVertices.coordinates.length).to.be(0);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('returns an array of features for GeometryCollection', function() {
|
||||
it('generates an array of features for GeometryCollection', function() {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
@@ -406,8 +482,9 @@ describe('ol.parser.GeoJSON', function() {
|
||||
coordinates: [[[7, 8], [9, 10], [11, 12], [7, 8]]]
|
||||
}]
|
||||
};
|
||||
var features = parser.parseAsFeatureCollection_(json,
|
||||
var result = parser.parseAsFeatureCollection_(json,
|
||||
{callback: callback});
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(3);
|
||||
|
||||
@@ -418,9 +495,11 @@ describe('ol.parser.GeoJSON', function() {
|
||||
expect(pointVertices.coordinates.length).to.be(2);
|
||||
expect(lineVertices.coordinates.length).to.be(4);
|
||||
expect(polygonVertices.coordinates.length).to.be(8);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('returns an array of features for Point', function() {
|
||||
it('generates an array of features for Point', function() {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
@@ -443,8 +522,9 @@ describe('ol.parser.GeoJSON', function() {
|
||||
type: 'Point',
|
||||
coordinates: [1, 2]
|
||||
};
|
||||
var features = parser.parseAsFeatureCollection_(json,
|
||||
var result = parser.parseAsFeatureCollection_(json,
|
||||
{callback: callback});
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
@@ -453,9 +533,11 @@ describe('ol.parser.GeoJSON', function() {
|
||||
expect(pointVertices.coordinates.length).to.be(2);
|
||||
expect(lineVertices.coordinates.length).to.be(0);
|
||||
expect(polygonVertices.coordinates.length).to.be(0);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('returns an array of features for LineString', function() {
|
||||
it('generates an array of features for LineString', function() {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
@@ -478,8 +560,9 @@ describe('ol.parser.GeoJSON', function() {
|
||||
type: 'LineString',
|
||||
coordinates: [[3, 4], [5, 6]]
|
||||
};
|
||||
var features = parser.parseAsFeatureCollection_(json,
|
||||
var result = parser.parseAsFeatureCollection_(json,
|
||||
{callback: callback});
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
@@ -488,9 +571,11 @@ describe('ol.parser.GeoJSON', function() {
|
||||
expect(pointVertices.coordinates.length).to.be(0);
|
||||
expect(lineVertices.coordinates.length).to.be(4);
|
||||
expect(polygonVertices.coordinates.length).to.be(0);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
it('returns an array of features for Polygon', function() {
|
||||
it('generates an array of features for Polygon', function() {
|
||||
var pointVertices = new ol.geom.SharedVertices();
|
||||
var lineVertices = new ol.geom.SharedVertices();
|
||||
var polygonVertices = new ol.geom.SharedVertices();
|
||||
@@ -513,8 +598,9 @@ describe('ol.parser.GeoJSON', function() {
|
||||
type: 'Polygon',
|
||||
coordinates: [[[7, 8], [9, 10], [11, 12], [7, 8]]]
|
||||
};
|
||||
var features = parser.parseAsFeatureCollection_(json,
|
||||
var result = parser.parseAsFeatureCollection_(json,
|
||||
{callback: callback});
|
||||
var features = result.features;
|
||||
|
||||
expect(features.length).to.be(1);
|
||||
|
||||
@@ -523,6 +609,8 @@ describe('ol.parser.GeoJSON', function() {
|
||||
expect(pointVertices.coordinates.length).to.be(0);
|
||||
expect(lineVertices.coordinates.length).to.be(0);
|
||||
expect(polygonVertices.coordinates.length).to.be(8);
|
||||
|
||||
expect(result.metadata.projection).to.be('EPSG:4326');
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user