AnsweredAssumed Answered

Strange behaviour when updating a Graphic

Question asked by matt.thery on Oct 18, 2018
Latest reply on Oct 18, 2018 by odoe

Hello,

 

I am trying to add a graphic on the map and update its angle/position based on a property received from an API (google streetview).

 

I am creating a GraphicsLayer that I add to the map, I then add a Graphic with the initial position/angle returned by the API. That's working fine.

 

I then wanted to update the graphic's position for when the user moves in the streetview window. As it's not possible yet to update a graphic (api 4.9) , I remove the graphic from the layer, change its geometry and add it back. Working fine too.

Now I want to modify the angle of the graphic, I am using the same process, it's successfully changing the angle of the newly added graphic, and removing the old one from the layer, but they all seem to stay "floating "on the map somehow.

Below is the code: (I also tried to create a brand new Graphic instead of cloning, same behaviour)

function setAngle(graphic, newHeading){
   graphicsLayerMap.remove(graphic); // tried removeAll()
   currentPointer = graphic.clone();
   currentPointer.symbol.angle = newHeading
   graphicsLayerMap.add(currentPointer);
}
panorama.addListener('pov_changed', function() {
   if(currentPointer != null){
      const newHeading = panorama.getPov().heading;
      setAngle(currentPointer, newHeading)
   }
});

 

And the result (in blue the rogue graphics, and in red the correct one within the layer):

 

If anyone can help me make sense of that.

Outcomes