[OpenLayers-Dev] Deactivate Draw-Control after feature added

Paul Spencer pspencer at dmsolutions.ca
Tue Apr 8 06:33:20 EDT 2008


Kevin, I am using the same technique and it works just fine.

The featureAdded callback gets called during  
DrawFeature.drawFeature().  This function does not appear to be in  
your stack trace (nor is toggle()) so that isn't your problem at this  
point.

It looks like you have some other code hanging around that is causing  
you problems - something that is handling the dblclick it looks like.

Cheers

Paul

On 8-Apr-08, at 5:27 AM, Kevin Kempfer wrote:
> Crossposting this to the dev list, looks like nobody knows on the  
> user list.
>
> Kevin
>
> ----------------
> Hi,
>
> I'm trying to let the user draw a line feature and deactivate the draw
> feature after the feature was added to the map. Here's my code:
>
> var drawControls = {
>                 point: new OpenLayers.Control.DrawFeature(vectors,
>                             OpenLayers.Handler.Point),
>                 line: new OpenLayers.Control.DrawFeature(vectors,
> 		OpenLayers.Handler.Path,{featureAdded: toggle }
> 			),
>                 rectangle: new OpenLayers.Control.DrawFeature(vectors,
>                             OpenLayers.Handler.Box),
>                 select: new OpenLayers.Control.SelectFeature(vectors),
>             };
>
>             for(var key in drawControls) {
>                 map.addControl(drawControls[key]);
>             }
>
>
> function toggle(feature){
> 	var linecontrol = drawControls['line'];
> 	linecontrol.deactivate();
> }
>
> I get an error as soon as the control gets deactivated:
> this.point has no properties
> -> this.point.destroy();
>
> Here's the trace from FireBug:
> destroyFeature()Point.js (line 128)
> destroyFeature()Path.js (line 81)
> finalize()Point.js (line 139)
> dblclick(dblclick clientX=0, clientY=0)Path.js (line 240)
> triggerEvent("dblclick", dblclick clientX=0, clientY=0)Events.js  
> (line 612)
> handleBrowserEvent(dblclick clientX=0, clientY=0)Events.js (line 640)
> bindAsEventListener(dblclick clientX=0, clientY=0)
>
> Looks like the control gets deactivated too early in the feature- 
> adding
> process. Is there any advice on how to deactivate a draw control after
> drawing a feature?
>
> Thanks,
>
> Kevin
>
> -- 
> http://www.kevinkempfer.de
> Tel.: +49 7071 860303
> ICQ:  2186573
> Skype: kevin0815
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev


__________________________________________

    Paul Spencer
    Chief Technology Officer
    DM Solutions Group Inc
    http://www.dmsolutions.ca/




More information about the Dev mailing list