035自建符号Symbol选择对话框.docx
- 文档编号:4649463
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:15
- 大小:129.19KB
035自建符号Symbol选择对话框.docx
《035自建符号Symbol选择对话框.docx》由会员分享,可在线阅读,更多相关《035自建符号Symbol选择对话框.docx(15页珍藏版)》请在冰点文库上搜索。
035自建符号Symbol选择对话框
【035】自建符号Symbol选择对话框
第一步:
建立独立的Windows窗体:
命名为:
SymbologyFrmLee
1.运行效果如下所示:
2.全局参数:
esriSymbologyStyleClasspStyleClass; //获取显示的为点类、线类还是填充类等的,赋值给symbologyControl控件,然后就显示这一类符号
publicIStyleGalleryItempStyleGalleryItem; //获取选择的项
ILegendClasspLegendClass; //获取传递进来的图例
ILayerpLayer;
boolcontextMenuMoreSymbolInitiated=false; //判断右键菜单是否已经初始化了
3.给窗体添加参数:
publicSymbologyFrmLee(ILegendClasstempLegendClass,ILayertempLayer)
{
InitializeComponent();
pLegendClass=tempLegendClass; //通过点击toccontrol时候可以获得要素类的LegendClass!
pLayer=tempLayer; //点击的图层
}
4.窗体加载事件:
privatevoidSymbologyFrm_Load(objectsender,EventArgse)
{
switch(((IFeatureLayer)pLayer).FeatureClass.ShapeType) //判断图层中要素类的图形类型,不同类型显示的调节值的控件不同
{
caseesriGeometryType.esriGeometryPoint:
//点
pStyleClass=esriSymbologyStyleClass.esriStyleClassMarkerSymbols;
lbColor.Visible=true;
lbWidth.Visible=true;
lbWidth.Text="符号大小";
lbAngle.Visible=true;
btColor.Visible=true;
nudWidth.Visible=true;
cbColor.Visible=true;
nudAngle.Visible=true;
break;
caseesriGeometryType.esriGeometryPolyline:
//线
pStyleClass=esriSymbologyStyleClass.esriStyleClassLineSymbols;
lbColor.Visible=true;
lbColor.Location=System.Drawing.Point.Add(lbColor.Location,newSize(0,12));
lbWidth.Visible=true;
lbWidth.Location=System.Drawing.Point.Add(lbWidth.Location,newSize(0,24));
lbWidth.Text="线符号粗细";
btColor.Visible=true;
cbColor.Visible=true;
btColor.Location=System.Drawing.Point.Add(btColor.Location,newSize(0,12));
cbColor.Location=System.Drawing.Point.Add(cbColor.Location,newSize(0,12));
nudWidth.Visible=true;
nudWidth.Location=System.Drawing.Point.Add(nudWidth.Location,newSize(0,24));
break;
caseesriGeometryType.esriGeometryPolygon:
//面
pStyleClass=esriSymbologyStyleClass.esriStyleClassFillSymbols;
lbColor.Visible=true;
lbWidth.Visible=true;
lbWidth.Text="框线宽度";
lbOutlineColor.Visible=true;
btColor.Visible=true;
btOutlineColor.Visible=true;
nudWidth.Visible=true;
cbColor.Visible=true;
cbOutlineColor.Visible=true;
break;
default:
this.Close();
break;
}
stringstrInstall=@"C:
\ProgramFiles(x86)\ArcGIS"; //安装目录,10中可以用函数获得RuntimeManager可以获取!
//ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path可以获得Engine的安装目录
stringstylePath=strInstall+@"\Styles\ESRI.ServerStyle"; //获取ESRI.ServerStyle文件
axSymbologyControl1.LoadStyleFile(stylePath); //加载此文件
axSymbologyControl1.StyleClass=pStyleClass; //将上面获得的pStyleClass赋值过去,显示点、线还是面,由此决定!
IStyleGalleryItempCurrentStyleGalleryItem=newStyleGalleryItem(); //新建当前符号的实例
pCurrentStyleGalleryItem.Name="当前符号";
pCurrentStyleGalleryItem.Item=pLegendClass.Symbol; //将当前的图例symbol赋值过去
ISymbologyStyleClasspSymbologyStyleClass=axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass); //QI,加入这个新建项
pSymbologyStyleClass.AddItem(pCurrentStyleGalleryItem,0);
pSymbologyStyleClass.SelectItem(0); //同时选中
}
5.选择项的时候触发:
privatevoidaxSymbologyControl1_OnItemSelected(objectsender,ISymbologyControlEvents_OnItemSelectedEvente)
{
pStyleGalleryItem=e.styleGalleryItemasIStyleGalleryItem; //获取选择项
PreviewPicture(); //在图片框中显示
if(((IFeatureLayer)pLayer).FeatureClass.ShapeType==esriGeometryType.esriGeometryPoint) //点,将属性传递到调节的控件上
{
IRgbColorpColor=((IMarkerSymbol)pStyleGalleryItem.Item).ColorasIRgbColor;
btColor.BackColor=Color.FromArgb(pColor.Red,pColor.Green,pColor.Blue); //赋值颜色
nudAngle.Value=Convert.ToDecimal(((IMarkerSymbol)pStyleGalleryItem.Item).Angle); //赋值角度
nudWidth.Value=Convert.ToDecimal(((IMarkerSymbol)pStyleGalleryItem.Item).Size); //赋值大小
}
if(((IFeatureLayer)pLayer).FeatureClass.ShapeType==esriGeometryType.esriGeometryPolyline) //线
{
IRgbColorpColor=((ILineSymbol)pStyleGalleryItem.Item).ColorasIRgbColor;
btColor.BackColor=Color.FromArgb(pColor.Red,pColor.Green,pColor.Blue); //赋值线的颜色
nudWidth.Value=Convert.ToDecimal(((ILineSymbol)pStyleGalleryItem.Item).Width); //赋值线的宽度
}
if(((IFeatureLayer)pLayer).FeatureClass.ShapeType==esriGeometryType.esriGeometryPolygon) //面
{
IRgbColorpColor=((IFillSymbol)pStyleGalleryItem.Item).ColorasIRgbColor;
btColor.BackColor=Color.FromArgb(pColor.Red,pColor.Green,pColor.Blue); //赋值填充的颜色
nudWidth.Value=Convert.ToDecimal(((IFillSymbol)pStyleGalleryItem.Item).Outline.Width); //赋值边框宽度
pColor=((IFillSymbol)pStyleGalleryItem.Item).Outline.ColorasIRgbColor;
btOutlineColor.BackColor=Color.FromArgb(pColor.Red,pColor.Green,pColor.Blue); //赋值边框颜色
}
}
6.将pStyleGalleryItem反映到picture上的方法:
privatevoidPreviewPicture()
{
ISymbologyStyleClasspSymbologyStyle=axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass); //因为其有方法PreviewStyle
stdole.IPictureDisppicture=pSymbologyStyle.PreviewItem(pStyleGalleryItem,pictureBox1.Width,pictureBox1.Height); //建立实例
Imageimage=Image.FromHbitmap(newIntPtr(picture.Handle)); //转成C#支持的Image实例
pictureBox1.Image=image; //赋值过去
}
▲将控件的操作操作反映到picture上:
7.点、线、面填充颜色传递:
IRgbColorpColor=newRgbColor(); //颜色实例
pColor.RGB=255;
tagRECTpTag=newtagRECT(); //用于下面显示ColorPalette的位置
pTag.left=btColor.PointToScreen(System.Drawing.Point.Empty).X; //按钮控件的左边全局横坐标
pTag.bottom=btColor.PointToScreen(System.Drawing.Point.Empty).Y+btColor.Height; //按钮控件的下边全局纵坐标
IColorPalettepColorPalette=newColorPalette();
pColorPalette.TrackPopupMenu(refpTag,pColor,false,0); //显示ColorPalette
pColor=pColorPalette.ColorasIRgbColor; //获取选中的颜色
Colorcolor=Color.FromArgb(pColor.Red,pColor.Green,pColor.Blue); //将颜色转为C#颜色
btColor.BackColor=color;
switch(((IFeatureLayer)pLayer).FeatureClass.ShapeType) //判断几何体样式
{
caseesriGeometryType.esriGeometryPoint:
//点
((IMarkerSymbol)pStyleGalleryItem.Item).Color=pColor; //转为IMarkerSymbol,注意改好后要在图片上显示
PreviewPicture();
break;
caseesriGeometryType.esriGeometryPolyline:
//线
((ILineSymbol)pStyleGalleryItem.Item).Color=pColor; //转为ILineSymbol
PreviewPicture();
break;
caseesriGeometryType.esriGeometryPolygon:
//面
((IFillSymbol)pStyleGalleryItem.Item).Color=pColor; //转为IFillSymbol
PreviewPicture();
break;
default:
break;
}
8.点的大小、线的宽度、填充边框宽度传递:
switch(((IFeatureLayer)pLayer).FeatureClass.ShapeType)
{
caseesriGeometryType.esriGeometryPoint:
((IMarkerSymbol)pStyleGalleryItem.Item).Size=Convert.ToDouble(nudWidth.Value); //点的大小,注意改后要在图片上显示
PreviewPicture();
break;
caseesriGeometryType.esriGeometryPolyline:
((ILineSymbol)pStyleGalleryItem.Item).Width=Convert.ToDouble(nudWidth.Value); //线的宽度
PreviewPicture();
break;
caseesriGeometryType.esriGeometryPolygon:
ILineSymbolpLineSymbol=((IFillSymbol)pStyleGalleryItem.Item).Outline; //实例化一个linesymbol然后赋值过去,直接赋值的话没有反应
pLineSymbol.Width=Convert.ToDouble(nudWidth.Value); //赋值
((IFillSymbol)pStyleGalleryItem.Item).Outline=pLineSymbol; //在赋值给填充的外框
PreviewPicture();
break;
default:
break;
}
9.填充外边框颜色的传递:
IRgbColorpColor=newRgbColor();
pColor.RGB=255;
tagRECTptagRECT=newtagRECT();
ptagRECT.left=btOutlineColor.PointToScreen(System.Drawing.Point.Empty).X;
ptagRECT.bottom=btOutlineColor.PointToScreen(System.Drawing.Point.Empty).Y+btOutlineColor.Height;
IColorPalettepColorPalette=newColorPalette();
pColorPalette.TrackPopupMenu(refptagRECT,pColor,false,0);
pColor=pColorPalette.ColorasIRgbColor;
btOutlineColor.BackColor=Color.FromArgb(pColor.Red,pColor.Green,pColor.Blue);
ILineSymbolpLineSymbol=((IFillSymbol)pStyleGalleryItem.Item).Outline;
pLineSymbol.Color=pColor;
((IFillSymbol)pStyleGalleryItem.Item).Outline=pLineSymbol;
PreviewPicture();
颜色显示效果如下:
10.点的角度实现如下:
((IMarkerSymbol)pStyleGalleryItem.Item).Angle=Convert.ToDouble(nudAngle.Value);
PreviewPicture();
11.更多符号的实现:
privatevoidbtMore_Click(objectsender,EventArgse)
{
if(contextMenuMoreSymbolInitiated==false) //如果没有初始化,则首先初始化
{
stringstylePath=@"C:
\ProgramFiles(x86)\ArcGIS\Styles"; //获取styles文件夹,并将里面*.ServerStyle文件赋值到数组中,用于加载
string[]strFiles=Directory.GetFiles(stylePath,"*.ServerStyle");
ToolStripMenuItem[]symbolContextMenuItem=newToolStripMenuItem[strFiles.Length+1]; //定义菜单项,最后一个为另类
for(inti=0;i { symbolContextMenuItem[i]=newToolStripMenuItem(); //首先新建,然后允许选中时是否有checked变化 symbolContextMenuItem[i].CheckOnClick=true; symbolContextMenuItem[i].Text=System.IO.Path.GetFileNameWithoutExtension(strFiles[i]); //将名字赋值给text属性,完整地址赋值给name,便于加载 if(symbolContextMenuItem[i].Text=="ESRI") symbolContextMenuItem[i].Checked=true; //默认是加载的这个文件,所以默认选中 symbolContextMenuItem[i].Name=strFiles[i]; } symbolContextMenuItem[strFiles.Length]=newToolStripMenuItem(); //最后一个菜单项 symbolContextMenuItem[strFiles.Length].Text="更多工具"; symbolContextMenuItem[strFiles.Length].Name="AddMoreSymbol"; contextMenuStrip1.Items.AddRange(symbolContextMenuItem); //将菜单项添加到右键菜单中 contextMenuMoreSymbolInitiated=true; //将此值赋值为true,以便之后不用执行这一部分了 } contextMenuStrip1.Show(btMore.Location); //弹出右键菜单 } 12.点击右键菜单: privatevoidcontextMenuStrip1_ItemClicked(objectsender,ToolStripItemClickedEventArgse) { ToolStripMenuItempToolStripMenuItem=e.ClickedItemasToolStripMenuItem; //首先获取点击项 if(pToolStripMenuItem.Name=="AddMoreSymbol") //最后一项,打开对话框,浏览想要打开的文件 { if(openFileDialog1.ShowDialog()==DialogResult.OK) { axSymbologyControl1.LoadStyleFile(openFileDialog1.FileName); axSymbologyControl1.Refresh(); } } else //其他项 { if(pToolStripMenuIt
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 035 自建 符号 Symbol 选择 对话框