[OpenLayers-Users] DrawFeature with callback?
Nino Saturnino Martinez Vazquez Wael
nino.martinez at jayway.dk
Mon Dec 8 06:50:53 EST 2008
Hi again
What if you want todo the exact same thing with the editing toolbar?
map.addControl(new
OpenLayers.Control.EditingToolbar(vectors,OpenLayers.Handler.Polygon,{'featureAdded':
serialize}));
Does not work...
Adorian Ardelean wrote:
> Hi Nino,
>
> This works ok for me:
>
> dosomething = function (feature)
> {
> //do something with polygon
> alert("yeeehaaa");
> };
>
>
> controls = {
> polygon: new
> OpenLayers.Control.DrawFeature(regions,OpenLayers.Handler.Polygon,
> {'featureAdded': dosomething})
> }
>
>
> All the best,
> Adorian
>
>
> On Fri, Dec 5, 2008 at 2:03 PM, Nino Saturnino Martinez Vazquez Wael
> <nino.martinez at jayway.dk <mailto:nino.martinez at jayway.dk>> wrote:
>
> 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>
> <mailto: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-openlayers
> ), 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>
> <mailto: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
>
>
>
>
> --
> 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
More information about the Users
mailing list