Updating rendered graphic attributes

3050
14
Jump to solution
09-07-2021 01:29 AM
PeterBell2
New Contributor II

Hello,

We are currently trying to optimise some of our code (which uses version 100.10 of the SDK), and the Graphics in particular. We are currently setting the symbol of each Graphic to a PictureMarkerSymbol, which seems to be quite inefficient as suggested by this forum post: https://community.esri.com/t5/arcgis-runtime-sdk-for-net-questions/adding-a-large-number-of-graphics... We have lots of different symbols in our program, but many Graphics are using the same symbol. Each type of Graphic is added to a different graphics overlay. 

I have been experimenting with using renderers as suggested by the linked post, but feels like I have hit a dead end. Our Graphics represent things like ships currently sailing, and we need to update the position and rotation of each graphic roughly once per second. I have got a DictionaryRenderer working with attribute dictionaries for the Graphics to start with the correct rotation, but my issue is that I don't see a way of then updating the rotation after the Graphics have been added to the overlay. 

Is there a way to get this working? Or is there another approach that would be better for dynamic data visualisation like this?

0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor

You can use SetAttributeValue something like:

myGraphic.SetAttributeValue("ANGLE", boat.angle);

 

View solution in original post

14 Replies
DominiqueBroux
Esri Frequent Contributor

If all graphics of one graphic overlay use the same symbol,  you can use a SimpleRenderer based on your picture marker symbol.
If the symbol is depending on an attribute you can use an UniqueValueRenderer 
Then you can set a rotation expression on the renderer to apply a rotation based on an expression. For example, if the expected rotation is coming from an attribute:
  renderer.RotationExpression = "[rotation]"

0 Kudos
PeterBell2
New Contributor II

Hi Dominique, thanks for the reply. I have set up the rotation expression as described for my DictionaryRenderer, and I then initialise the Graphic like this:

Dictionary<string, object> attributes = new Dictionary<string, object>();
attributes["ANGLE"] = boat.angle;
attributes["Style"] = "BoatImage";
Graphic graphic = new Graphic(boat.Location, attributes);
graphicsOverlay.Graphics.Add(graphic);

This correctly sets the rotation, but I don't see how to change the rotation after this. Modifying the attribute dictionary does not seem to have any effect. Am I misunderstanding how the attributes work?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

You can use SetAttributeValue something like:

myGraphic.SetAttributeValue("ANGLE", boat.angle);

 

PeterBell2
New Contributor II

Aha! Perfect! I assume this means I need to switch from Graphics to Features. I will investigate further, thanks for your help!

JoeHershman
MVP Regular Contributor

A graphic is a GeoElement, so has an Attributes property.  I would think sticking with the graphic in a GraphicsOverlay would render faster.

Thanks,
-Joe
0 Kudos
PeterBell2
New Contributor II

Graphic does have the Attributes property, but as far as I can tell it has no SetAttributeValue method?

0 Kudos
dotMorten_esri
Esri Notable Contributor

> Graphic does have the Attributes property, but as far as I can tell it has no SetAttributeValue method?

You can use:
myGraphic.Attributes["fieldname"] = newValue;

0 Kudos
PeterBell2
New Contributor II

Ah excellent! My mistake - I thought I had tried this but evidently not! 

0 Kudos
PreetiMaske
Esri Contributor

Looking at you code in your initial post, I see you mentioned you are using a DictionaryRenderer. I think you might be mixing up creating a dictionary of attributes to a DictionaryRenderer. 
DictionaryRenderer is a renderer based on arcade script in a stylx file. The stylx file contains symbols and values is published from pro. When this stylx is used to create a dictionary renderer, elements (graphics or features) are rendered sing symbols from this symbol style file based on the attribute value configured in dictionary renderer.
https://developers.arcgis.com/net/styles-and-data-visualization/display-symbols-with-a-dictionary-re...

0 Kudos