[Users] Problem with FeatureStore.getRecordFromFeature()
Adam Ratcliffe
adam at prema.co.nz
Fri May 21 11:26:08 CEST 2010
Hi Eric,
The feature is a new feature that's created with the OpenLayers.Control.DrawFeature control. The feature belongs to a WFS layer and is saved via its Save strategy. It seems the FeatureStore is unaware of the change in the feature's state when the layer is saved.
Am I seeing this issue because the FeatureStore expects the layer to be saved via the store's save() method only?
Cheers
Adam
On 21/05/2010, at 7:53 PM, Eric Lemoine wrote:
> On Thursday, May 20, 2010, Adam Ratcliffe <adam at prema.co.nz> wrote:
>> I have a FeatureStore instance associated with a map vector layer, the vector layer has a DrawFeature control associated with it.
>>
>> When a new feature is created the FeatureStore.onFeaturesAdded() method is called to create a new record in the store for the feature. The record is created but it does not receive the Open Layers feature ID because it's in an INSERT state, as per this code in the FeatureReader class:
>>
>> // newly inserted features need to be made into phantom records
>> var id = (feature.state === OpenLayers.State.INSERT) ? undefined : feature.id;
>> records[records.length] = new recordType(values, id);
>>
>> If I save the vector layer the feature is updated to no longer be in an INSERT state.
>
> Is the feature updated or is a new feature created?
>
>> When I try to retrieve the record for the feature from the store using the FeatureStore.getRecordFromFeature() method it fails due to this logic in FeatureStore.getRecordFromFeature():
>>
>> if(feature.state !== OpenLayers.State.INSERT) {
>> record = this.getById(feature.id);
>> } else {
>> var index = this.findBy(function(r) {
>> return r.get("feature") === feature;
>> });
>> if(index > -1) {
>> record = this.getAt(index);
>> }
>> }
>>
>> The record is no longer in an INSERT state so it will try to find the record by feature ID but the record only exists as a phantom (ID less) record in the store.
>>
>> Is this a bug or do I need to explicitly update the record in the store after the feature is saved?
>
> In my opunion you'd be better off destroying the feature marked
> "INSERT" and creating and adding a new feature (with an id).
>
> Cheers,
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com
More information about the Users
mailing list