Hello !
I would like to clone in a new array (a deep copy without references) the features I have selected from a feature layer with the getSelectedFeatures() method.
I try to use lang.clone from dojo but it doesn't work. I have this error : "TypeError: this._url is null".
I understand it cames from the feature layer. But I don't know how to fix this error or even if it's possible to do what I want to do by this way. I'm quite new with JSAPI.
I already used lang.clone with polygons from serviceAreaSolveResult and it worked very well !
Could someone help me on this problem ?
Thanks in advance.
Clemini.
Solved! Go to Solution.
Cloning Graphic objects may not be a good idea. especially if it is already added to the map. GraphicsLayer to which it has been added will be one of the properties of the graphic object.
The best thing to do is to convert it to json and create a new graphic from that json.
var jsonGraphic = graphic.toJson();
var newGraphic = new Graphic(jsonGraphic);
You could do a for loop on your getSelectedFeatures and then use push to get them into a new array?
Cloning Graphic objects may not be a good idea. especially if it is already added to the map. GraphicsLayer to which it has been added will be one of the properties of the graphic object.
The best thing to do is to convert it to json and create a new graphic from that json.
var jsonGraphic = graphic.toJson();
var newGraphic = new Graphic(jsonGraphic);
Thank you very much !
It works.
I had already seen this method (toJson) but I had badly implemented.
Glad I could help, Please mark the question as answered.