Get Coordinates from Polygon in OpenLayers

htmljavascriptopenlayers-2polygonvector

please could someone help me and bless me with an example of how to get coordinates from a polygon in OpenLayers?

Best Answer

you can get the coordinates of your shape as below code:

vectorLayer.features[i].geometry.getBounds();

and also you can get covered area, centroid of your shape, vertices of ypur shape, length or geodesic area.

if you want specific feature bounds, you can write order of your feature [i] place like this:

vectorLayer.features[3].geometry.getBounds();

and below code will give all bounds of your features example :

var ft = vectorLayer.features;
for(var i=0; i< ft.length; i++){
    console.log(vectorLayer.features[i].geometry.getBounds());
};

I hope that will be useful for you....