Tests for setExtent; improved comments.

This commit is contained in:
ahocevar
2011-10-08 14:34:59 -04:00
parent 281ae3dfe7
commit b56af5a5cf
3 changed files with 40 additions and 7 deletions

View File

@@ -387,12 +387,11 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
/**
* Property: rightOfDateLine
* {Boolean} Keeps track of the location of the map extent's center
* relative to the date line. The <setExtent> method compares this value
* (which is the one from the previous <setExtent> call) with the current
* position of the map extent relative to the date line and updates the
* xOffset when the extent's center has moved from one side of the date
* line to the other.
* {Boolean} Keeps track of the location of the map extent relative to the
* date line. The <setExtent> method compares this value (which is the one
* from the previous <setExtent> call) with the current position of the map
* extent relative to the date line and updates the xOffset when the extent
* has moved from one side of the date line to the other.
*/
/**

View File

@@ -24,6 +24,7 @@
t.plan(2);
var r = new OpenLayers.Renderer();
r.map = {};
var extent = new OpenLayers.Bounds(1,2,3,4);
r.resolution = 1;
r.setExtent(extent, true);

View File

@@ -616,7 +616,40 @@
tearDown();
}
function test_setExtent(t) {
t.plan(10);
setUp();
var resolution = 1;
var r = create_renderer();
r.map = {
getMaxExtent: function() {
return new OpenLayers.Bounds(-180,-90,180,90);
},
getResolution: function() {
return resolution;
},
baseLayer: {wrapDateLine: true}
}
r.setExtent(new OpenLayers.Bounds(179, -1, 182, 1), true);
t.eq(r.rightOfDateLine, true, "on the right side of the dateline");
t.eq(r.xOffset, r.map.getMaxExtent().getWidth(), "correct xOffset");
r.setExtent(new OpenLayers.Bounds(179.5, -1, 182.5, 1), false);
t.eq(r.rightOfDateLine, true, "still on the right side of the dateline");
t.eq(r.xOffset, r.map.getMaxExtent().getWidth(), "still correct xOffset");
resolution = 2;
r.setExtent(new OpenLayers.Bounds(178, -2, 184, 2), true);
t.eq(r.rightOfDateLine, true, "still on the right side of the dateline");
t.eq(r.xOffset, r.map.getMaxExtent().getWidth() / resolution, "xOffset adjusted for new resolution");
r.setExtent(new OpenLayers.Bounds(-184, -2, 178, 2), false);
t.eq(r.rightOfDateLine, false, "on the left side of the dateline");
t.eq(r.xOffset, 0, "no xOffset");
r.setExtent(new OpenLayers.Bounds(178, -2, 184, 2), true);
t.eq(r.rightOfDateLine, true, "back on the right side of the dateline");
t.eq(r.xOffset, r.map.getMaxExtent().getWidth() / resolution, "correct xOffset");
tearDown();
}
</script>
</head>