Select to view content in your preferred language

Since 4.33 - Graphic.clone() does not clone the layer - Bug?

239
2
Jump to solution
a week ago
SebastianKrings
Frequent Contributor

We are using Graphic.clone().

const leftGraphic = originalGraphic.clone();

Since the upgrade to 4.33 the layer attribute of the cloned object is null (not undefined) while the layer is set correctly for the original graphic.

Prior to the update the clone also contained a valid layer.
This leads to problems when doing applyEdits on the clones without layer information.

Since it worked before, I assume this is a bug. Can anyone confirm that or show me further info about that? The 4.33 docs only say that clone is doing a deep copy of the graphic. So no hint the layer may is excluded.
Only the fact that the layer is set to null instead of undefined let me imagine this may be intended for some reason.

My workaround is to set the layer manually:

const leftGraphic = originalGraphic.clone();
leftGraphic.layer = originalGraphic.layer;
0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there,

This was a breaking change introduced in version 4.33, as noted in the release notes here:
https://developers.arcgis.com/javascript/latest/release-notes/#core-api-breaking-changes

To summarize:

  • Cloning a Graphic no longer populates the layer property of the cloned graphic. This is because the cloned graphic is not associated with any layer. If you need to clone a graphic and associate it with a specific layer, set the layer property manually after cloning. This affects any workflows that result in cloned graphics, such as search result graphics.


To help address this, we’re introducing a new origin property on Graphic which will be cloned automatically. This can be used to indicate where the graphic originally came from, offering a more appropriate way to track its source. I will update you once this property is 

Let me know if you have any questions or need further clarification.

View solution in original post

0 Kudos
2 Replies
UndralBatsukh
Esri Regular Contributor

Hi there,

This was a breaking change introduced in version 4.33, as noted in the release notes here:
https://developers.arcgis.com/javascript/latest/release-notes/#core-api-breaking-changes

To summarize:

  • Cloning a Graphic no longer populates the layer property of the cloned graphic. This is because the cloned graphic is not associated with any layer. If you need to clone a graphic and associate it with a specific layer, set the layer property manually after cloning. This affects any workflows that result in cloned graphics, such as search result graphics.


To help address this, we’re introducing a new origin property on Graphic which will be cloned automatically. This can be used to indicate where the graphic originally came from, offering a more appropriate way to track its source. I will update you once this property is 

Let me know if you have any questions or need further clarification.

0 Kudos
SebastianKrings
Frequent Contributor

Hey
Thanks for the info.

Though I dont get the reason:
"This is because the cloned graphic is not associated with any layer."

For me that sound like:
"The layer is not included because the layer is not included".

0 Kudos