[OpenLayers-Users] Scale control outside the map

Jorge Gaspar Sanz Salinas jsanz at osgeo.org
Tue May 19 03:51:25 EDT 2009


2009/5/19 Eric Lemoine <eric.lemoine at camptocamp.com>:
> On Monday, May 18, 2009, Jorge Gaspar Sanz Salinas <jsanz at osgeo.org> wrote:
>> Hi, this is my first post on this list, I'm starting to develop with
>> OL and the first think I've to say is that Open Layers (code and docs)
>> is amazing.
>>
>> Well I've been in trouble with the scale control so I want to share
>> the topic, for your interest.
>>
>> Working with OL 2.7, if I create a control passing a div parameter to
>> draw the scale text outside the map, it doesn't place it right.
>>
>> I have to create the control and afterwards set the div parameter in
>> order to have it working.
>>
>> I've debugged a little bit and I think OL is overwriting the custom
>> div with the default one but I'm not an experienced JS dev and I don't
>> know how to resolve this issue. May I create a ticket for 2.8 on trac?
>
> Hi
>
> Tickets are for bugs in OpenLayers. The issue you're having does not
> sound like a bug in the library to me. Anyway, please provide some
> code for people to be able to help you with that.
>
>

Sure, I planned to do it today:

I've published to simple examples with what I should expect[1] and
what I actually have to do[2]. I know it's pretty simple but I take me
a little to realize how to resolve it and my only purpose is to share
it as I've got (for that) mi work done.

Briefly, I understood that this should work for every control. To put
the scale control in a div with the "scale" id:

map.addControl( new OpenLayers.Control.Scale({div:
document.getElementById("scale")}));

But, this doesn't work, instead I have to do it in two steps:

var control = new OpenLayers.Control.Scale();
control.div = document.getElementById("scale");
map.addControl(control);

I hope I explained myself correctly.

Cheers
[1] https://correo.prodevelop.es/descarga/testOLscale/scale1.html
[2] https://correo.prodevelop.es/descarga/testOLscale/scale2.html
-- 
Jorge Gaspar Sanz Salinas
Ingeniero en Geodesia y Cartografía
http://wiki.osgeo.org/wiki/Jorge_Sanz



More information about the Users mailing list