Merge pull request #255 from ahocevar/255
LayerSwitcher broken when rendered to custom div. r=@elemoine
This commit is contained in:
@@ -120,7 +120,7 @@ OpenLayers.Control.LayerSwitcher =
|
|||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
||||||
this.layerStates = [];
|
this.layerStates = [];
|
||||||
|
|
||||||
if(this.roundedCorner) {
|
if(this.roundedCorner) {
|
||||||
OpenLayers.Console.warn('roundedCorner option is deprecated');
|
OpenLayers.Console.warn('roundedCorner option is deprecated');
|
||||||
}
|
}
|
||||||
@@ -143,6 +143,7 @@ OpenLayers.Control.LayerSwitcher =
|
|||||||
changebaselayer: this.redraw,
|
changebaselayer: this.redraw,
|
||||||
scope: this
|
scope: this
|
||||||
});
|
});
|
||||||
|
this.events.unregister("buttonclick", this, this.onButtonClick);
|
||||||
|
|
||||||
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
||||||
},
|
},
|
||||||
@@ -157,13 +158,18 @@ OpenLayers.Control.LayerSwitcher =
|
|||||||
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
||||||
|
|
||||||
this.map.events.on({
|
this.map.events.on({
|
||||||
buttonclick: this.onButtonClick,
|
|
||||||
addlayer: this.redraw,
|
addlayer: this.redraw,
|
||||||
changelayer: this.redraw,
|
changelayer: this.redraw,
|
||||||
removelayer: this.redraw,
|
removelayer: this.redraw,
|
||||||
changebaselayer: this.redraw,
|
changebaselayer: this.redraw,
|
||||||
scope: this
|
scope: this
|
||||||
});
|
});
|
||||||
|
if (this.outsideViewport) {
|
||||||
|
this.events.attachToElement(this.div);
|
||||||
|
this.events.register("buttonclick", this, this.onButtonClick);
|
||||||
|
} else {
|
||||||
|
this.map.events.register("buttonclick", this, this.onButtonClick);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,15 +25,17 @@
|
|||||||
t.ok( div != null, "draw returns its div" );
|
t.ok( div != null, "draw returns its div" );
|
||||||
}
|
}
|
||||||
function test_Control_LayerSwitcher_outsideViewport (t) {
|
function test_Control_LayerSwitcher_outsideViewport (t) {
|
||||||
t.plan( 2 );
|
t.plan( 4 );
|
||||||
|
|
||||||
map = new OpenLayers.Map('map');
|
map = new OpenLayers.Map('map');
|
||||||
control = new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')});
|
control = new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')});
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
t.eq(control.div.style.width, "250px", "Div is not minimized when added.");
|
t.eq(control.div.style.width, "250px", "Div is not minimized when added.");
|
||||||
|
t.ok(control.events.element && control.events.listeners.buttonclick, "[outside] Events instance attached to div and has buttonclick event");
|
||||||
control = new OpenLayers.Control.LayerSwitcher();
|
control = new OpenLayers.Control.LayerSwitcher();
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
t.eq(control.div.style.width, "0px", "Div is minimized when added.");
|
t.eq(control.div.style.width, "0px", "Div is minimized when added.");
|
||||||
|
t.ok(!control.events.element && map.events.listeners.buttonclick, "[inside] Events instance not attached to div and buttonclick event registered on map");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Control_LayerSwitcher_loadContents(t) {
|
function test_Control_LayerSwitcher_loadContents(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user