Ticket #2446 (closed feature: invalid)

Opened 3 years ago

Last modified 3 years ago

Deactivating OpenLayers.Control.DrawFeature after featureadded causes error: 'this.layer.renderer' is null or not an object

Reported by: ElijahBitting Owned by:
Priority: minor Milestone: 2.9 Release
Component: Control.DrawFeature Version: 2.8
Keywords: Cc:
State: Complete

Description

I am using OpenLayers.Control.DrawFeature control to draw regular polygons (very similar to OpenLayers Example: "OpenLayers Draw Feature Example" (http://openlayers.org/dev/examples/draw-feature.html). But I need to grab and display the drawn polygon's geometry in WKT. This all works fine, but I want to restore the "Navigation" control after a feature is drawn. i.e. I don't want clicking on the map immediately after drawing a polygon to cause a 2nd polygon to be drawn. So at the end of the Method I register as the "featureadded" handler, I call a function that deactivates the DrawFeature control. This causes the following error in IE8.0.6001.18702: "error: 'this.layer.renderer' is null or not an object"

After a little tracing I found the error occurred as a result of the following statement:

this.layer.renderer.clear();

At this point "this" is the control's handler and it's layer has been set to null. So I simply wrapped this statement and the next (which also references this.layer) in a simple if(this.layer) check.

Attachments

ol_patch.txt Download (332 bytes) - added by ElijahBitting 3 years ago.

Change History

Changed 3 years ago by ElijahBitting

Changed 3 years ago by ahocevar

  • state changed from Review to Awaiting User Feedback

Try setting {persist: true} in the handlerOptions. This should fix your issue without making the change you showed in your patch. Please report back if that works. If so, we can add a note in the documentation of the persist option.

Changed 3 years ago by ElijahBitting

  • status changed from new to closed
  • state changed from Awaiting User Feedback to Complete
  • resolution set to invalid

Setting { persist: true } in handlerOptions (via control constructor) did the trick. Thank you!

Note: See TracTickets for help on using tickets.