I am using OpenLayers JS to draw a polygon and now I want map extents of the drawn polygon one final click (i.e. user finish drawing polygon or double click is done). For drawing the polygon I am using following code:
action = Ext.create('GeoExt.Action', {
text: "Draw Poly",
icon: 'Images/poly.png',
control: new OpenLayers.Control.DrawFeature(
vector, OpenLayers.Handler.Polygon
),
map: map,
// button options
toggleGroup: "draw",
allowDepress: false,
tooltip: "Draw Polygon",
// check item options
group: "draw"
});
This code is written using OpenLayers JS, Ext JS and GeoExt JS.
Can anyone please tell me how to get map extents for the drawn polygon?
Best Answer
You need to listen to the featureadded event of the vector layer, and then get the geometry there.
Have a look at the following JavaScript code:
You can also see this working example: http://jsfiddle.net/devdatta/sFaag/