Merge branch 'master' into tile-fade-in

Conflicts:
	tests/Tile/Image.html
This commit is contained in:
Éric Lemoine
2012-01-17 09:27:55 +01:00
95 changed files with 818 additions and 246 deletions
+4 -1
View File
@@ -141,7 +141,7 @@
function test_isEligible(t) {
t.plan(9);
t.plan(10);
var control = new OpenLayers.Control.Split();
var geometry = OpenLayers.Geometry.fromWKT("LINESTRING(0 1, 1 2)");
@@ -176,6 +176,9 @@
control.targetFilter.value = "baz";
t.eq(control.isEligible(feature), true, "feature is eligible if it matches filter");
delete feature.geometry;
t.eq(control.isEligible(feature), false, "feature with no geometry is not eligible");
control.destroy();
}
+4 -1
View File
@@ -41,7 +41,7 @@
function test_read(t) {
t.plan(16);
t.plan(17);
var obj = format.read(csw_response);
@@ -65,6 +65,9 @@
t.eq(testRecord.type, "BriefRecord", "check value for record.type");
t.eq(testRecord.title, [{value:"Sample title"}], "check value for record.title");
// test empty subject
t.eq(testRecord.subject, [], "Empty subject tags are ignored");
//test bbox
t.eq(testRecord.BoundingBox.length, 2, "object contains 2 BoundingBoxes");
var bbox = testRecord.BoundingBox[0];
+2
View File
@@ -21,6 +21,8 @@ var csw_response =
'<csw:BriefRecord xmlns:geonet="http://www.fao.org/geonetwork" xmlns:ows="http://www.opengis.net/ows" xmlns:dc="http://purl.org/dc/elements/1.1/">' +
'<dc:identifier>895ac38b-7aef-4a21-b593-b35a6fc7bba9</dc:identifier>' +
'<dc:title>Sample title</dc:title>' +
'<dc:subject />' +
'<dc:subject />' +
'<ows:BoundingBox crs="::Lambert Azimuthal Projection">' +
'<ows:LowerCorner>156 -3</ows:LowerCorner>' +
'<ows:UpperCorner>37 83</ows:UpperCorner>' +
+104
View File
@@ -250,6 +250,110 @@
"resize correctly adjusts y of component 4");
}
function test_containsPoint(t) {
/**
* The ring:
* edge 3
* (5, 10) __________ (15, 10)
* / /
* edge 4 / / edge 2
* / /
* (0, 0) /_________/ (10, 0)
* edge 1
*/
var components = [
new OpenLayers.Geometry.Point(0, 0),
new OpenLayers.Geometry.Point(10, 0),
new OpenLayers.Geometry.Point(15, 10),
new OpenLayers.Geometry.Point(5, 10)
];
var ring = new OpenLayers.Geometry.LinearRing(components);
function p(x, y) {
return new OpenLayers.Geometry.Point(x, y);
}
// contains: 1 (touches), true (within), false (outside)
var cases = [{
point: p(5, 5), contains: true
}, {
point: p(20, 20), contains: false
}, {
point: p(15, 15), contains: false
}, {
point: p(0, 0), contains: 1 // lower left corner
}, {
point: p(10, 0), contains: 1 // lower right corner
}, {
point: p(15, 10), contains: 1 // upper right corner
}, {
point: p(5, 10), contains: 1 // upper left corner
}, {
point: p(5, 0), contains: 1 // on edge 1
}, {
point: p(5, -0.1), contains: false // below edge 1
}, {
point: p(5, 0.1), contains: true // above edge 1
}, {
point: p(12.5, 5), contains: 1 // on edge 2
}, {
point: p(12.4, 5), contains: true // left of edge 2
}, {
point: p(12.6, 5), contains: false // right of edge 2
}, {
point: p(10, 10), contains: 1 // on edge 3
}, {
point: p(10, 9.9), contains: true // below edge 3
}, {
point: p(10, 10.1), contains: false // above edge 3
}, {
point: p(2.5, 5), contains: 1 // on edge 4
}, {
point: p(2.4, 5), contains: false // left of edge 4
}, {
point: p(2.6, 5), contains: true // right of edge 4
}];
var len = cases.length;
t.plan(len);
var c;
for (var i=0; i<len; ++i) {
c = cases[i];
t.eq(ring.containsPoint(c.point), c.contains, "case " + i + ": " + c.point);
}
}
function test_containsPoint_precision(t) {
/**
* The test for linear ring containment was sensitive to failure when
* looking for ray crossings on nearly vertical edges. With a loss
* of precision in calculating the x-coordinate for the crossing,
* the method would erronously determine that the x-coordinate was
* not within the (very narrow) x-range of the nearly vertical edge.
*
* The test below creates a polygon whose first vertical edge is
* nearly horizontal. The test point lies "far" outside the polygon
* and we expect the containsPoint method to return false.
*/
t.plan(1);
var components = [
new OpenLayers.Geometry.Point(10000020.000001, 1000000),
new OpenLayers.Geometry.Point(10000020.000002, 1000010), // nearly vertical
new OpenLayers.Geometry.Point(10000030, 1000010),
new OpenLayers.Geometry.Point(10000030, 1000000)
];
var ring = new OpenLayers.Geometry.LinearRing(components);
var point = new OpenLayers.Geometry.Point(10000000, 1000001);
t.eq(ring.containsPoint(point), false, "false for point outside polygon with nearly vertical edge");
}
</script>
</head>
+37
View File
@@ -534,6 +534,43 @@
map.destroy();
}
function test_freehand_maxVertices(t) {
t.plan(1);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
var layer = new OpenLayers.Layer.Vector("foo", {
maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
isBaseLayer: true
});
map.addLayer(layer);
var control = new OpenLayers.Control({});
var log = {};
var MAX_VERTICES = 2;
var doneCallback = function(geo) {
t.eq(geo.components.length, MAX_VERTICES,
'When maxVertices is reached, the geometry is finalized automatically');
};
var handler = new OpenLayers.Handler.Path(control,
{'done': doneCallback},
{freehand: true,
maxVertices: MAX_VERTICES});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
// mock up feature freehand drawing
handler.activate();
var evt = {xy: new OpenLayers.Pixel(0, 0)};
handler.mousemove(evt);
handler.mousedown(evt);
evt = {xy: new OpenLayers.Pixel(20, 20)};
handler.mousemove(evt);
evt = {xy: new OpenLayers.Pixel(40, 40)};
handler.mousemove(evt);
map.destroy();
}
/**
* Helper functions for editing method tests
*/
+66 -3
View File
@@ -672,19 +672,82 @@
// 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, true, "event says zoomChanged true - poor name");
t.eq(log.event.zoomChanged, false, "event says zoomChanged false");
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 true");
t.ok(!zoomChanged,
"redraw calls moveTo with zoomChanged false");
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);
+4 -2
View File
@@ -65,7 +65,7 @@
}
function test_Layer_HTTPRequest_mergeNewParams (t) {
t.plan( 8 );
t.plan( 9 );
var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options);
@@ -97,7 +97,9 @@
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();
}
+7 -6
View File
@@ -191,13 +191,14 @@
//closeOnMove
var checkMapEvent = function(map, popup) {
var startListeners = map.events.listeners['movestart'];
for(var i=0; i < startListeners.length; i++) {
var listener = startListeners[i];
if ((listener.obj == popup) && (listener.func == popup.hide)) {
return true;
if (startListeners) {
for (var i = 0; i < startListeners.length; i++) {
var listener = startListeners[i];
if ((listener.obj == popup) && (listener.func == popup.hide)) {
return true;
}
}
}
}
return false;
};
var registered = checkMapEvent(map1, popup);
+90
View File
@@ -0,0 +1,90 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_initialize(t) {
t.plan(3);
var protocol = new OpenLayers.Protocol.CSW({formatOptions: {foo: "bar"},});
t.ok(protocol instanceof OpenLayers.Protocol.CSW.v2_0_2,
"initialize returns instance of default versioned protocol");
var format = protocol.format;
t.ok(format instanceof OpenLayers.Format.CSWGetRecords.v2_0_2, "Default format created");
t.ok(format.foo, "bar", "formatOptions set correctly");
protocol.destroy();
}
function test_read(t) {
t.plan(6);
var protocol = new OpenLayers.Protocol.CSW({
url: "http://some.url.org",
parseData: function(request) {
t.eq(request.responseText, "foo", "parseData called properly");
return "foo";
}
});
var _POST = OpenLayers.Request.POST;
var expected, status;
OpenLayers.Request.POST = function(obj) {
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetRecords request is correct");
obj.status = status;
obj.responseText = "foo";
obj.options = {};
t.delay_call(0.1, function() {obj.callback.call(this)});
return obj;
};
expected = readXML("GetRecords");
status = 200;
var data = {
"resultType": "results",
"maxRecords": 100,
"Query": {
"typeNames": "gmd:MD_Metadata",
"ElementSetName": {
"value": "full"
}
}
};
var response = protocol.read({
params: data,
callback: function(response) {
t.eq(response.data, "foo", "user callback properly called with data");
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly to user callback");
}
});
var options = {
params: data,
callback: function(response) {
t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback");
}
};
status = 400;
var response = protocol.read(options);
OpenLayers.Request.POST = _POST;
}
function readXML(id) {
var xml = document.getElementById(id).firstChild.nodeValue;
return new OpenLayers.Format.XML().read(xml).documentElement;
}
</script>
</head>
<body>
<div id="map" style="width:512px; height:256px"> </div>
<div id="GetRecords"><!--
<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" resultType="results" maxRecords="100">
<csw:Query typeNames="gmd:MD_Metadata">
<csw:ElementSetName>full</csw:ElementSetName>
</csw:Query>
</csw:GetRecords>
--></div>
</body>
</html>
+32
View File
@@ -368,6 +368,38 @@
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(2);
var map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("invalid", "", {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);
tile.draw();
t.delay_call(0.1, function() {
// 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();
});
}
</script>
</head>
+1
View File
@@ -184,6 +184,7 @@
<li>Protocol/HTTP.html</li>
<li>Protocol/Script.html</li>
<li>Protocol/WFS.html</li>
<li>Protocol/CSW.html</li>
<li>Protocol/SOS.html</li>
<li>Renderer.html</li>
<li>Renderer/Canvas.html</li>