Hello.
I need to pass graphic's attributes to new graphic which updated by sketchViewModel in "update-complete" event of sketchViewModel. because addGraphic function is adding new graphic on every event and losing attributes.
i think that i need some code as below (red lines)
switch (evt.type) {
case "draw-complete":
graphic.attributes = {
"test": "testdata",
"id": mygraphicslayer.graphics.count()
}
break;
case "update-complete":
graphic.attributes = OLDGRAPHIC'S.ATTRIBUTES;
break;
}
addGraphic function code which i used below.
sketchViewModel.on("draw-complete", addGraphic);
sketchViewModel.on("update-complete", addGraphic);
sketchViewModel.on("update-cancel", addGraphic);
function addGraphic(evt) {
var geometry = evt.geometry;
var symbol;
// Choose a valid symbol based on return geometry
switch (geometry.type) {
case "point":
symbol = pointSymbol;
break;
case "polyline":
symbol = polylineSymbol;
break;
default:
symbol = polygonSymbol;
break;
}
// Create a new graphic; add it to the GraphicsLayer
var graphic = new Graphic({
geometry: geometry,
symbol: symbol
});
switch (evt.type) {
case "draw-complete":
graphic.attributes = {
"test": "testdata"
}
break;
}
tempGraphicsLayer.add(graphic);
console.log(graphic.attributes);
// Remove stored reference to the updated graphic
// Required in 'update-complete' callback specifically
updateGraphic= null;
}