Add view abstraction
This commit is contained in:
@@ -4,6 +4,7 @@ goog.require('ol.Collection');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.source.XYZ');
|
||||
|
||||
@@ -24,56 +25,6 @@ describe('ol.Map', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('create constraints', function() {
|
||||
|
||||
describe('create resolution constraint', function() {
|
||||
|
||||
describe('with no options', function() {
|
||||
it('gives a correct resolution constraint function', function() {
|
||||
var options = {};
|
||||
var fn = ol.Map.createConstraints_(options).resolution;
|
||||
expect(fn(156543.03392804097, 0))
|
||||
.toRoughlyEqual(156543.03392804097, 1e-9);
|
||||
expect(fn(78271.51696402048, 0))
|
||||
.toRoughlyEqual(78271.51696402048, 1e-10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with maxResolution, numZoomLevels, and zoomFactor options',
|
||||
function() {
|
||||
it('gives a correct resolution constraint function', function() {
|
||||
var options = {
|
||||
maxResolution: 81,
|
||||
numZoomLevels: 4,
|
||||
zoomFactor: 3
|
||||
};
|
||||
var fn = ol.Map.createConstraints_(options).resolution;
|
||||
expect(fn(82, 0)).toEqual(81);
|
||||
expect(fn(81, 0)).toEqual(81);
|
||||
expect(fn(27, 0)).toEqual(27);
|
||||
expect(fn(9, 0)).toEqual(9);
|
||||
expect(fn(3, 0)).toEqual(3);
|
||||
expect(fn(2, 0)).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with resolutions', function() {
|
||||
it('gives a correct resolution constraint function', function() {
|
||||
var options = {
|
||||
resolutions: [97, 76, 65, 54, 0.45]
|
||||
};
|
||||
var fn = ol.Map.createConstraints_(options).resolution;
|
||||
expect(fn(97, 0), 97);
|
||||
expect(fn(76, 0), 76);
|
||||
expect(fn(65, 0), 65);
|
||||
expect(fn(54, 0), 54);
|
||||
expect(fn(0.45, 0), 0.45);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('create interactions', function() {
|
||||
|
||||
var options;
|
||||
@@ -158,11 +109,13 @@ describe('ol.Map', function() {
|
||||
});
|
||||
|
||||
map = new ol.Map({
|
||||
center: new ol.Coordinate(0, 0),
|
||||
layers: new ol.Collection([layer]),
|
||||
renderer: ol.RendererHint.DOM,
|
||||
target: 'map',
|
||||
zoom: 1
|
||||
view: new ol.View2D({
|
||||
center: new ol.Coordinate(0, 0),
|
||||
zoom: 1
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -183,7 +136,7 @@ describe('ol.Map', function() {
|
||||
var duration = 500;
|
||||
var destination = new ol.Coordinate(1000, 1000);
|
||||
|
||||
var origin = map.getCenter();
|
||||
var origin = map.getView().getCenter();
|
||||
var start = new Date().getTime();
|
||||
var x0 = origin.x;
|
||||
var y0 = origin.y;
|
||||
@@ -202,7 +155,7 @@ describe('ol.Map', function() {
|
||||
x = destination.x;
|
||||
y = destination.y;
|
||||
}
|
||||
map.setCenter(new ol.Coordinate(x, y));
|
||||
map.getView().setCenter(new ol.Coordinate(x, y));
|
||||
if (more) {
|
||||
animationDelay.start();
|
||||
}
|
||||
@@ -220,7 +173,7 @@ describe('ol.Map', function() {
|
||||
waits(100);
|
||||
runs(function() {
|
||||
expect(o.callback).toHaveBeenCalled();
|
||||
var loc = map.getCenter();
|
||||
var loc = map.getView().getCenter();
|
||||
expect(loc.x).not.toEqual(origin.x);
|
||||
expect(loc.y).not.toEqual(origin.y);
|
||||
expect(loc.x).not.toEqual(destination.x);
|
||||
@@ -230,7 +183,7 @@ describe('ol.Map', function() {
|
||||
// confirm that the map has reached the destination after the duration
|
||||
waits(duration);
|
||||
runs(function() {
|
||||
var loc = map.getCenter();
|
||||
var loc = map.getView().getCenter();
|
||||
expect(loc.x).toEqual(destination.x);
|
||||
expect(loc.y).toEqual(destination.y);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user