ThinkGeo.com    |     Documentation    |     Premium Support

SQL SPatial Connection

 Please help me adding SQL Spatial Layer to Map1 in my silverlight applicatin 


DB details:


UNAME: wael     PW: password   DB Name:Incidents   Table Name: SQLSpatial     


 


I would be thankfull if some guide me to right way


 


Regards


Wael



This is my XAM Code 
  
  
 using System; 
 using System.Collections.Generic; 
 using System.Linq; 
 using System.Net
 using System.Windows; 
 using System.Windows.Controls; 
 using System.Windows.Documents; 
 using System.Windows.Input; 
 using System.Windows.Media; 
 using System.Windows.Media.Animation; 
 using System.Windows.Shapes; 
 using ThinkGeo.MapSuite.SilverlightEdition; 
 using ThinkGeo.MapSuite.SilverlightCore; 
  
 namespace Samples6683 
 { 
     public partial class MainPage : UserControl 
     { 
         public MainPage() 
         { 
             InitializeComponent(); 
         } 
  
         private void LayoutRoot_Loaded(object sender, RoutedEventArgs e) 
         { 
             Map1.MapUnit = GeographyUnit.Meter; 
             Map1.Background = new SolidColorBrush(Color.FromArgb(255, 156, 187, 216)); 
             Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962); 
  
             ServerLayerOverlay serverLayerOverlay = new ServerLayerOverlay("NativeServerWithGoogleRoadMap", "SilverlightMapConnector1"); 
             Map1.Overlays.Add(serverLayerOverlay); 
  
             //ServerLayerOverlay serverLayerOverlay1 = new ServerLayerOverlay("NativeServerWithVirtualEarthMap", "SilverlightMapConnector1"); 
             //Map1.Overlays.Add(serverLayerOverlay1); 
  
             ServerLayerOverlay serverLayerOverlay2 = new ServerLayerOverlay("NativeServerWithMsSql", "SilverlightMapConnector1"); 
             Map1.Overlays.Add(serverLayerOverlay2); 
  
             Map1.Refresh(); 
         } 
     } 
 } 
  
  
  
 This is my ASP net code 
  
 using System; 
 using System.Collections.Generic; 
 using System.Linq; 
 using System.Web; 
 using System.Web.UI; 
 using System.Web.UI.WebControls; 
 using ThinkGeo.MapSuite.Core; 
 using ThinkGeo.MapSuite.SilverlightEdition; 
 using System.Drawing; 
 using System.Globalization; 
  
 namespace Samples6683.Web 
 { 
     public partial class _Default : System.Web.UI.Page 
     { 
         protected void Page_Load(object sender, EventArgs e) 
         { 
             if (!Page.IsPostBack) 
             { 
                 GoogleMapsLayer googleRoadLayer = new GoogleMapsLayer(); 
                 googleRoadLayer.MapType = GoogleMapsMapType.RoadMap; 
                 ServerLayerOverlay layerWithGoogelRoadMapOverlay = new ServerLayerOverlay("NativeServerWithGoogleRoadMap"); 
                 layerWithGoogelRoadMapOverlay.Layers.Add(googleRoadLayer); 
                 SilverlightMapConnector1.ServerLayerOverlays.Add(layerWithGoogelRoadMapOverlay); 
  
                 //// Please set your own information about those parameters below. 
                 //string accountId = "wael"; 
                 //string password = "v2500"; 
                 //string clientIpAddress = "localhost"; 
                 //string cacheDirectory = @"c:\temp"; 
                 //VirtualEarthLayer worldLayer = new VirtualEarthLayer(accountId, password, clientIpAddress, cacheDirectory); 
                 //ServerLayerOverlay layerWithVirtualEarthOverlay = new ServerLayerOverlay("NativeServerWithVirtualEarthMap"); 
                 //SilverlightMapConnector1.ServerLayerOverlays.Add(layerWithVirtualEarthOverlay); 
  
                 // Please set your own information about those parameters below. 
                 string connectString = "Data Source=10.42.128.158,1041;Initial Catalog=Incidents;Persist Security Info=True;User ID=wael;Password=v2500"; 
                 MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "SqlSpatial", "gid"); 
                 sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; 
                 sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
                 ServerLayerOverlay layerWithMsSql2008FeatureOverlay = new ServerLayerOverlay("NativeServerWithMsSql"); 
                 layerWithMsSql2008FeatureOverlay.Layers.Add(sql2008Layer); 
                 SilverlightMapConnector1.ServerLayerOverlays.Add(layerWithMsSql2008FeatureOverlay); 
  
             } 
         } 
     } 
 } 
  
  
 neither the google maps nor the sql spatial can be seen on the map. also note that my area of interest are in the middle east  
  & I dont know how to adjust the focus extent of the map to get my area of interest (I can not predict the numbers) 
  
  
 thank you

Dear wael, 



Thank you for your sample code, I have checked it and tried, I think the code didn't have problems, and I can show the GoogleMap(sorry I can't test your sql), maybe the problem is in the project, so I remake a sample using your code and reference right dlls, please download it have an other try. 



Also I have changed the extent to the Middle East. I hope it can help you. 



Regards, 



Gary



SamplesUsingGoogle&Sql.zip (15.9 KB)