📄 exportmap.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using System.Collections;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.Display;
/// <summary>
/// Summary description for ExportMap
/// </summary>
public class ExportMap
{
private ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapObject;
private ESRI.ArcGIS.Server.IServerContext serverContext;
private ESRI.ArcGIS.Carto.IMapServerObjects mapServerObj;
private double titleXPos;
private double titleYPos;
public ExportMap(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map tempMapObject, ESRI.ArcGIS.Server.IServerContext tempServerContext, double titleX, double titleY)
{
mapObject = tempMapObject;
serverContext = tempServerContext;
mapServerObj = (IMapServerObjects)serverContext.ServerObject;
titleXPos = titleX;
titleYPos = titleY;
}
public string ExportMapControlNew(int dpi, string imageType, string title)
{
//Set image type to pdf (need to make a choice in args
ESRI.ArcGIS.Carto.IImageType imgType = (IImageType) serverContext.CreateObject("esriCarto.ImageType");
imgType.Format = GetesriImageType(imageType);
//Set image resolution to dpi
ESRI.ArcGIS.Carto.IImageDisplay imgDisplay =(IImageDisplay) serverContext.CreateObject("esriCarto.ImageDisplay");
imgDisplay.DeviceResolution = dpi;
//Fill the image description (used to create export) with type and resolution
ESRI.ArcGIS.Carto.IImageDescription imgDesc = (IImageDescription)serverContext.CreateObject("esriCarto.ImageDescription");
imgDesc.Type = imgType;
imgDesc.Display = imgDisplay;
//Get the default PageDescription for use in creation of export
ESRI.ArcGIS.Carto.IMapServerLayout mapLayout = (IMapServerLayout)mapServerObj;
ESRI.ArcGIS.Carto.IPageDescription pd = mapLayout.DefaultPageDescription;
//Get the MapDescription to modify it
ESRI.ArcGIS.Carto.IMapDescription myMapDesc =(IMapDescription) serverContext.CreateObject("esriCarto.MapDescription");
myMapDesc = pd.MapFrames.get_Element(0).MapDescription;
//Get coordinates of current map extent
double lXMin;
double lXMax;
double lYMin;
double lYMax;
lXMin = mapObject.Extent.XMin;
lXMax = mapObject.Extent.XMax;
lYMin = mapObject.Extent.YMin;
lYMax = mapObject.Extent.YMax;
//Calculate center point of current map extent
ESRI.ArcGIS.Geometry.IPoint pCenterPoint;
pCenterPoint =(IPoint) serverContext.CreateObject("esriGeometry.Point");
pCenterPoint.SpatialReference = myMapDesc.SpatialReference;
pCenterPoint.X = lXMin + (lXMax - lXMin) / 2;
pCenterPoint.Y = lYMin + (lYMax - lYMin) / 2;
//Assign center point and map scale to new CenterAndScale object
ESRI.ArcGIS.Carto.ICenterAndScale pCenterScale;
pCenterScale = (ICenterAndScale)serverContext.CreateObject("esriCarto.CenterAndScale");
pCenterScale.Center = pCenterPoint;
//Set scale to equal the map controls scale
pCenterScale.MapScale = mapObject.Scale;
pd.MapFrames.get_Element(0).MapDescription.MapArea = (IMapArea) pCenterScale;
pd.MapFrames.get_Element(0).MapDescription.LayerDescriptions.get_Element(3).SetSelectionSymbol = true;
//Enumerate through all functionalities of the map control and set which layers are visible or not
System.Collections.IEnumerable funcEnum =mapObject.GetFunctionalities();
int mapFrameElement = 0;
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisfunctionality in funcEnum)
{
ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (IMapFunctionality)gisfunctionality;
string[] layerIDs = null;
string[] layerNames = null;
mf.GetLayers(out layerIDs, out layerNames);
if (layerIDs.Length > 1)
{
foreach (string id in layerIDs)
{
bool visible = mf.GetLayerVisibility(id);
if (visible)
{
pd.MapFrames.get_Element(mapFrameElement).MapDescription.LayerDescriptions.get_Element(int.Parse(id)).Visible = true;
}
else
{
pd.MapFrames.get_Element(mapFrameElement).MapDescription.LayerDescriptions.get_Element(int.Parse(id)).Visible = false;
}
//pd.MapFrames.Element(0).MapDescription.LayerDescriptions.Element(id).ScaleSymbols = True
}
mapFrameElement += 1;
}
}
//-------------------------------
//-------------------------------
//-------------------------------
//Setup the FormattedTextSymbol used for font settings
ESRI.ArcGIS.Display.IFormattedTextSymbol textFormattedSymbol = (IFormattedTextSymbol) serverContext.CreateObject("esriDisplay.TextSymbol");
textFormattedSymbol.HorizontalAlignment =(esriTextHorizontalAlignment) ESRI.ArcGIS.ADF.ArcGISServer.esriTextHorizontalAlignment.esriTHAFull;
textFormattedSymbol.VerticalAlignment = (esriTextVerticalAlignment)ESRI.ArcGIS.ADF.ArcGISServer.esriTextVerticalAlignment.esriTVABottom;
stdole.IFontDisp fontDisp = textFormattedSymbol.Font;
fontDisp.Name = "Arial";
fontDisp.Bold = false;
fontDisp.Underline = false;
if ((fontDisp != null))
{
textFormattedSymbol.Font = fontDisp;
}
textFormattedSymbol.Size = 23;
//Create text element
ESRI.ArcGIS.Carto.ITextElement pTextElement =(ITextElement) serverContext.CreateObject("esriCarto.TextElement");
pTextElement.Text = title;
pTextElement.Symbol = textFormattedSymbol;
//Set position
ESRI.ArcGIS.Geometry.IPoint pPoint =(IPoint) serverContext.CreateObject("esriGeometry.Point");
//Main Code Old One
//pPoint.X = titleXPos;
//pPoint.Y = titleYPos;
pPoint.X = 1.25;
pPoint.Y = 28.5;
ESRI.ArcGIS.Carto.IElement pElement;
pElement = (IElement)pTextElement;
pElement.Geometry = pPoint;
//Create custom graphics
ESRI.ArcGIS.Carto.IGraphicElements pCustGraphics = (IGraphicElements)serverContext.CreateObject("esriCarto.GraphicElements");
IGraphicElement pText = (IGraphicElement)pTextElement;
pCustGraphics.Add(pText);
//Add custom graphics to PageDescription
pd.CustomGraphics = pCustGraphics;
//-------------------------------
//-------------------------------
//-------------------------------
//-------------------------------
//-------------------------------
//-------------------------------
//Setup for the Copyright notice to the Exported Map
ESRI.ArcGIS.Display.IFormattedTextSymbol textFormattedSymbolCopyright = (IFormattedTextSymbol)serverContext.CreateObject("esriDisplay.TextSymbol");
textFormattedSymbolCopyright.HorizontalAlignment = (esriTextHorizontalAlignment)ESRI.ArcGIS.ADF.ArcGISServer.esriTextHorizontalAlignment.esriTHAFull;
textFormattedSymbolCopyright.VerticalAlignment = (esriTextVerticalAlignment)ESRI.ArcGIS.ADF.ArcGISServer.esriTextVerticalAlignment.esriTVABottom;
stdole.IFontDisp fontDispcopy = textFormattedSymbolCopyright.Font;
fontDispcopy.Name = "Verdana";
fontDispcopy.Bold = false;
fontDispcopy.Underline = false;
if ((fontDispcopy != null))
{
textFormattedSymbolCopyright.Font = fontDispcopy;
}
textFormattedSymbolCopyright.Size = 6;
//Create text element
ESRI.ArcGIS.Carto.ITextElement pTextElementCopyRight = (ITextElement)serverContext.CreateObject("esriCarto.TextElement");
pTextElementCopyRight.Text = "Copyright 2007. ";
pTextElementCopyRight.Symbol = textFormattedSymbolCopyright;
//Set position
ESRI.ArcGIS.Geometry.IPoint pPointCopyRight = (IPoint)serverContext.CreateObject("esriGeometry.Point");
pPointCopyRight.X = 7;
pPointCopyRight.Y = 0.5;
ESRI.ArcGIS.Carto.IElement pElementCopyright;
pElementCopyright = (IElement)pTextElementCopyRight;
pElementCopyright.Geometry = pPointCopyRight;
//Create custom graphics
// ESRI.ArcGIS.Carto.IGraphicElements pCustGraphicsCopyRight = (IGraphicElements)serverContext.CreateObject("esriCarto.GraphicElements");
IGraphicElement pTextCopy = (IGraphicElement)pTextElementCopyRight;
//pCustGraphicsCopyRight.Add(pTextCopy);
pCustGraphics.Add(pTextCopy);
//Add custom graphics to PageDescription
pd.CustomGraphics = pCustGraphics;
//-------------------------------
//-------------------------------
//-------------------------------
//Refresh server object?
//mapServerObj.RefreshServerObjects()
//Create the export and get the url of the export created
ESRI.ArcGIS.Carto.ILayoutImage layoutImg = mapLayout.ExportLayout(pd, imgDesc);
string urlString = layoutImg.URL;
string url = layoutImg.URL;
return urlString;
// New added Code
}
public esriImageFormat GetesriImageType(string ImageType)
{
switch (ImageType)
{
case "BMP":
return esriImageFormat.esriImageBMP;
case "JPG":
return esriImageFormat.esriImageJPG;
case "DIB":
return esriImageFormat.esriImageDIB;
case "TIFF":
return esriImageFormat.esriImageTIFF;
case "PNG":
return esriImageFormat.esriImagePNG;
case "PNG24":
return esriImageFormat.esriImagePNG24;
case "EMF":
return esriImageFormat.esriImageEMF;
case "PS":
return esriImageFormat.esriImagePS;
case "PDF":
return esriImageFormat.esriImagePDF;
case "AI":
return esriImageFormat.esriImageAI;
case "GIF":
return esriImageFormat.esriImageGIF;
default:
return esriImageFormat.esriImagePDF;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -