I have found a workaround to my problem, but it does not actually solve the problem. A little backstory first. I may shed some light as to why I am having the problem. One thing I did not mention was that the whole mapping process takes place in WCF service which is hosted by a Windows Service. I realized when I developed the service I should probably try out the MapEngine, but I had a very large class library that performed all my core mapping functionality, most importantly reading layer definitions from a layer metadata repository and dynamically adding them to the map, for our existing interactive winforms mapping application. I did not want to reinvent the wheel on this as MapEngine deals with layers completely different than WinformsMap.
So I thought that I would just create a parentless WinformsMap but never add it to anything. Something as simple as:
WinformsMap Map = new WinformsMap {Height = 600, Width = 400};
and use that as my map. In extensive testing on my Windows 7 64 bit box it worked like a charm. I could create the map with my existing class libraries and simple Map.DrawToBitmap, convert to a smaller size and I had the thumbnail I needed. Things went south when I tried to implement on the Window 2008 server. I got the clipping behavior previously outlined in this post.
One interesting point to note, during initial testing of the WCF service on the 2008 server I was hosting my WCF service from a form and everything worked great, but as soon as I deployed using a Windows Service the output image got clipped. Maybe that difference may identify the problem.
My solution was to go ahead and not reinvent the wheel with new class libraries for MapEngine. I went ahead and created the Map using the parentless WinformsMap control, just as I had been, but instead of Map.DrawToBitMap I convert the contents of the WinformsMap to a MapEngine and get the bitmap from MapEngine. Once I thought it out the conversion was pretty simple. I have included the snippet of how I am doing this. Please note that I am accounting for specific overlays in my Winforms map and how they translate to mapEngine layers.
Hope this helps anyone who may have experienced this problem or highlights why the problem was occuring in the first place.
Eric
public MapEngine ConvertMapToEngine()
{
MapEngine mapEngine = new MapEngine();
mapEngine.ShowLogo = false;
LayerOverlay layerOverlay;
foreach (Overlay overlay in Map.Overlays)
{
if (object.Equals(overlay.GetType(), typeof(LayerOverlay)))
{
layerOverlay = (LayerOverlay)overlay;
foreach (Layer layer in layerOverlay.Layers)
{
if (overlay.Name == "BaseMapOverlay")
mapEngine.DynamicLayers.Add(layer);
if (overlay.Name == "ImageOverlay")
mapEngine.StaticLayers.Add(layer);
}
}
}
mapEngine.CurrentExtent = Map.CurrentExtent;
return mapEngine;
}
public Bitmap GetMapBitmap2(int width, int height)
{
MapEngine mapEngine = ConvertMapToEngine();
Bitmap bitmap = new Bitmap(width, height);
mapEngine.OpenAllLayers();
mapEngine.DrawStaticLayers(bitmap, Map.MapUnit);
mapEngine.DrawDynamicLayers(bitmap, Map.MapUnit);
mapEngine.CloseAllLayers();
bitmap.Save(@"C:\mapengine.bmp");
return bitmap;
}