1

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. Can you give me some tips or sample code or some links?

2

you can get vector layer extent:

vector.getDataExtent();

for getting features:

vector.features;

for getting first feature geometry:

vector.features[0].geometry.x
vector.features[0].geometry.y

for getting centroid of your first feature:

vector.features[0].geometry.getCentroid();

for getting first feature coordinate as string:

vector.features[0].geometry.toString();

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)
| improve this answer | |
  • What's the equivalent of vector.features[0].geometry.x in OpenLayers 3? – user1919 Nov 26 '15 at 12:03
2

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.

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

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