Add tests for ol.reproj.*
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
goog.provide('ol.test.reproj.Image');
|
||||||
|
|
||||||
|
describe('ol.reproj.Image', function() {
|
||||||
|
function createImage(pixelRatio) {
|
||||||
|
return new ol.reproj.Image(
|
||||||
|
ol.proj.get('EPSG:3857'), ol.proj.get('EPSG:4326'),
|
||||||
|
[-180, -85, 180, 85], 10, pixelRatio,
|
||||||
|
function(extent, resolution, pixelRatio) {
|
||||||
|
return new ol.Image(extent, resolution, pixelRatio, [],
|
||||||
|
'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=', '',
|
||||||
|
function(image, src) {
|
||||||
|
image.getImage().src = src;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('changes state as expected', function(done) {
|
||||||
|
var image = createImage(1);
|
||||||
|
expect(image.getState()).to.be(ol.ImageState.IDLE);
|
||||||
|
image.listen('change', function() {
|
||||||
|
if (image.getState() == ol.ImageState.LOADED) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
image.load();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns correct canvas size', function(done) {
|
||||||
|
var image = createImage(1);
|
||||||
|
image.listen('change', function() {
|
||||||
|
if (image.getState() == ol.ImageState.LOADED) {
|
||||||
|
var canvas = image.getImage();
|
||||||
|
expect(canvas.width).to.be(36);
|
||||||
|
expect(canvas.height).to.be(17);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
image.load();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('respects pixelRatio', function(done) {
|
||||||
|
var image = createImage(2);
|
||||||
|
image.listen('change', function() {
|
||||||
|
if (image.getState() == ol.ImageState.LOADED) {
|
||||||
|
var canvas = image.getImage();
|
||||||
|
expect(canvas.width).to.be(72);
|
||||||
|
expect(canvas.height).to.be(34);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
image.load();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
goog.require('ol.Image');
|
||||||
|
goog.require('ol.ImageState');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.reproj.Image');
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
goog.provide('ol.test.reproj');
|
||||||
|
|
||||||
|
describe('ol.reproj', function() {
|
||||||
|
|
||||||
|
describe('#calculateSourceResolution', function() {
|
||||||
|
var proj3857 = ol.proj.get('EPSG:3857');
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var origin = [0, 0];
|
||||||
|
var point3857 = [50, 40];
|
||||||
|
var point4326 = ol.proj.transform(point3857, proj3857, proj4326);
|
||||||
|
|
||||||
|
it('is identity for identical projection', function() {
|
||||||
|
var result;
|
||||||
|
var resolution = 500;
|
||||||
|
result = ol.reproj.calculateSourceResolution(
|
||||||
|
proj3857, proj3857, origin, resolution);
|
||||||
|
expect(result).to.be(resolution);
|
||||||
|
|
||||||
|
result = ol.reproj.calculateSourceResolution(
|
||||||
|
proj3857, proj3857, point3857, resolution);
|
||||||
|
expect(result).to.be(resolution);
|
||||||
|
|
||||||
|
result = ol.reproj.calculateSourceResolution(
|
||||||
|
proj4326, proj4326, point4326, resolution);
|
||||||
|
expect(result).to.be(resolution);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calculates correctly', function() {
|
||||||
|
var resolution4326 = 5;
|
||||||
|
|
||||||
|
var resolution3857 = ol.reproj.calculateSourceResolution(
|
||||||
|
proj3857, proj4326, point4326, resolution4326);
|
||||||
|
expect(resolution3857).not.to.be(resolution4326);
|
||||||
|
expect(resolution3857).to.roughlyEqual(555974.3714343394, 1e-6);
|
||||||
|
|
||||||
|
var result = ol.reproj.calculateSourceResolution(
|
||||||
|
proj4326, proj3857, point3857, resolution3857);
|
||||||
|
expect(result).to.be(resolution4326);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
goog.require('ol.reproj');
|
||||||
|
goog.require('ol.proj');
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
goog.provide('ol.test.reproj.Tile');
|
||||||
|
|
||||||
|
describe('ol.reproj.Tile', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 ' +
|
||||||
|
'+k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy ' +
|
||||||
|
'+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
|
||||||
|
'+units=m +no_defs');
|
||||||
|
var proj27700 = ol.proj.get('EPSG:27700');
|
||||||
|
proj27700.setExtent([0, 0, 700000, 1300000]);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
delete proj4.defs['EPSG:27700'];
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function createTile(pixelRatio, opt_tileSize) {
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var proj3857 = ol.proj.get('EPSG:3857');
|
||||||
|
return new ol.reproj.Tile(
|
||||||
|
proj3857, ol.tilegrid.createForProjection(proj3857), proj4326,
|
||||||
|
ol.tilegrid.createForProjection(proj4326, 3, opt_tileSize),
|
||||||
|
3, 2, -2, pixelRatio, function(z, x, y, pixelRatio) {
|
||||||
|
return new ol.ImageTile([z, x, y], ol.TileState.IDLE,
|
||||||
|
'data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=', '',
|
||||||
|
function(tile, src) {
|
||||||
|
tile.getImage().src = src;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('changes state as expected', function(done) {
|
||||||
|
var tile = createTile(1);
|
||||||
|
expect(tile.getState()).to.be(ol.TileState.IDLE);
|
||||||
|
tile.listen('change', function() {
|
||||||
|
if (tile.getState() == ol.TileState.LOADED) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tile.load();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is empty when outside target tile grid', function() {
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var proj3857 = ol.proj.get('EPSG:3857');
|
||||||
|
var tile = new ol.reproj.Tile(
|
||||||
|
proj3857, ol.tilegrid.createForProjection(proj3857),
|
||||||
|
proj4326, ol.tilegrid.createForProjection(proj4326),
|
||||||
|
0, -1, 0, 1, function() {
|
||||||
|
expect().fail('No tiles should be required');
|
||||||
|
});
|
||||||
|
expect(tile.getState()).to.be(ol.TileState.EMPTY);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is empty when outside source tile grid', function() {
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var proj27700 = ol.proj.get('EPSG:27700');
|
||||||
|
var tile = new ol.reproj.Tile(
|
||||||
|
proj27700, ol.tilegrid.createForProjection(proj27700),
|
||||||
|
proj4326, ol.tilegrid.createForProjection(proj4326),
|
||||||
|
3, 2, -2, 1, function() {
|
||||||
|
expect().fail('No tiles should be required');
|
||||||
|
});
|
||||||
|
expect(tile.getState()).to.be(ol.TileState.EMPTY);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('respects tile size of target tile grid', function(done) {
|
||||||
|
var tile = createTile(1, [100, 40]);
|
||||||
|
tile.listen('change', function() {
|
||||||
|
if (tile.getState() == ol.TileState.LOADED) {
|
||||||
|
var canvas = tile.getImage();
|
||||||
|
expect(canvas.width).to.be(100);
|
||||||
|
expect(canvas.height).to.be(40);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tile.load();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('respects pixelRatio', function(done) {
|
||||||
|
var tile = createTile(3, [60, 20]);
|
||||||
|
tile.listen('change', function() {
|
||||||
|
if (tile.getState() == ol.TileState.LOADED) {
|
||||||
|
var canvas = tile.getImage();
|
||||||
|
expect(canvas.width).to.be(180);
|
||||||
|
expect(canvas.height).to.be(60);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tile.load();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
goog.require('ol.ImageTile');
|
||||||
|
goog.require('ol.TileState');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.reproj.Tile');
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
goog.provide('ol.test.reproj.Triangulation');
|
||||||
|
|
||||||
|
describe('ol.reproj.Triangulation', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 ' +
|
||||||
|
'+k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy ' +
|
||||||
|
'+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
|
||||||
|
'+units=m +no_defs');
|
||||||
|
var proj27700 = ol.proj.get('EPSG:27700');
|
||||||
|
proj27700.setExtent([0, 0, 700000, 1300000]);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
delete proj4.defs['EPSG:27700'];
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('constructor', function() {
|
||||||
|
it('is trivial for identity', function() {
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var triangulation = new ol.reproj.Triangulation(proj4326, proj4326,
|
||||||
|
[20, 20, 30, 30], [-180, -90, 180, 90], 0);
|
||||||
|
expect(triangulation.getTriangles().length).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is empty when outside source extent', function() {
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var proj27700 = ol.proj.get('EPSG:27700');
|
||||||
|
var triangulation = new ol.reproj.Triangulation(proj27700, proj4326,
|
||||||
|
[0, 0, 10, 10], proj27700.getExtent(), 0);
|
||||||
|
expect(triangulation.getTriangles().length).to.be(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can handle null source extent', function() {
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var triangulation = new ol.reproj.Triangulation(proj4326, proj4326,
|
||||||
|
[20, 20, 30, 30], null, 0);
|
||||||
|
expect(triangulation.getTriangles().length).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can handle wrapX in source', function() {
|
||||||
|
proj4.defs('merc_180', '+proj=merc +lon_0=180 +units=m +no_defs');
|
||||||
|
var proj_ = ol.proj.get('merc_180');
|
||||||
|
proj_.setExtent([-20026376.39, -20048966.10, 20026376.39, 20048966.10]);
|
||||||
|
|
||||||
|
var proj4326 = ol.proj.get('EPSG:4326');
|
||||||
|
var triangulation = new ol.reproj.Triangulation(proj4326, proj_,
|
||||||
|
proj_.getExtent(), [-180, -90, 180, 90], 0);
|
||||||
|
expect(triangulation.getWrapsXInSource()).to.be(true);
|
||||||
|
var triExtent = triangulation.calculateSourceExtent();
|
||||||
|
expect(triExtent[2] < triExtent[0]).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.reproj.Triangulation');
|
||||||
Reference in New Issue
Block a user