[OpenLayers-Users] OpenLayers.Control.ScaleLine : Add a
coefficient
Andreas Hocevar
ahocevar at opengeo.org
Thu Mar 24 17:34:52 EDT 2011
I think your map and/or layer configuration must be wrong. Usually this kind of problem appears when your map units don't match the projection's distance units.
I'd say there is no need to introduce a coefficient. Check your projection, and configure the map or base layer with the according units.
Regards,
Andreas.
On Mar 24, 2011, at 19:03 , Micka wrote:
> 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 :
>
> • float calculateTheCoefficient(float length, int pixels ); // length in meter , pixels number of pixels that the length represent
> • 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
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list