Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have basic WMS layer and vector layer in openlayers. Using EditingToolbar i can draw some features as shown below

enter image description here

Then I want to get some information (like distance and extent) of drawn features in any format.At the movement I stuck on above point. Pls give me some tips or sample code or some links.

Thanks for your valuable time

share|improve this question
up vote 1 down vote accepted

you can get vector layer extent:


for getting features:


for getting first feature geometry:


for getting centroid of your first feature:


for getting first feature coordinate as string:


for getting distance one point to another (it cant give geodetic result):

var p1 =   new OpenLayers.Geometry.Point(10,20);
var p2 =   new OpenLayers.Geometry.Point(30,40);

var distance = p1.distanceTo(p2)

i hope it helps you...

share|improve this answer
What's the equivalent of vector.features[0].geometry.x in OpenLayers 3? – user1919 Nov 26 '15 at 12:03

Use a SelectFeature control, and listen to featureselected events on the layer. The listener can use event.feature.geometry.getArea() to get the selected polygon's area, for example.

share|improve this answer
Yes ,Thanks for answer,can u give some sample codes or some links – sacprasanna May 6 '12 at 16:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.