I have only recently discovered ServiceFeatureTable. I had previously been using a ghastly process of http request, and then parsing the json to get features. It was all too hard, but it worked.
ServiceFeatureTable has been a revelation, and I'm converting all my ghastly code to use ServiceFeatureTable. I've got most of the functionality converted, but one area has me baffled. I have a feature which is (say) type 1. How do I get the symbol for type 1? I used to knife and fork my way though a json response, but surely there's a simple primitive to get this? I've seen ShowSymbol, but I can't see how to apply it. What I really need is a way to get all the symbols, by type, from the ServiceFeatureTable.
As to using the symbol in KML - I currently convert the symbol imageData to Base64, save it to a local file, and put a reference to this file in the KML. Is there a better way?
https://services.ga.gov.au/gis/rest/services/NM_Transport_Infrastructure/MapServer/4
Solved! Go to Solution.
First cast the renderer as UniqueValueRenderer and then get uniquevalues
```
var uvr= layer.Renderer as UniqueValueRenderer;
var uv_values= uvr.UniqueValues;
```
I have a WPF app and in a ViewModel I get the image like this:
private async Task GenerateImage()
{
var legendInfos = (await _layer.GetLegendInfosAsync()).ToList();
if (legendInfos.Count > 0)
{
// This is dummed down to 1st
var symbol = await legendInfos.First().Symbol.CreateSwatchAsync();
var stream = await symbol.GetEncodedBufferAsync();
// LayerImageSource is a property of my VM where a View's image binds its source
LayerImageSource = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
}
}
_layer is a Layer which you can get from the ServiceFeatureTable:
var layer = new FeatureLayer(table)
Very nearly there. The result of the GetLegendInfosAsync is a collection of 10 legendinfo. The Name property of this maps to "Label" when you look at the capabilities of the resource. Unfortunately, Label is not unique. I need both the Value and Label fields. The Value field is what I see in the retrieved feature. The Label field denotes which symbol to use. I've listed the 10 symbols this server provides below. Any ideas?
UniqueValueInfos:
Apparently, what I need to do is access layer.Renderer.UniqueValues and it has all I need. With the object inspector at runtime, I can see all the values I need. However, when I put layer.Renderer.UniqueValues in my code, the IDE says "Error BC30456 'uniquevalues' is not a member of 'Renderer'."
It looks to me I have a bug in the esri libraries 😞
First cast the renderer as UniqueValueRenderer and then get uniquevalues
```
var uvr= layer.Renderer as UniqueValueRenderer;
var uv_values= uvr.UniqueValues;
```
That seems to work, but why is it necessary to use this 'trick'?