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.
464 lines
22 KiB
464 lines
22 KiB
using System; |
|
using System.Collections.Generic; |
|
using ESRI.ArcGIS.Geometry; |
|
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Display; |
|
using ESRI.ArcGIS.ADF; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.esriSystem; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using System.Runtime.InteropServices; |
|
using ESRI.ArcGIS.DataSourcesFile; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
using System.Windows.Data; |
|
using System.Windows.Documents; |
|
using System.Windows.Input; |
|
using System.Drawing; |
|
using System.Xml.Linq; |
|
using System.Data; |
|
using System.Xml; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Plugin.LayerProperty.Entity; |
|
using KGIS.Plugin.LayerProperty.Utils; |
|
using KGIS.Framework.Maps; |
|
using Kingo.PluginServiceInterface; |
|
|
|
namespace KGIS.Plugin.LayerProperty.View |
|
{ |
|
/// <summary> |
|
/// UCStyleSet.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class UCLayerStyleSet : BaseWindow |
|
{ |
|
private string m_CurrentName = string.Empty; |
|
private ILayer m_Layer; |
|
private esriGeometryType GeometryType; |
|
private IStyleGalleryClass m_SymbologyStyleClass; |
|
private ISymbol m_Symbol; |
|
private IFillSymbol m_FillSymbol; |
|
//private IHookHelper m_hookHelper { get; set; } |
|
public UCLayerStyleSet(ILayer layer) |
|
{ |
|
InitializeComponent(); |
|
//this.m_hookHelper = hookHelper; |
|
this.m_Layer = layer; |
|
//IFeatureLayer feature = this.m_Layer as IFeatureLayer; |
|
//this.m_CurrentName = feature.FeatureClass.AliasName; |
|
this.m_CurrentName = layer.Name; |
|
this.Title = m_CurrentName + "图层样式设置"; |
|
InitData(); |
|
} |
|
|
|
private void InitData() |
|
{ |
|
try |
|
{ |
|
IFeatureLayer2 featureLayer = this.m_Layer as IFeatureLayer2; |
|
if (featureLayer != null) |
|
{ |
|
this.GeometryType = featureLayer.ShapeType; |
|
switch (this.GeometryType) |
|
{ |
|
case esriGeometryType.esriGeometryPoint: |
|
this.m_SymbologyStyleClass = new MarkerSymbolStyleGalleryClassClass(); |
|
break; |
|
case esriGeometryType.esriGeometryPolyline: |
|
this.m_SymbologyStyleClass = new LineSymbolStyleGalleryClassClass(); |
|
break; |
|
case esriGeometryType.esriGeometryPolygon: |
|
this.m_SymbologyStyleClass = new FillSymbolStyleGalleryClassClass(); |
|
break; |
|
} |
|
ISimpleRenderer simpleRenderer = (featureLayer as IGeoFeatureLayer).Renderer as ISimpleRenderer; |
|
if (simpleRenderer != null) |
|
{ |
|
this.m_Symbol = simpleRenderer.Symbol; |
|
} |
|
else |
|
{ |
|
this.m_Symbol = RenderUtil.GetDefaultSymbol(this.GeometryType); |
|
} |
|
this.m_FillSymbol = (this.m_Symbol as IFillSymbol); |
|
|
|
} |
|
BindSelection(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
} |
|
|
|
|
|
|
|
private void Close(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
} |
|
|
|
|
|
/// <summary> |
|
/// 绑定选中的图层样式 |
|
/// </summary> |
|
private void BindSelection() |
|
{ |
|
IWorkspaceFactory pWSFactory = null; |
|
IFeatureClass SourceFeatureClass = null; |
|
try |
|
{ |
|
if (MapsManager.Instance.CurrProjectInfo == null) return; |
|
string appLayerConfigspath = System.IO.Path.Combine((MapsManager.Instance.CurrProjectInfo as ProjectInfo).ProjDir, "AppLayerConfigs.xml"); |
|
if (!System.IO.File.Exists(appLayerConfigspath)) |
|
{ |
|
return; |
|
} |
|
bool isHave = false;//图层配置默认没有 |
|
LayerEntity selectEntity = new LayerEntity(); |
|
XDocument xDoc = XDocument.Load(appLayerConfigspath); |
|
XElement element = xDoc.Element("Layers"); |
|
foreach (var item in element.Elements("Layer")) |
|
{ |
|
if (item.Attribute("LayerCaption").Value == m_CurrentName) |
|
{ |
|
isHave = true; |
|
selectEntity.LayerName = item.Attribute("LayerName").Value; |
|
selectEntity.LayerLabelName = item.Attribute("LayerLabelName").Value; |
|
selectEntity.LayerCaption = item.Attribute("LayerCaption").Value; |
|
selectEntity.LayerBorderStyle = int.Parse(item.Attribute("LayerBorderStyle").Value); |
|
selectEntity.LayerBorderWidth = double.Parse(item.Attribute("LayerBorderWidth").Value); |
|
selectEntity.LayerFillColor = ColorTranslator.FromHtml(item.Attribute("LayerFillColor").Value); |
|
selectEntity.LayerBorderColor = ColorTranslator.FromHtml(item.Attribute("LayerBorderColor").Value); |
|
selectEntity.LayerLableColor = ColorTranslator.FromHtml(item.Attribute("LayerLableColor").Value); |
|
if (item.Attribute("LayerPath") != null) |
|
{ |
|
selectEntity.LayerPath = item.Attribute("LayerPath").Value; |
|
} |
|
break; |
|
} |
|
} |
|
if (isHave == false) |
|
{ |
|
selectEntity.LayerCaption = m_CurrentName; |
|
selectEntity.LayerBorderStyle = 0; |
|
selectEntity.LayerBorderWidth = 1; |
|
Color fillColor = Converter.FromRGBColor(this.m_FillSymbol.Color as IRgbColor); |
|
selectEntity.LayerFillColor = fillColor; |
|
selectEntity.LayerBorderColor = Converter.FromRGBColor(this.m_FillSymbol.Outline.Color as IRgbColor); |
|
selectEntity.LayerLableColor = ColorTranslator.FromHtml("#FF000000"); |
|
//if (m_CurrentName == "调绘成果") |
|
//{ |
|
// string prodic = Platform.Instance.GetProjectInfo().ProjDir; |
|
// string dgbpath = System.IO.Path.Combine(prodic, "外业助手.gdb\\WYDH\\DHCG"); |
|
// selectEntity.LayerPath = dgbpath; |
|
|
|
//} |
|
} |
|
|
|
LayerLabelName.Items.Clear(); |
|
if (!string.IsNullOrEmpty(selectEntity.LayerPath)) |
|
{ |
|
try |
|
{ |
|
if (selectEntity.LayerPath.ToUpper().EndsWith("SHP") && true == System.IO.File.Exists(selectEntity.LayerPath)) |
|
{ |
|
string filename = System.IO.Path.GetDirectoryName(selectEntity.LayerPath); |
|
|
|
pWSFactory = new ShapefileWorkspaceFactoryClass(); |
|
IWorkspace pWorkspace = pWSFactory.OpenFromFile(filename, 0); |
|
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; |
|
SourceFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(selectEntity.LayerPath)); |
|
|
|
|
|
} |
|
else |
|
{ |
|
if (!string.IsNullOrWhiteSpace(selectEntity.LayerName)) |
|
{ |
|
SourceFeatureClass= MapsManager.Instance.MapService.GetFeatureClassByName(selectEntity.LayerName); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
|
|
} |
|
|
|
|
|
if (SourceFeatureClass != null) |
|
{ |
|
for (int i = 0; i < SourceFeatureClass.Fields.FieldCount; i++) |
|
{ |
|
IField field = SourceFeatureClass.Fields.Field[i]; |
|
if (field.Name.ToLower().Contains("shape")) |
|
continue; |
|
LayerLabelName.Items.Add(field.Name); |
|
} |
|
} |
|
LayerLabelName.SelectedItem = selectEntity.LayerLabelName; |
|
} |
|
//图层边框样式 |
|
LayerBorderStyle.SelectedValue = selectEntity.LayerBorderStyle; |
|
//图层边框宽度 |
|
LayerBorderWidth.Text = selectEntity.LayerBorderWidth.ToString(); |
|
//图层填充颜色 |
|
LayerFillColor.Color = System.Windows.Media.Color.FromArgb(selectEntity.LayerFillColor.A, selectEntity.LayerFillColor.R, selectEntity.LayerFillColor.G, selectEntity.LayerFillColor.B); |
|
//图层边框颜色 |
|
LayerBorderColor.Color = System.Windows.Media.Color.FromArgb(selectEntity.LayerBorderColor.A, selectEntity.LayerBorderColor.R, selectEntity.LayerBorderColor.G, selectEntity.LayerBorderColor.B); |
|
//标注填充颜色 |
|
LayerLableColor.Color = System.Windows.Media.Color.FromArgb(selectEntity.LayerLableColor.A, selectEntity.LayerLableColor.R, selectEntity.LayerLableColor.G, selectEntity.LayerLableColor.B); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
finally { |
|
if(pWSFactory!=null) |
|
Marshal.ReleaseComObject(pWSFactory); |
|
|
|
} |
|
|
|
} |
|
/// <summary> |
|
/// 获取图层筛选中的图层 |
|
/// </summary> |
|
/// <returns></returns> |
|
private void btnSave_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
if (MapsManager.Instance.CurrProjectInfo == null) return; |
|
string appLayerConfigspath = System.IO.Path.Combine((MapsManager.Instance.CurrProjectInfo as ProjectInfo).ProjDir, "AppLayerConfigs.xml"); |
|
if (!System.IO.File.Exists(appLayerConfigspath)) return; |
|
bool configisHave = false;//默认没有配置 |
|
IMapControlDefault mapcontrol = MapsManager.Instance.MapService.Hook as IMapControlDefault; |
|
XDocument xDoc = XDocument.Load(appLayerConfigspath); |
|
XElement element = xDoc.Element("Layers"); |
|
foreach (var item in element.Elements("Layer")) |
|
{ |
|
if (item.Attribute("LayerCaption").Value == m_CurrentName) |
|
{ |
|
configisHave = true; |
|
string layerLabelName = LayerLabelName.SelectedItem == null ? "" : LayerLabelName.SelectedItem.ToString(); |
|
item.SetAttributeValue("LayerLabelName", layerLabelName); |
|
item.SetAttributeValue("LayerBorderStyle", LayerBorderStyle.SelectedValue.ToString()); |
|
item.SetAttributeValue("LayerBorderWidth", LayerBorderWidth.Text.Trim()); |
|
item.SetAttributeValue("LayerFillColor", System.Windows.Media.Color.FromArgb(LayerFillColor.Color.A, LayerFillColor.Color.R, LayerFillColor.Color.G, LayerFillColor.Color.B)); |
|
item.SetAttributeValue("LayerBorderColor", System.Windows.Media.Color.FromArgb(LayerBorderColor.Color.A, LayerBorderColor.Color.R, LayerBorderColor.Color.G, LayerBorderColor.Color.B)); |
|
item.SetAttributeValue("LayerLableColor", System.Windows.Media.Color.FromArgb(LayerLableColor.Color.A, LayerLableColor.Color.R, LayerLableColor.Color.G, LayerLableColor.Color.B)); |
|
List<LayerField> lstField = ReadlistfromXml(item.Elements("LayerField")); |
|
bool isHave = false; |
|
foreach (LayerField field in lstField) |
|
{ |
|
if (field.Name == layerLabelName) |
|
{ |
|
isHave = true; |
|
} |
|
} |
|
if (!isHave) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
XElement newElement = new XElement("LayerField"); |
|
newElement.Add(new XAttribute("Name", layerLabelName)); |
|
newElement.Add(new XAttribute("Alias", layerLabelName)); |
|
item.Add(newElement); |
|
} |
|
SeDataCatalogStyle(layerLabelName); |
|
break; |
|
} |
|
} |
|
|
|
// if (m_hookHelper.ActiveView != null) |
|
// { |
|
// //调用此函数使TOC能够被update |
|
// m_hookHelper.ActiveView.ContentsChanged(); |
|
// m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground | esriViewDrawPhase.esriViewForeground | |
|
//esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection | |
|
//esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGraphicSelection, null, m_hookHelper.ActiveView.Extent); |
|
// } |
|
element.Save(appLayerConfigspath); |
|
|
|
if (configisHave == false)//在配置文件中未找到图层的配置项 |
|
{ |
|
XElement xLayer = new XElement("Layer"); |
|
IFeatureLayer feature = this.m_Layer as IFeatureLayer; |
|
string layerNameStr = feature.Name; |
|
string layerCaptionStr = feature.FeatureClass.AliasName; |
|
//图层别名 |
|
XAttribute layerName = new XAttribute("LayerName", layerNameStr); |
|
//图层别名 |
|
XAttribute layerCaption = new XAttribute("LayerCaption", layerCaptionStr); |
|
//边框样式 |
|
XAttribute layerBorderStyle = new XAttribute("LayerBorderStyle", LayerBorderStyle.SelectedValue.ToString()); |
|
//边框宽度 |
|
XAttribute layerBorderWidth = new XAttribute("LayerBorderWidth", LayerBorderWidth.Text.Trim()); |
|
|
|
//填充颜色 |
|
XAttribute layerFillColor = new XAttribute("LayerFillColor", System.Windows.Media.Color.FromArgb(LayerFillColor.Color.A, LayerFillColor.Color.R, LayerFillColor.Color.G, LayerFillColor.Color.B)); |
|
//边框颜色 |
|
XAttribute layerBorderColor = new XAttribute("LayerBorderColor", System.Windows.Media.Color.FromArgb(LayerBorderColor.Color.A, LayerBorderColor.Color.R, LayerBorderColor.Color.G, LayerBorderColor.Color.B)); |
|
//标签颜色 |
|
XAttribute layerLableColor = new XAttribute("LayerLableColor", System.Windows.Media.Color.FromArgb(LayerLableColor.Color.A, LayerLableColor.Color.R, LayerLableColor.Color.G, LayerLableColor.Color.B)); |
|
|
|
XAttribute layerLabelName = new XAttribute("LayerLabelName", ""); |
|
xLayer.Add(layerName, layerCaption, layerBorderStyle, layerBorderWidth, layerFillColor, layerBorderColor, layerLableColor, layerLabelName); |
|
|
|
element.Add(xLayer); |
|
xDoc.Save(appLayerConfigspath); |
|
SeDataCatalogStyle(); |
|
} |
|
|
|
MessageHelper.Show("保存成功"); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
} |
|
|
|
private void SeDataCatalogStyle(string layerLabelName="") |
|
{ |
|
try |
|
{ |
|
if (this.m_FillSymbol != null) |
|
{ |
|
//填充颜色 |
|
IColor color = this.m_FillSymbol.Color; |
|
Color fillColor = System.Drawing.Color.FromArgb(LayerFillColor.Color.A, LayerFillColor.Color.R, LayerFillColor.Color.G, LayerFillColor.Color.B); |
|
color = (IColor)Converter.ToRGBColor(fillColor); |
|
color.Transparency = LayerFillColor.Color.A; |
|
this.m_FillSymbol.Color = color; |
|
|
|
|
|
//设置边框颜色、样式、宽度 |
|
ISimpleLineSymbol pMarkerLineSymbol = new SimpleLineSymbolClass(); |
|
Color borderColor = System.Drawing.Color.FromArgb(LayerBorderColor.Color.A, LayerBorderColor.Color.R, LayerBorderColor.Color.G, LayerBorderColor.Color.B); |
|
IColor outlineColor = (IColor)Converter.ToRGBColor(borderColor); |
|
pMarkerLineSymbol.Width = Math.Abs(Convert.ToDouble(LayerBorderWidth.Text.Trim())); |
|
pMarkerLineSymbol.Color = outlineColor; |
|
outlineColor.Transparency = this.LayerBorderColor.Color.A; |
|
|
|
if (LayerBorderStyle.SelectedValue.ToString() == "0")//实线 |
|
{ |
|
pMarkerLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; |
|
} |
|
else if (LayerBorderStyle.SelectedValue.ToString() == "1")//虚线 |
|
{ |
|
pMarkerLineSymbol.Style = esriSimpleLineStyle.esriSLSDash; |
|
} |
|
else if (LayerBorderStyle.SelectedValue.ToString() == "2")//点 |
|
{ |
|
pMarkerLineSymbol.Style = esriSimpleLineStyle.esriSLSDot; |
|
} |
|
else if (LayerBorderStyle.SelectedValue.ToString() == "3")//点划线 |
|
{ |
|
pMarkerLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDot; |
|
} |
|
else if (LayerBorderStyle.SelectedValue.ToString() == "4")//两点划线 |
|
{ |
|
pMarkerLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; |
|
} |
|
this.m_FillSymbol.Outline = pMarkerLineSymbol; |
|
|
|
if (!string.IsNullOrWhiteSpace(layerLabelName)) |
|
{ |
|
IGeoFeatureLayer pGeoFeatureLayer = this.m_Layer as IGeoFeatureLayer; |
|
pGeoFeatureLayer.AnnotationProperties.Clear();//必须执行,因为里面有一个默认的 |
|
IBasicOverposterLayerProperties pBasic = new BasicOverposterLayerPropertiesClass(); |
|
ITextSymbol pTextSymbol = new TextSymbolClass(); |
|
Color textColor = System.Drawing.Color.FromArgb(LayerLableColor.Color.A, LayerLableColor.Color.R, LayerLableColor.Color.G, LayerLableColor.Color.B); |
|
IColor lableColor = (IColor)Converter.ToRGBColor(textColor); |
|
ILabelEngineLayerProperties pLableEngine = new LabelEngineLayerPropertiesClass(); |
|
pTextSymbol.Color = lableColor;//设置字体颜色 |
|
string pLable = "[" + layerLabelName + "]"; |
|
pLableEngine.Expression = pLable; |
|
pLableEngine.IsExpressionSimple = true; |
|
pBasic.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape; |
|
pLableEngine.BasicOverposterLayerProperties = pBasic; |
|
pLableEngine.Symbol = pTextSymbol; |
|
pGeoFeatureLayer.AnnotationProperties.Add(pLableEngine as IAnnotateLayerProperties); |
|
pGeoFeatureLayer.DisplayAnnotation = true; |
|
pLableEngine.Symbol = pTextSymbol; |
|
} |
|
} |
|
} |
|
catch(Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
} |
|
|
|
private List<LayerField> ReadlistfromXml(IEnumerable<XElement> element) |
|
{ |
|
var fields = new List<LayerField>(); |
|
try |
|
{ |
|
if (element != null && element.Count() > 0) |
|
{ |
|
foreach (var item in element) |
|
{ |
|
var layerfield = new LayerField() |
|
{ |
|
Name = item.Attribute("Name").Value, |
|
}; |
|
fields.Add(layerfield); |
|
} |
|
} |
|
return fields; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
return fields; |
|
} |
|
} |
|
|
|
private void LayerBorderWidth_PreviewKeyDown(object sender, KeyEventArgs e) |
|
{ |
|
try |
|
{ |
|
bool shiftKey = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;//判断shifu键是否按下 |
|
if (shiftKey == true) //当按下shift |
|
{ |
|
e.Handled = true;//不可输入 |
|
} |
|
else //未按shift |
|
{ |
|
if (!((e.Key >= Key.D0 && e.Key <= Key.D9) || (e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || e.Key == Key.Delete || e.Key == Key.Back || e.Key == Key.Tab || e.Key == Key.Enter)) |
|
{ |
|
e.Handled = true;//不可输入 |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
} |
|
|
|
private void Layer_SelectionChanged(object sender, SelectionChangedEventArgs e) |
|
{ |
|
try |
|
{ |
|
BindSelection(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
} |
|
|
|
private void Border_MouseDown(object sender, MouseButtonEventArgs e) |
|
{ |
|
//this.DragMove(); |
|
} |
|
} |
|
}
|
|
|