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.
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.
OK, That is the easy part.
you create point using the Point class and the coordinate you returned from SQL database.
And a simple marker symbol
Then create a graphic from the above two
and add that to the maps graphics layer
Refer to this sample for more specific code:
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.
CREATE TRIGGER [dbo].[tigger] ON [dbo].[feature class] after INSERT,UPDATE NOT FOR REPLICATIONAS BEGIN SET NOCOUNT ON; UPDATE p SET SHAPE = CASE WHEN i.SHAPE IS NOT NULL THEN p.SHAPE ELSE Geography::STPointFromText('POINT(' + CAST(p.LON AS VARCHAR(20)) + ' ' + CAST(p.LAT AS VARCHAR(20)) + ')', 4269) END, LON = CASE WHEN p.SHAPE IS NULL THEN p.LON ELSE p.SHAPE.Long END, LAT = CASE WHEN p.SHAPE IS NULL THEN p.LAT ELSE p.SHAPE.Lat END FROM feature class AS pINNER JOIN inserted AS i ON i.globalid = p.globalid;END
Retrieving data ...