[OpenLayers-Users] display on-the-fly area while drawing a region
on the map?
Martin Ouellet
geomartino at gmail.com
Tue Nov 22 13:39:51 EST 2011
Thanks Toby for your quick answer.
obviously, I really have to do it on the mouse move (because I force the
user to draw a regular polygon with only 4 sides by clicking and then
dragging).
I never wrote a custom listener in OL, do you have examples or links?
MartinO
On Tue, Nov 22, 2011 at 11:03 AM, Toby Reinicke <ramotswa at gmail.com> wrote:
> Hi Martin.
> Have a look at http://openlayers.org/dev/examples/measure.html and look
> at the immediate option. It'll work on each click, doing it on mouse move
> youd have to write a mouse move listener into the draw tool and do
> appropriate stuff there,
> Toby
>
> On 22 Nov 2011, at 15:51, Martin Ouellet <geomartino at gmail.com> wrote:
>
> > Hi all,
> >
> > Currently I used this piece of code to allow the user to draw a region
> of interest on the map:
> >
> > drawControls = new OpenLayers.Control();
> > OpenLayers.Util.extend(drawControls, {
> > draw: function() {
> > this.box = new
> OpenLayers.Handler.RegularPolygon(drawControls,
> > {"done": this.notice}, {sides:4, irregular:true,
> persist:true});
> > },
> > notice: function(geom) {
> > // whatever you want it to do after the box has been drawn
> > var feature = new OpenLayers.Feature.Vector(geom);
> > layer_zone_extraction.addFeatures(feature);
> > //afficher la superficie de la zone dessiné
> > var bounds = getExtractBounds();
> > var ll = new OpenLayers.LonLat(bounds.left, bounds.bottom);
> > var ur = new OpenLayers.LonLat(bounds.right, bounds.top);
> > var superficieKm =
> Math.abs(((bounds.left-bounds.right)/1000)*((bounds.top-bounds.bottom)/1000));
> > $('#message').jGrowl(superficieKm.toFixed(2) + " km²");
> > }
> > });
> >
> > Is it's possible to display the area value on-the-fly while the user
> draw it instead of after he finished?
> >
> > Thanks you in advance!
> >
> > MartinO
> > _______________________________________________
> > Users mailing list
> > Users at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20111122/48ac894b/attachment.html
More information about the Users
mailing list