[OpenLayers-Users] DrawFeature with callback?
Nino Saturnino Martinez Vazquez Wael
nino.martinez at jayway.dk
Fri Dec 5 06:59:09 EST 2008
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
More information about the Users
mailing list