I would like to have a user draw a Polygon (or Line) onto a web map with the Javascript ArcGIS API drawing tools. For the life of me I can't figure out how to pull that polygon from the client and get it to my server. It baffles me. Help?
So I am going to assume that you drawing the polygon in a graphics layer. You just need to grab the polygon (graphic) from the graphics layer. Then you can do this:
This will give you the JSON representation of the polygon. Then you can just pass that as a parameter to your web service. You can even call toJson() method of most of the Esri objects to the JSON for that object. I would provide more information, but you do no provide any more code and you do not provide how you are creating the graphics. Is there more that you need to know? More here: https://developers.arcgis.com/en/javascript/jsapi/geometry.html EDIT If you need to grab the graphic you have a couple of options. You can grab it when you are adding the graphic in the addGraphic method found in this sample: https://developers.arcgis.com/en/javascript/jssamples/graphics_add.html which is the sample I am assuming you may be using. The other option and somewhat more elegant in my opinion I would listen to the onGraphicAdd event of the graphics layer to grab it then. https://developers.arcgis.com/en/javascript/jsapi/graphicslayer.html#ongraphicadd So like this:
| |||||||||
|
I know it's annoying to see posts that have no code. So this is my finished code. It is only for polygons, it grabs a user input polygon as a json object. Converts it to a string. Passes the string to a hidden field and uses a button_click to pass the string to code behind where I send it to the ArcSDE geodatabase through SQL Server 2008.
Navigate to your project area, then click the button below to draw on map. Click to draw project boundary
| |||
|