ThinkGeo.com    |     Documentation    |     Premium Support

Can't get complete bitmap

 Hi,


I'm tring to save bitmap of a map but I have problem with it.  When I try to save the bitmap, I got just the overlay but not the WMSLayer.  But without the saving bitmap, it displays fine.


 




Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));  
                Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46);  
                Map1.MapUnit = GeographyUnit.DecimalDegree;  
  
                WorldMapKitWmsWebOverlay worldMapKitWmsWebOverlay = new WorldMapKitWmsWebOverlay();  
                Map1.CustomOverlays.Add(worldMapKitWmsWebOverlay);

                ShapeFileFeatureLayer zipLayer = new ShapeFileFeatureLayer(ConfigurationSettings.AppSettings["Default2"] + "\\tl_2010_26_zcta510.shp");
                zipLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
                zipLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("ZCTA5CE10", new GeoFont("Verdana", 7, DrawingFontStyles.Regular), new GeoSolidBrush(GeoColor.StandardColors.LightSlateGray));

                zipLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
  
                InMemoryFeatureLayer selectedZipLayer = new InMemoryFeatureLayer();  
                
                selectedZipLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.LightGreen, GeoColor.GeographicColors.Sand, 2);
                selectedZipLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Country1("ZCTA5CE10");
                selectedZipLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                selectedZipLayer.DrawingMarginPercentage = 50;

                selectedZipLayer.InternalFeatures.Clear();  
                
                zipLayer.Open();  
                Feature features = zipLayer.QueryTools.GetFeaturesByColumnValue("ZCTA5CE10", "49508")[0];
                Feature features2 = zipLayer.QueryTools.GetFeaturesByColumnValue("ZCTA5CE10", "49512")[0];
                Feature features3 = zipLayer.QueryTools.GetFeaturesByColumnValue("ZCTA5CE10", "49323")[0];
                zipLayer.Close();

                InMemoryFeatureLayer CircleLayer = new InMemoryFeatureLayer();
                
                CircleLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.SimpleColors.DarkOrange, 2);
                CircleLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Country1("ZCTA5CE10");
                CircleLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                CircleLayer.DrawingMarginPercentage = 50; 

                PointShape pointInEquator = new PointShape(double.Parse("0", CultureInfo.InvariantCulture), double.Parse("0", CultureInfo.InvariantCulture));

                EllipseShape cir = new EllipseShape(pointInEquator, 20, 20, Map1.MapUnit, DistanceUnit.Mile);
                cir.TranslateByOffset(-85.6680556, 42.9633333);
                CircleLayer.InternalFeatures.Add(new Feature(cir));

                selectedZipLayer.InternalFeatures.Add("49508", features);
                selectedZipLayer.InternalFeatures.Add("49512", features2);
                selectedZipLayer.InternalFeatures.Add("49323", features3);

                LayerOverlay staticOverlay = new LayerOverlay("StaticOverlay");
                staticOverlay.IsBaseOverlay = false;
                staticOverlay.Layers.Add("ZipLayer", zipLayer);
                Map1.CustomOverlays.Add(staticOverlay);

                LayerOverlay dynamicOverlay = new LayerOverlay("DynamicOverlay");
                dynamicOverlay.IsBaseOverlay = false;
                dynamicOverlay.TileType = TileType.SingleTile;
                dynamicOverlay.Layers.Add("HighlightLayer", selectedZipLayer);
                dynamicOverlay.Layers.Add("Highlight2Layer", CircleLayer);
                Map1.CustomOverlays.Add(dynamicOverlay);

                if (selectedZipLayer.InternalFeatures.Count > 1)  
            {

                selectedZipLayer.Open();
                RectangleShape zipRect = selectedZipLayer.GetBoundingBox();
                Map1.CurrentExtent = selectedZipLayer.GetBoundingBox();
                selectedZipLayer.Close();

                CircleLayer.Open();
                RectangleShape cirRect = CircleLayer.GetBoundingBox();
                //Map1.CurrentExtent = CircleLayer.GetBoundingBox();
                CircleLayer.Close();
                string str = zipRect.GetWellKnownText();
                PolygonShape ps = new PolygonShape(str);
                Map1.CurrentExtent.ExpandToInclude(cir);
                 selectedZipLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(50, GeoColor.StandardColors.Green);
                
                ((LayerOverlay)Map1.CustomOverlays[1]).Redraw();
                ((LayerOverlay)Map1.CustomOverlays[2]).Redraw();  

            }
                Bitmap bmp = Map1.GetBitmap(400, 400);
                bmp.Save(@"C:\Users\vvu\Desktop\New folder (2)\CSharp\CSWebEditionSample\bin\c.png");


Hello Vinh, 
  
 Thanks for your post and code. The WmsOverlay is actually a wrapper of the client layer; it only gathers user settings and creating web DOM tree node (eg. Image tag), then let web browser retrieve the image stream, it isn’t responsible for requesting images, but our map engine GetBitmap method only handle the images which draws on the GeoCanvas. 
  
 So the GetBitmap is NOT going to get the GoogleMap, BingMap and wms OVERLAYS, but it is going to get the GoogleMap, BingMap, OpenStreetMap and wms LAYERS. You see in our API, we make the most of distinction between OVERLAYS and LAYERS . So we have GoogleOverlay, BingMapsOverlay, OpenStreetMapOverlay and WmsOverlay for OVERLAYS and we have GoogleMapsLayer, BingMapsLayer, OpenStreetMapLayer and WmsRasterLayer for LAYERS. Using an overlay, it is going to be more efficient because it is going to use drawing techniques specific to the edition (web, wpf , silverlight etc). When using layers it is generic but it comes with the advantage that it is going to show in the image from GetBitmap. So, for getting the image with GetBitmap, I suggest you create code to use WmsRasterLayer instead of WmsOverlay. 
  
 I hope that this helps. 
  
 Regards, 
  
 Gary