Fire the 'changelayer:visibility' event from layer's display method

Move the changelayer event firing logic for in / out of resolution range
from the Map class to the Layer class. Tests have been also been created
to specifically test that the display method works correctly and fires
events only when needed.
This commit is contained in:
Matt Priour
2012-10-09 11:10:55 -05:00
parent 74103ec3e0
commit f17a3c70e4
4 changed files with 60 additions and 4 deletions
+35
View File
@@ -858,6 +858,41 @@
"setOpacity() does not trigger changelayer if the opacity value is the same");
}
function test_display(t) {
t.plan(8);
var map, layer, log;
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer("", {
alwaysInRange: true,
visibility: true
});
map.addLayer(layer);
log = [];
map.events.register('changelayer', t, function(event) {
log.push({
layer: event.layer,
property: event.property
});
});
layer.display(false);
t.eq(layer.div.style.display, "none", "display() set layer's display style to correct value");
t.eq(layer.getVisibility(), true, "display() does not affect layer's visibility state");
t.eq(log.length, 1, "display() triggers changelayer once");
t.ok(log[0].layer == layer, "changelayer listener called with expected layer");
t.eq(log[0].property, "visibility", "changelayer listener called with expected property");
layer.visibility = false;
layer.display(true);
t.eq(layer.div.style.display, "block", "display() set layer's display style to correct value");
t.eq(layer.getVisibility(), false, "display() does not affect layer's visibility state");
// This call must not trig the event because the opacity value is the same.
log = [];
layer.display(true);
t.eq(log.length, 0, "display() does not trigger changelayer if the display value is the same");
}
/******
*