[OpenLayers-Users] Vector feature attribute name

Alexandre Dube adube at mapgears.com
Mon Oct 27 10:00:24 EDT 2008


Hi list,

  I have a little problem with attribute names for vector features.  In 
my application, I have 2 data sources ( shapefiles and postGIS ) that 
share the exact same kind of data.  The only difference is the attribute 
names, which are respectively in uppercase and lowercase ( ex. : 
RES_CO_REG, res_co_reg )

  My application must interact in both ways they are written ( or 
preferably, ANY way they are written), so before using an attribute 
name, I use this little function I've written :

OpenLayers.Feature.Vector.prototype.getAttributeName = function (szName) {
    szName = szName.toUpperCase();
    var szAttribute, key;
  for ( key in this.attributes ) {
      szAttribute = key.toUpperCase();
      if (szAttribute == szName)
          return key;
  }
  return false;
}

This works on feature objects.  I didn't find a way to do it otherwise.  
Like when using the addUniqueValueRules function, I have to do the 
following :
oRegStyleMap.addUniqueValueRules("default", "RES_CO_REG", aRegColor);
oRegStyleMap.addUniqueValueRules("default", "res_co_reg", aRegColor);

  To me, it seems like my solution is a big waste of time ( having to 
loop into each attribute name every time )...  Is there a better way to 
do it ?

-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list