[OpenLayers-Users] OpenLayers.Control.ScaleLine : Add a
coefficient
Micka
mickamusset at gmail.com
Thu Mar 24 14:03:23 EDT 2011
Hey,
Well, I've gotten the source code of this module, so now i'm trying to add a
coeficient K .
The goal is to give the possibility to adjust the scaleline.
For that, I thought that we can add two function on this module :
1. float calculateTheCoefficient(float length, int pixels ); //
length in meter , pixels number of pixels that the length represent
2. void setTheCoefficient ( float k );
The first function will calculate the coefficient with the actual resolution
and the length/pixels .
the second function will save the coefficient for the update function() .
What do you think ?
My problem, is that i don't know how to do code the first function .......
update: function() {
var res = this.map.getResolution();
* res*= k;*
if (!res) {
return;
}
// convert maxWidth to map units
var maxSizeData = this.maxWidth * res;
// decide whether to use large or small scale units
var topUnits;
if(maxSizeData > 0.1) {
topUnits = this.topOutUnits;
} else {
topUnits = this.topInUnits;
}
// and to map units units
var curMapUnits = this.map.units;
var inches = OpenLayers.INCHES_PER_UNIT;
var topMax = maxSizeData * inches[curMapUnits] /
inches[topUnits];
// now trim this down to useful block length
var topRounded = this.getBarLen(topMax);
// and back to display units
topMax = topRounded / inches[curMapUnits] * inches[topUnits];
// and to pixel units
var topPx = topMax / res;
// now set the pixel widths
this.eTop.style.width = Math.round(topPx) + "px";
// and the values inside them
this.eTop.innerHTML = topRounded + " " + topUnits;
},
CLASS_NAME: "OpenLayers.Control.ScaleLine"
}
On Thu, Mar 24, 2011 at 3:03 PM, mickal <mickamusset at gmail.com> wrote:
> Hi,
>
> The scale that the module displayed to me is not right, I mean :
>
> 50 pixel => 1000km
> but in reality :
> 50 pixel => 100 m
>
> is it possible to add a coefficient to this module ? to adjust the scale
> that it displayed.
>
>
> Because otherwise I have to change my map, and this process is very long.
>
>
> thx,
>
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/OpenLayers-Control-ScaleLine-Add-a-coefficient-tp6204219p6204219.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110324/8ccebf47/attachment.html
More information about the Users
mailing list