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

P Kishor punk.kish at gmail.com
Thu Sep 10 09:38:12 EDT 2009


On Thu, Sep 10, 2009 at 8:14 AM, Christopher Schmidt
<crschmidt at metacarta.com> wrote:
> 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.

Hi Chris,

I am not sure (1) what to patch, the code so that it is consistent, or
the documentation so that it shows the user to deal with the current
inconsistency in the code behavior, and (2) I really have no clue how
to patch.

I have already written up the inconsistency in this email thread, and
also written up how to work around it. I will be happy to clean the
write up a bit more and stick it in a wiki or wherever appropriate,
but other than that, I really have no idea how to proceed forward as
much as I would like to do so.

Please advise.


>
> Regards,
> --
> Christopher Schmidt
> MetaCarta
>



-- 
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