/// <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. CES. 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;