Hi,
the Runtime documentation describes five constructor, which could be used to create a FeatureTable. One of them creates a class based on a FeatureTable.
Normally, a FeatureTable is based on a service, such as the ServiceFeatureTable, and is usually stored in a database. But I need a FeatureLayer on the fly based on in memory data.
So I thought in my case the FeatureCollectionTable would be the right way, because it is based on a FeatureTable and so I should be able to create a FeatureLayer from it.
The following code is compileable:
<SPAN class="keyword token">var</SPAN> fields <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>Field<SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Field</SPAN><SPAN class="punctuation token">(</SPAN>FieldType<SPAN class="punctuation token">.</SPAN>Text<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Field1"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Field1"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">50</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> table <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureCollectionTable</SPAN><SPAN class="punctuation token">(</SPAN>fields<SPAN class="punctuation token">,</SPAN> GeometryType<SPAN class="punctuation token">.</SPAN>Point<SPAN class="punctuation token">,</SPAN> SpatialReferences<SPAN class="punctuation token">.</SPAN>WebMercator<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> featureLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureLayer</SPAN><SPAN class="punctuation token">(</SPAN>table<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
MyMapView<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN>OperationalLayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>featureLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>But when executing this code, I got an exception:
System.ArgumentException: 'Invalid argument: Cannot create a feature layer from a feature collection table. Add the feature collection table to a feature collection.'
Now I'm a bit confused: Why can't I do that, a FeatureCollectionTable inherits from the FeatureTable?
Is that a bug? Is this work as designed?
A FeatureCollection doesn't get me where I want to be: Among other things, I want to be able to restrict data by DefinitionExpression, but this is only possible with the FeatureLayer.
Kind regards,
Max