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.
354 lines
17 KiB
354 lines
17 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Display; |
|
using KGIS.Framework.AE.ExtensionMethod; |
|
using KGIS.Framework.Commands; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.Framework.LayerStyleConvert; |
|
using Kingo.Framework.LayerStyleConvert.Common; |
|
using Kingo.Framework.LayerStyleConvert.XSDClass; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using UIShell.OSGi; |
|
|
|
namespace Kingo.Plugin.MapView.Commands |
|
{ |
|
/// <summary> |
|
/// 保存工程-功能点 |
|
/// </summary> |
|
public class CmdSaveProject : BaseMenuCommand |
|
{ |
|
IHookHelper m_hookHelper = null; |
|
private IDataCatalogService _DataCatalog = null; |
|
public override void OnClick() |
|
{ |
|
try |
|
{ |
|
Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" }); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("保存工程时发生异常,异常信息如下:" + ex.Message); |
|
} |
|
} |
|
|
|
private void GetLayersSymbol() |
|
{ |
|
try |
|
{ |
|
if (_DataCatalog == null) |
|
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>(); |
|
|
|
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (projectInfo == null || _DataCatalog.CurrentLayers == null) return; |
|
|
|
//获取图层样式 |
|
LayerCfg layerInfo = _DataCatalog.CurrentLayers as LayerCfg; |
|
List<LayerCfg> list = layerInfo.GetAllItem(); |
|
if (list != null && list.Count != 0) |
|
{ |
|
foreach (var item in list) |
|
{ |
|
ILayer layer = item.Data as ILayer; |
|
if (layer != null) |
|
{ |
|
if (layer is IFeatureLayer) |
|
{ |
|
if (layer.Name == "变更范围图斑") |
|
{ |
|
} |
|
Renderer randerer = SymbolConvert.Instance().GetRenderer((layer as IGeoFeatureLayer).Renderer); |
|
LabelingInfo labelingInfo = null; |
|
LabelStyleConvert styleConvert = new LabelStyleConvert(); |
|
List<LabelingInfo> labelInfo = styleConvert.EsriLabelToCustomLabels((layer as IGeoFeatureLayer).AnnotationProperties); |
|
if (labelInfo != null && labelInfo.Count > 0) |
|
labelingInfo = labelInfo[0]; |
|
|
|
if (labelingInfo != null) |
|
{ |
|
//AdvancedDrawimgInfoManager ad = new AdvancedDrawimgInfoManager(); |
|
//string jsons = ad.GetRenderer(randerer, labelingInfo); |
|
//item.Symbol = jsons; |
|
AdvancedDrawingInfo adi = new AdvancedDrawingInfo(); |
|
adi.DrawingInfo.Renderer = randerer; |
|
adi.DrawingInfo.LabelingInfo = labelInfo; |
|
item.Symbol = adi.ToJson(); |
|
|
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
private void SaveLayersToXML() |
|
{ |
|
try |
|
{ |
|
if (_DataCatalog == null) |
|
_DataCatalog = BundleRuntime.Instance.GetFirstOrDefaultService<IDataCatalogService>(); |
|
|
|
ProjectInfo projectInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (projectInfo == null || _DataCatalog.CurrentLayers == null) return; |
|
|
|
//获取图层样式 |
|
LayerCfg layerInfo = _DataCatalog.CurrentLayers as LayerCfg; |
|
List<LayerCfg> list = layerInfo.GetAllItem(); |
|
if (list != null && list.Count != 0) |
|
{ |
|
foreach (var item in list) |
|
{ |
|
ILayer layer = item.Data as ILayer; |
|
if (layer != null) |
|
{ |
|
if (layer is IFeatureLayer) |
|
{ |
|
if (layer.Name == "变更范围图斑") |
|
{ |
|
} |
|
Renderer randerer = SymbolConvert.Instance().GetRenderer((layer as IGeoFeatureLayer).Renderer); |
|
LabelingInfo labelingInfo = null; |
|
LabelStyleConvert styleConvert = new LabelStyleConvert(); |
|
List<LabelingInfo> labelInfo = styleConvert.EsriLabelToCustomLabels((layer as IGeoFeatureLayer).AnnotationProperties); |
|
if (labelInfo != null && labelInfo.Count > 0) |
|
labelingInfo = labelInfo[0]; |
|
|
|
if (labelingInfo != null) |
|
{ |
|
//AdvancedDrawimgInfoManager ad = new AdvancedDrawimgInfoManager(); |
|
//string jsons = ad.GetRenderer(randerer, labelingInfo); |
|
//item.Symbol = jsons; |
|
AdvancedDrawingInfo adi = new AdvancedDrawingInfo(); |
|
adi.DrawingInfo.Renderer = randerer; |
|
adi.DrawingInfo.LabelingInfo = labelInfo; |
|
item.Symbol = adi.ToJson(); |
|
|
|
} |
|
} |
|
} |
|
} |
|
} |
|
//设置图层样式 |
|
string layerStylePath = System.IO.Path.Combine(projectInfo.ProjDir, "LatersToXML.xml"); |
|
if (System.IO.File.Exists(layerStylePath)) |
|
{ |
|
LayerCfg layerInfoClass = SerializeAPI.DeserializeToObject2<LayerCfg>(layerStylePath); |
|
if (layerInfoClass != null && layerInfoClass.Layers != null) |
|
{ |
|
List<LayerCfg> layerInfolist = layerInfo.GetAllItem(); |
|
foreach (var item in layerInfolist) |
|
{ |
|
ILayer layer = item.Data as ILayer; |
|
if (layer != null) |
|
{ |
|
if (layer is IFeatureLayer) |
|
{ |
|
if (layer.Name == "变更范围图斑") |
|
{ |
|
} |
|
if (!string.IsNullOrWhiteSpace(item.Symbol)) |
|
{ |
|
AdvancedDrawingInfo ad = AdvancedDrawingInfo.FromJson(item.Symbol); |
|
//ItemInfo itemInfo = ItemInfo.FromJson(item.Symbol); |
|
if (ad != null) |
|
{ |
|
//Symbol symbol = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol; |
|
|
|
//Renderer rander = SymbolConvert.Instance().GetItemInfoRenderer((layer as IGeoFeatureLayer).Renderer); |
|
|
|
if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.SimpleRenderer) |
|
{ |
|
|
|
Symbol symbol1 = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.SimpleRenderer).Symbol; |
|
//if (symbol1 is CIMSymbolReference) |
|
//{ |
|
ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol1, SymbolTypeEnum.Fill); |
|
(layer as IGeoFeatureLayer).Renderer = simpleRander2 as IFeatureRenderer; |
|
continue; |
|
//} |
|
|
|
|
|
} |
|
else if (ad.DrawingInfo.Renderer is Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer) |
|
{ |
|
//Symbol symbol = (ad.DrawingInfo.Renderer as Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer).DefaultSymbol; |
|
//ISimpleRenderer simpleRander2 = SymbolConvert.Instance().GetSimpleRenderer(symbol, SymbolTypeEnum.Fill); |
|
//(layer as IGeoFeatureLayer).Renderer = simpleRander2 as IFeatureRenderer; |
|
continue; |
|
} |
|
|
|
//if (symbol != null) |
|
//{ |
|
// ISymbol gisSymbol = null; |
|
// IFeatureLayer2 featureLayer = layer as IFeatureLayer2; |
|
// ESRI.ArcGIS.Geometry.esriGeometryType geometryType = featureLayer.ShapeType; |
|
|
|
// ISimpleRenderer simpleRenderer = (featureLayer as IGeoFeatureLayer).Renderer as ISimpleRenderer; |
|
// if (simpleRenderer != null) |
|
// { |
|
// gisSymbol = simpleRenderer.Symbol; |
|
// } |
|
// else |
|
// { |
|
// gisSymbol = GetDefaultSymbol(geometryType); |
|
// } |
|
|
|
// ISimpleRenderer simpleRander = null; |
|
// //面 |
|
// if (gisSymbol is IFillSymbol) |
|
// { |
|
// simpleRander = SymbolConvert.Instance().GetSimpleRenderer(symbol, SymbolTypeEnum.Fill); |
|
// } |
|
// //线 |
|
// else if (gisSymbol is ILineSymbol) |
|
// { |
|
// simpleRander = SymbolConvert.Instance().GetSimpleRenderer(symbol, SymbolTypeEnum.Line); |
|
// } |
|
// //点 |
|
// else if (gisSymbol is IMarkerSymbol) |
|
// { |
|
// simpleRander = SymbolConvert.Instance().GetSimpleRenderer(symbol, SymbolTypeEnum.Point); |
|
// } |
|
|
|
//(layer as IGeoFeatureLayer).Renderer = simpleRander as IFeatureRenderer; |
|
//} |
|
} |
|
|
|
|
|
|
|
} |
|
//IFillSymbol fillSymbol = getLayerFillSymbol(item.Layer as ILayer); |
|
//if (fillSymbol != null) |
|
//{ |
|
// System.Drawing.Color fillColor = Converter.FromRGBColor(fillSymbol.Color as IRgbColor); |
|
// System.Drawing.Color borderColor = Converter.FromRGBColor(fillSymbol.Outline.Color as IRgbColor); |
|
|
|
|
|
// layerInfo.layerBorderColor = System.Windows.Media.Color.FromArgb(borderColor.A, borderColor.R, borderColor.G, borderColor.B).ToString(); |
|
// layerInfo.layerFillColor = System.Windows.Media.Color.FromArgb(fillColor.A, fillColor.R, fillColor.G, fillColor.B).ToString(); |
|
|
|
|
|
// if (fillSymbol.Outline is ISimpleLineSymbol) |
|
// { |
|
// ISimpleLineSymbol esriSymbol = fillSymbol.Outline as ISimpleLineSymbol; |
|
// if (esriSymbol != null) |
|
// { |
|
// layerInfo.LayerBorderStyle = (int)esriSymbol.Style; |
|
// layerInfo.layerBorderWidth = esriSymbol.Width; |
|
// } |
|
// } |
|
//} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
//将对象序列化成字符串 |
|
string Str = SerializeAPI.SerializeToXML<LayerCfg>(_DataCatalog.CurrentLayers as LayerCfg); |
|
Byte[] bytearr = System.Text.Encoding.Default.GetBytes(Str);//Encoding.UTF8.GetBytes(Str); |
|
using (Stream stream = new System.IO.FileStream(projectInfo.ProjDir + "\\" + "LatersToXML.xml", FileMode.Create, FileAccess.Write, FileShare.None)) |
|
{ |
|
stream.Write(bytearr, 0, bytearr.Length); |
|
stream.Close(); |
|
} |
|
} |
|
catch (Exception) |
|
{ |
|
throw; |
|
} |
|
} |
|
|
|
private ISymbol GetDefaultSymbol(ESRI.ArcGIS.Geometry.esriGeometryType geometryType) |
|
{ |
|
try |
|
{ |
|
ISymbol result = null; |
|
IRgbColor rgbColor = new RgbColorClass(); |
|
rgbColor.Red = 184; |
|
rgbColor.Green = 242; |
|
rgbColor.Blue = 200; |
|
switch (geometryType) |
|
{ |
|
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: |
|
result = (new SimpleMarkerSymbolClass |
|
{ |
|
Color = rgbColor, |
|
Style = ESRI.ArcGIS.Display.esriSimpleMarkerStyle.esriSMSCircle |
|
} as ISymbol); |
|
goto IL_B3; |
|
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint: |
|
goto IL_B3; |
|
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: |
|
break; |
|
case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: |
|
result = (new SimpleFillSymbolClass |
|
{ |
|
Color = rgbColor, |
|
Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSSolid |
|
} as ISymbol); |
|
goto IL_B3; |
|
default: |
|
if (geometryType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryLine) |
|
{ |
|
goto IL_B3; |
|
} |
|
break; |
|
} |
|
result = (new SimpleLineSymbolClass |
|
{ |
|
Color = rgbColor, |
|
Width = 1.0, |
|
Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid |
|
} as ISymbol); |
|
IL_B3: |
|
return result; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message); |
|
} |
|
return null; |
|
} |
|
public override void OnCreate(object Hook) |
|
{ |
|
try |
|
{ |
|
if (m_hookHelper == null) |
|
{ |
|
m_hookHelper = new HookHelper |
|
{ |
|
Hook = Hook |
|
}; |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("初始化 保存 命令时异常,异常信息如下:" + ex.Message); |
|
} |
|
} |
|
|
|
public override bool Enabled |
|
{ |
|
get |
|
{ |
|
//验证是否打开工程 |
|
if (!(KGIS.Framework.Maps.MapsManager.Instance.MapService.GetProjectInfo() is ProjectInfo ProInfo)) |
|
return false; |
|
else |
|
return true; |
|
} |
|
} |
|
} |
|
}
|
|
|