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.
490 lines
22 KiB
490 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.Framework.Maps; |
|
using Kingo.Plugin.MapView.Entity; |
|
using Kingo.PluginServiceInterface; |
|
|
|
namespace Kingo.Plugin.MapView.Views |
|
{ |
|
/// <summary> |
|
/// UCLayerStyleSet.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 IActiveView _activeView; |
|
//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(); |
|
_activeView = MapsManager.Instance.MapService.getAxMapControl().ActiveView; |
|
} |
|
|
|
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 = GetDefaultSymbol(this.GeometryType); |
|
} |
|
this.m_FillSymbol = (this.m_Symbol as IFillSymbol); |
|
|
|
} |
|
BindSelection(); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
} |
|
|
|
|
|
private ISymbol GetDefaultSymbol(esriGeometryType geometryType) |
|
{ |
|
try |
|
{ |
|
ISymbol result = null; |
|
IRgbColor rgbColor = new RgbColorClass(); |
|
rgbColor.Red = 184; |
|
rgbColor.Green = 242; |
|
rgbColor.Blue = 200; |
|
switch (geometryType) |
|
{ |
|
case esriGeometryType.esriGeometryPoint: |
|
result = (new SimpleMarkerSymbolClass |
|
{ |
|
Color = rgbColor, |
|
Style = esriSimpleMarkerStyle.esriSMSCircle |
|
} as ISymbol); |
|
goto IL_B3; |
|
case esriGeometryType.esriGeometryMultipoint: |
|
goto IL_B3; |
|
case esriGeometryType.esriGeometryPolyline: |
|
break; |
|
case esriGeometryType.esriGeometryPolygon: |
|
result = (new SimpleFillSymbolClass |
|
{ |
|
Color = rgbColor, |
|
Style = esriSimpleFillStyle.esriSFSSolid |
|
} as ISymbol); |
|
goto IL_B3; |
|
default: |
|
if (geometryType != esriGeometryType.esriGeometryLine) |
|
{ |
|
goto IL_B3; |
|
} |
|
break; |
|
} |
|
result = (new SimpleLineSymbolClass |
|
{ |
|
Color = rgbColor, |
|
Width = 1.0, |
|
Style = esriSimpleLineStyle.esriSLSSolid |
|
} as ISymbol); |
|
IL_B3: |
|
return result; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
return null; |
|
} |
|
|
|
|
|
|
|
private void Close(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
} |
|
|
|
|
|
/// <summary> |
|
/// 绑定选中的图层样式 |
|
/// </summary> |
|
private void BindSelection() |
|
{ |
|
IWorkspaceFactory pWSFactory = null; |
|
IFeatureClass SourceFeatureClass = null; |
|
try |
|
{ |
|
string appLayerConfigspath = System.IO.Path.Combine((MapsManager.Instance.CurrProjectInfo as ProjectInfo).ProjDir, "AppLayerConfigs.xml"); |
|
|
|
if (!System.IO.File.Exists(appLayerConfigspath)) |
|
{ |
|
XmlDataDocument xml = new XmlDataDocument(); |
|
XmlElement layersElement = xml.CreateElement("Layers"); |
|
xml.AppendChild(layersElement); |
|
xml.Save(appLayerConfigspath); |
|
|
|
} |
|
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.LayerLableName = item.Attribute("LayerLableName").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"); |
|
} |
|
|
|
LayerLabelName.Items.Clear(); |
|
if (this.m_Layer is IFeatureLayer) |
|
{ |
|
try |
|
{ |
|
|
|
IFeatureLayer featureLayer = this.m_Layer as IFeatureLayer; |
|
if (featureLayer != null) |
|
SourceFeatureClass = featureLayer.FeatureClass; |
|
} |
|
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.LayerLableName; |
|
} |
|
//图层边框样式 |
|
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 |
|
{ |
|
string appLayerConfigspath = System.IO.Path.Combine((MapsManager.Instance.CurrProjectInfo as ProjectInfo).ProjDir, "AppLayerConfigs.xml"); |
|
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("LayerLableName", 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; |
|
} |
|
} |
|
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 layerLableName = new XAttribute("LayerLableName", ""); |
|
xLayer.Add(layerName, layerCaption, layerBorderStyle, layerBorderWidth, layerFillColor, layerBorderColor, layerLableColor, layerLableName); |
|
|
|
element.Add(xLayer); |
|
xDoc.Save(appLayerConfigspath); |
|
SeDataCatalogStyle(); |
|
} |
|
|
|
this.Close(); |
|
} |
|
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; |
|
} |
|
} |
|
_activeView.PartialRefresh(esriViewDrawPhase.esriViewAll, m_Layer, _activeView.Extent); |
|
} |
|
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(); |
|
} |
|
} |
|
}
|
|
|