Updating symbol attributes

3100
6
03-11-2016 12:11 PM
ClayHarter
New Contributor II

I am trying to dynamically update the attributes of  symbols of  existing graphics object. I can iterate over my existing graphics objects and update the  symbol attributes but my MapView does not display the updated  objects.  I even tried clearing the graphics layer and adding the updated graphics objects.  Is there any way to force a redraw?  My test code looks like  this:

function highlightTest(){
   var highlightSymbol = new SimpleMarkerSymbol({
   color: [0, 255, 0],
   outline: new SimpleLineSymbol({
   color: [0, 255, 255],
   width: 2
   })
  });
   var existingGraphics= pointLayer.graphics.clone();
   pointLayer.clear();
   existingGraphics.forEach(function(item, i){
  item.symbol=highlightSymbol;
   pointLayer.add(item);
  });
}

I suspect I am missing something....

Tags (1)
0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

Clay,

  Have you looked at the redraw method on the GraphicsLayer?

GraphicsLayer | API Reference | ArcGIS API for JavaScript | redraw

0 Kudos
ClayHarter
New Contributor II

I am using v4.0 beta and there is no such method (I was looking for it!) .  In v4 I believe that when properties change they send change events to registered listeners and I expected (or hoped...) that the change would bubble  up to the GraphicsLayer (or LayerView? ) and it would refresh.

Interestingly I just discovered that if I zoom it forces a re rendering of the graphics and the new symbol attributes are used (but a map resize does not cause this)

Thanks,

Clay

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Clay,

  Sorry I did not see any tags specifying that you were asking about 4.0. The 4.0 Beta 3 is still lacking and this is likely one of those.

0 Kudos
KristianEkenes
Esri Regular Contributor

Clay,

Can you post a link or jsbin to a sample app? It will be faster to look at if I see it in context.

Thanks!

0 Kudos
ClayHarter
New Contributor II

Here is a jsbin link : JS Bin - Collaborative JavaScript Debugging

1) click Add points - this creates a graphics layer with 1000 points and adds it to the map

2) click  Zoom to data - thsi zoosm to a area where teh data is

3) click Highlight - This iterates through all the graphics items and changes their symbol. Note that in the sceneview symbols don't change

4) click 2d/3d - This switches to a mapview . Note that same map with same graphics layer shows new symbols when viewed in mapView

0 Kudos
KristianEkenes
Esri Regular Contributor

Clay,

I think there's a few things going on here. The clone() method wasn't implemented on all classes in beta3, so calling graphic.clone() returns an error. That's one issue. Another (as Robert already alluded to) is the redraw functionality isn't really there in beta3. It will be implemented for 4.0 final though.

0 Kudos