git-svn-id: http://svn.openlayers.org/trunk/openlayers@8804 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
204 lines
7.1 KiB
HTML
204 lines
7.1 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
function test_initialize(t) {
|
|
t.plan(1);
|
|
|
|
var ratio = 4;
|
|
|
|
var s = new OpenLayers.Strategy.BBOX({ratio: ratio});
|
|
t.eq(s.ratio, ratio, "ctor sets ratio");
|
|
}
|
|
|
|
function test_activate(t) {
|
|
t.plan(5);
|
|
|
|
var l = new OpenLayers.Layer.Vector();
|
|
var s = new OpenLayers.Strategy.BBOX();
|
|
s.setLayer(l);
|
|
|
|
t.eq(s.active, false, "not active after construction");
|
|
|
|
var activated = s.activate();
|
|
t.eq(activated, true, "activate returns true");
|
|
t.eq(s.active, true, "activated after activate");
|
|
t.ok(l.events.listeners["moveend"][0].obj == s &&
|
|
l.events.listeners["moveend"][0].func == s.update,
|
|
"activates registers moveend listener");
|
|
t.ok(l.events.listeners["refresh"][0].obj == s &&
|
|
l.events.listeners["refresh"][0].func == s.update,
|
|
"activates registers refresh listener");
|
|
}
|
|
|
|
function test_update(t) {
|
|
t.plan(5);
|
|
|
|
// Create a dummy layer that can act as the map base layer.
|
|
// This will be unnecessary if #1921 is addressed (allowing
|
|
// map to have different projection than base layer).
|
|
var dummy = new OpenLayers.Layer(null, {isBaseLayer: true});
|
|
|
|
var strategy = new OpenLayers.Strategy.BBOX({
|
|
ratio: 1 // makes for easier comparison to map bounds
|
|
});
|
|
var layer = new OpenLayers.Layer.Vector(null, {
|
|
isBaseLayer: true,
|
|
protocol: new OpenLayers.Protocol(),
|
|
strategies: [strategy]
|
|
});
|
|
|
|
// create a map with the layers and a center
|
|
var map = new OpenLayers.Map("map");
|
|
map.addLayers([dummy, layer]);
|
|
map.zoomToMaxExtent();
|
|
|
|
/**
|
|
* The setCenter call above should set strategy bounds. I *think* this
|
|
* issue is captured in http://trac.openlayers.org/ticket/1835.
|
|
* For now, I'm going to force an update on the strategy. This line
|
|
* should be removed when the issue(s) described in #1835 are addressed.
|
|
*/
|
|
strategy.update({force: true});
|
|
|
|
// test that the strategy bounds were set
|
|
t.ok(map.getExtent().equals(strategy.bounds), "[set center] bounds set to map extent");
|
|
|
|
// zoom and test that bounds are not reset
|
|
var old = strategy.bounds.clone();
|
|
map.zoomIn();
|
|
t.ok(strategy.bounds.equals(old), "[zoom in] bounds not reset");
|
|
|
|
// force update and check that bounds change
|
|
strategy.update({force: true});
|
|
t.ok(!strategy.bounds.equals(old), "[force update] bounds changed");
|
|
t.ok(strategy.bounds.equals(map.getExtent()), "[force update] bounds set to map extent");
|
|
|
|
// change the layer projection to confirm strategy uses same
|
|
layer.projection = new OpenLayers.Projection("EPSG:900913");
|
|
strategy.update({force: true});
|
|
var from = map.getProjectionObject();
|
|
var to = layer.projection;
|
|
t.ok(strategy.bounds.equals(map.getExtent().transform(from, to)), "[force update different proj] bounds transformed");
|
|
|
|
|
|
}
|
|
|
|
function test_triggerRead(t) {
|
|
t.plan(4);
|
|
|
|
var s = new OpenLayers.Strategy.BBOX();
|
|
|
|
var filter = {"fake": "filter"};
|
|
|
|
s.createFilter = function() {
|
|
return filter;
|
|
};
|
|
s.response = {"fake": "response"};
|
|
|
|
var protocol = new OpenLayers.Protocol({
|
|
read: function(options) {
|
|
t.ok(options.filter == filter,
|
|
"protocol read called with correct filter");
|
|
t.ok(options.callback == s.merge,
|
|
"protocol read called with correct callback");
|
|
t.ok(options.scope == s,
|
|
"protocol read called with correct scope");
|
|
},
|
|
abort: function(response) {
|
|
t.eq(response, s.response,
|
|
"protocol abort called with correct response");
|
|
}
|
|
});
|
|
|
|
s.setLayer({protocol: protocol});
|
|
|
|
// 4 tests
|
|
s.triggerRead();
|
|
}
|
|
|
|
function test_createFilter(t) {
|
|
t.plan(3);
|
|
|
|
var s = new OpenLayers.Strategy.BBOX();
|
|
|
|
var f;
|
|
|
|
// 2 test
|
|
s.setLayer({});
|
|
f = s.createFilter();
|
|
t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Spatial/) != -1,
|
|
"createFilter returns a spatial filter object");
|
|
t.eq(f.type, OpenLayers.Filter.Spatial.BBOX,
|
|
"createFilter returns a BBOX-typed filter");
|
|
|
|
// 1 test
|
|
s.setLayer({filter: {fake: "filter"}});
|
|
f = s.createFilter();
|
|
t.ok(f.CLASS_NAME.search(/^OpenLayers.Filter.Logical/) != -1,
|
|
"createFilter returns a logical filter object");
|
|
}
|
|
|
|
function test_merge(t) {
|
|
t.plan(4);
|
|
|
|
var strategy = new OpenLayers.Strategy.BBOX();
|
|
|
|
// create map with default projection
|
|
var map = new OpenLayers.Map("map");
|
|
|
|
// create layer with custom projection
|
|
var layer = new OpenLayers.Layer.Vector(null, {
|
|
isBaseLayer: true,
|
|
strategies: [strategy],
|
|
protocol: new OpenLayers.Protocol(),
|
|
projection: new OpenLayers.Projection("EPSG:900913")
|
|
});
|
|
map.addLayer(layer);
|
|
map.zoomToMaxExtent();
|
|
|
|
// create some features
|
|
var geometries = [
|
|
new OpenLayers.Geometry.Point(100, 200),
|
|
new OpenLayers.Geometry.Point(1000, 2000)
|
|
];
|
|
var features = [
|
|
new OpenLayers.Feature.Vector(geometries[0].clone()),
|
|
new OpenLayers.Feature.Vector(geometries[1].clone())
|
|
];
|
|
|
|
// call merge with a mocked up response
|
|
strategy.merge({features: features});
|
|
|
|
// test that feature geometries have been transformed to map projection
|
|
var from = layer.projection;
|
|
var to = map.getProjectionObject();
|
|
t.geom_eq(layer.features[0].geometry, features[0].geometry.transform(from, to), "[different proj] feature 0 geometry transformed");
|
|
t.geom_eq(layer.features[1].geometry, features[1].geometry.transform(from, to), "[different proj] feature 1 geometry transformed");
|
|
|
|
// same as above but with same map/layer projection
|
|
layer.destroyFeatures();
|
|
layer.projection = map.getProjectionObject();
|
|
|
|
features = [
|
|
new OpenLayers.Feature.Vector(geometries[0].clone()),
|
|
new OpenLayers.Feature.Vector(geometries[1].clone())
|
|
];
|
|
|
|
// call merge again with mocked up response
|
|
strategy.merge({features: features});
|
|
|
|
// test that feature geometries have not been transformed
|
|
t.geom_eq(layer.features[0].geometry, features[0].geometry, "[same proj] feature 0 geometry not transformed");
|
|
t.geom_eq(layer.features[1].geometry, features[1].geometry, "[same proj] feature 1 geometry not transformed");
|
|
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 400px; height: 200px" />
|
|
</body>
|
|
</html>
|