Hi everyone!
I've got a code: JS Bin - Collaborative JavaScript Debugging, I can mark something, but how can I save my work so I could use it later? I would be great to have it in JSON format. Could someone help me?
Solved! Go to Solution.
Yeah! I did it!
If someone would to copy this is all the code: JS Bin - Collaborative JavaScript Debugging
Azariasz,
You can use the toJSON and fromJSON method of the Graphics class. https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html#toJSON
Thank you for comment, I saw this method, but I still don't know how to get geometries?
In 3.21 version I used this code:
function addGraphic(evt) {
//deactivate the toolbar and clear existing graphics
tb.deactivate();
map.enableMapNavigation();
// figure out which symbol to use
var symbol = fillSymbol;
map.graphics.add(new Graphic(evt.geometry, symbol));
var obj=evt.geometry.rings;
var poly_cords="";
for ( var path = 0; path <obj.length; path ++ ) {
//For each point in the path...
for ( var pt = 0; pt < obj[path].length; pt++ ) {
poly_cords+=obj[path][pt][0].toFixed(1)+', ';
poly_cords+=obj[path][pt][1].toFixed(1)+' \n';
}
poly_cords+='---\n';
}
document.getElementById('cords').value += poly_cords;
}
Now I even try:
sketch.on("draw-end", addGraphic);
function addGraphic(evt) {
console.log("WORKS!");
}
but still nothing 😞 How can I get it?
sketch.on('create', function(evt){
if(evt.state === 'complete'){
console.log(evt.graphic);
}
});
It helps a lot! I also played with
sketch.on("update", function(event){
...
}
but I realised that I really don't need to know about every single change. I only want to save done work. It should be like this:
How to do that? Is it possible?
Same thing check the event state for "complete"
sketch.on("update", function(event){
if(event.state === 'complete'){
//do something
}
}
Yeah! I did it!
If someone would to copy this is all the code: JS Bin - Collaborative JavaScript Debugging