JS API - Select map features and add to array

2319
1
09-15-2015 09:06 AM
JoeN
by
New Contributor

I've been asked to add a map to an existing ASP.NET data collection form. ArcGIS API for JavaScript seems like the best way to do this, but I've always struggled a bit with JavaScript. Any suggestions appreciated.

 

Users want to select multiple polygons from the map. They would like to make selections with individual mouse clicks, not by drawing/dragging selection box around polygons. Values from the data collection form (including selected polygon names) are saved to SQL Server tables when users click ASP.NET "Save" button.

 

So, basically, I'm looking for help with adding/removing polygon values to/from a Javascript array(?) with each mouse click on the map. Then, at ASP.NET button click event, JS array needs to be converted to C# values and from there insert into the DB.

 

Thanks,

Tags (1)
0 Kudos
1 Reply
TyroneBiggums
Occasional Contributor III

In your event, you can just create a JavaScript array and push (look at jQuery push to an array) to it. To remove look into jQuery grep. You can also go a step further and create a custom JavaScript object, create an new instance of that object and populate properties in that object. This way, you'd have an array of custom objects.

To convert your array from JavaScript to C#, look into JavaScriptSerializer. If you ever want to go back from C# to JavaScript, use JSON.parse in JavaScript.

FYI, the data you want to add to your array is Esri, but the concept is not (it sounds that way, at least). You might find a lot more specific info on JavaScript arrays and objects on stackoverflow. Then refer back here for the data you want to add to your array.

0 Kudos