[OpenLayers-Users] DrawFeature with callback?

Nino Saturnino Martinez Vazquez Wael nino.martinez at jayway.dk
Mon Dec 8 05:19:55 EST 2008


The stuff that Adorian wrote about worked :)

But thanks Arnd..

Arnd Wippermann wrote:
> There seems to be only "cancel" and "done" as callbacks for
> OpenLayers.Handler.RegularPolygon, but how to use them I don't have a clue.
>
> The "done" callback is declared in OpenLayers.Control.DrawFeature to draw
> the feature, trigger "featureadded" and call a empty function featureAdded.
>
> This function you can declare to do something after the feature is added to
> the layer.
>
> polygonControl.featureAdded = function() { dosomething();};
>
> or (not tested) you can register the event "featureadded" to the control.
>
>
> Arnd Wippermann
>  
>
> -----Ursprüngliche Nachricht-----
> Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
> Auftrag von Nino Saturnino Martinez Vazquez Wael
> Gesendet: Freitag, 5. Dezember 2008 14:03
> An: Adorian Ardelean
> Cc: users at openlayers.org
> Betreff: Re: [OpenLayers-Users] DrawFeature with callback?
>
> Okay so I now have this, still not working though:
>
>        
>
> <html xmlns="http://www.w3.org/1999/xhtml">
>   <head>
>     <title>OpenLayers Regular Polygon Example</title>
>     <script src="http://openlayers.org/api/OpenLayers.js"></script>
>     <script type="text/javascript">
>         var map, polygonControl;
>         OpenLayers.Util.onImageLoadErrorColor = "transparent";
>         function init(){
>             map = new OpenLayers.Map('map');
>            
>             var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
>                 "http://labs.metacarta.com/wms/vmap0?", {layers: 'basic'});
>
>             var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");
>
>             map.addLayers([wmsLayer, polygonLayer]);
>             map.addControl(new OpenLayers.Control.LayerSwitcher());
>             map.addControl(new OpenLayers.Control.MousePosition());
>
>             dosomething = function (polygon)
>             {
>                 //do something with polygon
>                 alert("yeeehaaa");
>             };
>
>             polyOptions = {sides: 4, callbacks: {'featureAdded': 
> dosomething}  };
>             polygonControl = new
> OpenLayers.Control.DrawFeature(polygonLayer,
>                                             
> OpenLayers.Handler.RegularPolygon,
>                                             {handlerOptions: polyOptions
>                                                 });
>            
>             map.addControl(polygonControl);
>            
>             map.setCenter(new OpenLayers.LonLat(0, 0), 3);
>            
>             document.getElementById('noneToggle').checked = true;
>         }
>         function setOptions(options) {
>             polygonControl.handler.setOptions(options);
>         }
>         function setSize(fraction) {
>             var radius = fraction * map.getExtent().getHeight();
>             polygonControl.handler.setOptions({radius: radius,
>                                                angle: 0});
>         }
>     </script>
>
>   </head>
>   <body onload="init()">
>     <h2 id="title">OpenLayers Regular Polygon Example</h2>
>     <p id="shortdesc">
>       Shows how to use the RegularPolygon handler to draw features with
>       different numbers of sides.
>     </p>
>     <div id="map" class="smallmap"></div>
>     <div id="config">
>        
>         <ul id="controls"><b>Map Controls</b>
>
>             <li>
>                 <input type="radio" name="type"
>                        value="none" id="noneToggle"
>                        onclick="polygonControl.deactivate()"
>                        checked="checked" />
>                 <label for="noneToggle">navigate</label>
>             </li>
>             <li>
>                 <input type="radio" name="type"
>                        value="polygon" id="polygonToggle"
>                        onclick="polygonControl.activate()" />
>                 <label for="polygonToggle">draw polygon</label>
>             </li>
>
>         </ul>
>
>     </div>
>   </body>
>
> </html>
>
>
> Adorian Ardelean wrote:
>   
>> Hi,
>>
>> I presume you have to specify the event name somehow. Try including this:
>>
>> dosomething = function (feature)
>> {
>>
>> }
>>
>>  ...callbacks: {'featureAdded': dosomething}...
>>
>>
>> All the best,
>> Adorian
>>
>> On Fri, Dec 5, 2008 at 12:59 PM, Nino Saturnino Martinez Vazquez Wael 
>> <nino.martinez at jayway.dk <mailto:nino.martinez at jayway.dk>> wrote:
>>
>>     Hi Guys
>>
>>     Im doing a integration for the Apache Wicket framework(
>>
>>     
> http://wicketstuff.org/confluence/display/STUFFWIKI/wicket-contrib-openlayer
> s
>   
>>     ), and want to add some more features. Im looking into adding the
>>     possibility to draw polygons, however I cant find a example where
>>     theres
>>     a simple callback involved once the polygon are drawn, however the api
>>     mentions it's possible.
>>
>>     As you can see from the below code the only thing I need for this
>>     little
>>     thing to work are the function that calls the alert to be picked up.
>>     Please say if you want me to elaborate further.
>>
>>
>>     <html xmlns="http://www.w3.org/1999/xhtml">
>>      <head>
>>        <title>OpenLayers Regular Polygon Example</title>
>>        <script src="http://openlayers.org/api/OpenLayers.js"></script>
>>        <script type="text/javascript">
>>            var map, polygonControl;
>>            OpenLayers.Util.onImageLoadErrorColor = "transparent";
>>            function init(){
>>                map = new OpenLayers.Map('map');
>>
>>                var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
>>                    "http://labs.metacarta.com/wms/vmap0?", {layers:
>>     'basic'});
>>
>>                var polygonLayer = new OpenLayers.Layer.Vector("Polygon
>>     Layer");
>>
>>                map.addLayers([wmsLayer, polygonLayer]);
>>                map.addControl(new OpenLayers.Control.LayerSwitcher());
>>                map.addControl(new OpenLayers.Control.MousePosition());
>>
>>                polyOptions = {sides: 4, callbacks:
>>     {function(value){alert('yeeeha');}}  };
>>                polygonControl = new
>>     OpenLayers.Control.DrawFeature(polygonLayer,
>>
>>     OpenLayers.Handler.RegularPolygon,
>>                                                {handlerOptions:
>>     polyOptions
>>                                                    });
>>
>>                map.addControl(polygonControl);
>>
>>                map.setCenter(new OpenLayers.LonLat(0, 0), 3);
>>
>>                document.getElementById('noneToggle').checked = true;
>>                 document.getElementById('irregularToggle').checked =
>>     false;
>>            }
>>            function setOptions(options) {
>>                polygonControl.handler.setOptions(options);
>>            }
>>            function setSize(fraction) {
>>                var radius = fraction * map.getExtent().getHeight();
>>                polygonControl.handler.setOptions({radius: radius,
>>                                                   angle: 0});
>>            }
>>        </script>
>>
>>      </head>
>>      <body onload="init()">
>>        <h2 id="title">OpenLayers Regular Polygon Example</h2>
>>        <p id="shortdesc">
>>          Shows how to use the RegularPolygon handler to draw features with
>>          different numbers of sides.
>>        </p>
>>        <div id="map" class="smallmap"></div>
>>        <div id="config">
>>
>>            <ul id="controls"><b>Map Controls</b>
>>
>>                <li>
>>                    <input type="radio" name="type"
>>                           value="none" id="noneToggle"
>>                           onclick="polygonControl.deactivate()"
>>                           checked="checked" />
>>                    <label for="noneToggle">navigate</label>
>>                </li>
>>                <li>
>>                    <input type="radio" name="type"
>>                           value="polygon" id="polygonToggle"
>>                           onclick="polygonControl.activate()" />
>>                    <label for="polygonToggle">draw polygon</label>
>>                </li>
>>
>>            </ul>
>>
>>        </div>
>>      </body>
>>
>>     </html>
>>
>>
>>
>>
>>     -Nino
>>     _______________________________________________
>>     Users mailing list
>>     Users at openlayers.org <mailto:Users at openlayers.org>
>>     http://openlayers.org/mailman/listinfo/users
>>
>>
>>
>>
>> --
>> Dr. Adorian Ardelean
>> coordinator of myNature Project
>>
>> http://mybiosis.info/nature/portal.php?pagename=firstpage [a Romanian 
>> biodiversity-database] 
>> http://mybiosis.info/nature/portal.php?pagename=adorian [CV]
>>     
>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684




More information about the Users mailing list