TransformFeature.unsetFeature seems to have a bug

classic Classic list List threaded Threaded
2 messages Options
gpa
Reply | Threaded
Open this post in threaded view
|

TransformFeature.unsetFeature seems to have a bug

gpa
Hi!

I'm currently implementing GWT-classes to support TransformFeature with gwt-openlayers. Everything was ok except one thing: when calling unsetfeature() then setfeature(f) after a rotation, the box's shape became inconsistent.

I first started looking for the bug in my java code, but after some research, I found that the problem was in the Javascript.
Indeed in the setFeature method, the box is moved to the new feature, then rotate at the inverse of the current rotation, finally scaled.

setFeature: function(feature, initialParams) {
...
        var oldRotation = this.rotation;
        var oldCenter = this.center;
...
        var featureBounds = this.feature.geometry.getBounds();
        this.box.move(featureBounds.getCenterLonLat());
        this.box.geometry.rotate(-oldRotation, oldCenter);
        this._angle = 0;
...
}

I found the problem did not happen when I didn't call the "deactivate()" or "unsetfeature()" functions. Then I found this little line in the TransformFeature.js (line 327):

unsetFeature: function() {
    	if (this.active) {
    		this.deactivate();
    	} else {
	    	this.feature = null;
	    	this.rotation = 0;
	    	this.scale = 1;
	    	this.ratio = 1;
    	}
}


It means that when you unset a rotated feature then you set a new one, the box cannot be unrotated, the scale arrive on it and the great box became dirty.

After commented it, the bug is gone. I looked for it on the OpenLayers.transformFeature example and found that the unsetFeature (or deactivate) method is never called. After putting a call in the code, the bug appears. Here the code I added to this file "http://dev.openlayers.org/releases/OpenLayers-2.11/examples/transform-feature.html" to make the bug appear (just after control creation) :
control.events.register("transformcomplete", control, function() { var feature = control.feature; control.unsetFeature(); control.setFeature(feature); });
Did you ever heard about it ? Is that really a bug or a bad manipulation from me ?

Regards,

Guillaume
Reply | Threaded
Open this post in threaded view
|

Re: TransformFeature.unsetFeature seems to have a bug

Frost89
Hi there!

I have been searching for a bug in my code for some time, because I've had the same problem.

This definetly seems like a bug in OpenLayers.