Function for getting great circle lengths
This commit is contained in:
@@ -221,21 +221,21 @@ describe('ol.proj', function() {
|
||||
});
|
||||
it('returns the correct point resolution for EPSG:4326 with custom units', function() {
|
||||
var pointResolution = ol.proj.getPointResolution('EPSG:4326', 1, [0, 0], 'm');
|
||||
expect (pointResolution).to.roughlyEqual(111194.874284, 1e-5);
|
||||
expect(pointResolution).to.roughlyEqual(111195.0802335329, 1e-5);
|
||||
pointResolution = ol.proj.getPointResolution('EPSG:4326', 1, [0, 52], 'm');
|
||||
expect (pointResolution).to.roughlyEqual(89826.367538, 1e-5);
|
||||
expect(pointResolution).to.roughlyEqual(89826.53390979706, 1e-5);
|
||||
});
|
||||
it('returns the correct point resolution for EPSG:3857', function() {
|
||||
var pointResolution = ol.proj.getPointResolution('EPSG:3857', 1, [0, 0]);
|
||||
expect (pointResolution).to.be(1);
|
||||
expect(pointResolution).to.be(1);
|
||||
pointResolution = ol.proj.getPointResolution('EPSG:3857', 1, ol.proj.fromLonLat([0, 52]));
|
||||
expect (pointResolution).to.roughlyEqual(0.615661, 1e-5);
|
||||
expect(pointResolution).to.roughlyEqual(0.615661, 1e-5);
|
||||
});
|
||||
it('returns the correct point resolution for EPSG:3857 with custom units', function() {
|
||||
var pointResolution = ol.proj.getPointResolution('EPSG:3857', 1, [0, 0], 'degrees');
|
||||
expect (pointResolution).to.be(1);
|
||||
expect(pointResolution).to.be(1);
|
||||
pointResolution = ol.proj.getPointResolution('EPSG:4326', 1, ol.proj.fromLonLat([0, 52]), 'degrees');
|
||||
expect (pointResolution).to.be(1);
|
||||
expect(pointResolution).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -108,3 +108,72 @@ describe('ol.Sphere', function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.Sphere.getLength()', function() {
|
||||
var cases = [{
|
||||
geometry: new ol.geom.Point([0, 0]),
|
||||
length: 0
|
||||
}, {
|
||||
geometry: new ol.geom.MultiPoint([[0, 0], [1, 1]]),
|
||||
length: 0
|
||||
}, {
|
||||
geometry: new ol.geom.LineString([
|
||||
[12801741.441226462, -3763310.627144653],
|
||||
[14582853.293918837, -2511525.2348457114],
|
||||
[15918687.18343812, -2875744.624352243],
|
||||
[16697923.618991036, -4028802.0261344076]
|
||||
]),
|
||||
length: 4407939.124914191
|
||||
}, {
|
||||
geometry: new ol.geom.LineString([
|
||||
[115, -32],
|
||||
[131, -22],
|
||||
[143, -25],
|
||||
[150, -34]
|
||||
]),
|
||||
options: {projection: 'EPSG:4326'},
|
||||
length: 4407939.124914191
|
||||
}, {
|
||||
geometry: new ol.geom.MultiLineString([
|
||||
[
|
||||
[115, -32],
|
||||
[131, -22],
|
||||
[143, -25],
|
||||
[150, -34]
|
||||
], [
|
||||
[115, -32],
|
||||
[131, -22],
|
||||
[143, -25],
|
||||
[150, -34]
|
||||
]
|
||||
]),
|
||||
options: {projection: 'EPSG:4326'},
|
||||
length: 2 * 4407939.124914191
|
||||
}, {
|
||||
geometry: new ol.geom.GeometryCollection([
|
||||
new ol.geom.LineString([
|
||||
[115, -32],
|
||||
[131, -22],
|
||||
[143, -25],
|
||||
[150, -34]
|
||||
]),
|
||||
new ol.geom.LineString([
|
||||
[115, -32],
|
||||
[131, -22],
|
||||
[143, -25],
|
||||
[150, -34]
|
||||
])
|
||||
]),
|
||||
options: {projection: 'EPSG:4326'},
|
||||
length: 2 * 4407939.124914191
|
||||
}];
|
||||
|
||||
cases.forEach(function(c, i) {
|
||||
it('works for case ' + i, function() {
|
||||
var c = cases[i];
|
||||
var length = ol.Sphere.getLength(c.geometry, c.options);
|
||||
expect(length).to.equal(c.length);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user