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!
How would adding a unique key be a surrogate?
Fulfilling the requirements for specific functionality isn't a hack.
We don't explicitly document that an object ID is required
but it is implied in that the main use case for feature layers is using data from ArcGIS Server.
As you've outlined, it's possible to publish data with AGS that doesn't have an object ID.
We'll update the docs.
A couple more questions: what's the mode for your feature layer? What kind of things are you wanting to do client side?
I would have thought that now it has a unique identifier for each feature calling refresh() on the layer wouldn't cause all features to be removed then redrawn, e.g. I'd have thought that only 'new' features i.e. with an OID not known to the client would be drawn and likewise the only features removed would be ones that are no longer in the JSON returned from AGS. I'm seeing ALL features being removed and then added which isn't very efficient!
That's as designed: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/featurelayer.htm#refresh
What if features have been modified since they were originally retrieved?
Then I'd update those features rather than removing and re-adding them...that's what I would have thought happens based on the above. If ALL the features are going to be removed then re-added regardless then what's the point of the OID in this scenario?
It also does a remove/add when zooming/panning to an existing feature, is that expected?
The crux of the issue is this:- what I really want is to know when a new feature has been added within the current extent and I can't see which of the public events would yield that information, is there a way to do this without having to initiate my own separate query/processing? (also knowing in future which have been removed/updated would be useful!)
If you're using a layer from a map service as a feature layer, only new features are added. If your feature layer points to a feature service, all features are removed then added. Is the source for your feature layer a layer from a map service or a feature service?
Yes, this is expected because features are generalized on a per zoom level basis. See the "Feature Generalization" section of Feature Layer Best Practices.
I should have asked this before...can you expand on this workflow a bit? As you've found out, we don't provide events that fire for the specific addition of new features outside of events related to aplyEdits.
OK, time-series of dynamic point features being inserted ad-hoc by an external process into a database, I'd like to know (on the client-side) that new features (and how many) have been added since the last refresh. The way it's working at present is acceptable but it'd be much better to be able to distinguish between new and existing (temporally) features without providing my own state maintenance. If it can't be done 'out-the-box' then fair enough, I just want to make sure I haven't missed something in the API that I could hook into and/or some settings that would change the behaviour to provide this level of detail.
You're not missing anything, the feature layer doesn't provide the events you're describing. If you don't want to build this out yourself, you might want to look into tracking server: http://www.esri.com/software/arcgis/tracking-server/index.html