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?

closed as too broad by PolyGeo Jun 12 '17 at 8:37

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

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)
  • 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.

  • 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.