remove the jsunit tests
This commit is contained in:
@@ -1,46 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.array');
|
|
||||||
|
|
||||||
|
|
||||||
function testBinaryFindNearest() {
|
|
||||||
var arr = [1000, 500, 100];
|
|
||||||
|
|
||||||
assertEquals(0, ol.array.binaryFindNearest(arr, 10000));
|
|
||||||
assertEquals(0, ol.array.binaryFindNearest(arr, 1000));
|
|
||||||
assertEquals(0, ol.array.binaryFindNearest(arr, 900));
|
|
||||||
|
|
||||||
assertEquals(1, ol.array.binaryFindNearest(arr, 750));
|
|
||||||
|
|
||||||
assertEquals(1, ol.array.binaryFindNearest(arr, 550));
|
|
||||||
assertEquals(1, ol.array.binaryFindNearest(arr, 500));
|
|
||||||
assertEquals(1, ol.array.binaryFindNearest(arr, 450));
|
|
||||||
|
|
||||||
assertEquals(2, ol.array.binaryFindNearest(arr, 300));
|
|
||||||
|
|
||||||
assertEquals(2, ol.array.binaryFindNearest(arr, 200));
|
|
||||||
assertEquals(2, ol.array.binaryFindNearest(arr, 100));
|
|
||||||
assertEquals(2, ol.array.binaryFindNearest(arr, 50));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testLinearFindNearest() {
|
|
||||||
var arr = [1000, 500, 100];
|
|
||||||
|
|
||||||
assertEquals(0, ol.array.linearFindNearest(arr, 10000));
|
|
||||||
assertEquals(0, ol.array.linearFindNearest(arr, 1000));
|
|
||||||
assertEquals(0, ol.array.linearFindNearest(arr, 900));
|
|
||||||
|
|
||||||
assertEquals(1, ol.array.linearFindNearest(arr, 750));
|
|
||||||
|
|
||||||
assertEquals(1, ol.array.linearFindNearest(arr, 550));
|
|
||||||
assertEquals(1, ol.array.linearFindNearest(arr, 500));
|
|
||||||
assertEquals(1, ol.array.linearFindNearest(arr, 450));
|
|
||||||
|
|
||||||
assertEquals(2, ol.array.linearFindNearest(arr, 300));
|
|
||||||
|
|
||||||
assertEquals(2, ol.array.linearFindNearest(arr, 200));
|
|
||||||
assertEquals(2, ol.array.linearFindNearest(arr, 100));
|
|
||||||
assertEquals(2, ol.array.linearFindNearest(arr, 50));
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,238 +0,0 @@
|
|||||||
goog.require('goog.array');
|
|
||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.Collection');
|
|
||||||
goog.require('ol.CollectionEventType');
|
|
||||||
|
|
||||||
|
|
||||||
function testEmpty() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
assertEquals(0, collection.getLength());
|
|
||||||
assertTrue(goog.array.equals(collection.getArray(), []));
|
|
||||||
assertUndefined(collection.getAt(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testConstruct() {
|
|
||||||
var array = [0, 1, 2];
|
|
||||||
var collection = new ol.Collection(array);
|
|
||||||
assertEquals(0, collection.getAt(0));
|
|
||||||
assertEquals(1, collection.getAt(1));
|
|
||||||
assertEquals(2, collection.getAt(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testPush() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
collection.push(1);
|
|
||||||
assertEquals(1, collection.getLength());
|
|
||||||
assertTrue(goog.array.equals(collection.getArray(), [1]));
|
|
||||||
assertEquals(1, collection.getAt(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testPushPop() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
collection.push(1);
|
|
||||||
collection.pop();
|
|
||||||
assertEquals(0, collection.getLength());
|
|
||||||
assertTrue(goog.array.equals(collection.getArray(), []));
|
|
||||||
assertUndefined(collection.getAt(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testInsertAt() {
|
|
||||||
var collection = new ol.Collection([0, 2]);
|
|
||||||
collection.insertAt(1, 1);
|
|
||||||
assertEquals(0, collection.getAt(0));
|
|
||||||
assertEquals(1, collection.getAt(1));
|
|
||||||
assertEquals(2, collection.getAt(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetAt() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
collection.setAt(1, 1);
|
|
||||||
assertEquals(2, collection.getLength());
|
|
||||||
assertUndefined(collection.getAt(0));
|
|
||||||
assertEquals(1, collection.getAt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testRemoveAt() {
|
|
||||||
var collection = new ol.Collection([0, 1, 2]);
|
|
||||||
collection.removeAt(1);
|
|
||||||
assertEquals(0, collection.getAt(0));
|
|
||||||
assertEquals(2, collection.getAt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForEachEmpty() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
var forEachCalled = false;
|
|
||||||
collection.forEach(function() {
|
|
||||||
forEachCalled = true;
|
|
||||||
});
|
|
||||||
assertFalse(forEachCalled);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForEachPopulated() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
collection.push(1);
|
|
||||||
collection.push(2);
|
|
||||||
var forEachCount = 0;
|
|
||||||
collection.forEach(function() {
|
|
||||||
++forEachCount;
|
|
||||||
});
|
|
||||||
assertEquals(2, forEachCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetAtEvent() {
|
|
||||||
var collection = new ol.Collection(['a', 'b']);
|
|
||||||
var index, prev;
|
|
||||||
goog.events.listen(collection, ol.CollectionEventType.SET_AT, function(e) {
|
|
||||||
index = e.index;
|
|
||||||
prev = e.prev;
|
|
||||||
});
|
|
||||||
collection.setAt(1, 1);
|
|
||||||
assertEquals(1, index);
|
|
||||||
assertEquals('b', prev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testRemoveAtEvent() {
|
|
||||||
var collection = new ol.Collection(['a']);
|
|
||||||
var index, prev;
|
|
||||||
goog.events.listen(
|
|
||||||
collection, ol.CollectionEventType.REMOVE_AT, function(e) {
|
|
||||||
index = e.index;
|
|
||||||
prev = e.prev;
|
|
||||||
});
|
|
||||||
collection.pop();
|
|
||||||
assertEquals(0, index);
|
|
||||||
assertEquals('a', prev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testInsertAtEvent() {
|
|
||||||
var collection = new ol.Collection([0, 2]);
|
|
||||||
var index;
|
|
||||||
goog.events.listen(
|
|
||||||
collection, ol.CollectionEventType.INSERT_AT, function(e) {
|
|
||||||
index = e.index;
|
|
||||||
});
|
|
||||||
collection.insertAt(1, 1);
|
|
||||||
assertEquals(1, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetAtBeyondEnd() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
var inserts = [];
|
|
||||||
goog.events.listen(
|
|
||||||
collection, ol.CollectionEventType.INSERT_AT, function(e) {
|
|
||||||
inserts.push(e.index);
|
|
||||||
});
|
|
||||||
collection.setAt(2, 0);
|
|
||||||
assertEquals(3, collection.getLength());
|
|
||||||
assertUndefined(collection.getAt(0));
|
|
||||||
assertUndefined(collection.getAt(1));
|
|
||||||
assertEquals(0, collection.getAt(2));
|
|
||||||
assertEquals(3, inserts.length);
|
|
||||||
assertEquals(0, inserts[0]);
|
|
||||||
assertEquals(1, inserts[1]);
|
|
||||||
assertEquals(2, inserts[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testLengthChangeInsertAt() {
|
|
||||||
var collection = new ol.Collection([0, 1, 2]);
|
|
||||||
var lengthEventDispatched;
|
|
||||||
goog.events.listen(collection, 'length_changed', function() {
|
|
||||||
lengthEventDispatched = true;
|
|
||||||
});
|
|
||||||
collection.insertAt(2, 3);
|
|
||||||
assertTrue(lengthEventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testLengthChangeRemoveAt() {
|
|
||||||
var collection = new ol.Collection([0, 1, 2]);
|
|
||||||
var lengthEventDispatched;
|
|
||||||
goog.events.listen(collection, 'length_changed', function() {
|
|
||||||
lengthEventDispatched = true;
|
|
||||||
});
|
|
||||||
collection.removeAt(0);
|
|
||||||
assertTrue(lengthEventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testLengthChangeSetAt() {
|
|
||||||
var collection = new ol.Collection([0, 1, 2]);
|
|
||||||
var lengthEventDispatched;
|
|
||||||
goog.events.listen(collection, 'length_changed', function() {
|
|
||||||
lengthEventDispatched = true;
|
|
||||||
});
|
|
||||||
collection.setAt(1, 1);
|
|
||||||
assertUndefined(lengthEventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForEach() {
|
|
||||||
var collection = new ol.Collection([1, 2, 4]);
|
|
||||||
var sum = 0;
|
|
||||||
collection.forEach(function(elem) {
|
|
||||||
sum += elem;
|
|
||||||
});
|
|
||||||
assertEquals(7, sum);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForEachScope() {
|
|
||||||
var collection = new ol.Collection([0]);
|
|
||||||
var that;
|
|
||||||
var uniqueObj = {};
|
|
||||||
collection.forEach(function(elem) {
|
|
||||||
that = this;
|
|
||||||
}, uniqueObj);
|
|
||||||
assertTrue(that === uniqueObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testAddEvent() {
|
|
||||||
var collection = new ol.Collection();
|
|
||||||
var elem;
|
|
||||||
goog.events.listen(collection, ol.CollectionEventType.ADD, function(e) {
|
|
||||||
elem = e.elem;
|
|
||||||
});
|
|
||||||
collection.push(1);
|
|
||||||
assertEquals(1, elem);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testAddRemoveEvent() {
|
|
||||||
var collection = new ol.Collection([1]);
|
|
||||||
var addedElem;
|
|
||||||
goog.events.listen(collection, ol.CollectionEventType.ADD, function(e) {
|
|
||||||
addedElem = e.elem;
|
|
||||||
});
|
|
||||||
var removedElem;
|
|
||||||
goog.events.listen(collection, ol.CollectionEventType.REMOVE, function(e) {
|
|
||||||
removedElem = e.elem;
|
|
||||||
});
|
|
||||||
collection.setAt(0, 2);
|
|
||||||
assertEquals(1, removedElem);
|
|
||||||
assertEquals(2, addedElem);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testRemove() {
|
|
||||||
var collection = new ol.Collection([1]);
|
|
||||||
var elem;
|
|
||||||
goog.events.listen(collection, ol.CollectionEventType.REMOVE, function(e) {
|
|
||||||
elem = e.elem;
|
|
||||||
});
|
|
||||||
collection.pop();
|
|
||||||
assertEquals(1, elem);
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.Extent');
|
|
||||||
goog.require('ol.Projection');
|
|
||||||
|
|
||||||
|
|
||||||
function testContainsPositive() {
|
|
||||||
var extent = new ol.Extent(1, 2, 3, 4);
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(1, 2)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(1, 3)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(1, 4)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(2, 2)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(2, 3)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(2, 4)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(3, 2)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(3, 3)));
|
|
||||||
assertTrue(extent.contains(new ol.Coordinate(3, 4)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testContainsNegative() {
|
|
||||||
var extent = new ol.Extent(1, 2, 3, 4);
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(0, 1)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(0, 2)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(0, 3)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(0, 4)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(0, 5)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(1, 1)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(1, 5)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(2, 1)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(2, 5)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(3, 1)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(3, 5)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(4, 1)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(4, 2)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(4, 3)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(4, 4)));
|
|
||||||
assertFalse(extent.contains(new ol.Coordinate(4, 5)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testTransform() {
|
|
||||||
var transformFn =
|
|
||||||
ol.Projection.getTransformFromCodes('EPSG:4326', 'EPSG:3857');
|
|
||||||
var sourceExtent = new ol.Extent(-15, -30, 45, 60);
|
|
||||||
var destinationExtent = sourceExtent.transform(transformFn);
|
|
||||||
assertNotNullNorUndefined(destinationExtent);
|
|
||||||
// FIXME check values with third-party tool
|
|
||||||
assertRoughlyEquals(-1669792.3618991037, destinationExtent.minX, 1e-9);
|
|
||||||
assertRoughlyEquals(-3503549.843504376, destinationExtent.minY, 1e-9);
|
|
||||||
assertRoughlyEquals(5009377.085697311, destinationExtent.maxX, 1e-9);
|
|
||||||
assertRoughlyEquals(8399737.889818361, destinationExtent.maxY, 1e-9);
|
|
||||||
}
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.interaction.ResolutionConstraint');
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToResolutionsZero() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToResolutions(
|
|
||||||
[1000, 500, 250, 100]);
|
|
||||||
assertEquals(1000, resolutionConstraint(1000, 0));
|
|
||||||
assertEquals(500, resolutionConstraint(500, 0));
|
|
||||||
assertEquals(250, resolutionConstraint(250, 0));
|
|
||||||
assertEquals(100, resolutionConstraint(100, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToResolutionsZoomIn() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToResolutions(
|
|
||||||
[1000, 500, 250, 100]);
|
|
||||||
assertEquals(500, resolutionConstraint(1000, 1));
|
|
||||||
assertEquals(250, resolutionConstraint(500, 1));
|
|
||||||
assertEquals(100, resolutionConstraint(250, 1));
|
|
||||||
assertEquals(100, resolutionConstraint(100, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToResolutionsZoomOut() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToResolutions(
|
|
||||||
[1000, 500, 250, 100]);
|
|
||||||
assertEquals(1000, resolutionConstraint(1000, -1));
|
|
||||||
assertEquals(1000, resolutionConstraint(500, -1));
|
|
||||||
assertEquals(500, resolutionConstraint(250, -1));
|
|
||||||
assertEquals(250, resolutionConstraint(100, -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToResolutionsNearestZero() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToResolutions(
|
|
||||||
[1000, 500, 250, 100]);
|
|
||||||
assertEquals(1000, resolutionConstraint(1050, 0));
|
|
||||||
assertEquals(1000, resolutionConstraint(950, 0));
|
|
||||||
assertEquals(500, resolutionConstraint(550, 0));
|
|
||||||
assertEquals(500, resolutionConstraint(400, 0));
|
|
||||||
assertEquals(250, resolutionConstraint(300, 0));
|
|
||||||
assertEquals(250, resolutionConstraint(200, 0));
|
|
||||||
assertEquals(100, resolutionConstraint(150, 0));
|
|
||||||
assertEquals(100, resolutionConstraint(50, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToResolutionsNearestZoomIn() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToResolutions(
|
|
||||||
[1000, 500, 250, 100]);
|
|
||||||
assertEquals(500, resolutionConstraint(1050, 1));
|
|
||||||
assertEquals(500, resolutionConstraint(950, 1));
|
|
||||||
assertEquals(250, resolutionConstraint(550, 1));
|
|
||||||
assertEquals(250, resolutionConstraint(450, 1));
|
|
||||||
assertEquals(100, resolutionConstraint(300, 1));
|
|
||||||
assertEquals(100, resolutionConstraint(200, 1));
|
|
||||||
assertEquals(100, resolutionConstraint(150, 1));
|
|
||||||
assertEquals(100, resolutionConstraint(50, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToResolutionsNearestZoomOut() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToResolutions(
|
|
||||||
[1000, 500, 250, 100]);
|
|
||||||
assertEquals(1000, resolutionConstraint(1050, -1));
|
|
||||||
assertEquals(1000, resolutionConstraint(950, -1));
|
|
||||||
assertEquals(1000, resolutionConstraint(550, -1));
|
|
||||||
assertEquals(1000, resolutionConstraint(450, -1));
|
|
||||||
assertEquals(500, resolutionConstraint(300, -1));
|
|
||||||
assertEquals(500, resolutionConstraint(200, -1));
|
|
||||||
assertEquals(250, resolutionConstraint(150, -1));
|
|
||||||
assertEquals(250, resolutionConstraint(50, -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToPowerZero() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
|
||||||
assertEquals(1024, resolutionConstraint(1024, 0));
|
|
||||||
assertEquals(512, resolutionConstraint(512, 0));
|
|
||||||
assertEquals(256, resolutionConstraint(256, 0));
|
|
||||||
assertEquals(128, resolutionConstraint(128, 0));
|
|
||||||
assertEquals(64, resolutionConstraint(64, 0));
|
|
||||||
assertEquals(32, resolutionConstraint(32, 0));
|
|
||||||
assertEquals(16, resolutionConstraint(16, 0));
|
|
||||||
assertEquals(8, resolutionConstraint(8, 0));
|
|
||||||
assertEquals(4, resolutionConstraint(4, 0));
|
|
||||||
assertEquals(2, resolutionConstraint(2, 0));
|
|
||||||
assertEquals(1, resolutionConstraint(1, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToPowerZoomIn() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
|
||||||
assertEquals(512, resolutionConstraint(1024, 1));
|
|
||||||
assertEquals(256, resolutionConstraint(512, 1));
|
|
||||||
assertEquals(128, resolutionConstraint(256, 1));
|
|
||||||
assertEquals(64, resolutionConstraint(128, 1));
|
|
||||||
assertEquals(32, resolutionConstraint(64, 1));
|
|
||||||
assertEquals(16, resolutionConstraint(32, 1));
|
|
||||||
assertEquals(8, resolutionConstraint(16, 1));
|
|
||||||
assertEquals(4, resolutionConstraint(8, 1));
|
|
||||||
assertEquals(2, resolutionConstraint(4, 1));
|
|
||||||
assertEquals(1, resolutionConstraint(2, 1));
|
|
||||||
assertEquals(1, resolutionConstraint(1, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToPowerZoomOut() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
|
||||||
assertEquals(1024, resolutionConstraint(1024, -1));
|
|
||||||
assertEquals(1024, resolutionConstraint(512, -1));
|
|
||||||
assertEquals(512, resolutionConstraint(256, -1));
|
|
||||||
assertEquals(256, resolutionConstraint(128, -1));
|
|
||||||
assertEquals(128, resolutionConstraint(64, -1));
|
|
||||||
assertEquals(64, resolutionConstraint(32, -1));
|
|
||||||
assertEquals(32, resolutionConstraint(16, -1));
|
|
||||||
assertEquals(16, resolutionConstraint(8, -1));
|
|
||||||
assertEquals(8, resolutionConstraint(4, -1));
|
|
||||||
assertEquals(4, resolutionConstraint(2, -1));
|
|
||||||
assertEquals(2, resolutionConstraint(1, -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSnapToPowerNearestZero() {
|
|
||||||
var resolutionConstraint =
|
|
||||||
ol.interaction.ResolutionConstraint.createSnapToPower(2, 1024, 10);
|
|
||||||
assertEquals(1024, resolutionConstraint(1050, 0));
|
|
||||||
assertEquals(1024, resolutionConstraint(9050, 0));
|
|
||||||
assertEquals(512, resolutionConstraint(550, 0));
|
|
||||||
assertEquals(512, resolutionConstraint(450, 0));
|
|
||||||
assertEquals(256, resolutionConstraint(300, 0));
|
|
||||||
assertEquals(256, resolutionConstraint(250, 0));
|
|
||||||
assertEquals(128, resolutionConstraint(150, 0));
|
|
||||||
assertEquals(128, resolutionConstraint(100, 0));
|
|
||||||
assertEquals(64, resolutionConstraint(75, 0));
|
|
||||||
assertEquals(64, resolutionConstraint(50, 0));
|
|
||||||
assertEquals(32, resolutionConstraint(40, 0));
|
|
||||||
assertEquals(32, resolutionConstraint(30, 0));
|
|
||||||
assertEquals(16, resolutionConstraint(20, 0));
|
|
||||||
assertEquals(16, resolutionConstraint(12, 0));
|
|
||||||
assertEquals(8, resolutionConstraint(9, 0));
|
|
||||||
assertEquals(8, resolutionConstraint(7, 0));
|
|
||||||
assertEquals(4, resolutionConstraint(5, 0));
|
|
||||||
assertEquals(4, resolutionConstraint(3.5, 0));
|
|
||||||
assertEquals(2, resolutionConstraint(2.1, 0));
|
|
||||||
assertEquals(2, resolutionConstraint(1.9, 0));
|
|
||||||
assertEquals(1, resolutionConstraint(1.1, 0));
|
|
||||||
assertEquals(1, resolutionConstraint(0.9, 0));
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.Coordinate');
|
|
||||||
goog.require('ol.TileCoord');
|
|
||||||
goog.require('ol.TileUrlFunction');
|
|
||||||
goog.require('ol.tilestore.XYZ');
|
|
||||||
|
|
||||||
|
|
||||||
function testXYZ() {
|
|
||||||
|
|
||||||
var xyzTileStore = new ol.tilestore.XYZ(
|
|
||||||
6, ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}'));
|
|
||||||
var tileGrid = xyzTileStore.getTileGrid();
|
|
||||||
|
|
||||||
var coordinate = new ol.Coordinate(829330.2064098881, 5933916.615134273);
|
|
||||||
var tileUrl;
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(
|
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 0));
|
|
||||||
assertEquals('0/0/0', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(
|
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 1));
|
|
||||||
assertEquals('1/1/0', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(
|
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 2));
|
|
||||||
assertEquals('2/2/1', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(
|
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 3));
|
|
||||||
assertEquals('3/4/2', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(
|
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 4));
|
|
||||||
assertEquals('4/8/5', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(
|
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 5));
|
|
||||||
assertEquals('5/16/11', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(
|
|
||||||
tileGrid.getTileCoordForCoordAndZ(coordinate, 6));
|
|
||||||
assertEquals('6/33/22', tileUrl);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testXYZWrapX() {
|
|
||||||
|
|
||||||
var xyzTileStore = new ol.tilestore.XYZ(
|
|
||||||
6, ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}'));
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(new ol.TileCoord(6, -31, -23));
|
|
||||||
assertEquals('6/33/22', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(new ol.TileCoord(6, 33, -23));
|
|
||||||
assertEquals('6/33/22', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(new ol.TileCoord(6, 97, -23));
|
|
||||||
assertEquals('6/33/22', tileUrl);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testXYZCropY() {
|
|
||||||
|
|
||||||
var xyzTileStore = new ol.tilestore.XYZ(
|
|
||||||
6, ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}'));
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(new ol.TileCoord(6, 33, -87));
|
|
||||||
assertUndefined(tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(new ol.TileCoord(6, 33, -23));
|
|
||||||
assertEquals('6/33/22', tileUrl);
|
|
||||||
|
|
||||||
tileUrl = xyzTileStore.getTileCoordUrl(new ol.TileCoord(6, 33, 41));
|
|
||||||
assertUndefined(tileUrl);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testXYZTileGridForEachTileCoordParentTileRange() {
|
|
||||||
|
|
||||||
var xyzTileGrid = new ol.tilegrid.XYZ(6);
|
|
||||||
|
|
||||||
var tileCoord = new ol.TileCoord(5, 11, 21);
|
|
||||||
var zs = [], tileRanges = [];
|
|
||||||
xyzTileGrid.forEachTileCoordParentTileRange(
|
|
||||||
tileCoord,
|
|
||||||
function(z, tileRange) {
|
|
||||||
zs.push(z);
|
|
||||||
tileRanges.push(tileRange);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
assertEquals(5, zs.length);
|
|
||||||
assertEquals(5, tileRanges.length);
|
|
||||||
|
|
||||||
assertEquals(4, zs[0]);
|
|
||||||
assertEquals(5, tileRanges[0].minX);
|
|
||||||
assertEquals(10, tileRanges[0].minY);
|
|
||||||
assertEquals(5, tileRanges[0].maxX);
|
|
||||||
assertEquals(10, tileRanges[0].maxY);
|
|
||||||
|
|
||||||
assertEquals(3, zs[1]);
|
|
||||||
assertEquals(2, tileRanges[1].minX);
|
|
||||||
assertEquals(5, tileRanges[1].minY);
|
|
||||||
assertEquals(2, tileRanges[1].maxX);
|
|
||||||
assertEquals(5, tileRanges[1].maxY);
|
|
||||||
|
|
||||||
assertEquals(2, zs[2]);
|
|
||||||
assertEquals(1, tileRanges[2].minX);
|
|
||||||
assertEquals(2, tileRanges[2].minY);
|
|
||||||
assertEquals(1, tileRanges[2].maxX);
|
|
||||||
assertEquals(2, tileRanges[2].maxY);
|
|
||||||
|
|
||||||
assertEquals(1, zs[3]);
|
|
||||||
assertEquals(0, tileRanges[3].minX);
|
|
||||||
assertEquals(1, tileRanges[3].minY);
|
|
||||||
assertEquals(0, tileRanges[3].maxX);
|
|
||||||
assertEquals(1, tileRanges[3].maxY);
|
|
||||||
|
|
||||||
assertEquals(0, zs[4]);
|
|
||||||
assertEquals(0, tileRanges[4].minX);
|
|
||||||
assertEquals(0, tileRanges[4].minY);
|
|
||||||
assertEquals(0, tileRanges[4].maxX);
|
|
||||||
assertEquals(0, tileRanges[4].maxY);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,389 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.Object');
|
|
||||||
|
|
||||||
|
|
||||||
function testModel() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
assertNotNullNorUndefined(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetUndefined() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
assertUndefined(m.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetSetGet() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
assertUndefined(m.get('k'));
|
|
||||||
m.set('k', 1);
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetValues() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
m.setValues({
|
|
||||||
k1: 1,
|
|
||||||
k2: 2
|
|
||||||
});
|
|
||||||
assertEquals(1, m.get('k1'));
|
|
||||||
assertEquals(2, m.get('k2'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testNotifyKeyEvent() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var eventDispatched = false;
|
|
||||||
goog.events.listen(m, 'k_changed', function() {
|
|
||||||
eventDispatched = true;
|
|
||||||
});
|
|
||||||
m.notify('k');
|
|
||||||
assertTrue(eventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindSetNotifyKeyEvent() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
var callbackCalled = false;
|
|
||||||
goog.events.listen(n, 'k_changed', function() {
|
|
||||||
eventDispatched = true;
|
|
||||||
});
|
|
||||||
n.bindTo('k', m);
|
|
||||||
m.set('k', 1);
|
|
||||||
assertTrue(eventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetNotifyKeyEvent() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var eventDispatched = false;
|
|
||||||
goog.events.listen(m, 'k_changed', function() {
|
|
||||||
eventDispatched = true;
|
|
||||||
});
|
|
||||||
m.set('k', 1);
|
|
||||||
assertTrue(eventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetBind() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
m.set('k', 1);
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
assertUndefined(n.get('k'));
|
|
||||||
n.bindTo('k', m);
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
assertEquals(1, n.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindSet() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
n.bindTo('k', m);
|
|
||||||
m.set('k', 1);
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
assertEquals(1, n.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindSetBackwards() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
n.bindTo('k', m);
|
|
||||||
n.set('k', 1);
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
assertEquals(1, n.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetBindBackwards() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
n.set('k', 1);
|
|
||||||
n.bindTo('k', m);
|
|
||||||
assertUndefined(m.get('k'));
|
|
||||||
assertUndefined(n.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindSetUnbind() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
n.bindTo('k', m);
|
|
||||||
n.set('k', 1);
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
assertEquals(1, n.get('k'));
|
|
||||||
n.unbind('k');
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
assertEquals(1, n.get('k'));
|
|
||||||
n.set('k', 2);
|
|
||||||
assertEquals(1, m.get('k'));
|
|
||||||
assertEquals(2, n.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testUnbindAll() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
n.bindTo('k', m);
|
|
||||||
n.set('k', 1);
|
|
||||||
assertEquals(m.get('k'), 1);
|
|
||||||
assertEquals(n.get('k'), 1);
|
|
||||||
n.unbindAll();
|
|
||||||
assertEquals(m.get('k'), 1);
|
|
||||||
assertEquals(n.get('k'), 1);
|
|
||||||
n.set('k', 2);
|
|
||||||
assertEquals(m.get('k'), 1);
|
|
||||||
assertEquals(n.get('k'), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindNotify() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
m.bindTo('k', n);
|
|
||||||
mEventDispatched = false;
|
|
||||||
goog.events.listen(m, 'k_changed', function() {
|
|
||||||
mEventDispatched = true;
|
|
||||||
});
|
|
||||||
nEventDispatched = false;
|
|
||||||
goog.events.listen(n, 'k_changed', function() {
|
|
||||||
nEventDispatched = true;
|
|
||||||
});
|
|
||||||
n.set('k', 1);
|
|
||||||
assertTrue(mEventDispatched);
|
|
||||||
assertTrue(nEventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindBackwardsNotify() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
n.bindTo('k', m);
|
|
||||||
mEventDispatched = false;
|
|
||||||
goog.events.listen(m, 'k_changed', function() {
|
|
||||||
mEventDispatched = true;
|
|
||||||
});
|
|
||||||
nEventDispatched = false;
|
|
||||||
goog.events.listen(n, 'k_changed', function() {
|
|
||||||
nEventDispatched = true;
|
|
||||||
});
|
|
||||||
n.set('k', 1);
|
|
||||||
assertTrue(mEventDispatched);
|
|
||||||
assertTrue(nEventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindRename() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
n.bindTo('kn', m, 'km');
|
|
||||||
m.set('km', 1);
|
|
||||||
assertEquals(m.get('km'), 1);
|
|
||||||
assertEquals(n.get('kn'), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindRenameEvents() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
kmEventDispatched = false;
|
|
||||||
goog.events.listen(m, 'km_changed', function() {
|
|
||||||
kmEventDispatched = true;
|
|
||||||
});
|
|
||||||
knEventDispatched = false;
|
|
||||||
goog.events.listen(n, 'kn_changed', function() {
|
|
||||||
knEventDispatched = true;
|
|
||||||
});
|
|
||||||
n.bindTo('kn', m, 'km');
|
|
||||||
m.set('km', 1);
|
|
||||||
assertEquals(m.get('km'), 1);
|
|
||||||
assertEquals(n.get('kn'), 1);
|
|
||||||
assertTrue(kmEventDispatched);
|
|
||||||
assertTrue(knEventDispatched);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testTransitiveBindForwards() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
var o = new ol.Object();
|
|
||||||
n.bindTo('kn', m, 'km');
|
|
||||||
o.bindTo('ko', n, 'kn');
|
|
||||||
m.set('km', 1);
|
|
||||||
assertEquals(1, m.get('km'));
|
|
||||||
assertEquals(1, n.get('kn'));
|
|
||||||
assertEquals(1, o.get('ko'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testTransitiveBindBackwards() {
|
|
||||||
var m = new ol.Object();
|
|
||||||
var n = new ol.Object();
|
|
||||||
var o = new ol.Object();
|
|
||||||
n.bindTo('kn', m, 'km');
|
|
||||||
o.bindTo('ko', n, 'kn');
|
|
||||||
o.set('ko', 1);
|
|
||||||
assertEquals(1, m.get('km'));
|
|
||||||
assertEquals(1, n.get('kn'));
|
|
||||||
assertEquals(1, o.get('ko'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testMrideyAccessors() {
|
|
||||||
// http://blog.mridey.com/2010/03/maps-javascript-api-v3-more-about.html
|
|
||||||
var a = new ol.Object();
|
|
||||||
a.set('level', 2);
|
|
||||||
assertEquals(2, a.get('level'));
|
|
||||||
var b = new ol.Object();
|
|
||||||
b.setValues({
|
|
||||||
level: 2,
|
|
||||||
index: 3,
|
|
||||||
description: 'Hello world.'
|
|
||||||
});
|
|
||||||
assertEquals(3, b.get('index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testMrideyBinding() {
|
|
||||||
// http://blog.mridey.com/2010/03/maps-javascript-api-v3-more-about.html
|
|
||||||
var a = new ol.Object();
|
|
||||||
a.set('level', 2);
|
|
||||||
var b = new ol.Object();
|
|
||||||
b.bindTo('index', a, 'level');
|
|
||||||
assertEquals(2, b.get('index'));
|
|
||||||
a.set('level', 3);
|
|
||||||
assertEquals(3, b.get('index'));
|
|
||||||
b.set('index', 4);
|
|
||||||
assertEquals(4, a.get('level'));
|
|
||||||
var c = new ol.Object();
|
|
||||||
c.bindTo('zoom', a, 'level');
|
|
||||||
assertEquals(4, c.get('zoom'));
|
|
||||||
b.unbind('index');
|
|
||||||
assertEquals(4, b.get('index'));
|
|
||||||
c.set('zoom', 5);
|
|
||||||
assertEquals(5, a.get('level'));
|
|
||||||
assertEquals(4, b.get('index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCircularBind() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
var b = new ol.Object();
|
|
||||||
a.bindTo('k', b);
|
|
||||||
assertThrows(function() {
|
|
||||||
b.bindTo('k', a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testPriority() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
var b = new ol.Object();
|
|
||||||
a.set('k', 1);
|
|
||||||
b.set('k', 2);
|
|
||||||
a.bindTo('k', b);
|
|
||||||
assertEquals(2, a.get('k'));
|
|
||||||
assertEquals(2, b.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testPriorityUndefined() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
var b = new ol.Object();
|
|
||||||
a.set('k', 1);
|
|
||||||
a.bindTo('k', b);
|
|
||||||
assertUndefined(a.get('k'));
|
|
||||||
assertUndefined(b.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetter() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
var x;
|
|
||||||
var setterCalled;
|
|
||||||
a.setX = function(value) {
|
|
||||||
this.x = value;
|
|
||||||
setterCalled = true;
|
|
||||||
};
|
|
||||||
a.set('x', 1);
|
|
||||||
assertEquals(1, a.get('x'));
|
|
||||||
assertUndefined(setterCalled);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSetterBind() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
var x;
|
|
||||||
var setterCalled;
|
|
||||||
a.setX = function(value) {
|
|
||||||
this.x = value;
|
|
||||||
setterCalled = true;
|
|
||||||
};
|
|
||||||
var b = new ol.Object();
|
|
||||||
b.bindTo('x', a);
|
|
||||||
b.set('x', 1);
|
|
||||||
assertEquals(1, a.get('x'));
|
|
||||||
assertEquals(1, b.get('x'));
|
|
||||||
assertTrue(setterCalled);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetter() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
var getterCalled;
|
|
||||||
a.getX = function() {
|
|
||||||
getterCalled = true;
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
assertUndefined(a.get('x'));
|
|
||||||
assertUndefined(getterCalled);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetterBind() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
var getterCalled;
|
|
||||||
a.getX = function() {
|
|
||||||
getterCalled = true;
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
var b = new ol.Object();
|
|
||||||
b.bindTo('x', a);
|
|
||||||
assertEquals(1, b.get('x'));
|
|
||||||
assertTrue(getterCalled);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBindSelf() {
|
|
||||||
var a = new ol.Object();
|
|
||||||
assertThrows(function() {
|
|
||||||
a.bindTo('k', a);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateWithOptions() {
|
|
||||||
var obj = new ol.Object({k: 1});
|
|
||||||
assertEquals(1, obj.get('k'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testEventTypeCaseSensitivity() {
|
|
||||||
var obj = new ol.Object();
|
|
||||||
var lowercaseEventDispatched = false;
|
|
||||||
goog.events.listen(obj, 'k_changed', function() {
|
|
||||||
lowercaseEventDispatched = true;
|
|
||||||
});
|
|
||||||
var uppercaseEventDispatched = false;
|
|
||||||
goog.events.listen(obj, 'K_changed', function() {
|
|
||||||
uppercaseEventDispatched = true;
|
|
||||||
});
|
|
||||||
obj.set('K', 1);
|
|
||||||
assertTrue(lowercaseEventDispatched);
|
|
||||||
assertFalse(uppercaseEventDispatched);
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
goog.require('goog.array');
|
|
||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.Coordinate');
|
|
||||||
goog.require('ol.Projection');
|
|
||||||
|
|
||||||
|
|
||||||
function _testAllEquivalent(codes) {
|
|
||||||
var projections = goog.array.map(codes, ol.Projection.getFromCode);
|
|
||||||
goog.array.forEach(projections, function(source) {
|
|
||||||
goog.array.forEach(projections, function(destination) {
|
|
||||||
assertTrue(ol.Projection.equivalent(source, destination));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testEpsg3857Equivalence() {
|
|
||||||
_testAllEquivalent([
|
|
||||||
'EPSG:3857',
|
|
||||||
'EPSG:102100',
|
|
||||||
'EPSG:102113',
|
|
||||||
'EPSG:900913'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testEpsg4326Equivalence() {
|
|
||||||
_testAllEquivalent([
|
|
||||||
'CRS:84',
|
|
||||||
'urn:ogc:def:crs:EPSG:6.6:4326',
|
|
||||||
'EPSG:4326'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testIdentityTransform() {
|
|
||||||
var epsg4326 = ol.Projection.getFromCode('EPSG:4326');
|
|
||||||
var uniqueObject = {};
|
|
||||||
var sourcePoint = new ol.Coordinate(uniqueObject, uniqueObject);
|
|
||||||
var destinationPoint = ol.Projection.transform(
|
|
||||||
sourcePoint, epsg4326, epsg4326);
|
|
||||||
assertFalse(sourcePoint === destinationPoint);
|
|
||||||
assertTrue(destinationPoint.x === sourcePoint.x);
|
|
||||||
assertTrue(destinationPoint.y === sourcePoint.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForwardSphericalMercatorOrigin() {
|
|
||||||
var point = ol.Projection.transformWithCodes(
|
|
||||||
new ol.Coordinate(0, 0), 'EPSG:4326', 'EPSG:3857');
|
|
||||||
assertNotNullNorUndefined(point);
|
|
||||||
assertEquals(0, point.x);
|
|
||||||
assertRoughlyEquals(0, point.y, 1e-9);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testInverseSphericalMercatorOrigin() {
|
|
||||||
var point = ol.Projection.transformWithCodes(
|
|
||||||
new ol.Coordinate(0, 0), 'EPSG:3857', 'EPSG:4326');
|
|
||||||
assertNotNullNorUndefined(point);
|
|
||||||
assertEquals(0, point.x);
|
|
||||||
assertEquals(0, point.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForwardSphericalMercatorAlastaira() {
|
|
||||||
// http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/
|
|
||||||
var point = ol.Projection.transformWithCodes(
|
|
||||||
new ol.Coordinate(-5.625, 52.4827802220782),
|
|
||||||
'EPSG:4326',
|
|
||||||
'EPSG:900913');
|
|
||||||
assertNotNullNorUndefined(point);
|
|
||||||
assertRoughlyEquals(-626172.13571216376, point.x, 1e-9);
|
|
||||||
assertRoughlyEquals(6887893.4928337997, point.y, 1e-9);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testInverseSphericalMercatorAlastaira() {
|
|
||||||
// http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/
|
|
||||||
var point = ol.Projection.transformWithCodes(
|
|
||||||
new ol.Coordinate(-626172.13571216376, 6887893.4928337997),
|
|
||||||
'EPSG:900913',
|
|
||||||
'EPSG:4326');
|
|
||||||
assertNotNullNorUndefined(point);
|
|
||||||
assertRoughlyEquals(-5.625, point.x, 1e-9);
|
|
||||||
assertRoughlyEquals(52.4827802220782, point.y, 1e-9);
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.Coordinate');
|
|
||||||
goog.require('ol.Rectangle');
|
|
||||||
|
|
||||||
|
|
||||||
function testCenter() {
|
|
||||||
var rectangle = new ol.Rectangle(1, 2, 3, 4);
|
|
||||||
var center = rectangle.getCenter();
|
|
||||||
assertEquals(2, center.x);
|
|
||||||
assertEquals(3, center.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testIntersects() {
|
|
||||||
|
|
||||||
var rectangle1 = new ol.Rectangle(50, 50, 100, 100);
|
|
||||||
|
|
||||||
function assertIntersects(rectangle2) {
|
|
||||||
assertTrue(rectangle1 + ' expected to intersect ' + rectangle2,
|
|
||||||
rectangle1.intersects(rectangle2));
|
|
||||||
}
|
|
||||||
function assertNotIntersects(rectangle2) {
|
|
||||||
assertFalse(rectangle1 + ' expected to not intersect ' + rectangle2,
|
|
||||||
rectangle1.intersects(rectangle2));
|
|
||||||
}
|
|
||||||
|
|
||||||
assertIntersects(rectangle1);
|
|
||||||
assertIntersects(new ol.Rectangle(20, 20, 80, 80));
|
|
||||||
assertIntersects(new ol.Rectangle(20, 50, 80, 100));
|
|
||||||
assertIntersects(new ol.Rectangle(20, 80, 80, 120));
|
|
||||||
assertIntersects(new ol.Rectangle(50, 20, 100, 80));
|
|
||||||
assertIntersects(new ol.Rectangle(50, 80, 100, 120));
|
|
||||||
assertIntersects(new ol.Rectangle(80, 20, 120, 80));
|
|
||||||
assertIntersects(new ol.Rectangle(80, 50, 120, 100));
|
|
||||||
assertIntersects(new ol.Rectangle(80, 80, 120, 120));
|
|
||||||
assertIntersects(new ol.Rectangle(20, 20, 120, 120));
|
|
||||||
assertIntersects(new ol.Rectangle(70, 70, 80, 80));
|
|
||||||
assertNotIntersects(new ol.Rectangle(10, 10, 30, 30));
|
|
||||||
assertNotIntersects(new ol.Rectangle(30, 10, 70, 30));
|
|
||||||
assertNotIntersects(new ol.Rectangle(50, 10, 100, 30));
|
|
||||||
assertNotIntersects(new ol.Rectangle(80, 10, 120, 30));
|
|
||||||
assertNotIntersects(new ol.Rectangle(120, 10, 140, 30));
|
|
||||||
assertNotIntersects(new ol.Rectangle(10, 30, 30, 70));
|
|
||||||
assertNotIntersects(new ol.Rectangle(120, 30, 140, 70));
|
|
||||||
assertNotIntersects(new ol.Rectangle(10, 50, 30, 100));
|
|
||||||
assertNotIntersects(new ol.Rectangle(120, 50, 140, 100));
|
|
||||||
assertNotIntersects(new ol.Rectangle(10, 80, 30, 120));
|
|
||||||
assertNotIntersects(new ol.Rectangle(120, 80, 140, 120));
|
|
||||||
assertNotIntersects(new ol.Rectangle(10, 120, 30, 140));
|
|
||||||
assertNotIntersects(new ol.Rectangle(30, 120, 70, 140));
|
|
||||||
assertNotIntersects(new ol.Rectangle(50, 120, 100, 140));
|
|
||||||
assertNotIntersects(new ol.Rectangle(80, 120, 120, 140));
|
|
||||||
assertNotIntersects(new ol.Rectangle(120, 120, 140, 140));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSize() {
|
|
||||||
var rectangle = new ol.Rectangle(0, 1, 2, 4);
|
|
||||||
var size = rectangle.getSize();
|
|
||||||
assertEquals(2, size.width);
|
|
||||||
assertEquals(3, size.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testNormalize() {
|
|
||||||
var rectangle = new ol.Rectangle(0, 1, 2, 3);
|
|
||||||
var coordinate;
|
|
||||||
|
|
||||||
coordinate = rectangle.normalize(new ol.Coordinate(1, 2));
|
|
||||||
assertEquals(0.5, coordinate.x);
|
|
||||||
assertEquals(0.5, coordinate.y);
|
|
||||||
|
|
||||||
coordinate = rectangle.normalize(new ol.Coordinate(0, 3));
|
|
||||||
assertEquals(0, coordinate.x);
|
|
||||||
assertEquals(1, coordinate.y);
|
|
||||||
|
|
||||||
coordinate = rectangle.normalize(new ol.Coordinate(2, 1));
|
|
||||||
assertEquals(1, coordinate.x);
|
|
||||||
assertEquals(0, coordinate.y);
|
|
||||||
|
|
||||||
coordinate = rectangle.normalize(new ol.Coordinate(0, 0));
|
|
||||||
assertEquals(0, coordinate.x);
|
|
||||||
assertEquals(-0.5, coordinate.y);
|
|
||||||
|
|
||||||
coordinate = rectangle.normalize(new ol.Coordinate(-1, 1));
|
|
||||||
assertEquals(-0.5, coordinate.x);
|
|
||||||
assertEquals(0, coordinate.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testToString() {
|
|
||||||
var rectangle = new ol.Rectangle(0, 1, 2, 3);
|
|
||||||
assertEquals('(0, 1, 2, 3)', rectangle.toString());
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.TileCoord');
|
|
||||||
|
|
||||||
|
|
||||||
function testConstructorOrderZXY() {
|
|
||||||
var tc1 = new ol.TileCoord(1, 2, 3);
|
|
||||||
assertEquals(1, tc1.z);
|
|
||||||
assertEquals(2, tc1.x);
|
|
||||||
assertEquals(3, tc1.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateFromQuadKey() {
|
|
||||||
var tileCoord = ol.TileCoord.createFromQuadKey('213');
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(3, tileCoord.x);
|
|
||||||
assertEquals(5, tileCoord.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateFromString() {
|
|
||||||
var str = '1/2/3';
|
|
||||||
var tc = ol.TileCoord.createFromString(str);
|
|
||||||
assertEquals(1, tc.z);
|
|
||||||
assertEquals(2, tc.x);
|
|
||||||
assertEquals(3, tc.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testQuadKey() {
|
|
||||||
assertEquals('213', (new ol.TileCoord(3, 3, 5)).quadKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testHash() {
|
|
||||||
var tc1 = new ol.TileCoord(3, 2, 1);
|
|
||||||
var tc2 = new ol.TileCoord(3, 1, 1);
|
|
||||||
assertTrue(tc1.hash() != tc2.hash());
|
|
||||||
}
|
|
||||||
@@ -1,465 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.Coordinate');
|
|
||||||
goog.require('ol.Extent');
|
|
||||||
goog.require('ol.Size');
|
|
||||||
goog.require('ol.TileCoord');
|
|
||||||
goog.require('ol.TileGrid');
|
|
||||||
|
|
||||||
|
|
||||||
var extent;
|
|
||||||
var resolutions;
|
|
||||||
var origin;
|
|
||||||
var origins;
|
|
||||||
var tileSize;
|
|
||||||
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
resolutions = [1000, 500, 250, 100];
|
|
||||||
extent = new ol.Extent(0, 0, 100000, 100000);
|
|
||||||
origin = new ol.Coordinate(0, 0);
|
|
||||||
origins = [];
|
|
||||||
tileSize = new ol.Size(100, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateValid() {
|
|
||||||
assertNotThrows(function() {
|
|
||||||
return new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateDuplicateResolutions() {
|
|
||||||
var resolutions = [100, 50, 50, 25, 10];
|
|
||||||
assertThrows(function() {
|
|
||||||
return new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateOutOfOrderResolutions() {
|
|
||||||
var resolutions = [100, 25, 50, 10];
|
|
||||||
assertThrows(function() {
|
|
||||||
return new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateOrigins() {
|
|
||||||
var resolutions = [100, 50, 25, 10];
|
|
||||||
var origins = [origin, origin, origin, origin];
|
|
||||||
assertNotThrows(function() {
|
|
||||||
return new ol.TileGrid(resolutions, extent, origins, tileSize);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateTooFewOrigins() {
|
|
||||||
var resolutions = [100, 50, 25, 10];
|
|
||||||
var origins = [origin, origin, origin];
|
|
||||||
assertThrows(function() {
|
|
||||||
return new ol.TileGrid(resolutions, extent, origins, tileSize);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateTooManyOrigins() {
|
|
||||||
var resolutions = [100, 50, 25, 10];
|
|
||||||
var origins = [origin, origin, origin, origin, origin];
|
|
||||||
assertThrows(function() {
|
|
||||||
return new ol.TileGrid(resolutions, extent, origins, tileSize);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetTileCoord() {
|
|
||||||
|
|
||||||
origin = new ol.Coordinate(0, 0);
|
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
var tileCoord;
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(0, 0), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(0, 100000), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(10, tileCoord.y);
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(100000, 0), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(10, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(100000, 100000), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(10, tileCoord.x);
|
|
||||||
assertEquals(10, tileCoord.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetTileCoordYSouth() {
|
|
||||||
|
|
||||||
origin = new ol.Coordinate(0, 100000);
|
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
var tileCoord;
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(0, 0), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(-10, tileCoord.y);
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(0, 100000), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(100000, 0), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(10, tileCoord.x);
|
|
||||||
assertEquals(-10, tileCoord.y);
|
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
|
||||||
new ol.Coordinate(100000, 100000), 3);
|
|
||||||
assertEquals(3, tileCoord.z);
|
|
||||||
assertEquals(10, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetTileCoordForCoordAndResolution() {
|
|
||||||
|
|
||||||
var tileSize = new ol.Size(256, 256);
|
|
||||||
var tileGrid = new ol.TileGrid([10], extent, origin, tileSize);
|
|
||||||
|
|
||||||
var coordinate;
|
|
||||||
var tileCoord;
|
|
||||||
|
|
||||||
// gets the first tile at the origin
|
|
||||||
coordinate = new ol.Coordinate(0, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets one tile northwest of the origin
|
|
||||||
coordinate = new ol.Coordinate(-1280, 1280);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(-1, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets one tile northeast of the origin
|
|
||||||
coordinate = new ol.Coordinate(1280, 1280);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets one tile southeast of the origin
|
|
||||||
coordinate = new ol.Coordinate(1280, -1280);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(-1, tileCoord.y);
|
|
||||||
|
|
||||||
// gets one tile southwest of the origin
|
|
||||||
coordinate = new ol.Coordinate(-1280, -1280);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(-1, tileCoord.x);
|
|
||||||
assertEquals(-1, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the tile to the east when on the edge
|
|
||||||
coordinate = new ol.Coordinate(2560, -1280);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(1, tileCoord.x);
|
|
||||||
assertEquals(-1, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the tile to the north when on the edge
|
|
||||||
coordinate = new ol.Coordinate(1280, -2560);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(-1, tileCoord.y);
|
|
||||||
|
|
||||||
// pixels are top aligned to the origin
|
|
||||||
coordinate = new ol.Coordinate(1280, -2559.999);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(-1, tileCoord.y);
|
|
||||||
|
|
||||||
// pixels are left aligned to the origin
|
|
||||||
coordinate = new ol.Coordinate(2559.999, -1280);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 10);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(-1, tileCoord.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testGetTileCoordForCoordAndResolutionFractional() {
|
|
||||||
|
|
||||||
var tileSize = new ol.Size(256, 256);
|
|
||||||
var tileGrid = new ol.TileGrid([1 / 3], extent, origin, tileSize);
|
|
||||||
|
|
||||||
var coordinate;
|
|
||||||
var tileCoord;
|
|
||||||
|
|
||||||
// These tests render at a resolution of 1. Because the layer's
|
|
||||||
// closest resolution is 1/3, the images are scaled by 1/3.
|
|
||||||
// In this scenario, every third tile will be one pixel wider when
|
|
||||||
// rendered (0,0 is normal; 1,0 is wider; 0,1 is taller; etc.)
|
|
||||||
|
|
||||||
// gets the first tile at the origin
|
|
||||||
coordinate = new ol.Coordinate(0, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the 1,0 tile at 256/3,0
|
|
||||||
coordinate = new ol.Coordinate(256 / 3, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(1, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// still gets the 1,0 tile at 512/3,0 - wider tile
|
|
||||||
coordinate = new ol.Coordinate(512 / 3, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(1, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the 2,0 tile at 513/3,0
|
|
||||||
coordinate = new ol.Coordinate(513 / 3, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(2, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the 3,0 tile at 768/3,0
|
|
||||||
coordinate = new ol.Coordinate(768 / 3, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(3, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the 4,0 tile at 1024/3,0
|
|
||||||
coordinate = new ol.Coordinate(1024 / 3, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(4, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// still gets the 4,0 tile at 1280/3,0 - wider tile
|
|
||||||
coordinate = new ol.Coordinate(1280 / 3, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(4, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the 5,0 tile at 1281/3,0
|
|
||||||
coordinate = new ol.Coordinate(1281 / 3, 0);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(5, tileCoord.x);
|
|
||||||
assertEquals(0, tileCoord.y);
|
|
||||||
|
|
||||||
// gets the 0,1 tile at 0,-256/3
|
|
||||||
coordinate = new ol.Coordinate(0, -256 / 3);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(-2, tileCoord.y);
|
|
||||||
|
|
||||||
// still gets the 0,1 tile at 0,-512/3 - taller tile
|
|
||||||
coordinate = new ol.Coordinate(0, -512 / 3);
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndResolution(
|
|
||||||
coordinate, 1);
|
|
||||||
assertEquals(0, tileCoord.z);
|
|
||||||
assertEquals(0, tileCoord.x);
|
|
||||||
assertEquals(-2, tileCoord.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetTileCoordCenter() {
|
|
||||||
|
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
var center;
|
|
||||||
|
|
||||||
center = tileGrid.getTileCoordCenter(new ol.TileCoord(0, 0, 0));
|
|
||||||
assertEquals(50000, center.x);
|
|
||||||
assertEquals(50000, center.y);
|
|
||||||
|
|
||||||
center = tileGrid.getTileCoordCenter(new ol.TileCoord(3, 0, 0));
|
|
||||||
assertEquals(5000, center.x);
|
|
||||||
assertEquals(5000, center.y);
|
|
||||||
|
|
||||||
center = tileGrid.getTileCoordCenter(new ol.TileCoord(3, 9, 9));
|
|
||||||
assertEquals(95000, center.x);
|
|
||||||
assertEquals(95000, center.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function testGetTileCoordExtent() {
|
|
||||||
|
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
var tileCoordExtent;
|
|
||||||
|
|
||||||
tileCoordExtent = tileGrid.getTileCoordExtent(new ol.TileCoord(0, 0, 0));
|
|
||||||
assertEquals(0, tileCoordExtent.minX);
|
|
||||||
assertEquals(0, tileCoordExtent.minY);
|
|
||||||
assertEquals(100000, tileCoordExtent.maxX);
|
|
||||||
assertEquals(100000, tileCoordExtent.maxY);
|
|
||||||
|
|
||||||
tileCoordExtent = tileGrid.getTileCoordExtent(new ol.TileCoord(3, 9, 0));
|
|
||||||
assertEquals(90000, tileCoordExtent.minX);
|
|
||||||
assertEquals(0, tileCoordExtent.minY);
|
|
||||||
assertEquals(100000, tileCoordExtent.maxX);
|
|
||||||
assertEquals(10000, tileCoordExtent.maxY);
|
|
||||||
|
|
||||||
tileCoordExtent = tileGrid.getTileCoordExtent(new ol.TileCoord(3, 0, 9));
|
|
||||||
assertEquals(0, tileCoordExtent.minX);
|
|
||||||
assertEquals(90000, tileCoordExtent.minY);
|
|
||||||
assertEquals(10000, tileCoordExtent.maxX);
|
|
||||||
assertEquals(100000, tileCoordExtent.maxY);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetExtentTileRange() {
|
|
||||||
|
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
var e = new ol.Extent(45000, 5000, 55000, 15000);
|
|
||||||
var tileRange;
|
|
||||||
|
|
||||||
tileRange = tileGrid.getTileRangeForExtentAndZ(e, 0);
|
|
||||||
assertEquals(0, tileRange.minY);
|
|
||||||
assertEquals(0, tileRange.minX);
|
|
||||||
assertEquals(0, tileRange.maxX);
|
|
||||||
assertEquals(0, tileRange.maxY);
|
|
||||||
|
|
||||||
tileRange = tileGrid.getTileRangeForExtentAndZ(e, 1);
|
|
||||||
assertEquals(0, tileRange.minX);
|
|
||||||
assertEquals(0, tileRange.minY);
|
|
||||||
assertEquals(1, tileRange.maxX);
|
|
||||||
assertEquals(0, tileRange.maxY);
|
|
||||||
|
|
||||||
tileRange = tileGrid.getTileRangeForExtentAndZ(e, 2);
|
|
||||||
assertEquals(1, tileRange.minX);
|
|
||||||
assertEquals(0, tileRange.minY);
|
|
||||||
assertEquals(2, tileRange.maxX);
|
|
||||||
assertEquals(0, tileRange.maxY);
|
|
||||||
|
|
||||||
tileRange = tileGrid.getTileRangeForExtentAndZ(e, 3);
|
|
||||||
assertEquals(4, tileRange.minX);
|
|
||||||
assertEquals(0, tileRange.minY);
|
|
||||||
assertEquals(5, tileRange.maxX);
|
|
||||||
assertEquals(1, tileRange.maxY);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForEachTileCoordParent() {
|
|
||||||
|
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
var zs = [], tileRanges = [];
|
|
||||||
|
|
||||||
tileGrid.forEachTileCoordParentTileRange(
|
|
||||||
new ol.TileCoord(3, 7, 3),
|
|
||||||
function(z, tileRange) {
|
|
||||||
zs.push(z);
|
|
||||||
tileRanges.push(tileRange);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
assertEquals(3, zs.length);
|
|
||||||
assertEquals(3, tileRanges.length);
|
|
||||||
|
|
||||||
assertEquals(2, zs[0]);
|
|
||||||
assertEquals(2, tileRanges[0].minX);
|
|
||||||
assertEquals(1, tileRanges[0].minY);
|
|
||||||
assertEquals(3, tileRanges[0].maxX);
|
|
||||||
assertEquals(1, tileRanges[0].maxY);
|
|
||||||
|
|
||||||
assertEquals(1, zs[1]);
|
|
||||||
assertEquals(1, tileRanges[1].minX);
|
|
||||||
assertEquals(0, tileRanges[1].minY);
|
|
||||||
assertEquals(1, tileRanges[1].maxX);
|
|
||||||
assertEquals(0, tileRanges[1].maxY);
|
|
||||||
|
|
||||||
assertEquals(0, zs[2]);
|
|
||||||
assertEquals(0, tileRanges[2].minX);
|
|
||||||
assertEquals(0, tileRanges[2].minY);
|
|
||||||
assertEquals(0, tileRanges[2].maxX);
|
|
||||||
assertEquals(0, tileRanges[2].maxY);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetZForResolutionExact() {
|
|
||||||
|
|
||||||
var tileGrid =
|
|
||||||
new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
|
|
||||||
assertEquals(0, tileGrid.getZForResolution(1000));
|
|
||||||
assertEquals(1, tileGrid.getZForResolution(500));
|
|
||||||
assertEquals(2, tileGrid.getZForResolution(250));
|
|
||||||
assertEquals(3, tileGrid.getZForResolution(100));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testGetZForResolutionApproximate() {
|
|
||||||
|
|
||||||
var tileGrid =
|
|
||||||
new ol.TileGrid(resolutions, extent, origin, tileSize);
|
|
||||||
|
|
||||||
assertEquals(0, tileGrid.getZForResolution(2000));
|
|
||||||
assertEquals(0, tileGrid.getZForResolution(1000));
|
|
||||||
assertEquals(0, tileGrid.getZForResolution(900));
|
|
||||||
assertEquals(1, tileGrid.getZForResolution(750));
|
|
||||||
assertEquals(1, tileGrid.getZForResolution(625));
|
|
||||||
assertEquals(1, tileGrid.getZForResolution(500));
|
|
||||||
assertEquals(1, tileGrid.getZForResolution(475));
|
|
||||||
assertEquals(2, tileGrid.getZForResolution(375));
|
|
||||||
assertEquals(2, tileGrid.getZForResolution(250));
|
|
||||||
assertEquals(2, tileGrid.getZForResolution(200));
|
|
||||||
assertEquals(3, tileGrid.getZForResolution(125));
|
|
||||||
assertEquals(3, tileGrid.getZForResolution(100));
|
|
||||||
assertEquals(3, tileGrid.getZForResolution(50));
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.TileRange');
|
|
||||||
|
|
||||||
|
|
||||||
function testContains() {
|
|
||||||
var tileRange = new ol.TileRange(1, 1, 3, 3);
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 0, 0)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 0, 1)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 0, 2)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 0, 3)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 0, 4)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 1, 0)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 1, 1)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 1, 2)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 1, 3)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 1, 4)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 2, 0)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 2, 1)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 2, 2)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 2, 3)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 2, 4)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 3, 0)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 3, 1)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 3, 2)));
|
|
||||||
assertTrue(tileRange.contains(new ol.TileCoord(0, 3, 3)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 3, 4)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 4, 0)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 4, 1)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 4, 2)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 4, 3)));
|
|
||||||
assertFalse(tileRange.contains(new ol.TileCoord(0, 4, 4)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBoundingTileRange() {
|
|
||||||
var tileRange = new ol.TileRange.boundingTileRange(
|
|
||||||
new ol.TileCoord(3, 1, 3),
|
|
||||||
new ol.TileCoord(3, 2, 0));
|
|
||||||
assertEquals(1, tileRange.minX);
|
|
||||||
assertEquals(0, tileRange.minY);
|
|
||||||
assertEquals(2, tileRange.maxX);
|
|
||||||
assertEquals(3, tileRange.maxY);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testBoundingTileRangeMixedZ() {
|
|
||||||
assertThrows(function() {
|
|
||||||
var tileRange = new ol.TileRange.boundingTileRange(
|
|
||||||
new ol.TileCoord(3, 1, 3),
|
|
||||||
new ol.TileCoord(4, 2, 0));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testForEachTileCoord() {
|
|
||||||
|
|
||||||
var tileRange = new ol.TileRange(0, 2, 1, 3);
|
|
||||||
|
|
||||||
var tileCoords = [];
|
|
||||||
tileRange.forEachTileCoord(5, function(tileCoord) {
|
|
||||||
tileCoords.push(new ol.TileCoord(tileCoord.z, tileCoord.x, tileCoord.y));
|
|
||||||
});
|
|
||||||
|
|
||||||
assertEquals(4, tileCoords.length);
|
|
||||||
|
|
||||||
assertEquals(5, tileCoords[0].z);
|
|
||||||
assertEquals(0, tileCoords[0].x);
|
|
||||||
assertEquals(2, tileCoords[0].y);
|
|
||||||
|
|
||||||
assertEquals(5, tileCoords[1].z);
|
|
||||||
assertEquals(0, tileCoords[1].x);
|
|
||||||
assertEquals(3, tileCoords[1].y);
|
|
||||||
|
|
||||||
assertEquals(5, tileCoords[2].z);
|
|
||||||
assertEquals(1, tileCoords[2].x);
|
|
||||||
assertEquals(2, tileCoords[2].y);
|
|
||||||
|
|
||||||
assertEquals(5, tileCoords[3].z);
|
|
||||||
assertEquals(1, tileCoords[3].x);
|
|
||||||
assertEquals(3, tileCoords[3].y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testSize() {
|
|
||||||
var tileRange = new ol.TileRange(0, 1, 2, 4);
|
|
||||||
var size = tileRange.getSize();
|
|
||||||
assertEquals(3, size.width);
|
|
||||||
assertEquals(4, size.height);
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
goog.require('goog.testing.jsunit');
|
|
||||||
goog.require('ol.TileCoord');
|
|
||||||
goog.require('ol.TileUrlFunction');
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateFromTemplate() {
|
|
||||||
var tileUrl = ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}');
|
|
||||||
assertEquals('3/2/1', tileUrl(new ol.TileCoord(3, 2, 1)));
|
|
||||||
assertUndefined(tileUrl(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testWithTileCoordTransform() {
|
|
||||||
var tileUrl = ol.TileUrlFunction.withTileCoordTransform(
|
|
||||||
function(tileCoord) {
|
|
||||||
return new ol.TileCoord(tileCoord.z, tileCoord.x, -tileCoord.y);
|
|
||||||
},
|
|
||||||
ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}'));
|
|
||||||
assertEquals('3/2/1', tileUrl(new ol.TileCoord(3, 2, -1)));
|
|
||||||
assertUndefined(tileUrl(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function testCreateFromTileUrlFunctions() {
|
|
||||||
var tileUrl = ol.TileUrlFunction.createFromTileUrlFunctions([
|
|
||||||
ol.TileUrlFunction.createFromTemplate('a'),
|
|
||||||
ol.TileUrlFunction.createFromTemplate('b')
|
|
||||||
]);
|
|
||||||
var tileUrl1 = tileUrl(new ol.TileCoord(1, 0, 0));
|
|
||||||
var tileUrl2 = tileUrl(new ol.TileCoord(1, 0, 1));
|
|
||||||
assertTrue(tileUrl1 != tileUrl2);
|
|
||||||
assertUndefined(tileUrl(null));
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user