Loading strategies now trigger loadstart and loadend events. r=crschmidt (closes #1840)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8973 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -176,6 +176,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
*/
|
||||
triggerRead: function() {
|
||||
this.layer.protocol.abort(this.response);
|
||||
this.layer.events.triggerEvent("loadstart");
|
||||
this.response = this.layer.protocol.read({
|
||||
filter: this.createFilter(),
|
||||
callback: this.merge,
|
||||
@@ -231,6 +232,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
}
|
||||
this.layer.addFeatures(features);
|
||||
}
|
||||
this.layer.events.triggerEvent("loadend");
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Strategy.BBOX"
|
||||
|
||||
@@ -71,6 +71,7 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
* Tells protocol to load data and unhooks the visibilitychanged event
|
||||
*/
|
||||
load: function() {
|
||||
this.layer.events.triggerEvent("loadstart");
|
||||
this.layer.protocol.read({
|
||||
callback: this.merge,
|
||||
scope: this
|
||||
@@ -101,6 +102,7 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
}
|
||||
this.layer.addFeatures(features);
|
||||
}
|
||||
this.layer.events.triggerEvent("loadend");
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Strategy.Fixed"
|
||||
|
||||
@@ -85,6 +85,42 @@
|
||||
|
||||
}
|
||||
|
||||
function test_events(t) {
|
||||
|
||||
t.plan(2);
|
||||
var log = {
|
||||
loadstart: 0,
|
||||
loadend: 0
|
||||
};
|
||||
|
||||
var map = new OpenLayers.Map("map");
|
||||
var layer = new OpenLayers.Layer.Vector(null, {
|
||||
strategies: [new OpenLayers.Strategy.BBOX()],
|
||||
protocol: new OpenLayers.Protocol({
|
||||
read: function(config) {
|
||||
config.callback.call(config.scope, {});
|
||||
}
|
||||
}),
|
||||
isBaseLayer: true,
|
||||
eventListeners: {
|
||||
loadstart: function() {
|
||||
++log.loadstart;
|
||||
},
|
||||
loadend: function() {
|
||||
++log.loadend;
|
||||
}
|
||||
}
|
||||
});
|
||||
map.addLayer(layer);
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
t.eq(log.loadstart, 1, "loadstart triggered");
|
||||
t.eq(log.loadend, 1, "loadend triggered");
|
||||
|
||||
map.destroy();
|
||||
|
||||
}
|
||||
|
||||
function test_triggerRead(t) {
|
||||
t.plan(4);
|
||||
|
||||
@@ -97,25 +133,37 @@
|
||||
};
|
||||
s.response = {"fake": "response"};
|
||||
|
||||
var log = {};
|
||||
|
||||
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");
|
||||
log.options = options;
|
||||
},
|
||||
abort: function(response) {
|
||||
t.eq(response, s.response,
|
||||
"protocol abort called with correct response");
|
||||
log.abort = response.fake;
|
||||
}
|
||||
});
|
||||
|
||||
s.setLayer({protocol: protocol});
|
||||
var layer = new OpenLayers.Layer.Vector(null, {
|
||||
strategies: [s],
|
||||
protocol: protocol,
|
||||
isBaseLayer: true
|
||||
});
|
||||
var map = new OpenLayers.Map("map");
|
||||
map.addLayer(layer);
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
t.ok(log.options.filter == filter,
|
||||
"protocol read called with correct filter");
|
||||
t.ok(log.options.callback == s.merge,
|
||||
"protocol read called with correct callback");
|
||||
t.ok(log.options.scope == s,
|
||||
"protocol read called with correct scope");
|
||||
t.eq(log.abort, "response",
|
||||
"protocol abort called with correct response");
|
||||
|
||||
map.destroy();
|
||||
|
||||
// 4 tests
|
||||
s.triggerRead();
|
||||
}
|
||||
|
||||
function test_createFilter(t) {
|
||||
|
||||
@@ -60,21 +60,69 @@
|
||||
"visibilitychanged listener unregistered");
|
||||
}
|
||||
|
||||
function tests_merge(t) {
|
||||
function test_events(t) {
|
||||
|
||||
t.plan(4);
|
||||
t.plan(2);
|
||||
|
||||
var log = {
|
||||
loadstart: 0,
|
||||
loadend: 0
|
||||
};
|
||||
|
||||
var map = new OpenLayers.Map("map");
|
||||
var layer = new OpenLayers.Layer.Vector(null, {
|
||||
strategies: [new OpenLayers.Strategy.Fixed()],
|
||||
protocol: new OpenLayers.Protocol({
|
||||
read: function(config) {
|
||||
config.callback.call(config.scope, {});
|
||||
}
|
||||
}),
|
||||
isBaseLayer: true,
|
||||
eventListeners: {
|
||||
loadstart: function() {
|
||||
++log.loadstart;
|
||||
},
|
||||
loadend: function() {
|
||||
++log.loadend;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
map.addLayer(layer);
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
t.eq(log.loadstart, 1, "loadstart triggered");
|
||||
t.eq(log.loadend, 1, "loadend triggered");
|
||||
|
||||
map.destroy();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function test_merge(t) {
|
||||
|
||||
t.plan(5);
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Fixed();
|
||||
|
||||
// create map with default projection
|
||||
var map = new OpenLayers.Map("map");
|
||||
|
||||
var log = {
|
||||
loadend: 0
|
||||
};
|
||||
|
||||
// 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")
|
||||
projection: new OpenLayers.Projection("EPSG:900913"),
|
||||
eventListeners: {
|
||||
loadend: function() {
|
||||
++log.loadend;
|
||||
}
|
||||
}
|
||||
});
|
||||
map.addLayer(layer);
|
||||
map.zoomToMaxExtent();
|
||||
@@ -92,6 +140,9 @@
|
||||
// call merge with a mocked up response
|
||||
strategy.merge({features: features});
|
||||
|
||||
// confirm that loadend was called
|
||||
t.eq(log.loadend, 1, "merge triggers loadend");
|
||||
|
||||
// test that feature geometries have been transformed to map projection
|
||||
var from = layer.projection;
|
||||
var to = map.getProjectionObject();
|
||||
|
||||
Reference in New Issue
Block a user