ThinkGeo.com    |     Documentation    |     Premium Support

Map legend

You guys need a way to easily implement a legend control,


The simplest way to do this would be to expose a DrawImage function of the style object that would take a size(width and height), and format png, jpeg, gif and return a  image representing the style, users could then show these images in their own legend control.  By the way what does the WebZoomLevelSet do.



Clava, 
  
 Thanks for the post, currently you can generate a small image based upon a style.  All you need to do is call the DrawSample method off of the Style object.    Now this API may be a little tricky because you have to pass in a geoCanvas that defines where the image will be drawn and the size.  But with this you can easily get an image of each type of style to build up your own legend.  To help make it clearer I have provided some sample code below that I hope helps: 
  
  
         public void TestGetStyleSampleImage() 
         { 
             // Create the style we want a sample for.  Note that not all styles have a sample. 
             // In that case it just returns nothing on the image. 
             AreaStyle myAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Green)); 
  
             // Get our sample bitmap 
             Bitmap sampleImage = GetStyleSampleImage(myAreaStyle); 
  
             // Now we save the GDI+ bitmap to a PNG on the disk but you can use the in memeory 
             // version just as well. 
             sampleImage.Save(@"C:\StyleSampleImage.png", System.Drawing.Imaging.ImageFormat.Png); 
             sampleImage.Dispose(); 
  
         } 
  
         public Bitmap GetStyleSampleImage(Style style) 
         { 
             // Create our GeoImage.  It is an abstract image type because we need 
             // to work with different drawing systems such as GDI+ or WPF 
             GeoImage geoImage = new GeoImage(100, 100); 
  
             // Create our Canvas, we will use the GDI+ canvas 
             GdiPlusGeoCanvas geoCanvas = new GdiPlusGeoCanvas(); 
  
             // Start the drawing.  The rectangle we pass in just needs to be the same dimensions 
             // as the GeoImage 
             geoCanvas.BeginDrawing(geoImage, new RectangleShape(0, 100, 100, 0)); 
  
             // Call the main method which is the DrawSample on the Style. 
             style.DrawSample(geoCanvas); 
  
             // Ending the drawing committes the drawing 
             geoCanvas.EndDrawing(); 
  
             // Since we have tha abstract GeoImage we need to convert it to a real image type. 
             // To do this we use the GetImageStream but need to pass in a canvas to do the real work. 
             // The result is an image stream that we can load into a bitmap in GDI+ 
             Bitmap sampleImage = new Bitmap(geoImage.GetImageStream(geoCanvas)); 
  
             return sampleImage; 
         }