[OpenLayers-Users] howto regist. featuremodified instead onModification ?

Pierre GIRAUD bluecarto at gmail.com
Sun Dec 14 08:19:33 EST 2008


Your first code should work fine. It looks good.
In your case, you don't need to specify any scope because in your
callback function you don't use "this".
However, keep the scope thing in mind, you may need it someday, in the
case you have to have something with a reference outside the callback.

Regards,
Pierre

On Fri, Dec 12, 2008 at 8:19 PM, Alexandre Dube <adube at mapgears.com> wrote:
> Well, I don't 100% understand.  Using on, what's the use of the scope ?
> The following works without scope :
>
>        olWFSRoads.events.on({
>            featuremodified: function(o) {
>                var oFeature = o.feature;
>                OpenLayers.Console.log("modified", oFeature.id);
>            }
>        });
>
>
> or the following works also, but scope is still useless here.
>
>        olWFSRoads.events.on({
>            featuremodified: function(o) {
>                onRoadModification(o.feature);
>            },
>            scope: this
>        });
>
> function onRoadModification(object) {
>    var oFeature = object.feature;
>    OpenLayers.Console.log("modified", oFeature.id);
> };
>
>
> In the end, I want to move my OpenLayers demo into MapFish and I want to
> use some widgets like the list of features which uses a Modification
> control.  It already has its own defined onModification function, so I
> have to get rid of mine and register an event instead.  Using one of the
> above method should do the trick, I am correct ?
>
> Thanks again for your help,
>
> Alexandre
>
>
> Eric Lemoine wrote:
>> You are correct.
>>
>> For information, the second argument to the register method is the
>> scope. "this" in the callback will reference the object this scope
>> references. Hope I'm clear enough.
>>
>> Note that can also use the "on" method:
>>
>> layer.events.on({
>>     featuremodified: function(o) {
>>     },
>>    scope: your_scope
>> });
>>
>> Cheers,
>>
>> Eric
>>
>> 2008/12/12, Alexandre Dube <adube at mapgears.com>:
>>
>>> Hi,
>>>
>>>   The onModification function of ModifyControl is deprecated.  How do
>>> you register a featuremodified instead ?
>>>
>>>   I've tried this but oFeature is the layer object instead of a feature :
>>>
>>>
>>> layer.events.register("featuremodified",'', onRoadModification);
>>>
>>> function onRoadModification(oFeature) {
>>>     OpenLayers.Console.log("modified", oFeature.id);
>>> };
>>>
>>>
>>> I tried ("featuremodified",this.feature, onRoadModification), not
>>> working either.
>>>
>>> this could work, but I'm not sure it's the good way to do it.
>>> function onRoadModification(object) {
>>>     oFeature = object.feature;
>>>     OpenLayers.Console.log("modified", oFeature.id);
>>> };
>>>
>>> The old onModification was called with (object.feature), so I suppose
>>> the above solution is the good way, but I just want to be sure.
>>>
>>> Any hint ?
>>>
>>> --
>>> Alexandre Dubé
>>> Mapgears
>>> www.mapgears.com
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>
>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



More information about the Users mailing list