[OpenLayers-Users] display on-the-fly area while drawing a region on the map?

Martin Ouellet geomartino at gmail.com
Tue Nov 22 10:51:43 EST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20111122/241290ce/attachment.html


More information about the Users mailing list