[OpenLayers-Users] Accessing a callback | Getting a polygon's
vertices
Harry Lam
mr.harry.lam at gmail.com
Wed Oct 14 17:10:26 EDT 2009
Hello community! This is my first post; I hope I'm not asking too trivial a
question. :) I'll get right into it:
Based on this example --
http://www.openlayers.org/dev/examples/drag-feature.html -- I have put a
similar control on my website where I can draw a polygon on my map. So what
I want to do is get the coordinates of my polygon’s vertices after I finish
drawing it.
According to
http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Handler/Polygon-js.html
there are callback functions called ‘point’ and ‘done’ that should be able
to give me what I want.
My question is how do I get control of those functions? I think I am a
little lacking in syntax knowledge as to how to set it up.
For example I have:
var drawpoly = new OpenLayers.Control.DrawFeature(vectorLayer,
OpenLayers.Handler.Polygon);
map.addControl(drawpoly);
which takes care of enabling the drawing feature. But I don’t know how to
get to the done() callback function from here.
On a separate note, I found this example online:
var drawpoly = new OpenLayers.Control.DrawFeature(vectorLayer,
OpenLayers.Handler.Polygon, {'featureAdded': polygonAdded});
...
polygonAdded = function (feature) {
//Yay, I can do stuff here!
}
which is pretty close to what I want, but I think the object passed to it is
not the polygon object I want to manipulate. (Or is it?)
If anyone has a better way to get the coordinates of a polygon (I assume I'd
get an x-y pixel value first and would have to convert to lat/lng), I'd love
to hear that, too. But knowing how to get to the callbacks would also be
useful in future applications. :)
Thanks for reading and considering!
--Harry
mr.harry.lam at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091014/f4682c76/attachment.html
More information about the Users
mailing list