[OpenLayers-Users] Accessing the events of DrawFeature and
ModifyFeature to calculate area
Albert Ang
bluesky003 at gmail.com
Thu Feb 18 22:26:21 EST 2010
Hi Christoph,
thank you very much for your assistance. I tried the following and it works
beautifully. One little problem is the closing of the polygon vertices.
Before adding the events listeners, a simple double-click will close the
polygon. After adding the events, sometimes I need to double-click twice to
close the polygon. Not a big problem though. Thanks again. - Albert Ang
function report(event) {
//OpenLayers.Console.log(event.type, event.feature ?
event.feature.id : event.components);
displayWKT(event.feature);
}
aoi.events.on({
"beforefeaturemodified": report,
"featuremodified": report,
"afterfeaturemodified": report,
"vertexmodified": report,
"sketchmodified": report,
"sketchstarted": report,
"sketchcomplete": report
});
function displayWKT(feature) {
var str = wkt.write(feature);
// not a good idea in general, just for this demo
//str = str.replace(/,/g, ', ');
document.getElementById('info').innerHTML = str;
document.aoi.vertex.value = str;
var areaAOI = feature.geometry.getGeodesicArea();
areaAOI = areaAOI / 1000000;
var areaAOIstr = 'Approx. area : ' + areaAOI + ' sq. km';
document.getElementById('area').innerHTML = areaAOIstr;
} // end function displayWKT(feature)
On Fri, Feb 19, 2010 at 2:05 AM, Christoph Ratke <christoph.ratke at gmx.net>wrote:
> Hi Mr. Ang,
>
> you can have a look here:
>
> http://dev.openlayers.org/releases/OpenLayers-2.8/examples/modify-feature.html
> or here:
>
> http://dev.openlayers.org/releases/OpenLayers-2.8/examples/highlight-feature.html
>
> Have a good day,
> Christoph
>
>
> Albert Ang schrieb:
> > Dear all,
> >
> > I need assistance in using the events of DrawFeature and
> > ModifyFeature. Can anyone provide some examples? I use the DrawFeature
> > and ModifyFeature as following but need guidance on how to use the
> > events of DrawFeature (featureadded) and ModifyFeatures
> > (featuremodified). Basically I like to use the
> > feature.geometry.getGeodesicArea() function to calculate area
> > dynamically when an user draws a polygon or when he modifies the polygon.
> >
> > controls = {
> > dpolygon: new OpenLayers.Control.DrawFeature(aoi,
> > OpenLayers.Handler.Polygon, drawOptions),
> > modify: new OpenLayers.Control.ModifyFeature(aoi,
> >
> > modifyOptions),
> > selectVector: new OpenLayers.Control.SelectFeature(aoi,
> > wktOptions)
> > }
> >
> > Thank you in advance.
> >
> > Albert
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> >
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100219/f1b7381e/attachment.html
More information about the Users
mailing list