Guys! I need some hint on getting the polygon coordinates... I have been trying for hours.. but, no help. Can we get the coordinates of dynamically created polygon. I am able to get the done status of drawing polygon, but cannot get the coordinates. This is how i am trying to do...
----- code ---- var polycontrol; function init(){ map = new OpenLayers.Map('map', {'maxResolution': 'auto'}); layer = new OpenLayers.Layer.WMS("OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'}); vectors = new OpenLayers.Layer.Vector("Vector Layer"); map.addLayers([layer, vectors]); map.setCenter(new OpenLayers.LonLat(lon, lat), zoom); map.setOptions({restrictedExtent:new OpenLayers.Bounds(-180, -90, 180, 90)}); map.addControl(new OpenLayers.Control.MousePosition()); } function addPolygon(){ polycontrol = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.Polygon, {'featureAdded': check}); map.addControl(polycontrol); polycontrol.activate(); } function check(obj){ var geometry = new OpenLayers.Geometry.Polygon(); alert(geometry.toString()); <================ Need Polygon Co-ordinates Here. alert(geometry.getBounds()); polycontrol.deactivate(); } ---- code ends ---- But, inside the check function, I get results like "POLYGON()" on geometry.toString()... Can anyone please help? <BIJOY> Bijoy wrote: > > I got this from another mail > > polycontrol = new OpenLayers.Control.DrawFeature(vectors, > OpenLayers.Handler.Polygon, {'featureAdded': YourFunction}); > map.addControl(polycontrol); > polycontrol.activate(); > > But, I am still stuck with getting the co-ordinates. > <BIJOY> > > > > Bijoy wrote: >> >> Thanks Kumar... >> But, am already using Polygon Handler in the Drawfeature control >> constructure. How do i combine both the constructor to get the "done" >> command. >> Can anyone help me, if you have any idea... >> <BIJOY> >> >> >> Kumar Mettu wrote: >>> >>> Bijoy, >>> >>> Have you tried using Polygon Handler Constructor? >>> >>> http://dev.openlayers.org/releases/OpenLayers-2.6/doc/apidocs/files/OpenLayers/Handler/Polygon-js.html >>> >>> This should answer your question. >>> >>> Kumar. >>> >>> Bijoy wrote: >>>> >>>> Thanks for the reply.. Salvaro, >>>> >>>> Can we call a function 'oncomplete' or 'done' of drawing a polygon. >>>> And, then may be I want to get the polygon coordinates. User completes >>>> the polygon drawing by doubleclicking. >>>> I am using the below URL as example: >>>> http://openlayers.org/dev/examples/select-feature.html >>>> >>>> <BIJOY> >>>> >>>> >>>> Salvaro wrote: >>>>> >>>>> >>>>> geometry.getBounds().getCenterLonlat() ? >>>>> >>>>> Salvaro. >>>>> >>>>> >>>>> Bijoy wrote: >>>>>> >>>>>> >>>>>> Hey, >>>>>> I am drawing a polygon using the handler as shown below: >>>>>> >>>>>> polycontrol = new OpenLayers.Control.DrawFeature(vectors, >>>>>> OpenLayers.Handler.Polygon); >>>>>> map.addControl(polycontrol); >>>>>> polycontrol.activate(); >>>>>> >>>>>> Now, how do I get polygon coordinates when I finish drawing the >>>>>> polygon? >>>>>> >>>>>> -- >>>>>> View this message in context: >>>>>> http://www.nabble.com/How-do-I-get-my-polygon-coordinates--tp19413142p19413142.html >>>>>> Sent from the OpenLayers Users mailing list archive at Nabble.com. >>>>>> >>>>>> _______________________________________________ >>>>>> Users mailing list >>>>>> Users@openlayers.org >>>>>> http://openlayers.org/mailman/listinfo/users >>>>>> >>>>>> >>>>> >>>>> -- >>>>> View this message in context: >>>>> http://n2.nabble.com/How-do-I-get-my-polygon-coordinates--tp1079900p1079911.html >>>>> Sent from the OpenLayers Users mailing list archive at Nabble.com. >>>>> >>>>> _______________________________________________ >>>>> Users mailing list >>>>> Users@openlayers.org >>>>> http://openlayers.org/mailman/listinfo/users >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > -- View this message in context: http://www.nabble.com/How-do-I-get-my-polygon-coordinates--tp19413142p19431317.html Sent from the OpenLayers Users mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users