Select to view content in your preferred language

GraphicsLayer Refresh and updating graphic attributes

4915
2
02-05-2012 06:05 PM
NickCameron
Deactivated User
Hi All,

Quick run down of my scenario -
I've got a graphics layer that graphics are added to from database calls, business objects are converted into applicable graphic objects and added or updated, they each have a set of attributes as well.
There's a periodic poll to retrieve the latest data and then update the graphics accordingly and display it on the map.
Currently all graphics are updated on every poll and re-added even if their data hasn't changed.

That all works fine, except the fact that on every poll and database refresh every graphic flickers as it is updated/added. What I would like to ideally happen is maintain the graphics that haven't changed, and only add/remove/update the ones that require it - with the goal being that only the changed graphics will flicker.

My problem is I think I have to call GraphicsLayer.Refresh() to ensure that any of the newly added or updated graphics have their attributes picked up. Calling GraphicsLayer.Refresh() forces every graphic to flicker anyway.
That's what I discovered from the limited amount of testing I've done so far anyway and seems to be suggested in this older post as well.
http://forums.esri.com/Thread.asp?c=158&f=2455&t=298650

Basically is there a way to have graphic attributes update without calling GraphicsLayer.Refresh()?

Thanks heaps,
Nick
0 Kudos
2 Replies
wangzhifang
Frequent Contributor
Hi, nick_cam1980,
the fact is that you do not need to call Refresh() method to update graphic's attribute or geometry. Just set/modify them first, the new value will be return when query again the graphic.
The proper idea is to use data binding for your situation. Maintain a graphics collection as the graphicslayer's data source, so when the collection changing, no matter attributes or geometries, the graphicslayer will automatically reflect the changes, no need to call Refresh() method.
0 Kudos
ChristopherHill
Deactivated User
when you poll your graphics, assuming you have a primary key in your Attributes can use Linq query to find new graphics, deleted graphic and updated graphics.

Adding new graphics:
add the new poll graphic if the primary key from the poll graphic is not present if any of the graphics in your graphics layer.

Removing deleted graphics:
Check all existing graphics to make sure the primary key is found in the new poll graphics, if the primary key attribute is not found in the poll graphic remove the graphic from the graphics layer.

Updating graphics
find all graphics ids that are both in graphics layer and in the new poll, then simply replace the attribute values.

you should not need to call GraphicsLayer.Refresh();
0 Kudos