I am having issues trying to capture and save the map image using the GetBitmap method.
The image which is displayed in the browser has the correct projection, however when I use the GetBitmap method and save the image out to a file, the projection of the image is not correct.
I have the full lic version of ThinkGeo MVC edition, the water marks in the image are due to me using my developer computer and iis express 8.
I downloaded the latest dll’s from our customer portal. The versions are as follows.
MapSuiteCore.dll 6.0.0.198
MvcEdition.dll 6.0.0.198
Image from the browser which is using correct projection
Saved image from GetBitmap using incorrect projection
This is the gist of the code I am using
public imageOutput SaveImageCommand( imageInput input )
{
Map map = GetMapFromRequest( input.MapSessionId );
var MyBitmap = map.GetBitmap( );
MyBitmap.Save( @"d:\testmapImage2.png", ImageFormat.Png );
return new imageOutput( );
}
public void CreateMap(){
Map map = new Map( MapName, new Unit( 100, UnitType.Percentage ), new Unit( 100, UnitType.Percentage ) );
map.MapBackground.BackgroundBrush = (new GeoSolidBrush( GeoColor.SimpleColors.Transparent ));
map.MapUnit = GeographyUnit.Meter;
LayerOverlay featuresOverlay = new LayerOverlay( "features" );
featuresOverlay.IsVisible = true;
featuresOverlay.IsBaseOverlay = false;
featuresOverlay.ServerCache.CacheDirectory = _settings.TileCachePath;
featuresOverlay.ServerCache.CacheId = Guid.NewGuid( ).ToString( );
featuresOverlay.Name = "features";
featuresOverlay.WebImageFormat = WebImageFormat.Png;
featuresOverlay.ClientCache.CacheId = "clientCacheID";
featuresOverlay.ClientCache.Duration = new TimeSpan( 0, 10, 0 );
featureOverlay.Layers.Add( ProcessFeatureShapes(input.ShapeData, projSphericalMercator) );
map.CustomOverlays.Add( featuresOverlay );
map.CurrentExtent = GetFullExtent( featureOverlay.Layers );
}
private RectangleShape GetFullExtent( GeoCollection<Layer> Layers )
{
List<BaseShape> rectangleShapes = new List<BaseShape>( );
foreach ( Layer layer in Layers )
{
layer.Open( );
if ( layer.HasBoundingBox == true )
rectangleShapes.Add( layer.GetBoundingBox( ) );
}
return ExtentHelper.GetBoundingBoxOfItems( rectangleShapes );
}
private InMemoryFeatureLayer ProcessFeatureShapes( HashSet<ShapeData> shapeDataCollection, Proj4Projection projSphericalMercator )
{
InMemoryFeatureLayer layer = new InMemoryFeatureLayer( );
layer.Open( );
layer.Columns.Add( new FeatureSourceColumn( "name", DbfColumnType.String.ToString( ), 100 ) );
layer.Columns.Add( new FeatureSourceColumn( "data", DbfColumnType.Double.ToString( ), 40 ) );
layer.EditTools.BeginTransaction( );
foreach ( var shapeData in shapeDataCollection )
{
var data = _shapeFileProvider.GetShapeFileBinaryData( shapeData.Geography.GeographyType, shapeData.ShapeFileName ); //get the well known binary data
Feature feature = new Feature( data );
feature.ColumnValues.Add( "name", shapeData.Name );
feature.ColumnValues.Add( "data", shapeData.DataValue.ToString( ) );
feature.GetBoundingBox( ); //force the calculation.
layer.EditTools.Add( feature );
}
layer.EditTools.CommitTransaction( );
layer.BuildIndex( );
layer.FeatureSource.Projection = projSphericalMercator;
layer.Close( );
return layer;
}