Get symbol for a FeatureTemplate

697
2
Jump to solution
05-03-2018 04:10 PM
MarkCollins
Occasional Contributor

Hello,

I was wondering if there is a way to get the symbol for a FeatureTemplate?  I'm trying to build a grid of feature templates for the user to choose from when editing a map layer.

In the old WPF API it used to work this way...

featuretemplate.GetSymbol(layer.Renderer)

I haven't been able to find anything that appears to be equivalent in the docs or object model. 

Thanks,

Mark

0 Kudos
1 Solution

Accepted Solutions
RichZwaap
Occasional Contributor III

You can use the Renderer.GetSymbol method for this. That requires a GeoElement, which you can create from the feature template's PrototypeAttributes.  So the code would be something like:

// We need a layer to access the renderer
var featureLayer = new FeatureLayer(
  new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/CommercialDamageAssessment/FeatureServer..."));
// The layer needs to be loaded to make its metadata accessible
await featureLayer.LoadAsync();
// With this particular service, the feature templates are enclosed in feature types,
// so get the feature type first.  Some services have the feature templates available
// directly off of the layer info.
var featureType =
  ((ServiceFeatureTable)featureLayer.FeatureTable).LayerInfo.FeatureTypes.First();
// Get the feature template
var featureTemplate = featureType.Templates.First();
// Create a graphic with the feature template's attributes
var prototypeGraphic = new Graphic(featureTemplate.PrototypeAttributes);
// Use the graphic to get the symbol from the renderer
var featureTemplateSymbol = featureLayer.Renderer.GetSymbol(prototypeGraphic);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope this helps.

View solution in original post

0 Kudos
2 Replies
RichZwaap
Occasional Contributor III

You can use the Renderer.GetSymbol method for this. That requires a GeoElement, which you can create from the feature template's PrototypeAttributes.  So the code would be something like:

// We need a layer to access the renderer
var featureLayer = new FeatureLayer(
  new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/CommercialDamageAssessment/FeatureServer..."));
// The layer needs to be loaded to make its metadata accessible
await featureLayer.LoadAsync();
// With this particular service, the feature templates are enclosed in feature types,
// so get the feature type first.  Some services have the feature templates available
// directly off of the layer info.
var featureType =
  ((ServiceFeatureTable)featureLayer.FeatureTable).LayerInfo.FeatureTypes.First();
// Get the feature template
var featureTemplate = featureType.Templates.First();
// Create a graphic with the feature template's attributes
var prototypeGraphic = new Graphic(featureTemplate.PrototypeAttributes);
// Use the graphic to get the symbol from the renderer
var featureTemplateSymbol = featureLayer.Renderer.GetSymbol(prototypeGraphic);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope this helps.

0 Kudos
MarkCollins
Occasional Contributor

Rich,

This was exactly what I was looking for and it works great. Thanks for the help!

-Mark

0 Kudos