SharpMap could not render to simple PictureBox

Topics: WinForms Controls
Mar 7, 2010 at 6:37 PM

Hi there,

I have a big problem. I am using your library SharpMap and after some research, I reach almost finally working application, BUT ...

look at this code:

 

 

SharpMap.Map myMap = new SharpMap.Map(new Size(600, 400));
            myMap.BackColor = Color.White;
            myMap.Center = new SharpMap.Geometries.Point(300, 200);
            SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Czech Republic", "http://wms.geology.cz/wmsconnector/com.esri.wms.Esrimap/HG1M");
            
            layWms.SpatialReferenceSystem = "EPSG:4326";
            layWms.AddLayer("0");
            layWms.AddLayer("1");
            layWms.SetImageFormat("image/jpeg");
            layWms.SRID = 4326;
            myMap.Layers.Add(layWms);            
            //Render the map
            System.Drawing.Image imgMap = myMap.GetMap();            
            
            // Stretches the image to fit the pictureBox.
            Bitmap bm = new Bitmap(imgMap);
            Graphics g = Graphics.FromImage(bm);            
            g.DrawString("bida", new System.Drawing.Font("Arial", 16), new System.Drawing.SolidBrush(System.Drawing.Color.Black), 0, 0, new System.Drawing.StringFormat(StringFormatFlags.NoWrap));
            g.Save();
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;            
            pictureBox1.ClientSize = new Size(imgMap.Size.Width, imgMap.Size.Height);
            pictureBox1.Image = (Image)bm;

    SharpMap.Map myMap = new SharpMap.Map(new Size(600, 400));

            myMap.BackColor = Color.White;

            myMap.Center = new SharpMap.Geometries.Point(300, 200);

 

            SharpMap.Layers.WmsLayer layWms = new SharpMap.Layers.WmsLayer("Czech Republic", "http://wms.geology.cz/wmsconnector/com.esri.wms.Esrimap/HG1M");

 

            layWms.SpatialReferenceSystem = "EPSG:4326";

            layWms.AddLayer("0");

            layWms.AddLayer("1");

            layWms.SetImageFormat("image/jpeg");

            layWms.SRID = 4326;

 

            myMap.Layers.Add(layWms);            

 

            //Render the map

            System.Drawing.Image imgMap = myMap.GetMap();            

            pictureBox1.Image = imgMap ;

 

Layers are fine, image format is fine, everything looks just fine, but imgMap (object of SharpMap.Map), is blank. I have just white Background.

 

Is something wrong on this code?

 

Thanks for feedback.

 

Peter

 

Coordinator
Mar 7, 2010 at 10:18 PM

Hello Peter,

your code lacks a call to map.ZoomToExtents() function.

Hth FObermaier

Mar 8, 2010 at 10:12 AM

thanks a lot FObermaier,

but why calling this function is missing in tutorial?

anyway, thanks again

 

Peter