FeatureLayer definitionExpression propertie only works with hosted feature service?

3594
7
Jump to solution
06-07-2016 03:01 AM
Jean-MarcRoy
New Contributor II

Hi all,

I try to set a definition expression on a feature layer that has been constructed with the source propertie. It seems that the definition expression propertie only works with hosted feature service. I tried to set a definition expression on the earthQuake example here : "Create a FeatureLayer with client side graphics | ArcGIS API for JavaScript 4.0 " but have no effects, but it works fine with hosted feature service.

Nothing mentioned this limitation in the documentation.

Can you confirm that or show a way to do that with a feature Layer that is not a hosted feature service?

Thanks in advance for your feedback.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jean-Marc,

  FeatureLayers that are created based on a FeatureCollection do have documented limitations:

new FeatureLayer(featureCollectionObject, options?)

Creates a new instance of a feature layer using a FeatureCollection object. The feature layer, when initialized with a feature collection object has the following behavior:

  • Edits are applied on the client not posted to the server.
  • The feature layer generates a unique object id for new features.
  • Does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.
  • The feature layer toJson method returns an object with the same properties as the feature collection. The returned object includes all the features that are in the layer when the method is called. This method can be used to access a serializable representation of the features that can be saved on the server.

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Emeritus

Jean-Marc,

  FeatureLayers that are created based on a FeatureCollection do have documented limitations:

new FeatureLayer(featureCollectionObject, options?)

Creates a new instance of a feature layer using a FeatureCollection object. The feature layer, when initialized with a feature collection object has the following behavior:

  • Edits are applied on the client not posted to the server.
  • The feature layer generates a unique object id for new features.
  • Does not support queries that need to be performed on the server, e.g. queries with a where clause or non-extent based spatial queries.
  • The feature layer toJson method returns an object with the same properties as the feature collection. The returned object includes all the features that are in the layer when the method is called. This method can be used to access a serializable representation of the features that can be saved on the server.
SteveCole
Frequent Contributor

The flip side is that you could store the "original" featureCollection in a variable. Now loop through that collection, looking for features that match your desired condition. If they match, add them to another feature collection (this, essentially, is your definition expression "collection"). Once the loop is finished, update the featuireLayer's featureCollection with the second set.

If you ever need to reset, you have the original stored in a variable so it's easy to just update that property once again. Performance may be a factor depending on the number of records we're talking about.

Steve

Jean-MarcRoy
New Contributor II

Thanks Steve,

Good idea, I will do something like that!

JoshuaTanner2
New Contributor III

Hey Steve, when you say 'update the featureLayer's featureCollection', do you know if there is a method or property to be able to do this?  I tried  `myfeaturelayer.set('source', newCollection);, but it doesn't update the layer at all.  If I check myfeaturelayer.source.items, it's showing the filtered collection, but the layer isn't updating at all. (I'm using the latest jsapi v4).

0 Kudos
SteveCole
Frequent Contributor

Joshua Tanner​ I haven't jumped onto the 4.x bandwagon yet. In the 3.x environment, I've used featureLayer.applyEdits to make the change:

curFeatures = [];

theLayer.clearSelection();

curFeatures = theLayer.graphics;

theLayer.applyEdits(newFeatures, null, curFeatures, null, null);

0 Kudos
JoshuaTanner2
New Contributor III

Thanks for the quick reply.  It would appear Esri hasn't implemented this in the 4.x API.  For now, creating a new feature layer and removing the old one every time I filter.  It seems to be fast, but I can guarantee it's not efficient.

0 Kudos
JackFairfield
Occasional Contributor II

Can anyone provide a workaround for this? Or is there a timetable for this being implemented?

0 Kudos