Merge branch 'master' of https://github.com/openlayers/openlayers into control-inheritance

This commit is contained in:
Marc Jansen
2012-05-15 08:34:53 +02:00
45 changed files with 593 additions and 360 deletions

View File

@@ -175,6 +175,15 @@
t.ok(isNaN(invalid.getTime()), "invalid has no time");
}
function test_regex(t) {
t.plan(1);
var regex = OpenLayers.Date.dateRegEx;
OpenLayers.Date.dateRegEx = /^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/;
var date = OpenLayers.Date.parse("-0501-03-01T00:00:00.000Z");
t.ok(!isNaN(date.getTime()), "date with negative year is parsed when providing alternative regex");
OpenLayers.Date.dateRegEx = regex;
}
</script>
</head>
<body>

View File

@@ -139,7 +139,7 @@
}
function test_Control_Permalink_base_with_query (t) {
t.plan( 3 );
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar" );
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" );
@@ -162,7 +162,38 @@
map.pan(-5, 0, {animate:false});
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'");
map.destroy();
}
function test_Control_Permalink_base_with_anchor (t) {
t.plan( 4 );
control = new OpenLayers.Control.Permalink('permalink', "./edit.html#foo" );
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS('Test Layer', "http://example.com" );
map.addLayer(layer);
if (!map.getCenter()) map.zoomToMaxExtent();
map.addControl(control);
map.pan(5, 0, {animate:false});
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B#foo';
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and anchor");
control = new OpenLayers.Control.Permalink('permalink', "./edit.html#" );
map.addControl(control);
map.pan(0, 0, {animate:false});
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B#';
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and an empty anchor");
control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar#test" );
OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&zoom=2&lat=0&lon=1.75781&layers=B#test';
map.addControl(control);
map.pan(5, 0, {animate:false});
map.pan(-5, 0, {animate:false});
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base, querystring and an anchor");
control = new OpenLayers.Control.Permalink('permalink', "./edit.html#foo", {anchor : true} );
map.addControl(control);
map.pan(0, 0, {animate:false});
OpenLayers.Util.getElement('edit_permalink').href = './edit.html#zoom=2&lat=0&lon=1.75781&layers=B';
t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and an empty anchor");
}
function test_Control_Permalink_nonRepeating (t) {

View File

@@ -21,7 +21,7 @@
t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" );
t.eq( feature.layer, layer, "feature.layer set correctly" );
t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers.Feature_"),
t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers_Feature_"),
"feature.id set correctly");
t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" );
t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL set correctly" );

View File

@@ -11,7 +11,7 @@
var g = new OpenLayers.Geometry();
t.eq(g.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME")
t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry_"),
t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers_Geometry_"),
"id correctly set");
}
@@ -22,7 +22,7 @@
var clone = geometry.clone();
t.eq(clone.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME")
t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers.Geometry_"),
t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers_Geometry_"),
"id correctly set");
}

View File

