Manually drew graphic on stream layer is not removed once graphic with same fieldTrackID is plotted on the same stream layer

950
3
11-03-2016 12:08 AM
Joo_PinTan
New Contributor III
////// SAMPLE JavaScript//////

//Init stream layer
var streamLayer = new StreamLayer(streamLayerUrl, streamLayerOptions);

//Manually add graphic object into stream layer during init
streamLayer.add(
  new Graphic(
    new Point(xLoc, yLoc, map.spatialReference),
    new SimpleMarkerSymbol(),
    {
      ID: "1" //trackIdField
    }
  )
);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

For example I got sample code as above which will manually plot a point on to stream layer during page on load.

After stream layer is starting to publish points to the layer, how to remove the point that manually drew which with same "trackIdField" value and replace by the point pushed out by stream layer itself?

Currently my result is the manually plotted point is not removed and the point plotted by stream layer will stacked on top of the manually plotted point (assume the x and y for the point is the same for both manually and stream layer plotted point).

Anyone have similar experience that can advise?

p/s: streamLayerOptions.maximumTrackPoints is default(1)

Tags (1)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Joo Pin Tan,

  You could attach to the graphic-add event and compare the geometry and if they are the same then delete you manually added point.

//Init stream layer
var streamLayer = new StreamLayer(streamLayerUrl, streamLayerOptions);

//Manually add graphic object into stream layer during init
var manualGra = new Graphic(
  new Point(xLoc, yLoc, map.spatialReference),
  new SimpleMarkerSymbol(),
  {
    ID: "1" //trackIdField
  }
);
streamLayer.add(manualGra);

streamLayer.on("graphic-add", lang.hitch(this, function(gra){
  if(gra.attributes.ID === manualGra.attributes.ID && gra.geometry == manualGra.geometry){
    streamLayer.remove(manualGra);
  }
}));
Joo_PinTan
New Contributor III

Yes. This is my alternate solution too. Manually remove the point during "graphic-add" event.

Just curious that will ArcGis remove the point automatically in stream layer even for the point that manually created provided that "trackId" is defined.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Joo Pin Tan,

   I don't think that there is suppose to be any code in the API to handle removing a manually placed graphic just because it has the same trackid.

Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.

0 Kudos