diff --git a/lib/OpenLayers/Control/PanZoomBar.js b/lib/OpenLayers/Control/PanZoomBar.js index 43d557adf2..3f8ef3b300 100644 --- a/lib/OpenLayers/Control/PanZoomBar.js +++ b/lib/OpenLayers/Control/PanZoomBar.js @@ -59,6 +59,14 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, { */ zoomWorldIcon: false, + /** + * APIProperty: panIcons + * {Boolean} Set this property to false not to display the pan icons. If + * false the zoom world icon is placed under the zoom bar. Defaults to + * true. + */ + panIcons: true, + /** * APIProperty: forceFixedZoomLevel * {Boolean} Force a fixed zoom level even though the map has @@ -144,26 +152,37 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, { this.buttons = []; var sz = new OpenLayers.Size(18,18); - var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y); - var wposition = sz.w; + if (this.panIcons) { + var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y); + var wposition = sz.w; - if (this.zoomWorldIcon) { - centered = new OpenLayers.Pixel(px.x+sz.w, px.y); - } + if (this.zoomWorldIcon) { + centered = new OpenLayers.Pixel(px.x+sz.w, px.y); + } - this._addButton("panup", "north-mini.png", centered, sz); - px.y = centered.y+sz.h; - this._addButton("panleft", "west-mini.png", px, sz); - if (this.zoomWorldIcon) { - this._addButton("zoomworld", "zoom-world-mini.png", px.add(sz.w, 0), sz); - - wposition *= 2; + this._addButton("panup", "north-mini.png", centered, sz); + px.y = centered.y+sz.h; + this._addButton("panleft", "west-mini.png", px, sz); + if (this.zoomWorldIcon) { + this._addButton("zoomworld", "zoom-world-mini.png", px.add(sz.w, 0), sz); + + wposition *= 2; + } + this._addButton("panright", "east-mini.png", px.add(wposition, 0), sz); + this._addButton("pandown", "south-mini.png", centered.add(0, sz.h*2), sz); + this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h*3+5), sz); + centered = this._addZoomBar(centered.add(0, sz.h*4 + 5)); + this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); + } + else { + this._addButton("zoomin", "zoom-plus-mini.png", px, sz); + centered = this._addZoomBar(px.add(0, sz.h)); + this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); + if (this.zoomWorldIcon) { + centered = centered.add(0, sz.h+3); + this._addButton("zoomworld", "zoom-world-mini.png", centered, sz); + } } - this._addButton("panright", "east-mini.png", px.add(wposition, 0), sz); - this._addButton("pandown", "south-mini.png", centered.add(0, sz.h*2), sz); - this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h*3+5), sz); - centered = this._addZoomBar(centered.add(0, sz.h*4 + 5)); - this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); return this.div; }, diff --git a/tests/Control/PanZoomBar.html b/tests/Control/PanZoomBar.html index f80f36172e..891527eab6 100644 --- a/tests/Control/PanZoomBar.html +++ b/tests/Control/PanZoomBar.html @@ -166,6 +166,50 @@ t.ok(map.zoom >= 0, 'map.zoom is never < 0 after random handle drag with forceFixedZoomLevel=true and fractionalZoom=true'); } } + + function test_Control_PanZoomBar_shows (t) { + t.plan(22); + + var control, map; + + control = new OpenLayers.Control.PanZoomBar({panIcons: true, zoomWorldIcon: false}); + map = new OpenLayers.Map('map', {controls: [control]}); + t.eq(control.buttons.length, 6, "(a) pan, no world - expected number of buttons"); + t.ok(control.buttons[0].id.match("_panup$"), "(a) pan, no world - pan up"); + t.ok(control.buttons[1].id.match("_panleft$"), "(a) pan, no world - pan left"); + t.ok(control.buttons[2].id.match("_panright$"), "(a) pan, no world - pan right"); + t.ok(control.buttons[3].id.match("_pandown$"), "(a) pan, no world - pan down"); + t.ok(control.buttons[4].id.match("_zoomin$"), "(a) pan, no world - zoom in"); + t.ok(control.buttons[5].id.match("_zoomout$"), "(a) pan, no world - zoom out"); + map.destroy(); + + control = new OpenLayers.Control.PanZoomBar({panIcons: true, zoomWorldIcon: true}); + map = new OpenLayers.Map('map', {controls:[control]}); + t.eq(control.buttons.length, 7, "(b) pan, world - expected number of buttons"); + t.ok(control.buttons[0].id.match("_panup$"), "(b) pan, world - pan up"); + t.ok(control.buttons[1].id.match("_panleft$"), "(b) pan, world - pan left"); + t.ok(control.buttons[2].id.match("_zoomworld$"), "(b) pan, world - zoom world"); + t.ok(control.buttons[3].id.match("_panright$"), "(b) pan, world - pan right"); + t.ok(control.buttons[4].id.match("_pandown$"), "(b) pan, world - pan down"); + t.ok(control.buttons[5].id.match("_zoomin$"), "(b) pan, world - zoom in"); + t.ok(control.buttons[6].id.match("_zoomout$"), "(b) pan, world - zoom out"); + map.destroy(); + + control = new OpenLayers.Control.PanZoomBar({panIcons: false, zoomWorldIcon: false}); + map = new OpenLayers.Map('map', {controls:[control]}); + t.eq(control.buttons.length, 2, "(c) no pan, no world - expected number of buttons"); + t.ok(control.buttons[0].id.match("_zoomin$"), "(c) no pan, no world - zoom in"); + t.ok(control.buttons[1].id.match("_zoomout$"), "(c) no pan, no world - zoom out"); + map.destroy(); + + control = new OpenLayers.Control.PanZoomBar({panIcons: false, zoomWorldIcon: true}); + map = new OpenLayers.Map('map', {controls:[control]}); + t.eq(control.buttons.length, 3, "(d) no pan, world - expected number of buttons"); + t.ok(control.buttons[0].id.match("_zoomin$"), "(d) no pan, world - zoom in"); + t.ok(control.buttons[1].id.match("_zoomout$"), "(d) no pan, world - zoom out"); + t.ok(control.buttons[2].id.match("_zoomworld$"), "(d) no pan, world - zoom world"); + map.destroy(); + }