I have a SQL database with spatial coordinates that I want to display in a Map View hosted in a web application. I have the Map View already rendered but I need some direction on where to start with getting the data displayed on the map.
The easiest way to do this without a lot of custom code on your front end (which will have to change everytime there's a backend change)...would be to add a trigger to pull the coordinates out of the geography (or geometry) object. This gives you a permanently populated and updated XY field.
<SPAN class="keyword token">CREATE</SPAN> <SPAN class="keyword token">TRIGGER</SPAN> <SPAN class="punctuation token">[</SPAN>dbo<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>tigger<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">ON</SPAN> <SPAN class="punctuation token">[</SPAN>dbo<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">[</SPAN>feature class<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">after</SPAN> <SPAN class="keyword token">INSERT</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="keyword token">UPDATE</SPAN> <SPAN class="operator token">NOT</SPAN> <SPAN class="keyword token">FOR</SPAN> <SPAN class="keyword token">REPLICATION</SPAN> <SPAN class="keyword token">AS</SPAN> <SPAN class="keyword token">BEGIN</SPAN> <SPAN class="keyword token">SET</SPAN> NOCOUNT <SPAN class="keyword token">ON</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">UPDATE</SPAN> p <SPAN class="keyword token">SET</SPAN> SHAPE <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">CASE</SPAN> <SPAN class="keyword token">WHEN</SPAN> i<SPAN class="punctuation token">.</SPAN>SHAPE <SPAN class="operator token">IS</SPAN> <SPAN class="operator token">NOT</SPAN> <SPAN class="token boolean">NULL</SPAN> <SPAN class="keyword token">THEN</SPAN> p<SPAN class="punctuation token">.</SPAN>SHAPE <SPAN class="keyword token">ELSE</SPAN> Geography::STPointFromText<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'POINT('</SPAN> <SPAN class="operator token">+</SPAN> CAST<SPAN class="punctuation token">(</SPAN>p<SPAN class="punctuation token">.</SPAN>LON <SPAN class="keyword token">AS</SPAN> <SPAN class="keyword token">VARCHAR</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">20</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">' '</SPAN> <SPAN class="operator token">+</SPAN> CAST<SPAN class="punctuation token">(</SPAN>p<SPAN class="punctuation token">.</SPAN>LAT <SPAN class="keyword token">AS</SPAN> <SPAN class="keyword token">VARCHAR</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">20</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">')'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">4269</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">END</SPAN><SPAN class="punctuation token">,</SPAN> LON <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">CASE</SPAN> <SPAN class="keyword token">WHEN</SPAN> p<SPAN class="punctuation token">.</SPAN>SHAPE <SPAN class="operator token">IS</SPAN> <SPAN class="token boolean">NULL</SPAN> <SPAN class="keyword token">THEN</SPAN> p<SPAN class="punctuation token">.</SPAN>LON <SPAN class="keyword token">ELSE</SPAN> p<SPAN class="punctuation token">.</SPAN>SHAPE<SPAN class="punctuation token">.</SPAN>Long <SPAN class="keyword token">END</SPAN><SPAN class="punctuation token">,</SPAN> LAT <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">CASE</SPAN> <SPAN class="keyword token">WHEN</SPAN> p<SPAN class="punctuation token">.</SPAN>SHAPE <SPAN class="operator token">IS</SPAN> <SPAN class="token boolean">NULL</SPAN> <SPAN class="keyword token">THEN</SPAN> p<SPAN class="punctuation token">.</SPAN>LAT <SPAN class="keyword token">ELSE</SPAN> p<SPAN class="punctuation token">.</SPAN>SHAPE<SPAN class="punctuation token">.</SPAN>Lat <SPAN class="keyword token">END</SPAN> <SPAN class="keyword token">FROM</SPAN> feature class <SPAN class="keyword token">AS</SPAN> p <SPAN class="keyword token">INNER</SPAN> <SPAN class="keyword token">JOIN</SPAN> inserted <SPAN class="keyword token">AS</SPAN> i <SPAN class="keyword token">ON</SPAN> i<SPAN class="punctuation token">.</SPAN>globalid <SPAN class="operator token">=</SPAN> p<SPAN class="punctuation token">.</SPAN>globalid <SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">END</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
OK, That is the easy part.
you create point using the Point class and the coordinate you returned from SQL database.
https://developers.arcgis.com/javascript/3/jsapi/point-amd.html#constructors
And a simple marker symbol
https://developers.arcgis.com/javascript/3/jsapi/simplemarkersymbol-amd.html#constructors
Then create a graphic from the above two
https://developers.arcgis.com/javascript/3/jsapi/graphic-amd.html#constructors
and add that to the maps graphics layer
https://developers.arcgis.com/javascript/3/jsapi/map-amd.html#graphics
Refer to this sample for more specific code:
https://developers.arcgis.com/javascript/3/jssamples/graphics_create_circles.html
Hi Robert,
Thank you for the feedback. I am able to return the data with ease but I'm unfamiliar with how to get the actual points on the map using the javascript.
Mathew,
You will need a web service to query and return the data in Json format. If you have some .Net development skills then a simple Google for Creating a RESTfull web service in .Net will do.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.