[OpenLayers-Users] Control documentation incomplete, inconsistent and misleading

P Kishor punk.kish at gmail.com
Wed Sep 9 23:59:34 EDT 2009


Per the docs for Control

"Controls by default are added to the map they are contained within
however it is possible to add a control to an external div by passing
the div in the options parameter."

which is followed by the example

"var control = new OpenLayers.Control({div: myDiv});"

That leads me, the user, to do the following to display MousePosition
in an external div

# in my html
<div id="map"></div>
<div id="coords"></div>
<div id="scale"></div>

# in my javascript -- this does not work
var ctrl_coords = new OpenLayers.Control({div: "coords"});
ctrl_coords.MousePosition();
map.addControl(ctrl_coords);

# in my javascript -- this also does not work
var ctrl_coords = new OpenLayers.Control.MousePosition({div: "coords"});
map.addControl(ctrl_coords);

# in my javascript -- this is the only thing that works
# but the mouse position is displayed on the map
var ctrl_coords = new OpenLayers.Control.MousePosition();
map.addControl(ctrl_coords);


So, it turns out, I have to write my code like so

# in my javascript
map.addControl(new OpenLayers.Control.MousePosition({div:
document.getElementById("coords")}));

Now, if I want to display the scale also in an external div, things
get even more bizarre

# in my javascript -- the following doesn't work
map.addControl(new OpenLayers.Control.MousePosition({div:
document.getElementById("scale")}));

# in my javascript -- the only thing that works is
var ctrl_scale = new OpenLayers.Control.Scale();
ctrl_scale.div = document.getElementById("scale");
map.addControl(ctrl_scale);


After battling with this for about 5 hours, I was able to figure the
above out via archived mailing list post for an earlier version of OL.
Is it possible to update the documentation to reflect the above, or to
fix OL so it behaves consistently?


-- 
Puneet Kishor http://www.punkish.org
Carbon Model http://carbonmodel.org
Charter Member, Open Source Geospatial Foundation http://www.osgeo.org
Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor
Nelson Institute, UW-Madison http://www.nelson.wisc.edu
-----------------------------------------------------------------------
Assertions are politics; backing up assertions with evidence is science
=======================================================================
Sent from Madison, WI, United States



More information about the Users mailing list