[OpenLayers-Users] scaleline in lon/lat projection

Jan jab at umk.pl
Wed Apr 28 08:34:07 EDT 2010


Hi,
I tried a simple example:

        var map, scalebar;

        function init(){

            map = new OpenLayers.Map('map');
            var layer = new OpenLayers.Layer.WMS(
                "OpenLayers WMS",
                "http://labs.metacarta.com/wms/vmap0",
                {layers: 'basic'}
            );
            map.addLayer(layer);

			var scalebar = new OpenLayers.Control.ScaleLine({
				geodesic: true
			});
			
            map.addControl(scalebar);

            map.zoomToMaxExtent();
        }

and Firebug gave me the following error:

Error: px is null
Source: http://openlayers.org/api/OpenLayers.js
Line: 895


What am I doing wrong? What other map parameters should be defined to make
geodesic scale line work properly?

Best regards,
Jan


2010/4/28 Bart van den Eijnden <bartvde at osgis.nl>

> Hi Jan,
>
> please use OpenLayers 2.9 where the ScaleLine control has a geodesic option
> which you will need to set to true, see:
>
> http://trac.openlayers.org/ticket/1890
>
> http://trac.openlayers.org/changeset/10110
>
> Best regards,
> Bart
>
> On Apr 28, 2010, at 1:33 PM, Jan wrote:
>
> Hi all,
> It seems that in lon/lat projections (e.g. EPSG 4326) the scale line is
> right only for the Equator (0 lat).
> If you look at the map, e.g.:
> http://dev.openlayers.org/addins/scalebar/trunk/examples/scalebar.html the
> scaleline stays constant even if you pan map from N to S. It seems that
> Poland for example has a width of 1000 km (W-E), while in fact it has
> approx. 600 km. This is just wrong and for "spatially-unaware" users it will
> give wrong information.
>
> AFAIK scale bar's width can be adjusted using:
>
> OpenLayers.INCHES_PER_UNIT["degrees"] = x;
>
> where x can be calculated using the length of a given parallel (in inches)
> divided by 360 degrees. The default inch per unit value is 4374754.
> 4374754 * 360 degrees = 1574911440 inches = 40000 km (the length of the
> Equator).
>
> It would be nice to implement a default functionality in OL for automatic
> adjustments of INCHES_PER_UNIT value based e.g. on the latitude of a map
> center (for example using moveend or zoomend map events). In this way, the
> scale bar would be always correct at least in the center of the map. If you
> create a map for higher latitudes it is crucial. The wrong scale line I
> would call even a bug (imagine using this scaleline in northern Canada or
> Norway).
>
> By the way, it seems that Google Maps uses this method to correct the scale
> line (check http://maps.google.com, pan the map in N/S direction and see
> how the scale line adjusts without changing the scale of the map).
>
> Best regards to all OL users,
> Jan
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100428/b16736ee/attachment.html


More information about the Users mailing list