Select to view content in your preferred language

FeatureLayer : Without ObjectId Field?

8532
29
04-02-2012 05:22 AM
__Rich_
Deactivated User
Hi,

I've got a layer within an AGS service that returns a load of point features based on dynamically changing data held in a non-spatial database via an ODBC connection, I'd like to connect a FeatureLayer to the service but it only renders a single feature in the map.

I can see from some investigations that the ESRI JavaScript relies (very heavily) on there being one field in the data that can be used as the 'ObjectIdField' to uniquely identify rows, there isn't an appropriate field in my data and I don't really want to arbitrarily generate something for these data.

Anyone found a way around this restriction?

Thanks.
0 Kudos
29 Replies
__Rich_
Deactivated User
What's the reasoning behind not wanting to add an object id field client side?


Hi Derek,

Where would I add it?

Would I need to intercept the query response and append the list of fields etc?

Thanks,

Rich
0 Kudos
derekswingley1
Deactivated User
Derek, do you have any samples on how to do this?


Sorry, no samples to show manually populating an object ID.

Rather than populating a unique ID yourself, an alternative is to use applyEdits to push your data into the feature layer. This is what the feature layer from feature collection sample does with data returned from flickr that does not have a unique identifier.
0 Kudos
__Rich_
Deactivated User
It's simple to add a unique field to your data client side. You can do it with three lines of code, something like:

dojo.forEach(data, function(d, idx) {
  d.attributes.oid = idx;
});


And in your feature collection, make sure your field named oid (or whatever you choose to name it) has a type of esriFieldTypeOID.


Where would that forEach sit?
0 Kudos
derekswingley1
Deactivated User
The forEach would run after you've retrieved your data but before you create your feature layer.

Since it sounds like you're not using a layer from a map service, I assumed your creating a feature layer from a feature collection. Are you using a feature collection?
0 Kudos
__Rich_
Deactivated User
The forEach would run after you've retrieved your data but before you create your feature layer.

Since it sounds like you're not using a layer from a map service, I assumed your creating a feature layer from a feature collection. Are you using a feature collection?


Nope, the data are from an AGS map service...which is why I'm surprised that this does not 'just work' out of the box.
0 Kudos
derekswingley1
Deactivated User
Nope, the data are from an AGS map service...which is why I'm surprised that this does not 'just work' out of the box.


In that case, it's best to add your unique ID on the server. Does the layer have a primary key? Are you able to make selections against it in ArcMap?
0 Kudos
__Rich_
Deactivated User
In that case, it's best to add your unique ID on the server. Does the layer have a primary key? Are you able to make selections against it in ArcMap?


I can query against the source in ArcMap, specifically I'm doing some DateDiff stuff to limit the results.

The nature of the data means it would be dangerous to choose a key from actual data fields as it would remove records that in reality are not duplicates.
0 Kudos
derekswingley1
Deactivated User
I can query against the source in ArcMap, specifically I'm doing some DateDiff stuff to limit the results.


Hmm, I'm surprised to hear that. Can you talk a bit more about your data source? How is the data added to ArcMap? What's the data store being used for this data?

The nature of the data means it would be dangerous to choose a key from actual data fields as it would remove records that in reality are not duplicates.


In that case, can you have your database auto-populate a unique field? All the main RDBMS's have this capability but you would probably have to create a new table and reload your data.
0 Kudos
__Rich_
Deactivated User
Will post more info tomorrow, bit too much to type on a phone!
0 Kudos
__Rich_
Deactivated User
Hmm, I'm surprised to hear that. Can you talk a bit more about your data source? How is the data added to ArcMap? What's the data store being used for this data?

Me too.

The data source is an XY Event Source, underlying that is a .odc file (created with ArcCatalog) that uses an ODBC DSN which in turn uses the SQL Server Native Client library to connect to a SQL Server instance.

But you don't need all that to reproduce the scenario, you could get to this point using a simple CSV file like:

long,lat,message
1,1,hello world
2,2,hello again world


In that case, can you have your database auto-populate a unique field? All the main RDBMS's have this capability but you would probably have to create a new table and reload your data.


Creating a surrogate key where it's appropriate for the data is acceptable, but in this case it'd be a hack, the (identity) value would have no 'meaning' to the data values etc.

The underlying issue is that although the FeatureLayer JS knows that the data has no OID value (and logs this fact to the console) it continues to try and use it as a key to the data, I can point you towards the method(s) in the class where this causes issues if that helps?

I understand the need for a key to identify data if, for example, I was providing some editing of persistable features, but in this case all I want to do is display the features in the map, just like the ArcGISDynamicServiceLayer would, but because I need some client-side functionality not available with an image-based layer type the FeatureLayer appeared to be the best choice....apart from this (rather severe) issue!
0 Kudos