简体   繁体   中英

OpenLayers overrides features id

I have a problem with OpenLayers + GeoExt2: I created a FeatureStore which features (downloaded via an API) contain an id attribute. When I try to represent the features in a grid panel, all the other attributes are properly represented (name, description, etc.) but the id is somehow overridden by the OpenLayers object's id, for instance "OpenLayers_Feature_Vector_363", instead of the "original" int id.

My store is defined as follows:

areaStore = Ext.create('GeoExt.data.FeatureStore', {
    layer: areaLayer,
        fields: [
            {type:'string', name: 'note'},
            {type:'int',    name: 'node' },
            {type:'string', name: 'description'},
            {type:'bool',   name: 'enabled'},
            {type:'int',    name: 'id'}
        ],
    autoLoad: false,
});

The columns that I put into my grid panel are defined as follows:

var areaColumns = [
    { dataIndex: 'id', header: 'ID', flex:1 },
    { dataIndex: 'description', flex: 1, header: 'Description' },
    { dataIndex: 'node', flex: 1, header: 'Node' },
    { dataIndex: 'enabled', flex: 1, header: 'Enabled'},
    { dataIndex: 'note', flex: 1, header: 'Note' }
]

Has anyone got the same problem when downloading features from a database via API? Thank you!

Have you tried using

{type:'int',    name: 'recordId',      mapping:'id'}

and

{ dataIndex: 'recordId', header: 'ID', flex:1 },

to check whether the id is read correctly from the data?

Have you played around with idProperty config option of the store, ie set it to someNonExistentIdProp ?

@Alexander: thank you for your answer, I tried right now with no luck, it actually seems like the id is undefined. That's odd, because all the other fields are read correctly and I'm sure the type of that field is integer.

[EDIT] Since I didn't get to find out why OpenLayers overwrites the properties' id and it happened before I could make any mapping to the original id attribute, I tried and managed to edit my GeoJSON format in order to add a recordId attribute to the features' properties and set it equal to the original id. In other words I edited the downloaded JSON before it was parsed and added as a OpenLayers feature vector, I added the recordId attribute, then used this one instead of 'id'.

I hope my solution will help someone who is having the same problem!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM