[OpenLayers-Dev] TransformFeature.unsetFeature seems to have a bug

gpa gpannetier at ubikod.com
Fri Apr 6 09:14:32 EDT 2012


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

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/TransformFeature-unsetFeature-seems-to-have-a-bug-tp4692609p4692609.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20120406/18e05323/attachment.html


More information about the Dev mailing list