give popups a 'closeOnMove' option. if set to true, the popup will close itself as soon as the map is pan/zoom (move)ed. patch by jrf, euzuro review by elemoine, cr5. (Closes #1726)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8397 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
new OpenLayers.Size(200,200),
|
new OpenLayers.Size(200,200),
|
||||||
"example popup",
|
"example popup",
|
||||||
true);
|
true);
|
||||||
|
popup.closeOnMove = true;
|
||||||
|
|
||||||
map.addPopup(popup);
|
map.addPopup(popup);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,6 +173,13 @@ OpenLayers.Popup = OpenLayers.Class({
|
|||||||
* Default is false.
|
* Default is false.
|
||||||
*/
|
*/
|
||||||
panMapIfOutOfView: false,
|
panMapIfOutOfView: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: closeOnMove
|
||||||
|
* {Boolean} When map pans, close the popup.
|
||||||
|
* Default is false.
|
||||||
|
*/
|
||||||
|
closeOnMove: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: map
|
* Property: map
|
||||||
@@ -253,6 +260,10 @@ OpenLayers.Popup = OpenLayers.Class({
|
|||||||
this.opacity = null;
|
this.opacity = null;
|
||||||
this.border = null;
|
this.border = null;
|
||||||
|
|
||||||
|
if (this.closeOnMove && this.map) {
|
||||||
|
this.map.events.unregister("movestart", this, this.hide);
|
||||||
|
}
|
||||||
|
|
||||||
this.events.destroy();
|
this.events.destroy();
|
||||||
this.events = null;
|
this.events = null;
|
||||||
|
|
||||||
@@ -294,6 +305,12 @@ OpenLayers.Popup = OpenLayers.Class({
|
|||||||
px = this.map.getLayerPxFromLonLat(this.lonlat);
|
px = this.map.getLayerPxFromLonLat(this.lonlat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this assumes that this.map already exists, which is okay because
|
||||||
|
// this.draw is only called once the popup has been added to the map.
|
||||||
|
if (this.closeOnMove) {
|
||||||
|
this.map.events.register("movestart", this, this.hide);
|
||||||
|
}
|
||||||
|
|
||||||
//listen to movestart, moveend to disable overflow (FF bug)
|
//listen to movestart, moveend to disable overflow (FF bug)
|
||||||
if (OpenLayers.Util.getBrowserName() == 'firefox') {
|
if (OpenLayers.Util.getBrowserName() == 'firefox') {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
function test_Popup_draw(t) {
|
function test_Popup_draw(t) {
|
||||||
t.plan( 13 );
|
t.plan( 15 );
|
||||||
|
|
||||||
var id = "chicken";
|
var id = "chicken";
|
||||||
var x = 50;
|
var x = 50;
|
||||||
@@ -144,6 +144,29 @@
|
|||||||
popup.moveTo(new OpenLayers.Pixel(x, y));
|
popup.moveTo(new OpenLayers.Pixel(x, y));
|
||||||
t.eq(popup.div.style.left, x + "px", "moveTo updates left position of popup.div correctly");
|
t.eq(popup.div.style.left, x + "px", "moveTo updates left position of popup.div correctly");
|
||||||
t.eq(popup.div.style.top, y + "px", "moveTo updates top position of popup.div correctly");
|
t.eq(popup.div.style.top, y + "px", "moveTo updates top position of popup.div correctly");
|
||||||
|
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
var registered = checkMapEvent(map1, popup);
|
||||||
|
t.ok(!registered, "when not 'closeOnMove', correctly not registered hide() on map's movestart.")
|
||||||
|
|
||||||
|
var popup2 = new OpenLayers.Popup('test');
|
||||||
|
popup2.closeOnMove = true;
|
||||||
|
map1.addPopup(popup2);
|
||||||
|
|
||||||
|
registered = checkMapEvent(map1, popup2);
|
||||||
|
t.ok(registered, "when 'closeOnMove', correctly registered hide() on map's movestart.")
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user