[OpenLayers-Dev] Get infos on newly created polygon with Draw Feature

Fabian Patzke (OL) listensammler at patzi.de
Thu Jun 24 05:35:12 EDT 2010


Hi, this might be a more user list orientated question, I guess :)

Leipold, Christopher wrote:
> 
> I'm trying to build a function that lets me draw a 'circle' (40-sided
> polygon) and then get the coordinates of it's center and get it's
> radius.
> 
> Drawing the circle is pretty straightforward (I just copied the code
> from http://openlayers.org/dev/examples/regular-polygons.html) but I
> don't have the slightest clue how to trigger the right event (which is
> sketchcomplete I guess).
> 
the event has to be on the layer you are drawing your polygon on.

var layer = new OpenLayers.Layer.Vector(
  "digi layer"
  ,{
    eventListeners: {
      "sketchcomplete": getRingCenter
    }
  }
);

function getRingCenter(feature) {
  window.alert(feature.geometry.getCentroid());
}

If you only want to have the eventListener to be active at a certain time do
it with

layer.events.on({"sketchcomplete": getRingCenter});
and
layer.events.un({"sketchcomplete": getRingCenter});

I think that will help you ...
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Get-infos-on-newly-created-polygon-with-Draw-Feature-tp5216851p5216950.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.



More information about the Dev mailing list