Added a position property to Control, which allows us to specify a default
location for each Control class, and saves us from *having* to supply a pixel position to the map.addControl() method -- the sensible default will tend to be used instead. git-svn-id: http://svn.openlayers.org/trunk/openlayers@269 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -11,6 +11,9 @@ OpenLayers.Control.prototype = {
|
|||||||
/** @type DOMElement */
|
/** @type DOMElement */
|
||||||
div: null,
|
div: null,
|
||||||
|
|
||||||
|
/** @type OpenLayers.Pixel */
|
||||||
|
position: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
@@ -27,7 +30,10 @@ OpenLayers.Control.prototype = {
|
|||||||
if (this.div == null) {
|
if (this.div == null) {
|
||||||
this.div = OpenLayers.Util.createDiv();
|
this.div = OpenLayers.Util.createDiv();
|
||||||
}
|
}
|
||||||
this.moveTo(px);
|
if (px != null) {
|
||||||
|
this.position = px.copyOf();
|
||||||
|
}
|
||||||
|
this.moveTo(this.position);
|
||||||
return this.div;
|
return this.div;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
OpenLayers.Control.PanZoom = Class.create();
|
OpenLayers.Control.PanZoom = Class.create();
|
||||||
OpenLayers.Control.PanZoom.prototype =
|
OpenLayers.Control.PanZoom.prototype =
|
||||||
Object.extend( new OpenLayers.Control(), {
|
Object.extend( new OpenLayers.Control(), {
|
||||||
// Array(...)
|
/** @type OpenLayers.Pixel */
|
||||||
|
position: new OpenLayers.Pixel(4,4),
|
||||||
|
|
||||||
|
/** @type Array(...) */
|
||||||
buttons: null,
|
buttons: null,
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
@@ -16,7 +19,8 @@ OpenLayers.Control.PanZoom.prototype =
|
|||||||
*/
|
*/
|
||||||
draw: function(px) {
|
draw: function(px) {
|
||||||
// initialize our internal div
|
// initialize our internal div
|
||||||
OpenLayers.Control.prototype.draw.apply(this);
|
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
||||||
|
px = this.position;
|
||||||
|
|
||||||
// place the controls
|
// place the controls
|
||||||
this.buttons = new Array();
|
this.buttons = new Array();
|
||||||
|
|||||||
@@ -93,9 +93,8 @@ OpenLayers.Map.prototype = {
|
|||||||
|
|
||||||
if (!this.controls) {
|
if (!this.controls) {
|
||||||
this.controls = [];
|
this.controls = [];
|
||||||
this.addControl(new OpenLayers.Control.MouseDefaults(), null );
|
this.addControl(new OpenLayers.Control.MouseDefaults());
|
||||||
this.addControl(new OpenLayers.Control.PanZoom(),
|
this.addControl(new OpenLayers.Control.PanZoom());
|
||||||
new OpenLayers.Pixel(4,4) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.popups = new Array();
|
this.popups = new Array();
|
||||||
|
|||||||
@@ -10,17 +10,21 @@
|
|||||||
t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
|
t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
|
||||||
}
|
}
|
||||||
function test_02_Control_PanZoom_addControl (t) {
|
function test_02_Control_PanZoom_addControl (t) {
|
||||||
t.plan( 6 );
|
t.plan( 8 );
|
||||||
map = new OpenLayers.Map('map');
|
map = new OpenLayers.Map('map');
|
||||||
control = new OpenLayers.Control.PanZoom();
|
control = new OpenLayers.Control.PanZoom();
|
||||||
t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
|
t.ok( control instanceof OpenLayers.Control.PanZoom, "new OpenLayers.Control.PanZoom returns object" );
|
||||||
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" );
|
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" );
|
||||||
map.addControl(control,
|
map.addControl(control);
|
||||||
new OpenLayers.Pixel(10,10));
|
|
||||||
t.ok( control.map === map, "Control.map is set to the map object" );
|
t.ok( control.map === map, "Control.map is set to the map object" );
|
||||||
t.ok( map.controls[2] === control, "map.controls contains control" );
|
t.ok( map.controls[2] === control, "map.controls contains control" );
|
||||||
t.eq( control.div.style.zIndex, "253", "Control div zIndexed properly" );
|
t.eq( control.div.style.zIndex, "253", "Control div zIndexed properly" );
|
||||||
t.eq( map.viewPortDiv.lastChild.style.zIndex, "253", "Viewport div contains control div" );
|
t.eq( map.viewPortDiv.lastChild.style.zIndex, "253", "Viewport div contains control div" );
|
||||||
|
t.eq( control.div.style.top, "4px", "Control div top located correctly by default");
|
||||||
|
|
||||||
|
var control2 = new OpenLayers.Control.PanZoom();
|
||||||
|
map.addControl(control2, new OpenLayers.Pixel(100,100));
|
||||||
|
t.eq( control2.div.style.top, "100px", "2nd control div is located correctly");
|
||||||
}
|
}
|
||||||
function test_03_Control_PanZoom_control_events (t) {
|
function test_03_Control_PanZoom_control_events (t) {
|
||||||
t.plan( 6 );
|
t.plan( 6 );
|
||||||
|
|||||||
Reference in New Issue
Block a user