Fixed ScaleLine when geodesic option is set to true and the map center is beyond the poles. Also added geodesic option to the Scale control. r=tschaub (closes #2600)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10657 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-08-20 23:29:33 +00:00
parent 3f172c501d
commit ee7065c9fa
3 changed files with 61 additions and 23 deletions

View File

@@ -2288,6 +2288,39 @@ OpenLayers.Map = OpenLayers.Class({
px.y = Math.round(px.y);
return px;
},
/**
* Method: getGeodesicPixelSize
*
* Parameters:
* px - {<OpenLayers.Pixel>} The pixel to get the geodesic length for. If
* not provided, the center pixel of the map viewport will be used.
*
* Returns:
* {<OpenLayers.Size>} The geodesic size of the pixel in kilometers.
*/
getGeodesicPixelSize: function(px) {
var lonlat = px ? this.getLonLatFromPixel(px) : (this.getCenter() ||
new OpenLayers.LonLat(0, 0));
var res = this.getResolution();
var left = lonlat.add(-res / 2, 0);
var right = lonlat.add(res / 2, 0);
var bottom = lonlat.add(0, -res / 2);
var top = lonlat.add(0, res / 2);
var dest = new OpenLayers.Projection("EPSG:4326");
var source = this.getProjectionObject() || dest;
if(!source.equals(dest)) {
left.transform(source, dest);
right.transform(source, dest);
bottom.transform(source, dest);
top.transform(source, dest);
}
return new OpenLayers.Size(
OpenLayers.Util.distVincenty(left, right),
OpenLayers.Util.distVincenty(bottom, top)
);
},