[Users] Problem with FeatureStore.getRecordFromFeature()

Adam Ratcliffe adam at prema.co.nz
Thu May 20 08:38:47 CEST 2010


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.  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?

Cheers
Adam


More information about the Users mailing list