<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
I want to be able to prevent a user from adding a new vertex to a
line sketch tool if I determine the location is invalid. <br>
So for example in <a
href="http://openlayers.org/dev/examples/editingtoolbar.html">http://openlayers.org/dev/examples/editingtoolbar.html</a>
I may want to prevent a user from clicking on the sea (the code to
work out if a point is valid or not is fine). <br>
<br>
My draw feature tool calls a pointHandler function correctly, but
there seems no way to cancel the addition of a new point. <br>
<br>
var myControl = OpenLayers.Control.DrawFeature(myLayer,
OpenLayers.Handler.Path, {<br>
callbacks: {<br>
point: pointHandler<br>
});<br>
<br>
function pointHandler = function(newPoint){<br>
if(!_isValidPoint){<br>
//none of the following work...<br>
//myControl.handler.destroyFeature();<br>
//myControl.removePoint();<br>
//newPoint= null;<br>
}<br>
}<br>
<br>
<br>
Looking at the source code for at <a
href="http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js">http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js</a>,
the callback occurs after the new geometry is added but before it is
drawn. <br>
<br>
<table class="code">
<tbody>
<tr>
<th id="L127"><a
href="http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js#L127">127</a></th>
<td> this.line.geometry.addComponent(</td>
</tr>
<tr>
<th id="L128"><a
href="http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js#L128">128</a></th>
<td> this.point.geometry,
this.line.geometry.components.length</td>
</tr>
<tr>
<th id="L129"><a
href="http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js#L129">129</a></th>
<td> );</td>
</tr>
<tr>
<th id="L130"><a
href="http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js#L130">130</a></th>
<td> this.callback("point", [this.point.geometry,
this.getGeometry()]);</td>
</tr>
<tr>
<th id="L131"><a
href="http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js#L131">131</a></th>
<td> this.callback("modify", [this.point.geometry,
this.getSketch()]);</td>
</tr>
<tr>
<th id="L132"><a
href="http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Handler/Path.js#L132">132</a></th>
<td> this.drawFeature();</td>
</tr>
</tbody>
</table>
<br>
<br>
I also tried a custom OpenLayers.Control.Click with stopSingle set
to true, but new points are added on the "mousedown" event, and so
the click control is called afterwards. <br>
<br>
Are there any ways to achieve this, or will it involve overriding
browser events?<br>
Apologies if this is in the wrong mailing list. <br>
Thanks for any help,<br>
<br>
Seth G. <br>
</body>
</html>