/// <summary>
/// Exports the current extent & visible layers on mapctrl to the specified format and the specified size.
/// </summary>
/// <param name="mapctrl">Map control to export layout from</param>
/// <param name="Size">Graphic Size</param>
/// <param name="Format">Graphic Ouput Format (JPG,PDF,PNG)</param>
/// <returns>URL to exported map layout</returns>
public string MapExportLayout(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl, string Size, string Format)
{
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality(1);
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mr = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)ags_mf.Resource;
// Get Server Object from Server Context
ESRI.ArcGIS.Server.IServerContext SC = ags_mr.ServerContextInfo.ServerContext;
//get map description
ESRI.ArcGIS.ADF.ArcGISServer.MapDescription CurADFMD = ags_mf.MapDescription;
//update extent to current extent
CurADFMD.MapArea.Extent = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfEnvelope(mapctrl.Extent);
//update layers to current layers on/off
for (int i = 0; i < CurADFMD.LayerDescriptions.Length; i++)
{
ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription Layer = (ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription)CurADFMD.LayerDescriptions.GetValue(i);
Layer.Visible = ags_mf.GetLayerVisibility(Layer.LayerID.ToString());
}
//convert map description to carto com map description
ESRI.ArcGIS.Carto.MapDescription CurCartMD = (ESRI.ArcGIS.Carto.MapDescription)ESRI.ArcGIS.ADF.ArcGISServer.Converter.ValueObjectToComObject(CurADFMD, SC);
//Get Map Server obj
ESRI.ArcGIS.Carto.IMapServer MapServer = (ESRI.ArcGIS.Carto.IMapServer)SC.ServerObject;
ESRI.ArcGIS.Carto.IMapServerInfo MapServerInfo = (ESRI.ArcGIS.Carto.IMapServerInfo)MapServer.GetServerInfo(MapServer.DefaultMapName);
ESRI.ArcGIS.Carto.IMapDescription MD = (ESRI.ArcGIS.Carto.IMapDescription)MapServerInfo.DefaultMapDescription;
// Create Image Type obj
ESRI.ArcGIS.Carto.IImageType ImgType = SC.CreateObject("esriCarto.ImageType") as ESRI.ArcGIS.Carto.IImageType;
// Create Image Display Obj
ESRI.ArcGIS.Carto.IImageDisplay ImgDisplay = SC.CreateObject("esriCarto.ImageDisplay") as ESRI.ArcGIS.Carto.IImageDisplay;
// Create Image Description Obj
ESRI.ArcGIS.Carto.IImageDescription ImgDesc = SC.CreateObject("esriCarto.ImageDescription") as ESRI.ArcGIS.Carto.IImageDescription;
//Set Image Format
switch (Format)
{
case "PDF":
ImgType.Format = ESRI.ArcGIS.Carto.esriImageFormat.esriImagePDF;
break;
case "JPG":
ImgType.Format = ESRI.ArcGIS.Carto.esriImageFormat.esriImageJPG;
break;
case "PNG":
ImgType.Format = ESRI.ArcGIS.Carto.esriImageFormat.esriImagePNG;
break;
}
ImgType.ReturnType = ESRI.ArcGIS.Carto.esriImageReturnType.esriImageReturnURL;
//Set Image Size
switch (Size)
{
case "800x600":
ImgDisplay.Height = 600;
ImgDisplay.Width = 800;
break;
case "1024x768":
ImgDisplay.Height = 768;
ImgDisplay.Width = 1024;
break;
case "1280x720":
ImgDisplay.Height = 720;
ImgDisplay.Width = 1280;
break;
case "1280x1024":
ImgDisplay.Height = 1024;
ImgDisplay.Width = 1280;
break;
}
try
{
ImgDisplay.DeviceResolution = double.Parse(Size);
}
catch (Exception e)
{
ImgDisplay.DeviceResolution = 90;
}
ImgDesc.Type = ImgType;
ImgDesc.Display = ImgDisplay;
//Get Map Layout
ESRI.ArcGIS.Carto.IMapServerLayout MapLayout = MapServer as ESRI.ArcGIS.Carto.IMapServerLayout;
ESRI.ArcGIS.Carto.IPageDescription PD = MapLayout.DefaultPageDescription;
//Get default map desc
ESRI.ArcGIS.Carto.IMapFrameDescription MapFrameDesc = PD.MapFrames.get_Element(0);
ESRI.ArcGIS.Carto.IMapDescription DefMapDesc = MapFrameDesc.MapDescription;
//Set default Map Description to current Map description, assuming we use first map frame here, change if necessary
PD.MapFrames.get_Element(0).MapDescription = CurCartMD;
//Export Layout
ESRI.ArcGIS.Carto.ILayoutImage LayoutImg = MapLayout.ExportLayout(PD, ImgDesc);
//Return URL to Image
return LayoutImg.URL;