ThinkGeo.com    |     Documentation    |     Premium Support

Add shape file

I want to import my shape file using following code.



            if (!Page.IsPostBack)
            {
                Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46); ;
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.MapUnit = GeographyUnit.DecimalDegree;
                
                ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath(@"~\T1\Point.shp"));
                ShapeFileFeatureLayer.BuildIndexFile(MapPath(@"~\T1\Point.shp"));
                LayerOverlay staticOverlay = new LayerOverlay();
                staticOverlay.IsBaseOverlay = false;
                staticOverlay.Layers.Add(worldLayer);
                Map1.CustomOverlays.Add(staticOverlay);
            }



I have attached my shape file.



When i am executing the code its shows nothing on the map control. 

T1.zip (2.23 KB)

Hi Keyur,



The reason why there is nothing shows up on the map, I just list them as following:




        
  1. The MapUnit is incorrect. The projection of the data you attached here is 3857, so we should change the MapUnit to GeographyUnit.Meter

  2.     
  3. The extent of Map is not properly set. We can try changing the extent based on the overlay’s boundingbox as the following:
        

        Map1.CurrentExtent = staticOverlay.GetBoundingBox();
        

        

  4.     
  5. Not apply the style to the layer. Please try following to apply a point style to layer.




worldLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

Please refer to wiki.thinkgeo.com/wiki/map_suite_style_guide learn more about Styles.



The following is the code snippet:


protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
          
         Map1.MapUnit = GeographyUnit.Meter;
         ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath(@"~\T1\Point.shp"));
         worldLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
         worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
         LayerOverlay staticOverlay = new LayerOverlay();
         staticOverlay.Layers.Add(worldLayer);
         Map1.CurrentExtent = staticOverlay.GetBoundingBox();
         Map1.CustomOverlays.Add(staticOverlay);
     }
 }





Regards,

Peter