[OpenLayers-Dev] Re: Get the center and radius of a circle

claudia office at gisgeo.pt
Fri Dec 10 15:23:03 EST 2010


Hi list, 
Here's how i solved the problem:

formats = {
  'in': {
  wkt: new OpenLayers.Format.WKT(in_options)
  }, 
  'out': {
  wkt: new OpenLayers.Format.WKT(out_options)
  } 
};

var limits=feature.geometry.getBounds();
var center=limits.getCenterLonLat();
var center2=new OpenLayers.Geometry.Point(center.lon, center.lat);
var center_feat=new OpenLayers.Feature.Vector(center2); 
var str = formats['out']['wkt'].write(center_feat, '1');
str = str.replace(/,/g, ', ');

/*coordinates must be inverted: switch lat and long. This is the center of
the geometry*/
var x=str.split("(");
var y=x[1].split(")");
var w=y[0].split(" ");
var str_new="POINT("+w[1]+" "+w[0]+")";

/* This is the radius of the circle*/
var radius=limits.getWidth()/2;

-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Get-the-center-and-radius-of-a-circle-tp5790419p5824505.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.


More information about the Dev mailing list