Ticket #3286 (new feature)

Opened 2 years ago

Last modified 2 years ago

proposal of a possibility to unset the transformed Feature on TransformFeature deactivation

Reported by: jbelem Owned by: ahocevar
Priority: minor Milestone: 2.13 Release
Component: Control.TransformFeature Version: 2.10
Keywords: Cc:
State: Needs More Work

Description

I thought about a possibility to reset a feature of an OpenLayers.Control.TransformFeature, like when activating this control the first time (feature is null and naturally no box is drawn).

When trying to call setFeature(null) on this control (e.g. to signal the control to loose any information about the just transformed feature) an error (in setFeature method) says "this.feature" is null. Therefore a way how to force the behaviour of the control on each activation to have the necessity of a feature to be set by a user first would be great, e.g. some workflow doing an unsetFeature(..) action, which might be applicable by this provided patch (please review!).

Thanks João Belém

Attachments

openlayers-3286.patch Download (1.1 KB) - added by jbelem 2 years ago.
testUnsetFeature.html Download (6.9 KB) - added by jbelem 2 years ago.
poor example for unsetFeature (Style points still visible after conrtol deactivation; I do not get it!)

Change History

Changed 2 years ago by ahocevar

  • state changed from Review to Needs More Work

Thanks @jbelem for the patch. Well done. Here are my suggestions for improvement:

  • I don't see a need to destroy and recreate the dragControl. Maybe you can change that.
  • Note that our coding style guidelines say that we always use curly braces for what we execute in an if clause.
  • An example and a basic unit test for the new unsetFeature method should be added. For the example, just extend the transform-feature example with an "Unset" (or whatever is appropriate) button.
  • unsetFeature should be an APIMethod.

Changed 2 years ago by jbelem

Changed 2 years ago by jbelem

Thanks @ahocevar for your hints. You're right, destroying and recreating dragControl was unnecessary. (I've picked it up from the destroy method of the TransformFeature control.)

Perhaps I've just the time to provide an example, however, I'm sure I'll have no spare time to provide a test case, sorry.

Changed 2 years ago by ahocevar

@jbelem: a question: what is the rationale behind destroying and recreating the box?

Changed 2 years ago by jbelem

@ahocevar: your question is reasonable, i've not explained it yet. So in my case, I destroy the transformed feature on deactivation of the TransformFeature control (please don't ask why!), however, I immediatelly add a new feature with the same transformed coordinates. Perhaps this special case does not justify the recreation of the box, more likely the fact that the box is distorted (instead of being rectangular) if I don't destroy and recreate the box, which therefore seemed to be a convenient fix. (Perhaps we can discuss this on the example which I just prepare and upload soon.)

Changed 2 years ago by jbelem

poor example for unsetFeature (Style points still visible after conrtol deactivation; I do not get it!)

Changed 2 years ago by jbelem

...seems like trac doesn't send email on attachment uploads... so I want to inform you about an example for unsetFeature method which I attached. It's a poor example, because the box points are still visible after deactivation of the control, which I don't understand... perhaps something in "control.box.destroy();" might not function, because of this poor call to destroy().

While testing this exapmle, the effect of this proposal, however, might be comprehensible to everyone.

Note: See TracTickets for help on using tickets.