/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add OpenDocument.OnClick implementation OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "选择地图文档"; dlg.Filter = "地图文档(*.mxd)|*.mxd"; string docName = null; if (dlg.ShowDialog() == DialogResult.OK) { docName = dlg.FileName; IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsMapDocument(docName)) { mapDoc.Open(docName, string.Empty); IMap map = mapDoc.get_Map(0); m_ControlsSynchronizer.ReplaceMap(map); mapDoc.Close(); RecnetFilesList.Add(docName); } else { MessageBox.Show("不可用的地图文档", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); RecnetFilesList.Remove(docName); } } }
public override void OnClick() { //获得符号信息 通过mxd System.Windows.Forms.OpenFileDialog dir = new System.Windows.Forms.OpenFileDialog(); dir.FileName = ""; dir.Filter = "ArcGis地图文档(*.mxd)|*.mxd"; dir.Multiselect = false; if (dir.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } string strMxdPath = dir.FileName; IMapDocument pMapDoc = new MapDocumentClass(); if (!pMapDoc.get_IsMapDocument(strMxdPath)) { return; } pMapDoc.Open(strMxdPath, ""); //获得所有的符号信息 并进行序列化 if (SaveMxdSymbolToXML(pMapDoc, System.Windows.Forms.Application.StartupPath + "\\..\\Template\\SymbolInfo.xml")) { Fan.Common.Error.ErrorHandle.ShowInform("提示", "符号信息更新成功!"); } else { Fan.Common.Error.ErrorHandle.ShowInform("提示", "无法更新符号信息!"); } }
/// <summary> /// 作用:打开TemplateMapDocument /// 作者:汪建龙 /// 编写时间:2016年12月23日11:18:34 /// </summary> /// <returns></returns> private IMapDocument OpenTemplateDocument() { try { IMapDocument tempMapDocumnet = new MapDocumentClass(); if (!tempMapDocumnet.get_IsPresent(TemplateMxdFileName) || !tempMapDocumnet.get_IsMapDocument(TemplateMxdFileName) || tempMapDocumnet.get_IsPasswordProtected(TemplateMxdFileName) || tempMapDocumnet.get_IsRestricted(TemplateMxdFileName)) { var message = string.Format("路径:\"{0}\"下的地图文档不正确,请拷贝该文件到该路径下", _templateMxdFileName); System.Diagnostics.Trace.WriteLine(message); return(null); } tempMapDocumnet.Open(TemplateMxdFileName, null); if (tempMapDocumnet.DocumentVersion == esriMapDocumentVersionInfo.esriMapDocumentVersionInfoFail) { var message = string.Format("路径:\"{0}\"下的地图文档版本不正确,请拷贝该文件到该路径下", TemplateMxdFileName); return(null); } return(tempMapDocumnet); }catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex); return(null); } }
public void OnClick_RecentFileMenuItem(string docName) { // TODO: Add OpenDocument.OnClick implementation IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsMapDocument(docName)) { mapDoc.Open(docName, string.Empty); IMap map = mapDoc.get_Map(0); m_ControlsSynchronizer.ReplaceMap(map); mapDoc.Close(); RecnetFilesList.Add(docName); } else { MessageBox.Show("不可用的地图文档", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); RecnetFilesList.Remove(docName); } }
/// <summary> /// 作用:MapControl加载mxd文件 /// 作者:汪建龙 /// 编写时间:2016年12月26日09:49:25 /// </summary> /// <param name="mapControl"></param> /// <param name="mxdFile"></param> public static void Load(this IMapControl2 mapControl, string mxdFile) { try { if (System.IO.File.Exists(mxdFile) == false) { return; } IMapDocument mapDocument = new MapDocumentClass(); if (!mapDocument.get_IsPresent(mxdFile) || !mapDocument.get_IsMapDocument(mxdFile) || mapDocument.get_IsPasswordProtected(mxdFile) || mapDocument.get_IsRestricted(mxdFile)) { string message = string.Format("路径:\"{0}\"下的地图文档不正确,请拷贝文件到该路径下。", mxdFile); System.Diagnostics.Trace.WriteLine(message); } else { mapDocument.Open(mxdFile, null); if (mapDocument.DocumentVersion == esriMapDocumentVersionInfo.esriMapDocumentVersionInfoFail) { string message = string.Format("路径:\"{0}\"下的地图文档版本不正确,请拷贝该文件到该路径下。", mxdFile); System.Diagnostics.Trace.WriteLine(message); } else if (mapDocument.MapCount > 0) { IMap map = mapDocument.get_Map(0); mapControl.Map = map; } } }catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex); } }
public bool AddGxFileLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sFileName) { try { if (sFileName == null) { sFileName = ""; } if (pBasicMap == null) { return(false); } if (string.IsNullOrEmpty(sFileName)) { OpenFileDialog dialog = new OpenFileDialog { Filter = "图层文件 (*.lyr)|*.lyr", Multiselect = false, Title = "选择输入的图层文件" }; if (dialog.ShowDialog() != DialogResult.OK) { return(false); } sFileName = dialog.FileName; dialog = null; } if (string.IsNullOrEmpty(sFileName)) { return(false); } if (!File.Exists(sFileName)) { Interaction.MsgBox("地图图层加载失败,图层文件 " + sFileName + " 不存在。", MsgBoxStyle.Exclamation, "错误警告"); return(false); } IMapDocument document = null; document = new MapDocumentClass(); if (!document.get_IsMapDocument(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是 MapDocument 文件。", MsgBoxStyle.Exclamation, "失败"); return(false); } if (document.get_IsRestricted(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败"); return(false); } document.Open(sFileName, null); ILayer pLayer = null; if (document.DocumentType == esriMapDocumentType.esriMapDocumentTypeLyr) { pLayer = document.get_Layer(0, 0); if (pLayer == null) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n图层文件或数据错误。", MsgBoxStyle.Exclamation, "加载失败"); } } else { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是地图图层文件。", MsgBoxStyle.Exclamation, "加载失败"); } document.Close(); document = null; if (pLayer == null) { return(false); } if (pParentLayer == null) { pBasicMap.AddLayer(pLayer); } else { pParentLayer.Add(pLayer); } IMapLayers layers = pBasicMap as IMapLayers; if (pParentLayer == null) { layers.MoveLayer(pLayer, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, pLayer, 0); } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGxFileLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public bool SaveMapDocument(IMxdContents pMxdContents, string sFileName, bool bOverwritePrompt, bool bUseRelativePaths, bool bCreateThumnbail, bool bSilent) { try { if (sFileName == null) { sFileName = ""; } if (pMxdContents == null) { MessageBox.Show("地图文档保存失败,Map 内容加载失败。", "错误警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (string.IsNullOrEmpty(sFileName)) { SaveFileDialog dialog = new SaveFileDialog { DefaultExt = "mxd", FileName = "无标题", Filter = "地图文档 (*.mxd)|*.mxd", OverwritePrompt = bOverwritePrompt, Title = "保存地图到文件" }; if (dialog.ShowDialog() != DialogResult.OK) { return(false); } sFileName = dialog.FileName; dialog = null; if (string.IsNullOrEmpty(sFileName)) { return(false); } } else if (((File.Exists(sFileName) & bOverwritePrompt) && !bSilent) && (Interaction.MsgBox("文件 " + sFileName + " 已存在。\r\n是否要替换?", MsgBoxStyle.YesNo, "确认替换") != MsgBoxResult.Yes)) { return(false); } if (File.Exists(sFileName)) { FileSystem.Kill(sFileName); } if (File.Exists(sFileName)) { MessageBox.Show("文件 " + sFileName + " 无法删除。\r\n共享冲突,文件正在使用。", "覆盖文件错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } IMapDocument document = null; document = new MapDocumentClass(); document.New(sFileName); document.ReplaceContents(pMxdContents); document.SetActiveView(pMxdContents.ActiveView); if (!document.get_IsMapDocument(sFileName)) { MessageBox.Show("文件 " + sFileName + " 无法保存。\r\n文件不是 MapDocument 文件。", "保存文件错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (document.get_IsRestricted(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法保存。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败"); return(false); } document.Save(bUseRelativePaths, bCreateThumnbail); document.Close(); document = null; return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "SaveMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
private IMapDocument OpenMapDocument(string sFileName, string sPassword) { try { if (sFileName == null) { sFileName = ""; } if (sPassword == null) { sPassword = ""; } if (string.IsNullOrEmpty(sFileName)) { OpenFileDialog dialog = new OpenFileDialog { Filter = "所有支持文件|*.mxd;*.mxt;*.pmf;*.lyr|地图文档 (*.mxd)|*.mxd|地图模板 (*.mxt)|*.mxt|发布地图 (*.pmf)|*.pmf|地图图层 (*.lyr)|*.lyr", Multiselect = false, Title = "选择的地图文件" }; if (dialog.ShowDialog() != DialogResult.OK) { return(null); } sFileName = dialog.FileName; dialog = null; } if (string.IsNullOrEmpty(sFileName)) { return(null); } if (!File.Exists(sFileName)) { Interaction.MsgBox("地图文档加载失败,文档文件 " + sFileName + " 不存在。", MsgBoxStyle.Exclamation, "错误警告"); return(null); } IMapDocument document = null; document = new MapDocumentClass(); if (!document.get_IsMapDocument(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是 MapDocument 文件。", MsgBoxStyle.Exclamation, "失败"); return(null); } if (document.get_IsRestricted(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败"); return(null); } if (document.get_IsPasswordProtected(sFileName)) { document.Open(sFileName, sPassword); } else { document.Open(sFileName, ""); } return(document); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "OpenMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
/// <summary> /// Called when a step of this type is executed in the workflow. /// </summary> /// <param name="JobID">ID of the job being executed</param> /// <param name="StepID">ID of the step being executed</param> /// <param name="argv">Array of arguments passed into the step's execution</param> /// <param name="ipFeedback">Feedback object to return status messages and files</param> /// <returns>Return code of execution for workflow path traversal</returns> public int Execute(int JobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback) { if (JobID <= 0) { throw new ArgumentOutOfRangeException("JobID", JobID, "Job ID must be a positive value"); } try { string strTemp = ""; bool bAttach = false; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[1], false, out strTemp)) { bAttach = true; } string strResolution; if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[2], false, out strResolution)) { strResolution = "1200"; } int iResolution = 1200; if (!Int32.TryParse(strResolution, out iResolution)) { iResolution = 1200; } string outputPath = ""; if (!bAttach) { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Filter = "PDF files (*.pdf)|*.pdf"; pSaveFileDialog.Title = "Choose output location..."; string strInitDir = ""; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strInitDir)) { if (System.IO.Directory.Exists(strInitDir)) { pSaveFileDialog.InitialDirectory = strInitDir; } } if (pSaveFileDialog.ShowDialog() != DialogResult.OK) { return(-1); } outputPath = pSaveFileDialog.FileName; } string inputPath = JTXUtilities.SaveJobMXD(JobID); if (bAttach) { outputPath = SystemUtilities.GetTemporaryFileLocation(inputPath, "pdf"); } // delete output file if it already exists System.IO.FileInfo fi = new System.IO.FileInfo(outputPath); if (fi.Exists) { fi.Delete(); } MapDocumentClass map = new MapDocumentClass(); if (!map.get_IsMapDocument(inputPath)) { throw new ApplicationException("Invalid map or specified map not found."); } map.Open(inputPath, null); IActiveView pActiveView = (IActiveView)map.PageLayout; IExport pExport = new ExportPDFClass(); pExport.ExportFileName = outputPath; tagRECT deviceFrameRect; deviceFrameRect.left = 0; deviceFrameRect.right = 800; deviceFrameRect.top = 0; deviceFrameRect.bottom = 600; pActiveView.ScreenDisplay.DisplayTransformation.set_DeviceFrame(ref deviceFrameRect); int iOutputResolution = iResolution; int iScreenResolution = 96; pExport.Resolution = iOutputResolution; IOutputRasterSettings pOutputRasterSettings = (IOutputRasterSettings)pExport; pOutputRasterSettings.ResampleRatio = 1; tagRECT exportRect; exportRect.left = pActiveView.ExportFrame.left * (iOutputResolution / iScreenResolution); exportRect.top = pActiveView.ExportFrame.top * (iOutputResolution / iScreenResolution); exportRect.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution); exportRect.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution); IEnvelope pPixelBoundsEnv = new EnvelopeClass(); pPixelBoundsEnv.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom); pExport.PixelBounds = pPixelBoundsEnv; int hdc = pExport.StartExporting(); pActiveView.Output(hdc, iOutputResolution, ref exportRect, null, null); pExport.FinishExporting(); pExport.Cleanup(); if (bAttach) { JTXUtilities.AddAttachmentToJob(JobID, outputPath, jtxFileStorageType.jtxStoreInDB); } return(0); } catch (Exception ex) { throw ex; } }
/// <summary> /// Called when a step of this type is executed in the workflow. /// </summary> /// <param name="JobID">ID of the job being executed</param> /// <param name="StepID">ID of the step being executed</param> /// <param name="argv">Array of arguments passed into the step's execution</param> /// <param name="ipFeedback">Feedback object to return status messages and files</param> /// <returns>Return code of execution for workflow path traversal</returns> public int Execute(int JobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback) { if (JobID <= 0) { throw new ArgumentOutOfRangeException("JobID", JobID, "Job ID must be a positive value"); } try { string strTemp = ""; bool bAttach = false; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[1], false, out strTemp)) { bAttach = true; } string strResolution; if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[2], false, out strResolution)) { strResolution = "1200"; } int iResolution = 1200; if (!Int32.TryParse(strResolution, out iResolution)) { iResolution = 1200; } string outputPath = ""; if (!bAttach) { SaveFileDialog pSaveFileDialog = new SaveFileDialog(); pSaveFileDialog.Filter = "PDF files (*.pdf)|*.pdf"; pSaveFileDialog.Title = "Choose output location..."; string strInitDir = ""; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strInitDir)) { if (System.IO.Directory.Exists(strInitDir)) { pSaveFileDialog.InitialDirectory = strInitDir; } } if (pSaveFileDialog.ShowDialog() != DialogResult.OK) { return -1; } outputPath = pSaveFileDialog.FileName; } string inputPath = JTXUtilities.SaveJobMXD(JobID); if (bAttach) { outputPath = SystemUtilities.GetTemporaryFileLocation(inputPath, "pdf"); } // delete output file if it already exists System.IO.FileInfo fi = new System.IO.FileInfo(outputPath); if (fi.Exists) { fi.Delete(); } MapDocumentClass map = new MapDocumentClass(); if (!map.get_IsMapDocument(inputPath)) throw new ApplicationException("Invalid map or specified map not found."); map.Open(inputPath, null); IActiveView pActiveView = (IActiveView)map.PageLayout; IExport pExport = new ExportPDFClass(); pExport.ExportFileName = outputPath; tagRECT deviceFrameRect; deviceFrameRect.left = 0; deviceFrameRect.right = 800; deviceFrameRect.top = 0; deviceFrameRect.bottom = 600; pActiveView.ScreenDisplay.DisplayTransformation.set_DeviceFrame(ref deviceFrameRect); int iOutputResolution = iResolution; int iScreenResolution = 96; pExport.Resolution = iOutputResolution; IOutputRasterSettings pOutputRasterSettings = (IOutputRasterSettings)pExport; pOutputRasterSettings.ResampleRatio = 1; tagRECT exportRect; exportRect.left = pActiveView.ExportFrame.left * (iOutputResolution / iScreenResolution); exportRect.top = pActiveView.ExportFrame.top * (iOutputResolution / iScreenResolution); exportRect.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution); exportRect.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution); IEnvelope pPixelBoundsEnv = new EnvelopeClass(); pPixelBoundsEnv.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom); pExport.PixelBounds = pPixelBoundsEnv; int hdc = pExport.StartExporting(); pActiveView.Output(hdc, iOutputResolution, ref exportRect, null, null); pExport.FinishExporting(); pExport.Cleanup(); if (bAttach) { JTXUtilities.AddAttachmentToJob(JobID, outputPath, jtxFileStorageType.jtxStoreInDB); } return 0; } catch (Exception ex) { throw ex; } }