@@ -174,6 +174,16 @@
t.eq(log, 0, "addOptions doesn't call initResolutions when layer is not in map");
}
function test_addOptionsScale(t) {
t.plan(1);
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.WMS();
map.addLayer(layer);
map.zoomToMaxExtent();
layer.addOptions({maxResolution: 0.5, numZoomLevels: 15});
t.eq(layer.alwaysInRange, false, "alwaysInRange should not be true anymore");
}
function test_Layer_StandardOptionsAccessors (t) {
t.plan( 4 );
@@ -398,6 +408,9 @@
"1.20", null, {maxScale: 100000, numZoomLevels: 3, units: "m"},
[141.11103491115225, 70.55551745557612, 35.27775872778806], 35.27775872778806, 141.11103491115225
], [
"1.21", null, {numZoomLevels: 2}, // maxResolution calculated based on the projection's maxExtent here
[1.40625, 0.703125], 0.703125, 1.40625
], [
/*
* Batch 2: custom map options map and sensible layer options
@@ -541,8 +554,8 @@
/*
* Batch 2.8: numZoomLevels set in the layer options
*/
"2.8.0", {maxResolution: 80}, {numZoomLevels: 4},
[80, 40, 20, 10], 10, 80
"2.8.0", {maxResolution: 80}, {numZoomLevels: 4}, // maxResolution calculated based on the projection's maxExtent here
[1.40625, 0.703125, 0.3515625, 0.17578125], 0.17578125, 1.40625
], [
"2.8.1", {maxResolution: 80, numZoomLevels: 4}, {numZoomLevels: null},
[80, 40, 20, 10], 10, 80
@@ -672,82 +685,19 @@
// test that the moveend event was triggered
t.ok(log.event, "an event was logged");
t.eq(log.event.type, "moveend", "moveend was triggered");
t.eq(log.event.zoomChanged, false, "event says zoomChanged false");
t.eq(log.event.zoomChanged, true, "event says zoomChanged true - poor name");
layer.moveTo = function(bounds, zoomChanged, dragging) {
var extent = layer.map.getExtent();
t.ok(bounds.equals(extent),
"redraw calls moveTo with the map extent");
t.ok(!zoomChanged,
"redraw calls moveTo with zoomChanged false");
t.ok(zoomChanged,
"redraw calls moveTo with zoomChanged true");
t.ok(!dragging,
"redraw calls moveTo with dragging false");
}
layer.redraw();
}
// This function includes integration tests to verify that the
// layer's moveTo function is called with the expected value
// for zoomChanged
function test_moveTo_zoomChanged(t) {
t.plan(6);
var log = {};
var map = new OpenLayers.Map('map');
var l1 = new OpenLayers.Layer('l1', {isBaseLayer: true});
l1.moveTo = function(bounds, zoomChanged, dragging) {
log.moveTo = {zoomChanged: zoomChanged};
OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
};
map.addLayer(l1);
map.zoomToMaxExtent();
log = {};
l1.redraw();
t.eq(log.moveTo.zoomChanged, false,
"[a] redraw calls moveTo with zoomChanged false");
log = {};
l1.resolution = null;
l1.redraw();
t.eq(log.moveTo.zoomChanged, true,
"[b] redraw calls moveTo with zoomChanged true");
l1.setVisibility(false);
log = {};
l1.setVisibility(true);
t.eq(log.moveTo.zoomChanged, false,
"[c] redraw calls moveTo with zoomChanged false");
l1.setVisibility(false);
map.zoomIn();
log = {};
l1.setVisibility(true);
t.eq(log.moveTo.zoomChanged, true,
"[d] redraw calls moveTo with zoomChanged true");
l1.moveTo = OpenLayers.Layer.prototype.moveTo;
var l2 = new OpenLayers.Layer('l2');
l2.moveTo = function(bounds, zoomChanged, dragging) {
log.moveTo = {zoomChanged: zoomChanged};
OpenLayers.Layer.prototype.moveTo.apply(this, arguments);
};
log = {};
map.addLayer(l2);
t.eq(log.moveTo.zoomChanged, true,
"[e] redraw calls moveTo with zoomChanged true");
map.removeLayer(l2);
log = {};
map.addLayer(l2);
t.eq(log.moveTo.zoomChanged, true,
"[f] redraw calls moveTo with zoomChanged true");
map.destroy();
}
function test_layer_setIsBaseLayer(t) {
t.plan(2);

View File

@@ -1,5 +1,19 @@
<html>
<head>
<script>
/**
* Because browsers that implement requestAnimationFrame may not execute
* animation functions while a window is not displayed (e.g. in a hidden
* iframe as in these tests), we mask the native implementations here. The
* native requestAnimationFrame functionality is tested in Util.html and
* in PanZoom.html (where a popup is opened before panning).
*/
window.requestAnimationFrame =
window.webkitRequestAnimationFrame =
window.mozRequestAnimationFrame =
window.oRequestAnimationFrame =
window.msRequestAnimationFrame = null;
</script>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var map, layer;
@@ -82,6 +96,26 @@
});
}
function test_initLayer_notempty(t) {
t.plan(1);
map = new OpenLayers.Map("map", {
projection: "EPSG:3857",
layers: [new OpenLayers.Layer("dummy", {isBaseLayer: true})]
});
map.zoomToExtent([-14768652, 4492113, -12263964, 5744457]);
var layer = new OpenLayers.Layer.Bing(OpenLayers.Util.extend({
isBaseLayer: false
}, options));
map.addLayer(layer);
var tile = layer.tileQueue[0];
t.delay_call(5, function() {
t.ok(tile.url, "Tile not empty");
map.destroy();
});
}
function test_attribution(t) {
t.plan(3);

View File

@@ -837,12 +837,12 @@
layer.serverResolutions = [2, 1];
resolution = 1;
zoom = layer.getServerZoom();
t.eq(zoom, 3, '[3] getServerZoom return value is correct');
t.eq(zoom, 1, '[3] getServerZoom return value is correct');
layer.serverResolutions = [2];
resolution = 0.5;
zoom = layer.getServerZoom();
t.eq(zoom, 2, '[4] getServerZoom return value is correct');
t.eq(zoom, 0, '[4] getServerZoom return value is correct');
var exc;
layer.serverResolutions = [0.5];

View File

@@ -68,7 +68,7 @@
}
function test_Layer_HTTPRequest_mergeNewParams (t) {
t.plan( 9 );
t.plan( 8 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
@@ -100,9 +100,7 @@
layer.redraw = function() {
t.ok(true, "layer.mergeNewParams calls layer.redraw");
t.ok(layer.resolution === null, "layer.mergeNewParams sets resolution to null");
};
layer.resolution = 'fake';
}
layer.mergeNewParams();
}

