I get the following error when trying to clone a grahic:
Uncaught TypeError: Cannot read property 'path' of null
If I cannot use Dojo lang.clone to copy a graphic, then can someone provide some sample code to do this?
I need to make a copy of a graphic, change it's name attribute, and add it to a FeatureLayer.
Thanks!
I get the error with this code:
var g = this.polylineGraphics.graphics[0];
var clone = lang.clone(g);
...
where as polylineGraphics:
| this.polylineGraphics = new FeatureLayer({ | |
| layerDefinition: { | |
| geometryType: 'esriGeometrypolyline', | |
| fields: [{ | |
| name: 'OBJECTID', | |
| type: 'esriFieldTypeOID', | |
| alias: 'OBJECTID', | |
| domain: null, | |
| editable: false, | |
| nullable: false | |
| }, { | |
| name: 'name', | |
| type: 'esriFieldTypeString', | |
| alias: 'name', | |
| domain: null, | |
| editable: true, | |
| nullable: false | |
| }] | |
| }, | |
| featureSet: null | |
| }, { | |
| id: 'polylineGraphics', | |
| title: 'polylineGraphics', | |
| mode: FeatureLayer.MODE_SNAPSHOT | |
| }); |
I wonder if this will work:
var clonedGraphic = new Graphic(sourceGraphic.toJson()):
This worked for me. Thanks.