实例介绍
【实例截图】
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GisExtent;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.GISClient;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using System.Threading;
using System.Text.RegularExpressions;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Framework;
using System.IO;
using System.Drawing.Imaging;
using System.Web;
using ESRI.ArcGIS.Display;
namespace WinformGui
{
public partial class FOutPic : Form
{
FLyrStyleSet _fLyrStyleSet = null;
ILayer _lyrIn = null;
ILayer _lyrTo = null;
IGroupLayer _lyrGroupIn = null;
double _lyrLineWith = 2;
int _red = 255;
int _green = 0;
int _blue = 0;
string _unionPicPath { get { return TempPicUrl("tempUnion"); } }
string TempPicUrl(object idx = null, string dirName = "")
{
string baseUrl = AppDomain.CurrentDomain.BaseDirectory;
idx = idx == null ? "temp" : idx;
baseUrl = System.IO.Path.Combine(baseUrl, "temp");
if (!string.IsNullOrEmpty(dirName))
{
baseUrl = System.IO.Path.Combine(baseUrl, dirName);
}
string picName = string.Format(@"{0}.jpg", idx);
return System.IO.Path.Combine(baseUrl, picName);
}
string TempPartPicUrl(object idx = null)
{
return TempPicUrl(idx, "part");
}
IColor _colorLine;
IColor ColorLine
{
get
{
_colorLine = new RgbColorClass
{
Red = _red,
Green = _green,
Blue = _blue
};
return _colorLine;
}
}
IMarkerSymbol _markerSymbol;
IMarkerSymbol MarkerSymbol
{
get
{
_markerSymbol = new SimpleMarkerSymbolClass
{
Color = ColorLine,
Size = _lyrLineWith
};
return _markerSymbol;
}
}
ILineSymbol _lineSymbol;
ILineSymbol LineSymbol
{
get
{
_lineSymbol = new SimpleLineSymbolClass();
_lineSymbol.Width = _lyrLineWith;
_lineSymbol.Color = ColorLine;
return _lineSymbol;
}
}
IFillSymbol _fillSymbol;
IFillSymbol FillSymbol
{
get
{
_fillSymbol = new SimpleFillSymbolClass();
_fillSymbol.Outline = LineSymbol;
ISimpleFillSymbol simpleFillSymbol = _fillSymbol as ISimpleFillSymbol;
simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull;
return _fillSymbol;
}
}
string GetGroupLyrName(Control ctrl)
{
return StringX.SubStringRight(ctrl.Text, 0, 2); ;
}
//右击图层
ILayer SelectLayer
{
get
{
esriTOCControlItem esriTOCControlItemP = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap basicMap = null;
ILayer selectLayer = null;
object unk = null;
object data = null;
tocCtrl.GetSelectedItem(ref esriTOCControlItemP, ref basicMap, ref selectLayer, ref unk, ref data);
return selectLayer;
}
}
public FOutPic()
{
InitializeComponent();
}
Action<string> WriteLog
{
get
{
return (logStr) =>
{
ThreadStart threadStartLog = () =>
{
rtbLog.Clear();
rtbLog.AppendText(logStr);
};
Invoke(threadStartLog);
};
}
}
Action<Exception> ShowPopUpAndLogExcept
{
get
{
return (ex) =>
{
ThreadStart dealThreadCtrl = () =>
{
MessageBox.Show(ex.Message);
};
Invoke(dealThreadCtrl);
LogX.ANew.DealLog(ex, WriteLog);
};
}
}
private void btnAddPolygon_Click(object sender, EventArgs e)
{
AddLyr2Lyrs(btnAddPolygon);
}
private void btnAddMerge_Click(object sender, EventArgs e)
{
AddLyr2Lyrs(btnAddMerge);
}
private void AddLyr2Lyrs(Control ctrl)
{
//ThreadStart threadStart = () =>
//{
try
{
IMap map = mapCtrl.Map;
IGroupLayer groupLayer = FindOrCreateGourpLyr(map, ctrl);
//匿名委托
Action<string> addLyr = (url) =>
{
bool isVisible = cbxAddIsvisible.Checked;
if (Regex.IsMatch(url, @"^http", RegexOptions.IgnoreCase))
{
//加地图服务
AddMapSvrLyr(url, groupLayer, isVisible);
}
else
{
//加本地矢量要素类
AddLocalFcLyr(url, groupLayer, isVisible);
}
};
//
OpenGisDataDialog aNew = OpenGisDataDialog.ANew;
aNew.Text = ctrl.Text;
aNew.SelectPathsDo(addLyr);
map.DeleteLayer(groupLayer);
map.AddLayer(groupLayer);
//图斑图层在最前,方便选图斑
if (ctrl == btnAddMerge)
{
string groupLyrName = GetGroupLyrName(btnAddPolygon);
IGroupLayer groupLayerPolygon = FindGroupLayer(map, groupLyrName);
if (groupLayerPolygon != null)
{
map.MoveLayer(groupLayerPolygon, 0);
}
}
}
catch (Exception ex)
{
MessageBox.Show("请添加要素类或地图服务。");
LogX.ANew.DealLog(ex, WriteLog);
//ShowPopUpAndLogExcept(ex);
}
//};
//Thread thread = new Thread(threadStart);
//thread.Start();
}
/// <summary>
/// 加本地矢量要素类
/// </summary>
/// <param name="url"></param>
/// <param name="groupLayer"></param>
private void AddLocalFcLyr(string url, IGroupLayer groupLayer, bool isVisible = true)
{
IFeatureClass fc = EsriX.GetFeatureClass(url);
IFeatureLayer ftLyr = new FeatureLayerClass();
ftLyr.FeatureClass = fc;
ftLyr.Name = fc.AliasName;
ftLyr.Visible = isVisible;
IGeoFeatureLayer geoFeatureLayer = ftLyr as IGeoFeatureLayer;
geoFeatureLayer.Renderer = GetRenderer(geoFeatureLayer);
groupLayer.Add(ftLyr);
}
private IFeatureRenderer GetRenderer(IGeoFeatureLayer geoFeatureLayer)
{
ISimpleRenderer simpleRenderer = new SimpleRendererClass();
IFeatureClass fc = geoFeatureLayer.FeatureClass;
esriGeometryType esriGeometryTypeP = fc.ShapeType;
switch (esriGeometryTypeP)
{
case esriGeometryType.esriGeometryPoint:
simpleRenderer.Symbol = MarkerSymbol as ISymbol;
break;
case esriGeometryType.esriGeometryMultipoint:
simpleRenderer.Symbol = MarkerSymbol as ISymbol;
break;
case esriGeometryType.esriGeometryPolyline:
simpleRenderer.Symbol = LineSymbol as ISymbol;
break;
case esriGeometryType.esriGeometryLine:
simpleRenderer.Symbol = LineSymbol as ISymbol;
break;
case esriGeometryType.esriGeometryPolygon:
simpleRenderer.Symbol = FillSymbol as ISymbol;
break;
}
return simpleRenderer as IFeatureRenderer;
}
/// <summary>
/// 加地图服务
/// </summary>
/// <param name="urlRoot"></param>
/// <param name="groupLayer"></param>
private void AddMapSvrLyr(string url, IGroupLayer groupLayer, bool isVisible = true)
{
IAGSServerConnectionFactory aGSServerConnectionFactory = new AGSServerConnectionFactoryClass();
IPropertySet propertySet = new PropertySet();
string urlEnum = GetValidMapSvrEnumUrl(url);
string mapSvrName = GetMapSvrNameDecode(url);
propertySet.SetProperty("url", urlEnum);
IAGSServerConnection aGSServerConnection = aGSServerConnectionFactory.Open(propertySet, 0);
IAGSEnumServerObjectName aGSEnumServerObjectName = aGSServerConnection.ServerObjectNames;
for (IAGSServerObjectName aGSServerObjectName = aGSEnumServerObjectName.Next(); aGSServerObjectName != null; aGSServerObjectName = aGSEnumServerObjectName.Next())
{
try
{
ILayer lyr = null;
if (aGSServerObjectName.Type == "MapServer")
{
IMapServerLayer mapSvrLyr = new MapServerLayerClass();
IName name = aGSServerObjectName as IName;
object openResult = name.Open();
IAGSServerObject aGSEnumServerObject = openResult as IAGSServerObject;
IMapServer mapSvr = aGSEnumServerObject as IMapServer;
string mapName = mapSvr.DefaultMapName;
mapSvrLyr.ServerConnect(aGSServerObjectName, mapName);
lyr = mapSvrLyr as ILayer;
}
if (lyr != null)
{
bool isAddLyr = true;
if (!string.IsNullOrEmpty(mapSvrName))
{
string lyrName = lyr.Name;
isAddLyr = Regex.IsMatch(lyrName, mapSvrName, RegexOptions.IgnoreCase);
}
if (isAddLyr)
{
ThreadStart dealThreadCtrl = () =>
{
try
{
lyr.Visible = isVisible;
groupLayer.Add(lyr);
}
catch (Exception ex)
{
ShowPopUpAndLogExcept(ex);
}
};
Invoke(dealThreadCtrl);
}
}
}
catch (Exception ex)
{
LogX.ANew.DealLog(ex, WriteLog);
}
}
}
private string GetMapSvrName(string url)
{
string result = "";
Match match = Regex.Match(url, @". /services/", RegexOptions.IgnoreCase);
if (match.Length > 0)
{
string urlSvc = match.Value;
string urlSvcAfter = url.Substring(urlSvc.Length - 1);
string[] urlSvcAfters = urlSvcAfter.Split(new string[] { @"/", @"\" }, StringSplitOptions.RemoveEmptyEntries);
result = urlSvcAfters[0];
for (int i = 1; i < urlSvcAfters.Length; i )
{
string svcAfter = urlSvcAfters[i];
if (!Regex.IsMatch(svcAfter, "MapServer", RegexOptions.IgnoreCase))
{
result = "/" svcAfter;
}
else
{
break;
}
}
}
return result;
}
private string GetMapSvrNameDecode(string url)
{
string temp = GetMapSvrName(url);
string result = HttpUtility.UrlDecode(temp);
return result;
}
private IGroupLayer FindOrCreateGourpLyr(IMap map, Control ctrl)
{
string groupLyrName = GetGroupLyrName(ctrl);
IGroupLayer groupLayer = FindGroupLayer(map, groupLyrName);
if (groupLayer == null)
{
groupLayer = new GroupLayerClass
{
Name = groupLyrName,
Visible = true
};
}
return groupLayer;
}
private static IGroupLayer FindGroupLayer(IMap map, string groupLyrName)
{
IEnumLayer enumLayer = map.Layers;
ILayer lyrParent = EsriX.FindLayerFirst(enumLayer, groupLyrName);
IGroupLayer groupLayer = lyrParent as IGroupLayer;
return groupLayer;
}
private string GetValidMapSvrEnumUrl(string url)
{
string validUrl = url;
Match match = Regex.Match(url, @"http[s]?://.*/rest", RegexOptions.IgnoreCase);
if (match.Length > 0)
{
validUrl = match.Value;
}
return validUrl;
}
private void FOutPic_Load(object sender, EventArgs e)
{
tocCtrl.SetBuddyControl(mapCtrl);
setToolbarControl(mapCtrl, toolbarCtrl);
}
private void setToolbarControl(object buddyCtrl, AxToolbarControl toolbarCtrl)
{
toolbarCtrl.SetBuddyControl(buddyCtrl);
string proId = "esriControlToolsMapNavigation.ControlsMapPanTool";
toolbarCtrl.AddItem(proId);
proId = "esriControlToolsMapNavigation.ControlsMapZoomInTool";
toolbarCtrl.AddItem(proId, -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
proId = "esriControlToolsMapNavigation.ControlsMapZoomOutTool";
toolbarCtrl.AddItem(proId, -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
proId = "esriControlToolsMapNavigation.ControlsMapFullExtentCommand";
toolbarCtrl.AddItem(proId, -1, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly);
}
private void toolbarCtrl_OnMouseDown(object sender, IToolbarControlEvents_OnMouseDownEvent e)
{
}
private void btnGeneratePic_Click(object sender, EventArgs e)
{
try
{
IMap map = mapCtrl.Map;
ISelection selection = map.FeatureSelection;
IEnumFeature enumFeature = selection as IEnumFeature;
//缩放至所选要素
IActiveView activeView = mapCtrl.ActiveView;
IEnvelope rawExtent = activeView.Extent;
ZoomToSelectFeature(enumFeature);
//设置图斑下所有可见矢量图层:线和填充为NoColor,点关闭图层,以达到非选中要素不可见
IEnumLayer enumLayer = map.Layers;
List<ILayer> needNoseePolygonLyrs = SetPolygonLayersNosee(enumLayer);
List<ILayer> needNoseeMergeLyrs = SetMergeLayersNosee(enumLayer);
if (needNoseeMergeLyrs.Count <= 0)
{
string mergeLyrName = GetGroupLyrName(btnAddMerge);
MessageBox.Show(string.Format("请添加可见{0}图层", mergeLyrName));
return;
}
//设置选中样式,以打印范围
SetRedOutLineNoFill(enumFeature);
tagRECT tagRECT = activeView.ExportFrame;
tagRECT.left = 0;
tagRECT.top = 0;
//水平像素
int onePicWidth = GetUiWidthPix();
tagRECT.right = onePicWidth;
//垂直像素
int onePicHigh = GetUiHighPix();
tagRECT.bottom = onePicHigh;
IExport export = new ExportJPEGClass();
//dpi
int dpi = (int)nudDpi.Value;
export.Resolution = dpi;
string baseUrl = AppDomain.CurrentDomain.BaseDirectory;
string dirPath = System.IO.Path.GetDirectoryName(TempPartPicUrl());
//清空文件夹
if (Directory.Exists(dirPath))
{
Directory.Delete(dirPath, true);
}
Directory.CreateDirectory(dirPath);
IEnvelope envelope = new EnvelopeClass();
envelope.PutCoords(tagRECT.left, tagRECT.top, tagRECT.right, tagRECT.bottom);
export.PixelBounds = envelope;
Dictionary<string, string> filePathLyrNames = new Dictionary<string, string>();
for (int i = 0; i < needNoseeMergeLyrs.Count; i )
{
ILayer lyrPrintMerge = needNoseeMergeLyrs[i];
lyrPrintMerge.Visible = true;
Refresh();
string lyrName = lyrPrintMerge.Name;
string fileName = Regex.Replace(lyrName, @"(\\|/)", "_");
string tempPicPath = TempPartPicUrl(fileName);
if (filePathLyrNames.ContainsKey(tempPicPath))
{
string appenName = Guid.NewGuid().ToString();
tempPicPath = FileX.GetReNameFileName(tempPicPath, appenName);
}
export.ExportFileName = tempPicPath;
filePathLyrNames.Add(tempPicPath, lyrName);
int hdc = export.StartExporting();
//没用
int dpiNoUse = dpi;
activeView.Output(hdc, dpiNoUse, ref tagRECT, null, null);
export.FinishExporting();
export.Cleanup();
lyrPrintMerge.Visible = false;
}
//恢复图层之前显示状态
RestoreState(needNoseePolygonLyrs, needNoseeMergeLyrs, rawExtent);
//写文字
string[] fileUrls = Directory.GetFiles(dirPath);
for (int i = 0; i < fileUrls.Length; i )
{
string fileUrl = fileUrls[i];
using (Bitmap bitmapPart = BitmapX.GetBitmapNoOccupyFile(fileUrl))
{
using (Graphics graphics = Graphics.FromImage(bitmapPart))
{
string drawStr = filePathLyrNames[fileUrl];
Font font = new Font("微软雅黑", 20);
int left = 10;
int top = 5;
Size size = TextRenderer.MeasureText(drawStr, font);
graphics.FillRectangle(Brushes.White, left, top, size.Width, size.Height);
graphics.DrawString(drawStr, font, Brushes.Blue, new PointF(left, top));
bitmapPart.Save(fileUrl);
}
}
}
//合图
int resutlPicQty = fileUrls.Length;
int marginWidth = 8;
int marginHigh = marginWidth;
int resutlWidth = (onePicWidth 2 * marginWidth) * resutlPicQty;
int resutlHigh = onePicHigh 2 * marginHigh;
using (Bitmap bitmapResult = new Bitmap(resutlWidth, resutlHigh))
{
using (Graphics graphicsResult = Graphics.FromImage(bitmapResult))
{
for (int i = 0; i < fileUrls.Length; i )
{
string fileUrl = fileUrls[i];
using (Bitmap bitmapPart = BitmapX.GetBitmapNoOccupyFile(fileUrl))
{
int multiple = i * 2 1;
int leftTopX = marginWidth * multiple i * onePicWidth;
int leftTopY = marginHigh;
graphicsResult.DrawImage(bitmapPart, leftTopX, leftTopY);
}
}
}
bitmapResult.Save(_unionPicPath);
}
//切换选项卡
if (File.Exists(_unionPicPath))
{
Bitmap bitmap = BitmapX.GetBitmapNoOccupyFile(_unionPicPath);
pbxResult.Image = bitmap;
tabCt_InTo.SelectedTab = tabPTo;
}
}
catch (Exception ex)
{
ShowPopUpAndLogExcept(ex);
}
}
private void RestoreState(List<ILayer> needNoseePolygonLyrs, List<ILayer> needNoseeMergeLyrs, IEnvelope rawExtent)
{
IActiveView activeView = mapCtrl.ActiveView;
activeView.Extent = rawExtent;
SetLyrSee(needNoseePolygonLyrs);
SetLyrSee(needNoseeMergeLyrs);
//清空临时画的图形
IGraphicsContainer graphicsContainer = mapCtrl.Map as IGraphicsContainer;
graphicsContainer.DeleteAllElements();
Refresh();
}
new private void Refresh()
{
mapCtrl.Update();
mapCtrl.Refresh();
mapCtrl.ActiveView.Refresh();
tocCtrl.Update();
tocCtrl.Refresh();
tocCtrl.ActiveView.Refresh();
}
private void SetRedOutLineNoFill(IEnumFeature enumFeature)
{
enumFeature.Reset();
for (IFeature ft = enumFeature.Next(); ft != null; ft = enumFeature.Next())
{
IGeometry geometry = ft.Shape;
IElement element = null;
if (geometry.Dimension == esriGeometryDimension.esriGeometry0Dimension)
{
element = new MarkerElementClass()
{
Symbol = MarkerSymbol
};
}
else if (geometry.Dimension == esriGeometryDimension.esriGeometry1Dimension)
{
element = new LineElementClass()
{
Symbol = LineSymbol
};
}
else if (geometry.Dimension == esriGeometryDimension.esriGeometry2Dimension)
{
element = new PolygonElementClass()
{
Symbol = FillSymbol
};
}
if (element != null)
{
IGraphicsContainer graphicsContainer = mapCtrl.Map as IGraphicsContainer;
element.Geometry = geometry;
graphicsContainer.AddElement(element, 0);
mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
}
private void SetLyrSee(List<ILayer> needNoseeLyrs)
{
foreach (ILayer lyr in needNoseeLyrs)
{
lyr.Visible = true;
}
}
/// <summary>
/// 设置图斑层不可见,仅图层组关闭,子图层不关
/// </summary>
/// <param name="enumLayer"></param>
/// <returns></returns>
private List<ILayer> SetPolygonLayersNosee(IEnumLayer enumLayer)
{
List<ILayer> needNoseeLyrs = new List<ILayer>();
enumLayer.Reset();
for (ILayer lyr = enumLayer.Next(); lyr != null; lyr = enumLayer.Next())
{
IGroupLayer groupLayer = lyr as IGroupLayer;
if (groupLayer == null) continue;
string groupLyrName = GetGroupLyrName(btnAddPolygon);
if (lyr.Name == groupLyrName && lyr.Visible)
{
SetNoseeAddList(needNoseeLyrs, lyr);
}
}
return needNoseeLyrs;
}
/// <summary>
/// 融合图层组不关,子图层全关
/// </summary>
/// <param name="enumLayer"></param>
/// <returns></returns>
private List<ILayer> SetMergeLayersNosee(IEnumLayer enumLayer)
{
List<ILayer> needNoseeLyrs = new List<ILayer>();
enumLayer.Reset();
for (ILayer lyr = enumLayer.Next(); lyr != null; lyr = enumLayer.Next())
{
IGroupLayer groupLayer = lyr as IGroupLayer;
if (groupLayer == null) continue;
string groupLyrName = GetGroupLyrName(btnAddMerge);
if (lyr.Name == groupLyrName && lyr.Visible)
{
//图层组内图层
SetNoSeeChildLyr(needNoseeLyrs, groupLayer);
}
}
return needNoseeLyrs;
}
private static void SetNoSeeChildLyr(List<ILayer> needNoseeLyrs, IGroupLayer groupLayer)
{
ICompositeLayer compositeLayer = groupLayer as ICompositeLayer;
for (int i = 0; i < compositeLayer.Count; i )
{
ILayer lyrChild = compositeLayer.Layer[i];
SetNoseeAddList(needNoseeLyrs, lyrChild);
}
}
private static void SetNoseeAddList(List<ILayer> needNoseeLyrs, ILayer lyrChild)
{
if (lyrChild.Visible)
{
lyrChild.Visible = false;
needNoseeLyrs.Add(lyrChild);
}
}
private bool ZoomToSelectFeature(IEnumFeature enumFeature)
{
bool isZoom = !cbxNowRegion.Checked;
if (isZoom)
{
IEnvelope envelope = GetEnvelopeByUnionBuffer(enumFeature);
//缩放
if (envelope != null)
{
IActiveView activeView = mapCtrl.ActiveView;
activeView.Extent = envelope;
activeView.Refresh();
}
}
return isZoom;
}
private static IEnvelope GetEnvelopeByFactory(ISelection selection)
{
IEnumGeometry enumGeometry = new EnumFeatureGeometry();
IEnumGeometryBind enumGeometryBind = enumGeometry as IEnumGeometryBind;
//出错
enumGeometryBind.BindGeometrySource(null, selection);
IGeometryFactory geometryFactory = new GeometryEnvironment() as IGeometryFactory;
IGeometry geoExtent = geometryFactory.CreateGeometryFromEnumerator(enumGeometry);
return geoExtent.Envelope;
}
private IEnvelope GetEnvelopeByUnionBuffer(IEnumFeature enumFeature)
{
IEnvelope envelope = null;
IGeometry geometry = UnionGeometry(enumFeature);
ITopologicalOperator tp = geometry as ITopologicalOperator;
if (tp != null)
{
double bufferValue = (double)nudBuffer.Value;
IGeometry geometryBuffer = tp.Buffer(bufferValue);
envelope = geometryBuffer.Envelope;
}
return envelope;
}
private static IEnvelope GetEnvelopeByUnion(IEnumFeature enumFeature)
{
IEnvelope envelope = null;
IGeometry geometry = UnionGeometry(enumFeature);
if (geometry != null)
{
envelope = geometry.Envelope;
}
return envelope;
}
private static IGeometry UnionGeometryExtent(IEnumFeature enumFeature)
{
ITopologicalOperator topoOperate = null;
for (IFeature ft = enumFeature.Next(); ft != null; ft = enumFeature.Next())
{
IGeometry geometry = ft.Extent as IGeometry;
if (topoOperate != null)
{
IGeometry geometryUnion = topoOperate.Union(geometry);
topoOperate = geometryUnion as ITopologicalOperator;
}
else
{
//首次
topoOperate = geometry as ITopologicalOperator;
}
}
return topoOperate as IGeometry;
}
private static IGeometry UnionGeometry(IEnumFeature enumFeature)
{
ITopologicalOperator topoOperate = null;
enumFeature.Reset();
for (IFeature ft = enumFeature.Next(); ft != null; ft = enumFeature.Next())
{
IGeometry geometry = ft.Shape;
if (topoOperate != null)
{
IGeometry geometryUnion = topoOperate.Union(geometry);
topoOperate = geometryUnion as ITopologicalOperator;
}
else
{
//首次
topoOperate = geometry as ITopologicalOperator;
}
}
return topoOperate as IGeometry;
}
private int GetUiHighPix()
{
return (int)nudHigh.Value; ;
}
private int GetUiWidthPix()
{
return (int)nudWidth.Value;
}
private int Get551010WidthOrHightPix(int defaultValue)
{
return defaultValue;
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (pbxResult.Image == null || !File.Exists(_unionPicPath))
{
btnGeneratePic_Click(null, null);
return;
}
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "jpg files(*.jpg)|*.jpg";
saveFileDialog.ShowDialog();
string saveUrl = saveFileDialog.FileName;
if (!string.IsNullOrEmpty(saveUrl))
{
//pbxResult.Image.Save(saveUrl);
File.Copy(_unionPicPath, saveUrl, true);
MessageBox.Show("完成。");
}
}
catch (Exception ex)
{
ShowPopUpAndLogExcept(ex);
}
}
private ImageCodecInfo GetImageEncoder(string fileExtensionIn)
{
ImageCodecInfo result = null;
ImageCodecInfo[] imageCodecInfos = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo imageCodecInfo in imageCodecInfos)
{
string filenameExtension = imageCodecInfo.FilenameExtension;
if (Regex.IsMatch(filenameExtension, fileExtensionIn, RegexOptions.IgnoreCase))
{
result = imageCodecInfo;
break;
}
}
return result;
}
private void tabPTo_Click(object sender, EventArgs e)
{
}
/// <summary>
/// 缩放至图层
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiZoon2Lyr_Click(object sender, EventArgs e)
{
if (SelectLayer != null)
{
IActiveView activeView = mapCtrl.ActiveView;
activeView.Extent = SelectLayer.AreaOfInterest;
activeView.Refresh();
}
}
/// <summary>
/// 移除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiRemoveLyr_Click(object sender, EventArgs e)
{
if (SelectLayer != null)
{
IMap map = mapCtrl.Map;
map.DeleteLayer(SelectLayer);
}
}
private void tocCtrl_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
int x = e.x;
int y = e.y;
esriTOCControlItem esriTOCControlItemP = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap basicMap = null;
object unk = null;
object data = null;
ILayer lyrIn = null;
tocCtrl.HitTest(x, y, ref esriTOCControlItemP, ref basicMap, ref lyrIn, ref unk, ref data);
if (e.button == 1)
{
//鼠标左击:移动图层顺序
_lyrIn = lyrIn;
IGroupLayer lyrGroup;
IMap map = mapCtrl.Map;
int lyrIdxToInGroupLyr = EsriX.FindLayerFirstInGroupLyr(map.Layers, lyrIn, out lyrGroup);
if (lyrIdxToInGroupLyr >= 0)
{
_lyrGroupIn = lyrGroup;
}
}
}
private void tocCtrl_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e)
{
int x = e.x;
int y = e.y;
esriTOCControlItem esriTOCControlItemP = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap basicMap = null;
object unk = null;
object data = null;
tocCtrl.HitTest(x, y, ref esriTOCControlItemP, ref basicMap, ref _lyrTo, ref unk, ref data);
switch (esriTOCControlItemP)
{
case esriTOCControlItem.esriTOCControlItemHeading:
break;
case esriTOCControlItem.esriTOCControlItemLayer:
if (e.button == 1)
{
//鼠标左击:移动图层顺序
if (_lyrIn != null && _lyrTo != null)
{
IMap map = mapCtrl.Map;
IGroupLayer lyrGroupToFind;
IGroupLayer lyrGroupTo = _lyrTo as IGroupLayer;
int lyrIdxToGroupLyr = EsriX.FindLayerFirstInGroupLyr(map.Layers, _lyrTo, out lyrGroupToFind);
IMapLayers mapLayers = map as IMapLayers;
if (lyrIdxToGroupLyr >= 0)
{
mapLayers.MoveLayerEx(_lyrGroupIn, lyrGroupToFind, _lyrIn, lyrIdxToGroupLyr);
}
else if (lyrGroupTo != null && lyrGroupTo != _lyrIn)
{
//如果目标图层组内没子图层
mapLayers.MoveLayerEx(_lyrGroupIn, lyrGroupTo, _lyrIn, 0);
}
}
}
else if (e.button == 2)
{
//鼠标右击:显示右击菜单
tsmiRename.Enabled = GetRenameEnabled(_lyrTo);
cmsToc.Show(tocCtrl, x, y);
}
break;
case esriTOCControlItem.esriTOCControlItemLegendClass:
if (_lyrTo != _lyrIn) break;
IGeoFeatureLayer geoFeatureLyr = _lyrTo as IGeoFeatureLayer;
if (geoFeatureLyr == null) break;
if (_fLyrStyleSet == null)
{
_fLyrStyleSet = new FLyrStyleSet();
}
_fLyrStyleSet.ShowDialog();
DialogResult dialogResult = _fLyrStyleSet.DialogResultX;
if (dialogResult == DialogResult.OK || dialogResult == DialogResult.Yes)
{
_lyrLineWith = (double)_fLyrStyleSet.nudWidth.Value;
_red = (int)_fLyrStyleSet.nudColorR.Value;
_green = (int)_fLyrStyleSet.nudColorG.Value;
_blue = (int)_fLyrStyleSet.nudColorB.Value;
geoFeatureLyr.Renderer = GetRenderer(geoFeatureLyr);
}
break;
case esriTOCControlItem.esriTOCControlItemMap:
break;
case esriTOCControlItem.esriTOCControlItemNone:
break;
}
Refresh();
}
private bool GetRenameEnabled(ILayer lyrTo)
{
bool result = true;
if (lyrTo is IGroupLayer && (lyrTo.Name == GetGroupLyrName(btnAddPolygon) || lyrTo.Name == GetGroupLyrName(btnAddMerge)))
{
result = false;
}
return result;
}
private int GetParentLocation(Control ctrl, bool isX)
{
int value = 0;
if (isX)
{
value = ctrl.Location.X;
}
else
{
value = ctrl.Location.Y;
}
Control ctrlParent = ctrl.Parent;
if (ctrlParent != null)
{
value = GetParentLocation(ctrlParent, isX);
}
return value;
}
private void pnlResult_Paint(object sender, PaintEventArgs e)
{
}
private void cbxNowRegion_CheckedChanged(object sender, EventArgs e)
{
}
private void pbxResult_Click(object sender, EventArgs e)
{
}
private void tsmiRename_Click(object sender, EventArgs e)
{
string lyrNameOld = _lyrTo.Name;
FRename fRename = new FRename();
fRename.txtRename.Text = lyrNameOld;
fRename.ShowDialog();
DialogResult dialogResult = fRename.DialogResult;
if (dialogResult == DialogResult.OK || dialogResult == DialogResult.Yes)
{
_lyrTo.Name = fRename.txtRename.Text;
Refresh();
}
}
}
}
标签: 服务 地出图:地图服务和要素类图
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论