View File

@@ -175,10 +175,9 @@
// test offset of 2
offset = 2;
zoom = 3;
var map = new OpenLayers.Map({
div: "map",
maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset)
div: "map"
});
var layer = new OpenLayers.Layer.TMS("TMS", "", {
layername: "basic",
@@ -189,7 +188,6 @@
map.setCenter(new OpenLayers.LonLat(0, 0), zoom);
var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
level = parseInt(tileurl.split("/")[2]);
t.eq(parseInt(tileurl.split("/")[2]), zoom + offset, "correct level for offset 2");
map.destroy();
@@ -199,8 +197,7 @@
zoom = 3;
var map = new OpenLayers.Map({
div: "map",
maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset)
div: "map"
});
var layer = new OpenLayers.Layer.TMS("TMS", "", {
layername: "basic",
@@ -211,12 +208,9 @@
map.setCenter(new OpenLayers.LonLat(0, 0), zoom);
var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
level = parseInt(tileurl.split("/")[2]);
t.eq(parseInt(tileurl.split("/")[2]), zoom + offset, "correct level for offset -1");
map.destroy();
}
function test_Layer_TMS_setMap(t) {

View File

@@ -869,32 +869,7 @@
"featuresadded event received expected number of features");
}
function test_redraw(t) {
t.plan(2);
// test that when redraw is called on a vector layer then
// moveTo gets called on the layer and receives zoomChanged
// true
var log = [];
var map = new OpenLayers.Map("map");
var layer = new OpenLayers.Layer.Vector("vector", {isBaseLayer: true});
map.addLayer(layer);
map.setCenter([0, 0], 5);
layer.moveTo = function(extent, zoomChanged) {
log.push(zoomChanged);
};
layer.redraw();
t.eq(log.length, 1, "redraw makes moveTo be called once");
if (log.length == 1) {
t.eq(log[0], true, "redraw makes moveTo be called with zoomChanged true");
}
map.destroy();
}
</script>
</head>

View File

@@ -1712,7 +1712,36 @@
t.eq(log[1], "move", "followed by move,");
t.eq(log[log.length-2], "move", "move again before we stop panning,");
t.eq(log[log.length-1], "moveend", "and moveend when we're done.");
}
function test_pan_no_anim_event_sequence(t) {
t.plan(4);
var log = [];
var map = new OpenLayers.Map("map");
map.addLayer(
new OpenLayers.Layer(null, {isBaseLayer: true})
);
map.setCenter(new OpenLayers.LonLat(0, 0), 5);
map.events.on({
"movestart": function() {
log.push("movestart");
},
"move": function() {
log.push("move");
},
"moveend": function() {
log.push("moveend");
}
});
map.pan(5,5, {animate: false});
t.eq(log.length, 3, "no more than 3 events happen.");
t.eq(log[0], "movestart", "pan sequence starts with movestart");
t.eq(log[1], "move", "followed by move,");
t.eq(log[2], "moveend", "and moveend when we're done.");
map.destroy();
}
// test if we can call updateSize before document.body is ready. updateOk

View File

@@ -13,7 +13,7 @@
popup = new OpenLayers.Popup();
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup"),
t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers_Popup"),
"valid default popupid");
var firstID = popup.id;
t.ok(popup.contentSize.equals(size), "good default popup.size");

View File

@@ -11,7 +11,7 @@
popup = new OpenLayers.Popup.Anchored();
t.ok( popup instanceof OpenLayers.Popup.Anchored, "new OpenLayers.Popup.Anchored returns Popup.Anchored object" );
t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup.Anchored"), "valid default popupid");
t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers_Popup_Anchored"), "valid default popupid");
var firstID = popup.id;
t.eq(popup.contentHTML, null, "good default popup.contentHTML");

View File

