You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1146 lines
54 KiB
1146 lines
54 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Display; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.AE.Enum; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.OpenData.Filter; |
|
using KGIS.Framework.OpenData.InterFace; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.Framework.LayerStyleConvert.Common; |
|
using Kingo.Framework.LayerStyleConvert.XSDClass; |
|
using Kingo.OpenData.Filter; |
|
using Kingo.Plugin.DTBJKLoadData.Model; |
|
using Kingo.PluginServiceInterface; |
|
using KUI.Windows; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Runtime.InteropServices; |
|
using System.Windows; |
|
using System.Windows.Input; |
|
using UIShell.OSGi; |
|
using Path = System.IO.Path; |
|
|
|
namespace Kingo.Plugin.DTBJKLoadData.View |
|
{ |
|
/// <summary> |
|
/// UCLoadDTBJKData.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class UCLoadDTBJKData : BaseWindow |
|
{ |
|
private IHookHelper hookHelper { get; set; } |
|
|
|
private IDataCatalogService _DataCatalog { get; set; } |
|
|
|
private Dictionary<string, int> JCKFiles { get; set; } |
|
|
|
public List<TableMapping> tableMappings = new List<TableMapping>(); |
|
|
|
private ProjectInfo ProjectInfo { get; set; } |
|
|
|
private string XZQDM { get; set; } |
|
private string FDD { get; set; } |
|
private string ZYJD { get; set; } |
|
private string TXDH { get; set; } |
|
/// <summary> |
|
/// 坐标系字符串 |
|
/// </summary> |
|
private string PrjFileStr { get; set; } |
|
|
|
private SystemConfig2 SystemCfg { get; set; } |
|
DTBJKLoadData_Default dTBJKLoadData_Default = null; |
|
public UCLoadDTBJKData(IHookHelper m_hookHelper) |
|
{ |
|
try |
|
{ |
|
InitializeComponent(); |
|
dTBJKLoadData_Default = DTBJKLoadData.GetDefaultType(); |
|
this.Loaded += (s, e) => |
|
{ |
|
hookHelper = m_hookHelper; |
|
if (ProjectInfo == null) |
|
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
tableMappings = dTBJKLoadData_Default.DTBJKInitialization(DTBJKLoadData.matchingRegion); |
|
dgTableMapping.ItemsSource = tableMappings; |
|
}; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("UCLoadDTBJKData初始化界面异常:" + ex.Message); |
|
LogAPI.Debug("UCLoadDTBJKData初始化界面异常:" + ex.StackTrace); |
|
} |
|
} |
|
|
|
#region 视图界面触发事件 |
|
/// <summary> |
|
/// 选择数据库文件夹 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void btnSelectedBaseData_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
tableMappings = dTBJKLoadData_Default.btnSelectedBaseData_Click(this); |
|
dgTableMapping.ItemsSource = null; |
|
dgTableMapping.ItemsSource = tableMappings; |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageBox.Show("选择数据库文件夹异常:" + ex.Message); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 获取影像文件集合 |
|
/// </summary> |
|
private List<string> InitYXData(string YXPath) |
|
{ |
|
try |
|
{ |
|
List<string> YXList = new List<string>(); |
|
if (string.IsNullOrWhiteSpace(YXPath)) |
|
{ |
|
return YXList; |
|
} |
|
DirectoryInfo folder = new DirectoryInfo(YXPath); |
|
FileInfo[] finfoList = folder.GetFiles("*", SearchOption.AllDirectories); |
|
foreach (FileInfo fileInfo in finfoList) |
|
{ |
|
if (fileInfo.Extension.Equals(".tif", StringComparison.CurrentCultureIgnoreCase) || |
|
fileInfo.Extension.Equals(".jpg", StringComparison.CurrentCultureIgnoreCase) || |
|
fileInfo.Extension.Equals(".img", StringComparison.CurrentCultureIgnoreCase)) |
|
{ |
|
YXList.Add(fileInfo.FullName); |
|
} |
|
} |
|
return YXList; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取影响文件失败:" + ex.Message); |
|
throw ex; |
|
} |
|
} |
|
|
|
private IFeatureRenderer GetSymbol(string pStrSymbol) |
|
{ |
|
IFeatureRenderer result = null; |
|
try |
|
{ |
|
if (!string.IsNullOrWhiteSpace(pStrSymbol)) |
|
{ |
|
AdvancedDrawingInfo ad = AdvancedDrawingInfo.FromJson(pStrSymbol); |
|
if (ad != null) |
|
{ |
|
if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.SimpleRenderer) |
|
{ |
|
Symbol symbol1 = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol; |
|
ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol1, SymbolTypeEnum.Fill); |
|
result = simpleRander2 as IFeatureRenderer; |
|
} |
|
else if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer) |
|
{ |
|
Renderer rander = ad.DrawingInfo.Renderer; |
|
IUniqueValueRenderer uniqueValueRander = SymbolConvert.Instance().GetUniqueValueRenderer(rander, SymbolTypeEnum.Fill); |
|
result = uniqueValueRander as IFeatureRenderer; |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取图层样式失败:" + ex.Message); |
|
LogAPI.Debug("获取图层样式失败:" + ex.StackTrace); |
|
} |
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 选择单个数据目录数据库路径 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void txt_NewSelectMouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
|
{ |
|
try |
|
{ |
|
var textBlock = sender as System.Windows.Controls.TextBlock; |
|
if (textBlock == null) return; |
|
if (textBlock.Tag.ToTrim() == "参考影像目录") |
|
{ |
|
System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog(); |
|
if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
|
{ |
|
TableMapping mapping = tableMappings.FirstOrDefault(x => x.S_TableAliasName.Equals(textBlock.Tag.ToTrim())); |
|
mapping.S_TablePath = folderDialog.SelectedPath.Trim(); |
|
} |
|
} |
|
else |
|
{ |
|
KGIS.Framework.OpenData.Control.OpenDataDialog pDialog = new KGIS.Framework.OpenData.Control.OpenDataDialog(); |
|
ISpatialDataObjectFilter pOFilter = new FilterGeoDatabasePersonal(); |
|
pDialog.AddFilter(pOFilter, true); |
|
pOFilter = new FilterGeoDatabaseFile(); |
|
pDialog.AddFilter(pOFilter, true); |
|
pDialog.AllowMultiSelect = false; |
|
pDialog.Title = "选择基础数据"; |
|
pDialog.RestoreLocation = true; |
|
pDialog.StartLocation = pDialog.FinalLocation; |
|
System.Windows.Forms.DialogResult dialogResult = pDialog.ShowDialog(); |
|
if (dialogResult == System.Windows.Forms.DialogResult.OK && pDialog.Selection.Count != 0) |
|
{ |
|
string ImportDataType = Path.GetExtension(pDialog.FinalLocation).ToUpper().Replace('.', ' ').TrimStart(); |
|
if (string.IsNullOrWhiteSpace(ImportDataType) || (ImportDataType != "GDB" && ImportDataType != "MDB" && ImportDataType != "SHP")) |
|
{ |
|
MessageHelper.Show("选择的数据路径有误,请根据过滤条件,重新选择数据库!!"); |
|
return; |
|
} |
|
if (sender is System.Windows.Controls.TextBlock) |
|
{ |
|
string textTagValue = (sender as System.Windows.Controls.TextBlock).Tag.ToString().Trim(); |
|
TableMapping mapping = tableMappings.FirstOrDefault(x => x.S_TableAliasName.Equals(textTagValue)); |
|
mapping.S_TablePath = pDialog.FinalLocation.Trim(); |
|
} |
|
} |
|
} |
|
dgTableMapping.ItemsSource = null; |
|
dgTableMapping.ItemsSource = tableMappings; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("选择基础数据库失败:" + ex.Message); |
|
LogAPI.Debug("选择基础数据库失败:" + ex.StackTrace); |
|
MessageHelper.Show("选择基础数据库失败:" + ex); |
|
} |
|
} |
|
|
|
private void BtnLoad_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
if (string.IsNullOrWhiteSpace(cobDataBase.Text)) |
|
{ |
|
MessageHelper.ShowTips("请选择基础库数据库路径!"); |
|
return; |
|
} |
|
EngineEditor engineEditor = new EngineEditor(); |
|
if (engineEditor.EditState == esriEngineEditState.esriEngineStateEditing) |
|
{ |
|
MessageHelper.ShowTips("当前处于编辑状态,请关闭后打开工程!"); |
|
return; |
|
} |
|
////湖南需求:地管理信息路径 必选项 |
|
//if (string.IsNullOrWhiteSpace(tableMappings.FirstOrDefault(x => x.S_TableAliasName.Equals("用地管理信息")).S_TablePath))//"用地管理信息" |
|
//{ |
|
// MessageHelper.ShowTips("用地管理信息路径不可为空!"); |
|
// return; |
|
//} |
|
//if (string.IsNullOrWhiteSpace(tableMappings.FirstOrDefault(x => x.S_TableAliasName.Equals("坡度图")).S_TablePath))//"坡度图" |
|
//{ |
|
// MessageHelper.ShowTips("坡度图路径不可为空!"); |
|
// return; |
|
//} |
|
if (_DataCatalog == null) |
|
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>(); |
|
if (_DataCatalog == null || tableMappings.Count == 0) return; |
|
|
|
this.ShowLoading("正在加载数据.......", 0, 0); |
|
var AllCurrentLayers = _DataCatalog.CurrentLayers; |
|
if (AllCurrentLayers is LayerCfg && (AllCurrentLayers as LayerCfg).Layers.Count != 0) |
|
{ |
|
if (KGIS.Framework.Utils.SysConfigsOprator.GetAppsetingValueByKey("IsCheckJCKSign").Equals("true")) |
|
EncryptionHelper.CheckJCKSign(new List<string>() { this.ProjectInfo.JCKPath }); |
|
foreach (LayerCfg itemCfg in (AllCurrentLayers as LayerCfg).Layers) |
|
{ |
|
if ("建库数据,监测数据,变更数据".Contains(itemCfg.LayerName)) continue; |
|
if (itemCfg.LayerType == EnumLayerType.GroupLayer) |
|
{ |
|
//预处理的新增图层 |
|
if (Platform.Instance.SystemType == SystemTypeEnum.YCLJK && "预处理".Contains(itemCfg.LayerName)) |
|
{ |
|
LoadLayerDataToMap(itemCfg, itemCfg.Layers, null); |
|
continue; |
|
} |
|
if (tableMappings.FirstOrDefault(x => x.S_TableAliasName.Contains(itemCfg.LayerName)) == null) |
|
continue; |
|
string FcPath = tableMappings.FirstOrDefault(x => x.S_TableAliasName.Contains(itemCfg.LayerName)).S_TablePath; |
|
if (itemCfg.LayerName == "坡度图" && FcPath.Contains("5级坡度图")) |
|
{ |
|
//FcPath = tableMappings.FirstOrDefault(x => x.S_TableAliasName.Equals("5级坡度图")).S_TablePath; |
|
|
|
} |
|
if (itemCfg.LayerName.Equals("基础数据库") && string.IsNullOrWhiteSpace(FcPath)) |
|
{ |
|
MessageHelper.ShowTips("基础数据库路径不可为空!"); |
|
return; |
|
} |
|
LoadLayerDataToMap(itemCfg, itemCfg.Layers, FcPath); |
|
} |
|
} |
|
_DataCatalog.CurrentLayers = AllCurrentLayers; |
|
_DataCatalog.UpdateTree(); |
|
SaveProjectAllPath(); |
|
|
|
//设置预处理新增图层的坐标系 |
|
if (Platform.Instance.SystemType == SystemTypeEnum.YCLJK && ProjectInfo != null && ProjectInfo.PrjFileStr != null) |
|
{ |
|
IWorkspaceAPI wsYCLAPI = new WorkspaceAPI(ProjectInfo.DTBYCLDatabase, WorkspaceTypeEnum.GDBFile, true); |
|
GeoDBAPI.SetGeoDatasetSpatialReference(wsYCLAPI.CurrentWorkspace, ProjectInfo.GetCurentProjectedCoordinate(), ProjectInfo.XYResolution); |
|
|
|
IWorkspaceAPI wsYCLYHAPI = new WorkspaceAPI(ProjectInfo.DTBYCLYHDatabase, WorkspaceTypeEnum.GDBFile, true); |
|
GeoDBAPI.SetGeoDatasetSpatialReference(wsYCLYHAPI.CurrentWorkspace, ProjectInfo.GetCurentProjectedCoordinate(), ProjectInfo.XYResolution); |
|
} |
|
|
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { Content = Platform.Instance.SystemType, MsgType = "LoadDTBViewData" }); |
|
this.CloseLoading(); |
|
this.Close(); |
|
if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK) |
|
SetJCTBLayer(); |
|
MessageHelper.ShowTips("基础数据加载成功!"); |
|
//RoomToMap(hookHelper.FocusMap); |
|
ZoomToJCDLTB(); |
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" }); |
|
//PluginServiceInterface.CommonHelper.ExeCommandOperation("执行全图"); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("BtnLoad_Click异常:" + ex.Message); |
|
LogAPI.Debug("BtnLoad_Click异常:" + ex.StackTrace); |
|
this.CloseLoading(); |
|
MessageHelper.ShowError("基础数据加载异常:" + ex.Message); |
|
} |
|
finally |
|
{ |
|
this.CloseLoading(); |
|
} |
|
} |
|
/// <summary> |
|
/// 设置监测图斑图层 |
|
/// </summary> |
|
private void SetJCTBLayer() |
|
{ |
|
try |
|
{ |
|
object GroupLayerInfo = null; |
|
if (ProjectInfo == null) |
|
ProjectInfo = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo); |
|
if (_DataCatalog == null) |
|
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>(); |
|
if (_DataCatalog == null) return; |
|
IFeatureLayer featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTB"); |
|
if (MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB") == null && featureLayer != null) |
|
{ |
|
IWorkspaceAPI wsAPI = new WorkspaceAPI(ProjectInfo.JCDatabase, WorkspaceTypeEnum.GDBFile); |
|
IWorkspaceAPI wsAPIs = new WorkspaceAPI(ProjectInfo.DTBBGGXDatabase, WorkspaceTypeEnum.GDBFile); |
|
GeoDBAPI.SetGeoDatasetSpatialReference(wsAPI.CurrentWorkspace, (featureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001); |
|
GeoDBAPI.SetGeoDatasetSpatialReference(wsAPIs.CurrentWorkspace, (featureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001); |
|
|
|
ILayer groupLayer = MapsManager.Instance.MapService.GetGroupLayer("JCTBSJ"); |
|
if (groupLayer == null) |
|
{ |
|
groupLayer = new GroupLayer() { Name = "监测数据" }; |
|
ILayerGeneralProperties layerGeneralProperties = groupLayer as ILayerGeneralProperties; |
|
layerGeneralProperties.LayerDescription = "JCTBSJ"; |
|
GroupLayerInfo = _DataCatalog.AddLayer(groupLayer); |
|
} |
|
if (GroupLayerInfo == null) |
|
GroupLayerInfo = _DataCatalog.GetNodeByLayer(groupLayer); |
|
IFeatureClassAPI jctbFcAPI = wsAPI.OpenFeatureClass("JCTB"); |
|
IFeatureLayer JcTBLayer = new FeatureLayer() { Name = "国家监测图斑", FeatureClass = jctbFcAPI.FeatureClass }; |
|
if (JcTBLayer is IFeatureLayerDefinition pFLDefinition) |
|
{ |
|
pFLDefinition.DefinitionExpression = "SJLY='GJJC'"; |
|
} |
|
_DataCatalog.AddLayer(JcTBLayer, GroupLayerInfo); |
|
IFeatureLayer ZZBGTBLayer = new FeatureLayer() { Name = "自主变更图斑", FeatureClass = jctbFcAPI.FeatureClass }; |
|
pFLDefinition = ZZBGTBLayer as IFeatureLayerDefinition; |
|
if (pFLDefinition != null) |
|
{ |
|
pFLDefinition.DefinitionExpression = "SJLY='ZZBG'"; |
|
} |
|
_DataCatalog.AddLayer(ZZBGTBLayer, GroupLayerInfo); |
|
_DataCatalog.UpdateTree(); |
|
if (groupLayer != null) Marshal.ReleaseComObject(groupLayer); |
|
Marshal.ReleaseComObject(groupLayer); |
|
if (wsAPI != null) wsAPI.CloseWorkspace();//释放资源 |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("配置监测变更图层失败:" + ex.Message); |
|
MessageHelper.ShowTips("配置监测变更图层失败:" + ex.Message); |
|
throw ex; |
|
} |
|
} |
|
private void btnClose_Click(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
} |
|
|
|
private void ChkSelectedAll_EditValueChanged(object sender, DevExpress.Xpf.Editors.EditValueChangedEventArgs e) |
|
{ |
|
|
|
} |
|
|
|
private void CheckBox_Click(object sender, RoutedEventArgs e) |
|
{ |
|
|
|
} |
|
#endregion |
|
|
|
/// <summary> |
|
/// 加载目录数据 |
|
/// </summary> |
|
/// <param name="JCMLMC">基础目录名称</param> |
|
private void LoadLayerDataToMap(LayerCfg ParentGroup, List<LayerCfg> layerInfo2s, string FcPath) |
|
{ |
|
try |
|
{ |
|
for (int i = 0; i < layerInfo2s.Count; i++) |
|
{ |
|
LayerCfg GroupLayerInfo = null; |
|
if (layerInfo2s[i].LayerType == EnumLayerType.GroupLayer) |
|
{ |
|
LoadLayerDataToMap(layerInfo2s[i], layerInfo2s[i].Layers, FcPath); |
|
} |
|
else |
|
{ |
|
GroupLayerInfo = GroupLayerInfo ?? ParentGroup; |
|
LayerCfg layerInfo3 = new LayerCfg(); |
|
if (layerInfo2s[i].LayerType == EnumLayerType.FeatureLayer) |
|
{ |
|
//预处理情况下的路径 |
|
if (Platform.Instance.SystemType == SystemTypeEnum.YCLJK) |
|
{ |
|
if (ProjectInfo == null) |
|
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProjectInfo == null) continue; |
|
if ("预处理,标注点,标注线,标注面,自主图斑".Contains(layerInfo2s[i].LayerName)) |
|
{ |
|
FcPath = ProjectInfo.DTBYCLYHDatabase; |
|
} |
|
else if ("外业图斑,重叠图斑".Contains(layerInfo2s[i].LayerName)) |
|
{ |
|
FcPath = ProjectInfo.DTBYCLDatabase; |
|
} |
|
} |
|
layerInfo2s[i].FcPath = FcPath; |
|
if (string.IsNullOrWhiteSpace(layerInfo2s[i].FcPath)) continue; |
|
WorkspaceTypeEnum workspaceType = WorkspaceTypeEnum.GDBFile; |
|
if (layerInfo2s[i].FcPath.ToLower().EndsWith(".mdb")) |
|
{ |
|
if (!File.Exists(layerInfo2s[i].FcPath)) |
|
{ |
|
layerInfo2s.Remove(layerInfo2s[i]); |
|
i--; |
|
continue; |
|
} |
|
workspaceType = WorkspaceTypeEnum.MDBFile; |
|
} |
|
else if (layerInfo2s[i].FcPath.ToLower().EndsWith(".gdb")) |
|
{ |
|
if (!Directory.Exists(layerInfo2s[i].FcPath)) |
|
{ |
|
layerInfo2s.Remove(layerInfo2s[i]); |
|
i--; |
|
continue; |
|
} |
|
workspaceType = WorkspaceTypeEnum.GDBFile; |
|
} |
|
else |
|
{ |
|
workspaceType = WorkspaceTypeEnum.ShapeFile; |
|
} |
|
IWorkspaceAPI wsAPI = new WorkspaceAPI(layerInfo2s[i].FcPath, workspaceType); |
|
//List<IFeatureClass> featureClasses = wsAPI.GetAllFeatureClass(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny); |
|
IFeatureClass fc = null; |
|
if (wsAPI.OpenFeatureClass2(layerInfo2s[i].FcName) == null) |
|
{ |
|
List<IFeatureClass> fcs = wsAPI.GetAllFeatureClass(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny); |
|
if (fcs != null && fcs.Count == 1) |
|
{ |
|
fc = fcs[0]; |
|
layerInfo2s[i].FcName = ((IDataset)fc).Name; |
|
} |
|
} |
|
else |
|
fc = wsAPI.OpenFeatureClass(layerInfo2s[i].FcName).FeatureClass; |
|
if (fc == null) continue; |
|
ILayer tempLayer = new FeatureLayer() { Name = layerInfo2s[i].LayerName, FeatureClass = fc }; |
|
#region 显示比例设置 |
|
tempLayer.MinimumScale = layerInfo2s[i].MinScale; |
|
tempLayer.MaximumScale = layerInfo2s[i].MaxScale; |
|
#endregion |
|
|
|
#region 图层透明度 |
|
if (tempLayer is ILayerEffects mLayerEffects)//透明度 |
|
mLayerEffects.Transparency = (short)layerInfo2s[i].Transparency; |
|
#endregion |
|
|
|
#region 是否显示 |
|
tempLayer.Visible = layerInfo2s[i].Visible;//是否显示 |
|
#endregion |
|
|
|
#region 过滤条件 |
|
IFeatureLayerDefinition pFLDefinition = tempLayer as IFeatureLayerDefinition; |
|
if (pFLDefinition != null) |
|
{ |
|
pFLDefinition.DefinitionExpression = layerInfo2s[i].DefinitionExpression; |
|
} |
|
#endregion |
|
|
|
#region 图层样式 |
|
IFeatureRenderer render = GetSymbol(layerInfo2s[i].Symbol); |
|
if (render != null) |
|
(tempLayer as IGeoFeatureLayer).Renderer = render; |
|
#endregion |
|
|
|
layerInfo2s[i].Data = tempLayer; |
|
if (wsAPI != null) wsAPI.CloseWorkspace(); |
|
} |
|
else if (layerInfo2s[i].LayerType == EnumLayerType.RasterLayer && ParentGroup.LayerName != "参考影像目录") |
|
{ |
|
if (string.IsNullOrWhiteSpace(layerInfo2s[i].FcPath)) continue; |
|
IRasterLayer layer = new RasterLayerClass(); |
|
layer.CreateFromFilePath(layerInfo2s[i].FcPath); |
|
layer.Name = layerInfo2s[i].LayerName; |
|
if (layer is ILayerEffects mLayerEffects) |
|
mLayerEffects.Transparency = (short)layerInfo2s[i].Transparency; |
|
layer.Visible = layerInfo2s[i].Visible; |
|
layerInfo2s[i].Data = layer; |
|
_DataCatalog.AddLayer(layer, GroupLayerInfo); |
|
layerInfo3 = GroupLayerInfo.Layers.FirstOrDefault(x => x.FcName == layer.Name); |
|
} |
|
else if (layerInfo2s[i].LayerType == EnumLayerType.RasterLayer && ParentGroup.LayerName == "参考影像目录") |
|
{ |
|
if (Directory.Exists(Path.Combine(FcPath, layerInfo2s[i].LayerName))) |
|
{ |
|
List<string> vs = InitYXData(Path.Combine(FcPath, layerInfo2s[i].LayerName)); |
|
foreach (var item in vs) |
|
{ |
|
layerInfo2s[i].FcPath = item; |
|
if (string.IsNullOrWhiteSpace(layerInfo2s[i].FcPath)) continue; |
|
IRasterLayer rl = new RasterLayerClass(); |
|
rl.CreateFromFilePath(item); |
|
if (rl.Renderer is IRasterStretch rst) |
|
{ |
|
RgbColorClass rgb = new RgbColorClass |
|
{ |
|
NullColor = true |
|
}; |
|
rst.Background = true; |
|
rst.BackgroundColor = rgb; |
|
rst.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE; |
|
} |
|
layerInfo2s[i].Data = rl; |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("LoadLayerDataToMap异常:" + ex.Message); |
|
LogAPI.Debug("LoadLayerDataToMap异常:" + ex.StackTrace); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 加载保存基础库所有路径 |
|
/// </summary> |
|
private void SaveProjectAllPath() |
|
{ |
|
try |
|
{ |
|
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProjectInfo != null && tableMappings.Count != 0) |
|
{ |
|
foreach (var Pathitem in tableMappings) |
|
{ |
|
switch (Pathitem.S_TableAliasName) |
|
{ |
|
case "参考影像目录": |
|
ProjectInfo.YXPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "5级坡度图": |
|
ProjectInfo.txtfivePDT = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "国检年末库": |
|
ProjectInfo.GJNMKPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "承诺耕地图层": |
|
ProjectInfo.CNGDPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "基础数据库": |
|
ProjectInfo.JCKPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "国家下发监测图斑": |
|
ProjectInfo.GJXFJCPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "撂荒耕地参考图层": |
|
ProjectInfo.LHGDPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "临时用地备案范围": |
|
ProjectInfo.LSYDFWPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "用地管理信息": |
|
ProjectInfo.YDGLXXPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "专项数据目录": |
|
ProjectInfo.ZXSJPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "城镇村等用地参考图层": |
|
ProjectInfo.CZCDYDPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "恢复属性参考图层": |
|
ProjectInfo.GDJHFSXPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
case "坡度图": |
|
ProjectInfo.PDTPath = Pathitem.S_TablePath ?? ""; |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
ProjectInfo.DataBaseName = cobDataBase.Text.ToString().Trim() ?? ""; |
|
ProjectInfo.Save(); |
|
if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK) |
|
MapsManager.Instance.MapService.LoadProject(SysAppPath.GetCurrentAppPath() + "DTBProject\\单图斑建库.KBG"); |
|
else if (Platform.Instance.SystemType == SystemTypeEnum.YCLJK) |
|
MapsManager.Instance.MapService.LoadProject(SysAppPath.GetCurrentAppPath() + "YCLProject\\图斑预处理.KBG"); |
|
else if (Platform.Instance.SystemType == SystemTypeEnum.WYZS) |
|
MapsManager.Instance.MapService.LoadProject(SysAppPath.GetCurrentAppPath() + "DTBZJProject\\单图斑质检.KBG"); |
|
InitJCKXZQDMAndZBX(); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("SaveProjectAllPath异常:" + ex.Message); |
|
LogAPI.Debug("SaveProjectAllPath异常:" + ex.StackTrace); |
|
throw ex; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 提取行政区代码及坐标系 |
|
/// </summary> |
|
/// <param name="dataPath"></param> |
|
/// <returns></returns> |
|
private void InitJCKXZQDMAndZBX() |
|
{ |
|
//解析基础库目录下的矢量数据,读取坐标参考,新建工程的坐标参考以基础库数据坐标参考为准 |
|
if (string.IsNullOrWhiteSpace(cobDataBase.Text)) |
|
{ |
|
throw new Exception("请选择基础库数据目录!"); |
|
} |
|
try |
|
{ |
|
ProjectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
IFeatureLayer featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTB"); |
|
if (featureLayer == null) |
|
featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑"); |
|
if (featureLayer == null || featureLayer.FeatureClass == null || featureLayer.FeatureClass.FeatureCount(null) == 0) |
|
{ |
|
throw new Exception("未加载基础_地类图斑或基础_地类图斑为空值,未能设置行政区代码及坐标系,请加载基础库数据!"); |
|
} |
|
IQueryFilter queryFilter = new QueryFilterClass() |
|
{ |
|
SubFields = featureLayer.FeatureClass.OIDFieldName + ",BSM" |
|
}; |
|
IFeatureCursor featureCursor = null; |
|
IFeature feature = null; |
|
try |
|
{ |
|
featureCursor = featureLayer.FeatureClass.Search(queryFilter, true); |
|
while ((feature = featureCursor.NextFeature()) != null) |
|
{ |
|
XZQDM = feature.get_Value(feature.Fields.FindField("BSM")).ToString().Substring(0, 6); |
|
break; |
|
} |
|
ISpatialReference spatialReference = (featureLayer.FeatureClass as IGeoDataset).SpatialReference; |
|
if (spatialReference == null) |
|
{ |
|
throw new Exception("设置影像失败!"); |
|
} |
|
SetPRJBySp(spatialReference); |
|
ProjectInfo.CODE = XZQDM ?? ""; |
|
ProjectInfo.PrjFileStr = PrjFileStr ?? ""; |
|
ProjectInfo.TXDH = TXDH.ToInt(); |
|
ProjectInfo.ZYJD = ZYJD.ToInt(); |
|
ProjectInfo.Save(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("设置行政区代码失败:" + ex.Message); |
|
LogAPI.Debug("设置行政区代码失败:" + ex.StackTrace); |
|
} |
|
finally |
|
{ |
|
if (featureCursor != null) |
|
{ |
|
Marshal.ReleaseComObject(featureCursor); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
this.XZQDM = ""; |
|
LogAPI.Debug("设置行政区代码失败:" + ex.Message); |
|
} |
|
if (string.IsNullOrWhiteSpace(this.XZQDM)) |
|
{ |
|
throw new Exception("获取基础库行政区代码失败!"); |
|
} |
|
if (string.IsNullOrWhiteSpace(this.PrjFileStr)) |
|
{ |
|
throw new Exception("获取基础库坐标参考失败!"); |
|
} |
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" }); |
|
} |
|
|
|
/// <summary> |
|
/// 设置坐标参考 |
|
/// </summary> |
|
/// <param name="spatialReference"></param> |
|
private void SetPRJBySp(ISpatialReference spatialReference) |
|
{ |
|
int t; |
|
string spatialrefstr = string.Empty; |
|
IESRISpatialReferenceGEN2 prjsr = spatialReference as IESRISpatialReferenceGEN2; |
|
prjsr.ExportToESRISpatialReference2(out spatialrefstr, out t); |
|
this.PrjFileStr = spatialrefstr; |
|
string beginstr = "["; |
|
int leftindex = spatialrefstr.IndexOf(beginstr) + beginstr.Length; |
|
string spatialrefrightstr = spatialrefstr.Substring(leftindex); |
|
int length = spatialrefrightstr.IndexOf(","); |
|
string spatialReferenceName = spatialrefrightstr.Substring(0, length).Replace("\"", ""); |
|
if (spatialReferenceName.ToTrim().ToLower().Contains("3_degree")) |
|
{ |
|
this.FDD = "3"; |
|
//3度分带 |
|
//combFD.SelectedIndex = 0; |
|
} |
|
else if (spatialReferenceName.ToTrim().ToLower().Contains("6_degree")) |
|
{ |
|
this.FDD = "6"; |
|
//6度分带 |
|
//combFD.SelectedIndex = 1; |
|
} |
|
else |
|
{ |
|
this.FDD = "0"; |
|
} |
|
//获取中央经线 |
|
try |
|
{ |
|
this.ZYJD = "0"; |
|
beginstr = "Central_Meridian"; |
|
leftindex = spatialrefstr.IndexOf(beginstr) + beginstr.Length; |
|
if (leftindex > beginstr.Length) |
|
{ |
|
spatialrefrightstr = spatialrefstr.Substring(leftindex); |
|
length = spatialrefrightstr.IndexOf("]"); |
|
double p1 = double.Parse(spatialrefrightstr.Substring(0, length).Split(',')[1]); |
|
this.ZYJD = p1.ToTrim(); |
|
} |
|
} |
|
catch (Exception ex1) |
|
{ |
|
LogAPI.Debug("新建工程 页面 中 设置项目坐标系 过程中 获取中央经线 时失败,异常原因: " + ex1 + " ; "); |
|
} |
|
//获取图形带号 |
|
try |
|
{ |
|
string str_spTXDH = "0"; |
|
this.TXDH = "0"; |
|
beginstr = "False_Easting"; |
|
leftindex = spatialrefstr.IndexOf(beginstr) + beginstr.Length; |
|
if (leftindex > beginstr.Length) |
|
{ |
|
spatialrefrightstr = spatialrefstr.Substring(leftindex); |
|
length = spatialrefrightstr.IndexOf("]"); |
|
string p7 = spatialrefrightstr.Substring(0, length).Split(',')[1]; |
|
//原方法强行转化有问题 |
|
//spTXDH.Text = int.Parse(p7.Replace("500000.0", "")).ToString(); |
|
string sTemp_1 = p7.Replace("500000.0", ""); |
|
int iTemp_1; |
|
if (ExtendMethd.JudgeIsCouldConversionInt(sTemp_1) == true) |
|
{ |
|
iTemp_1 = int.Parse(sTemp_1); |
|
str_spTXDH = iTemp_1.ToString(); |
|
} |
|
else |
|
{ |
|
str_spTXDH = "0"; |
|
} |
|
} |
|
else |
|
{ |
|
str_spTXDH = "0"; |
|
} |
|
this.TXDH = str_spTXDH; |
|
} |
|
catch (Exception ex2) |
|
{ |
|
LogAPI.Debug("新建工程 页面 中 设置项目坐标系 过程中 获取图形带号 时失败,异常原因: " + ex2 + " ; "); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 设置监测图斑图层 |
|
/// </summary> |
|
private void SetJCTBLayer2() |
|
{ |
|
try |
|
{ |
|
object GroupLayerInfo = null; |
|
IFeatureLayer featureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTB"); |
|
if (MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB") == null && featureLayer != null) |
|
{ |
|
IWorkspaceAPI wsAPI = new WorkspaceAPI(ProjectInfo.JCDatabase, WorkspaceTypeEnum.GDBFile); |
|
GeoDBAPI.SetGeoDatasetSpatialReference(wsAPI.CurrentWorkspace, (featureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001); |
|
ILayer groupLayer = MapsManager.Instance.MapService.GetGroupLayer("JCTBSJ"); |
|
if (groupLayer == null) |
|
{ |
|
groupLayer = new GroupLayer() { Name = "监测数据" }; |
|
ILayerGeneralProperties layerGeneralProperties = groupLayer as ILayerGeneralProperties; |
|
layerGeneralProperties.LayerDescription = "JCTBSJ"; |
|
GroupLayerInfo = _DataCatalog.AddLayer(groupLayer); |
|
} |
|
if (GroupLayerInfo == null) |
|
GroupLayerInfo = _DataCatalog.GetNodeByLayer(groupLayer); |
|
IFeatureClassAPI jctbFcAPI = wsAPI.OpenFeatureClass("JCTB"); |
|
IFeatureLayer JcTBLayer = new FeatureLayer() { Name = "国家监测图斑", FeatureClass = jctbFcAPI.FeatureClass }; |
|
if (JcTBLayer is IFeatureLayerDefinition pFLDefinition) |
|
{ |
|
pFLDefinition.DefinitionExpression = "SJLY='GJJC'"; |
|
} |
|
_DataCatalog.AddLayer(JcTBLayer, GroupLayerInfo); |
|
IFeatureLayer ZZBGTBLayer = new FeatureLayer() { Name = "自主变更图斑", FeatureClass = jctbFcAPI.FeatureClass }; |
|
pFLDefinition = ZZBGTBLayer as IFeatureLayerDefinition; |
|
if (pFLDefinition != null) |
|
{ |
|
pFLDefinition.DefinitionExpression = "SJLY='ZZBG'"; |
|
} |
|
_DataCatalog.AddLayer(ZZBGTBLayer, GroupLayerInfo); |
|
if (groupLayer != null) Marshal.ReleaseComObject(groupLayer); |
|
Marshal.ReleaseComObject(groupLayer); |
|
Marshal.ReleaseComObject(featureLayer); |
|
if (wsAPI != null) wsAPI.CloseWorkspace();//释放资源 |
|
} |
|
if (MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG") == null) |
|
{ |
|
GroupLayerInfo = null; |
|
IWorkspaceAPI wsAPI = new WorkspaceAPI(ProjectInfo.BGDatabase, WorkspaceTypeEnum.GDBFile); |
|
ILayer groupLayer = MapsManager.Instance.MapService.GetGroupLayer("BGSJ"); //new GroupLayer() { Name = "变更数据" }; |
|
if (groupLayer == null) |
|
{ |
|
groupLayer = new GroupLayer() { Name = "变更数据" }; |
|
ILayerGeneralProperties layerGeneralProperties = groupLayer as ILayerGeneralProperties; |
|
layerGeneralProperties.LayerDescription = "BGSJ"; |
|
GroupLayerInfo = _DataCatalog.AddLayer(groupLayer); |
|
} |
|
if (GroupLayerInfo == null) |
|
GroupLayerInfo = _DataCatalog.GetNodeByLayer(groupLayer); |
|
IFeatureClassAPI bgtbFcAPI = wsAPI.OpenFeatureClass("DLTBBG"); |
|
IFeatureLayer tempLayer = new FeatureLayer() { Name = "变更范围", FeatureClass = bgtbFcAPI.FeatureClass }; |
|
SetILayerSymbol(tempLayer, "DLTBBG"); |
|
_DataCatalog.AddLayer(tempLayer, GroupLayerInfo); |
|
_DataCatalog.UpdateTree(); |
|
System.Windows.Forms.Application.DoEvents();//处理当前交互产生的延迟过程(后续可优化数据绑定逻辑) |
|
Marshal.ReleaseComObject(groupLayer); |
|
if (wsAPI != null) wsAPI.CloseWorkspace();//释放资源 |
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { Content = Platform.Instance.SystemType, MsgType = "LoadDTBViewData" }); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("配置监测变更图层失败:" + ex.Message); |
|
MessageHelper.ShowTips("" + ex.Message); |
|
} |
|
} |
|
|
|
private void SetILayerSymbol(IFeatureLayer tempLayer, string LayerAliseName) |
|
{ |
|
IFeatureRenderer result = null; |
|
ISystemCfg cfg2 = BundleRuntime.Instance.GetFirstOrDefaultService<ISystemCfg>(); |
|
SystemCfg = cfg2.Load(); |
|
if (SystemCfg.BGLayerLoadCfg == null) |
|
{ |
|
SystemCfg.BGLayerLoadCfg = new List<LayerCfg>(); |
|
} |
|
LayerCfg layerCfg = SystemCfg.BGLayerLoadCfg.FirstOrDefault(x => x.FcName == LayerAliseName);//默认配置默认不为NULL |
|
if (layerCfg != null && !string.IsNullOrWhiteSpace(layerCfg.Symbol)) |
|
{ |
|
AdvancedDrawingInfo ad = AdvancedDrawingInfo.FromJson(layerCfg.Symbol); |
|
if (ad != null) |
|
{ |
|
if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.SimpleRenderer) |
|
{ |
|
Symbol symbol1 = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol; |
|
ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol1, SymbolTypeEnum.Fill); |
|
result = simpleRander2 as IFeatureRenderer; |
|
} |
|
else if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer) |
|
{ |
|
Renderer rander = ad.DrawingInfo.Renderer; |
|
IUniqueValueRenderer uniqueValueRander = SymbolConvert.Instance().GetUniqueValueRenderer(rander, SymbolTypeEnum.Fill); |
|
result = uniqueValueRander as IFeatureRenderer; |
|
} |
|
} |
|
#region 样式 |
|
if (result != null) |
|
(tempLayer as IGeoFeatureLayer).Renderer = result; |
|
#endregion |
|
|
|
#region 显示比例设置 |
|
tempLayer.MinimumScale = layerCfg.MinScale; |
|
tempLayer.MaximumScale = layerCfg.MaxScale; |
|
#endregion |
|
|
|
#region 图层透明度 |
|
if (tempLayer is ILayerEffects mLayerEffects)//透明度 |
|
mLayerEffects.Transparency = (short)layerCfg.Transparency; |
|
#endregion |
|
|
|
#region 是否显示 |
|
tempLayer.Visible = layerCfg.Visible;//是否显示 |
|
#endregion |
|
|
|
#region 是否可选择 |
|
tempLayer.Selectable = layerCfg.Selectable; |
|
#endregion |
|
|
|
#region 过滤条件 |
|
IFeatureLayerDefinition pFLDefinition = tempLayer as IFeatureLayerDefinition; |
|
if (pFLDefinition != null) |
|
{ |
|
pFLDefinition.DefinitionExpression = layerCfg.DefinitionExpression; |
|
} |
|
#endregion |
|
} |
|
} |
|
|
|
#region 全图展示 |
|
public bool RoomToMap(IMap pMap) |
|
{ |
|
try |
|
{ |
|
if (pMap == null) |
|
{ |
|
return false; |
|
} |
|
IActiveView pActiveView = pMap as IActiveView; |
|
double minValue = double.MinValue; |
|
double maxValue = double.MaxValue; |
|
double dlYMax = double.MinValue; |
|
double dlYMin = double.MaxValue; |
|
ILayer pLayer = null; |
|
for (int i = 0; i < pMap.LayerCount; i++) |
|
{ |
|
pLayer = pMap.get_Layer(i); |
|
if (pLayer is ICompositeLayer) |
|
{ |
|
GetCompositeLayerSideCoordinate(pLayer as ICompositeLayer, ref minValue, ref maxValue, ref dlYMax, ref dlYMin); |
|
|
|
} |
|
else |
|
{ |
|
GetLayerSideCoordinate(pLayer, ref minValue, ref maxValue, ref dlYMax, ref dlYMin); |
|
} |
|
} |
|
if ((((minValue == double.MinValue) && (maxValue == double.MaxValue)) && (dlYMax == double.MinValue)) && (dlYMin == double.MaxValue)) |
|
{ |
|
pActiveView.Extent = pActiveView.FullExtent; |
|
PartialRefresh(pActiveView); |
|
} |
|
else |
|
{ |
|
IEnvelope pGeometry = new EnvelopeClass();//GetEnvByCoor(minValue, maxValue, dlYMax, dlYMin); |
|
pGeometry.XMax = minValue; |
|
pGeometry.XMin = maxValue; |
|
pGeometry.YMax = dlYMax; |
|
pGeometry.YMin = dlYMin; |
|
|
|
LocateGeometry(pActiveView, pGeometry, 0.2); |
|
} |
|
|
|
return true; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("全图展示异常:" + ex); |
|
throw ex; |
|
} |
|
} |
|
private bool GetCompositeLayerSideCoordinate(ICompositeLayer pCompositeLayer, ref double dlXMax, ref double dlXMin, ref double dlYMax, ref double dlYMin) |
|
{ |
|
if (pCompositeLayer == null) |
|
{ |
|
return false; |
|
} |
|
for (int i = 0; i < pCompositeLayer.Count; i++) |
|
{ |
|
ILayer pLayer = pCompositeLayer.get_Layer(i); |
|
if (pLayer is ICompositeLayer) |
|
{ |
|
if (!GetCompositeLayerSideCoordinate(pLayer as ICompositeLayer, ref dlXMax, ref dlXMin, ref dlYMax, ref dlYMin)) |
|
{ |
|
return false; |
|
} |
|
} |
|
else if (!GetLayerSideCoordinate(pLayer, ref dlXMax, ref dlXMin, ref dlYMax, ref dlYMin)) |
|
{ |
|
return false; |
|
} |
|
} |
|
return true; |
|
} |
|
private bool GetLayerSideCoordinate(ILayer pLayer, ref double dlXMax, ref double dlXMin, ref double dlYMax, ref double dlYMin) |
|
{ |
|
if (pLayer == null || !pLayer.Valid) |
|
{ |
|
return false; |
|
} |
|
if (pLayer.Name.ToUpper() == "DEFAULT") |
|
return true; |
|
if (pLayer is ITable) |
|
{ |
|
try |
|
{ |
|
if ((pLayer as ITable).RowCount(null) == 0) |
|
{ |
|
return true; |
|
} |
|
} |
|
catch (Exception) |
|
{ |
|
} |
|
} |
|
IEnvelope areaOfInterest = pLayer.AreaOfInterest; |
|
if (areaOfInterest != null) |
|
{ |
|
dlXMax = Math.Max(dlXMax, areaOfInterest.XMax); |
|
dlXMin = Math.Min(dlXMin, areaOfInterest.XMin); |
|
dlYMax = Math.Max(dlYMax, areaOfInterest.YMax); |
|
dlYMin = Math.Min(dlYMin, areaOfInterest.YMin); |
|
} |
|
return true; |
|
} |
|
public bool LocateGeometry(IActiveView pActiveView, IGeometry pGeometry, double dblRatio) |
|
{ |
|
try |
|
{ |
|
if ((pGeometry == null) || (pActiveView == null)) |
|
{ |
|
return false; |
|
} |
|
if (pGeometry.IsEmpty) |
|
{ |
|
return false; |
|
} |
|
if ((pGeometry is IPoint) || (pGeometry is IMultipoint)) |
|
{ |
|
ITopologicalOperator @operator = pGeometry as ITopologicalOperator; |
|
@operator.Simplify(); |
|
pGeometry = @operator.Buffer(100.0); |
|
} |
|
IEnvelope envelope = pGeometry.Envelope; |
|
IPoint p = new PointClass(); |
|
if (envelope != null) |
|
{ |
|
p.X = (envelope.XMin + envelope.XMax) / 2.0; |
|
p.Y = (envelope.YMin + envelope.YMax) / 2.0; |
|
} |
|
double num = pActiveView.Extent.Width / pActiveView.Extent.Height; |
|
double num2 = envelope.Width / envelope.Height; |
|
if (num > num2) |
|
{ |
|
envelope.Width = envelope.Height * num; |
|
} |
|
else |
|
{ |
|
envelope.Height = envelope.Width / num; |
|
} |
|
envelope.Expand(1.0 + dblRatio, 1.0 + dblRatio, true); |
|
envelope.CenterAt(p); |
|
if (envelope.SpatialReference != pActiveView.FocusMap.SpatialReference) |
|
{ |
|
envelope.Project(pActiveView.FocusMap.SpatialReference); |
|
} |
|
pActiveView.Extent = envelope; |
|
//pActiveView.Extent.PutCoords(envelope.XMin, envelope.YMin, envelope.XMax, envelope.YMax); |
|
PartialRefresh(pActiveView); |
|
pActiveView.ScreenDisplay.UpdateWindow(); |
|
return true; |
|
} |
|
catch (Exception) |
|
{ |
|
return false; |
|
} |
|
} |
|
public bool PartialRefresh(IActiveView pActiveView) |
|
{ |
|
if (pActiveView == null) |
|
{ |
|
return false; |
|
} |
|
PartialRefresh(pActiveView, esriViewDrawPhase.esriViewForeground | esriViewDrawPhase.esriViewGraphicSelection | esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewBackground); |
|
return true; |
|
} |
|
public bool PartialRefresh(IActiveView pActiveView, esriViewDrawPhase enumViewDrawPhase) |
|
{ |
|
if (pActiveView == null) |
|
{ |
|
return false; |
|
} |
|
pActiveView.PartialRefresh(enumViewDrawPhase, null, pActiveView.Extent); |
|
return true; |
|
} |
|
#endregion |
|
|
|
#region 缩放至基础地类图斑 |
|
private void ZoomToJCDLTB() |
|
{ |
|
try |
|
{ |
|
if (hookHelper == null) |
|
return; |
|
object layer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("基础_地类图斑"); |
|
if (layer is ILayer) |
|
{ |
|
if (hookHelper.Hook is IPageLayoutControlDefault) |
|
{ |
|
IActiveView activeView = hookHelper.ActiveView; |
|
IDisplayTransformation displayTransformation = activeView.ScreenDisplay.DisplayTransformation; |
|
displayTransformation.VisibleBounds = (layer as ILayer).AreaOfInterest; |
|
hookHelper.ActiveView.Refresh(); |
|
} |
|
else |
|
{ |
|
this.hookHelper.ActiveView.Extent = (layer as ILayer).AreaOfInterest; |
|
} |
|
this.hookHelper.ActiveView.Refresh(); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("ZoomToJCDLTB异常:" + ex.Message); |
|
LogAPI.Debug("ZoomToJCDLTB异常:" + ex.StackTrace); |
|
} |
|
} |
|
#endregion |
|
|
|
} |
|
}
|
|
|