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

Christopher Schmidt crschmidt at metacarta.com
Thu Sep 10 09:14:51 EDT 2009


On Wed, Sep 09, 2009 at 10:59:34PM -0500, P Kishor wrote:
> 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?

Patches welcome.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list