Ticket #2446 (closed feature: invalid)
Deactivating OpenLayers.Control.DrawFeature after featureadded causes error: 'this.layer.renderer' is null or not an object
|Reported by:||ElijahBitting||Owned by:|
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:
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.