[OpenLayers-Users] Need to set modifyFeature mode after feature select

Tim Schaub tschaub at openplans.org
Tue Mar 11 12:22:18 EDT 2008


Hey-

Stephen Woodbridge wrote:
> Hi all,
> 
> I have features (polygons) that have an ftype attribute that can be 
> 'irregular|circle|rectangle' and I need to setup handlers or the modify 
> mode based on allowable constraints for each ftype.
> 
> So for example:
> 
> if (feature.attributes.ftype == 'irregular')
>    this.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
> else
>    this.mode = OpenLayers.Control.ModifyFeature.RESIZE |
>                OpenLayers.Control.ModifyFeature.ROTATE |
>                OpenLayers.Control.ModifyFeature.DRAG;
> 
> And if looks like it is already too late to do this when
> 
> this.onModificationStart(feature)
> 

I've just marked the onModification* methods as deprecated.  Since these 
can only be defined once, they are not an ideal way to handle messaging.

Instead, you should be listening for feature related events on the 
layer.  We've added a number of new events to the vector layer[1].

layer.events.on({
     "beforefeaturemodified": someListener
});

With the above, someListener is called before features are modified 
(with an object containing a feature property).  If that listener is a 
public method on some object, you can do the following:

layer.events.on({
     "beforefeaturemodified": someListener
     scope: someObject
});

The problem that you have identified is that we render vertices before 
triggering the event.  I've opened ticket 1427[2] with a patch to change 
this sequence.

In the meantime, you can listen for "featureselected" on the layer 
(which gets called before vertices get rendered by the ModifyFeature 
control):

layer.events.on({
     "featureselected": someListener
});

Note that you can register any number of listeners for any number of 
events (given the same scope) in a single call to layer.events.on[3]. 
You can also pass these listeners to the layer constructor if you'd 
rather do this at layer construction.  See the events.html[4] example 
for more detail.

Tim

[1] 
http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.EVENT_TYPES

[2] http://trac.openlayers.org/ticket/1427

[3] 
http://dev.openlayers.org/docs/files/OpenLayers/Events-js.html#OpenLayers.Events.on

[4] http://openlayers.org/dev/examples/events.html

> is called. It looks like this needs to be done in
> 
> this.selectFeature(object)
> 
> which is passed to the event handlers but I can not overload this 
> because it is passed to the event handler in ModifyFeature.initialize.
> 
> Can anyone confirm that his is indeed the current flow?
> Did I miss another way to hook into this or overload some other function?
> 
> In general I think it would be good to be able to modify the mode while 
> ModifyFeature is running or based on the feature (or its attributes) 
> that is being modified.
> 
> For example, bind a mode like rotate to the control key, then if the 
> ctrol key is held down while modification is in progress the 
> ModifyFeature would switch from its current mode to ROTATE only and when 
> the key is released it would go back to the previous mode it was in.
> 
> This would allow for more fine grained control over feature modifications.
> 
> I also think that part of what I'm trying to do could be abstracted to 
> be something like rule based modification. For example, a rule for 
> modifying an object that is tagged as a square vs. rectangle vs. circle 
> vs. irregular, etc. This could be done by handlers that enforce the 
> conditions or a clever definition of rules whatever that might be.
> 
> ok, better stop here, too many ideas from too many cups of coffee :)
> 
> Thanks,
>    -Steve W
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> !DSPAM:4033,47d695d3299394901796417!
> 




More information about the Users mailing list