Solved! Go to Solution.
var time = new Date().getTime().toString(); //javascript object with params for the save itself // and arrays for the various geometry types var saveObj = { name: name, description: description, time: time, userId: userId, department, department, project: project, polygons: [], polylines: [], points: [], markers: [], text: [] }; //create json of each polygon object and push it to the polygon array dojo.forEach(app.map.getLayer('gl_anno_polygon').graphics, function (g) { var obj = g.toJson(); saveObj.polygons.push(obj) }); //do the same polylines, points, etc //convert js object to json var save = dojo.toJson(saveObj); //use ajax and some form of RDBMS to save json object //parameters like name, userId, etc are also saved in separate fields in the database entry
{ "geometry": { "rings": [[[-13715131.833534349, 5759372.32022381], [-13714845.194678271, 5759200.336910164], [-13715299.039533727, 5758751.269368976], [-13715514.018675784, 5759042.685539322], [-13715131.833534349, 5759372.32022381]]], "spatialReference": { "wkid": 102100 } }, "attributes": { "id": "1375306164892" }, "symbol": { "color": [0, 115, 197, 51], "outline": { "color": [0, 115, 197, 255], "width": 1.5, "type": "esriSLS", "style": "esriSLSSolid" }, "type": "esriSFS", "style": "esriSFSSolid" }, "infoTemplate": { "title": "Polygon", "content": "<div style=\"line-height:1.5;\"><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.editStyle(${id}, 'polygon')\">Edit Polygon Style</a><br /><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.bringTop(${id}, 'polygon')\">Bring to Top</a><br /><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.sendBottom(${id}, 'polygon')\">Send to Bottom</a><br /><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.deleteGraphic(${id}, 'polygon')\">Delete</a></div>" } }
dojo.forEach(loadObj.polygons, function (polygon) { //the polygon param is the json for a single polygon // simply creating a graphic with the json recreates it attributes, symbol and info template var graphic = new esri.Graphic(polygon); //array of all loaded graphics for zooming features.push(graphic); //graphic id to identify polygon to edit, delete, etc graphic.graphic_id = polygon.attributes.id; //set custom objects of the graphic used by custom print task graphic.graphic_atts = polygon.attributes; graphic.graphic_it = polygon.infoTemplate; //is the graphic a text symbol also for printing graphic.graphic_text = false; //add to the annotation polygon layer app.map.getLayer('gl_anno_polygon').add(graphic) });
var time = new Date().getTime().toString(); //javascript object with params for the save itself // and arrays for the various geometry types var saveObj = { name: name, description: description, time: time, userId: userId, department, department, project: project, polygons: [], polylines: [], points: [], markers: [], text: [] }; //create json of each polygon object and push it to the polygon array dojo.forEach(app.map.getLayer('gl_anno_polygon').graphics, function (g) { var obj = g.toJson(); saveObj.polygons.push(obj) }); //do the same polylines, points, etc //convert js object to json var save = dojo.toJson(saveObj); //use ajax and some form of RDBMS to save json object //parameters like name, userId, etc are also saved in separate fields in the database entry
{ "geometry": { "rings": [[[-13715131.833534349, 5759372.32022381], [-13714845.194678271, 5759200.336910164], [-13715299.039533727, 5758751.269368976], [-13715514.018675784, 5759042.685539322], [-13715131.833534349, 5759372.32022381]]], "spatialReference": { "wkid": 102100 } }, "attributes": { "id": "1375306164892" }, "symbol": { "color": [0, 115, 197, 51], "outline": { "color": [0, 115, 197, 255], "width": 1.5, "type": "esriSLS", "style": "esriSLSSolid" }, "type": "esriSFS", "style": "esriSFSSolid" }, "infoTemplate": { "title": "Polygon", "content": "<div style=\"line-height:1.5;\"><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.editStyle(${id}, 'polygon')\">Edit Polygon Style</a><br /><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.bringTop(${id}, 'polygon')\">Bring to Top</a><br /><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.sendBottom(${id}, 'polygon')\">Send to Bottom</a><br /><a style=\"cursor:pointer;text-decoration:none;\" onclick=\"app.anno.deleteGraphic(${id}, 'polygon')\">Delete</a></div>" } }
dojo.forEach(loadObj.polygons, function (polygon) { //the polygon param is the json for a single polygon // simply creating a graphic with the json recreates it attributes, symbol and info template var graphic = new esri.Graphic(polygon); //array of all loaded graphics for zooming features.push(graphic); //graphic id to identify polygon to edit, delete, etc graphic.graphic_id = polygon.attributes.id; //set custom objects of the graphic used by custom print task graphic.graphic_atts = polygon.attributes; graphic.graphic_it = polygon.infoTemplate; //is the graphic a text symbol also for printing graphic.graphic_text = false; //add to the annotation polygon layer app.map.getLayer('gl_anno_polygon').add(graphic) });
Do I have to setup a custom arcgis server in production to be able to render map and save data?
Do I have to use geodatabase to store the information?
HI Ben,
I know its a old post but i need to do the same. I need to save the drawing (consisting of point , polygon, line , text) into database with user info and retrieve the same when the same user log in.
I have just one question to the solution ..can we use feature service to store the drawings. If your ans is yes can you please provide some input for the same.
Thanks