Select to view content in your preferred language

How do I Add pushpins and Polygon's from SQL Server?

2620
5
04-19-2011 05:07 AM
BrianCook
Emerging Contributor
Morning all,

How do I add Pushpins to the Graphics layer from an SQL database?

Thanks,
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
Have you looked into this blog post? http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/03/11/Sending-geometry-between-Silverlig...

I think you can use WCF service to get geometries from your SQL Server. Then it would be as simple as creating Graphics, setting their Geometry (Polygon or MapPoint), applying appropriate symbol (Fill or Marker), and adding them to your GraphicsLayer. http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddGraphicsXAML
0 Kudos
BrianCook
Emerging Contributor
Yes, I have a WCF Service, just was not sure how ESRI tag is supposed to look like to pull it from the DB.

With Bing Maps it would look like this;

            <m:Pushpin m:MapLayer.Position="{Binding Location}"  Background="Blue">

So i guess I should have asked; How do I do the above in ESRI?

Thanks,

Have you looked into this blog post? http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/03/11/Sending-geometry-between-Silverlig...

I think you can use WCF service to get geometries from your SQL Server. Then it would be as simple as creating Graphics, setting their Geometry (Polygon or MapPoint), applying appropriate symbol (Fill or Marker), and adding them to your GraphicsLayer. http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddGraphicsXAML
0 Kudos
JenniferNery
Esri Regular Contributor
If you have a pushpin image, you can create a PictureMarkerSymbol. You can download the SDK to get this image. This will be your Graphic.Symbol.
<esri:PictureMarkerSymbol x:Key="PinPictureMarkerSymbol" OffsetX="11" OffsetY="39" Source="/Assets/images/i_pushpin.png" />

Assuming you have already defined a map with GraphicsLayer, a push pin symbol and have retrieved the map coordinates (mp) from SQL Server.

GraphicsLayer l = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
Graphic g = new Graphic()
{
 Geometry = new MapPoint(mp.X, mp.Y, MyMap.SpatialReference),
 Symbol = this.LayoutRoot.Resources["PinPictureMarkerSymbol"] as Symbol
};
l.Graphics.Add(g);
0 Kudos
BrianCook
Emerging Contributor
Hi Jennifer.

Placing the symbol on the XAML I got.
If you have a pushpin image, you can create a PictureMarkerSymbol. You can download the SDK to get this image. This will be your Graphic.Symbol.
<esri:PictureMarkerSymbol x:Key="PinPictureMarkerSymbol" OffsetX="11" OffsetY="39" Source="/Assets/images/i_pushpin.png" />


Assuming you have already defined a map with GraphicsLayer, a push pin symbol and have retrieved the map coordinates (mp) from SQL Server.

GraphicsLayer l = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
Graphic g = new Graphic()
{
 Geometry = new MapPoint(mp.X, mp.Y, MyMap.SpatialReference),
 Symbol = this.LayoutRoot.Resources["PinPictureMarkerSymbol"] as Symbol
};
l.Graphics.Add(g);


How is the code portion reading/getting the positions from my DataService?

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
In the code-snippet, mp is the MapPoint retrieved from your DataService. This defines the location of the push pin.
0 Kudos