AnsweredAssumed Answered

How to clone a graphic to a new Graphics layer

Question asked by yogip933 on Apr 21, 2016
Latest reply on Apr 21, 2016 by yogip933

Hi, I'm a bit new to Javascript and the JSAPI, and am running into an issue.

I have an app with two maps. In the app, the user populates the first map by submitting a findTask. The results (points) are added to a Graphics layer. The user then is able to click on points they want to select for further analysis, and those points are copied to the second map.

 

The problem I'm having is when I copy the graphics to a new Graphics layer for the second map, they disappear from the first map. I'm seeing in Flex that there is a "graphic.Geometry.Clone()" function that allows one to clone points. Is there an equivalent in JSAPI? Or is there any other way I can copy (not cut) points from one map to the other?

 

array.map(firstLayer.graphics, function (graphic) {
  if (graphic.attributes["selected"] == true) {
    secondLayer.add(graphic);
    graphic.setSymbol(Selected_Marker);
  }
});

Outcomes