@@ -374,53 +374,6 @@
map.destroy();
}
// test for https://github.com/openlayers/openlayers/pull/36
// (more an integration test than a unit test)
function test_olImageLoadError(t) {
t.plan(6);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("invalid", "foo", {layers: 'basic'});
map.addLayer(layer);
var size = new OpenLayers.Size(5, 6);
var position = new OpenLayers.Pixel(20, 30);
var bounds = new OpenLayers.Bounds(1, 2, 3, 4);
var tile = new OpenLayers.Tile.Image(layer, position, bounds, null, size);
var log = [];
tile.events.register("loaderror", this, function(e) {
log.push([
e.object.imgDiv.style.visibility,
OpenLayers.Element.hasClass(e.object.imgDiv, 'olImageLoadError')
]);
});
tile.events.register("loadend", this, function(e) {
log.push(e);
})
tile.draw();
t.delay_call(0.1, function() {
t.eq(log.length, 2, "loaderror and loadend events triggered");
t.eq(log[0][0], "hidden", "tile still hidden when loaderror is triggered");
t.eq(log[0][1], true, "tile has olImageLoadError class already when loaderror is triggered");
t.ok(log[1].object === tile, "loadend event triggered after loaderror");
// check initial state
t.ok(OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError'),
'tile image has the olImageLoadError class (init state)');
layer.setVisibility(false);
layer.setVisibility(true);
t.ok(OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError'),
'tile image still has the olImageLoadError class');
map.destroy();
});
}
function test_getCanvasContext(t) {
if (!OpenLayers.CANVAS_SUPPORTED) {
t.plan(0);
@@ -445,7 +398,98 @@
});
}
}
/*
* A series of tests to verify the dimensions and positions
* of the tile frame and img after draw.
* Written for https://github.com/openlayers/openlayers/issues/441
*/
function test_draw_without_gutter_without_frame(t) {
t.plan(5);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS('blank',
'../../img/blank.gif',
{layers: 'fake'},
{isBaseLayer: true});
map.addLayer(layer);
var tile = new OpenLayers.Tile.Image(
layer,
new OpenLayers.Pixel(6, 6),
new OpenLayers.Bounds(5, 45, 6, 46),
null,
new OpenLayers.Size(256, 256));
tile.draw();
t.eq(tile.frame, null, 'no frame');
t.eq(parseInt(tile.imgDiv.style.left, 10), 6, 'correct tile img left');
t.eq(parseInt(tile.imgDiv.style.top, 10), 6, 'correct tile img top');
t.eq(parseInt(tile.imgDiv.style.width, 10), 256, 'correct tile img width');
t.eq(parseInt(tile.imgDiv.style.height, 10), 256, 'correct tile img height');
map.destroy();
}
function test_draw_without_gutter_with_frame(t) {
t.plan(8);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS('blank',
'../../img/blank.gif',
{layers: 'fake'},
{isBaseLayer: true});
map.addLayer(layer);
layer.gutter = 1; // this is just for a frame to be created for
// the tile
var tile = new OpenLayers.Tile.Image(
layer,
new OpenLayers.Pixel(6, 6),
new OpenLayers.Bounds(5, 45, 6, 46),
null,
new OpenLayers.Size(256, 256));
layer.gutter = null;
tile.draw();
t.eq(parseInt(tile.frame.style.left, 10), 6, 'correct tile frame left');
t.eq(parseInt(tile.frame.style.top, 10), 6, 'correct tile frame top');
t.eq(parseInt(tile.frame.style.width, 10), 256, 'correct tile frame width');
t.eq(parseInt(tile.frame.style.height, 10), 256, 'correct tile frame height');
t.eq(parseInt(tile.imgDiv.style.left, 10), 0, 'correct tile img left');
t.eq(parseInt(tile.imgDiv.style.top, 10), 0, 'correct tile img top');
t.eq(parseInt(tile.imgDiv.style.width, 10), 100, 'correct tile img width');
t.eq(parseInt(tile.imgDiv.style.height, 10), 100, 'correct tile img height');
map.destroy();
}
function test_draw_with_gutter(t) {
t.plan(8);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS('blank',
'../../img/blank.gif',
{layers: 'fake'},
{isBaseLayer: true, gutter: 15});
map.addLayer(layer);
var tile = new OpenLayers.Tile.Image(
layer,
new OpenLayers.Pixel(6, 6),
new OpenLayers.Bounds(5, 45, 6, 46),
null,
new OpenLayers.Size(256, 256));
tile.draw();
t.eq(parseInt(tile.frame.style.left, 10), 6, 'correct tile frame left');
t.eq(parseInt(tile.frame.style.top, 10), 6, 'correct tile frame top');
t.eq(parseInt(tile.frame.style.width, 10), 256, 'correct tile frame width');
t.eq(parseInt(tile.frame.style.height, 10), 256, 'correct tile frame height');
t.eq(parseInt(tile.imgDiv.style.left, 10), -5, 'correct tile img left');
t.eq(parseInt(tile.imgDiv.style.top, 10), -5, 'correct tile img top');
t.eq(parseInt(tile.imgDiv.style.width, 10), 111, 'correct tile img width');
t.eq(parseInt(tile.imgDiv.style.height, 10), 111, 'correct tile img height');
map.destroy();
}
</script>
</head>
<body>

View File

@@ -507,9 +507,8 @@
t.eq(element.style.opacity, '',
"element.style.opacity is removed when opacity = " + opacity);
//Safari 3 returns null for this value, which is okay
var filterString = (OpenLayers.BROWSER_NAME == 'safari') ? null : '';
t.eq(element.style.filter, filterString,
// Some browser returns null instead of '', which is okay
t.ok(element.style.filter == '' || element.style.filter == null,
"element.style.filter is removed when opacity = " + opacity);
}