[Users] Problem with FeatureStore.getRecordFromFeature()
Eric Lemoine
eric.lemoine at camptocamp.com
Fri May 21 09:53:35 CEST 2010
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