[OpenLayers-Users] How to get position of feature from DrawFeature?

gtg287y gtg287y at gmail.com
Wed Apr 7 14:38:54 EDT 2010


I am using the  Draw Feature Control to draw polygons (namely circles) on a
Vector Layer. I want to be able to save the center of the circle to a
variable, as well as the radius of the circle. 

I'm not seeing any native way to do this. When I draw a feature, I'm
assuming it's a Vector Feature, which has "geometry" and "attributes".  When
I look at the geometry, I get a bunch of points (I'm assuming 40, since
that's how many sides I told my polygon to have). 

My choices are to figure out some complicated way to turn that array of
points into a center and a radius, or (my preference) to manually save the
position the mouse is clicked down, and the position the mouse is let up
(down is center, the distance from up and down is the radius).  However, I'm
having difficulties doing that as well: There doesn't seem to be any way to
get a "mousedown" even from a Vector Layer? At least, I'm not seeing any
response when I do things like:


            polygonLayer.events.register("mousedown", feature,
function(evt){
               console.log("Mouse Down");
            });

Which implies to me that Vector Layer doesn't inherit from anythign with a
mouse down? 

Doing :


document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=function(event) {
alert(event.type) // "mousedown"
}


works fine...everywhere but my map and layer...which doesn't help me much,
and (I'm unfamiliar with javascript still),
polygonLayer.captureEvents(Event.MOUSEDOWN) doesn't work either (firebug
says the function "captureEvents" doesn't exist for VectorLayer.

I must be missing something obvious due to my inexperience: How can I find
out where a user's mouse is when the click down, then let up?

-Jenny

p.s. (Still haven't figured out my polygon refresh issue)
-- 
View this message in context: http://n2.nabble.com/How-to-get-position-of-feature-from-DrawFeature-tp4866710p4866710.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list