示例#1
0
        public void LineSelect(AxMapControl mapControl)
        {
            this.init();
            IGeometry pGeometryL;

            pGeometryL = mapControl.TrackLine();

            //新建选择集对象
            ISelectionEnvironment pSelectionEnvL;

            pSelectionEnvL = new SelectionEnvironmentClass();
            //改变选择集的默认颜色
            pSelectionEnvL.DefaultColor = pColor;
            //选择要素,并将其放入选择集
            mapControl.Map.SelectByShape(pGeometryL, pSelectionEnvL, false);
            mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,
                                                 null, null);
        }
示例#2
0
        public void AddLineByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y)
        {
            ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType;
            if (featype == esriGeometryType.esriGeometryPolyline)//判断层是否为线层
            {
                //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer;
                IFeatureClass      fc = l.FeatureClass;
                IFeatureClassWrite fr = fc as IFeatureClassWrite;
                IWorkspaceEdit     w  = (fc as IDataset).Workspace as IWorkspaceEdit;
                IFeature           f;
                //可选参数的设置
                object Missing = Type.Missing;
                IPoint p       = new PointClass();
                w.StartEditing(true);
                w.StartEditOperation();

                f = fc.CreateFeature();
                //定义一个多义线对象
                IRgbColor color = new RgbColor();
                // 设置颜色属性
                color.Red          = 255;
                color.Transparency = 255;

                //ISimpleLineSymbol PlyLine = new SimpleLineSymbolClass();
                //PlyLine.Color = color;
                //PlyLine.Style = esriSimpleLineStyle.esriSLSInsideFrame;
                //PlyLine.Width = 1;

                IGeometry iGeom = axMapControl1.TrackLine();

                AddLine(axMapControl1, iGeom);

                f.Shape = iGeom;
                fr.WriteFeature(f);
                w.StopEditOperation();
                w.StopEditing(true);
            }
        }
示例#3
0
 /// <summary>
 /// 测量线
 /// </summary>
 /// <param name="axMapControl"></param>
 public static void CreatLine(AxMapControl axMapControl)
 {
     try
     {
         IActiveView pActiveView = axMapControl.ActiveView;
         IScreenDisplay screenDisplay = pActiveView.ScreenDisplay;
         ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
         IRgbColor rgbClolor = new RgbColorClass();
         lineSymbol.Width = 2;
         rgbClolor.Red = 255;
         lineSymbol.Color = rgbClolor;
         IPolyline pLine = axMapControl.TrackLine() as IPolyline;
         screenDisplay.StartDrawing(screenDisplay.hDC, (short)esriScreenCache.esriNoScreenCache);
         screenDisplay.SetSymbol((ISymbol)lineSymbol);
         screenDisplay.DrawPolyline(pLine);
         screenDisplay.FinishDrawing();
         double l = Math.Abs(pLine.Length*100);
         //axMapControl.Map.MapUnits = esriUnits.esriKilometers;
         //DialogResult r =MessageBox.Show("长度为:" + l.ToString() + "公里(km)","长度测量结果");
         MessageBox.Show("长度为:" + Convert.ToDouble(l).ToString("0.000") + "千米(km)", "长度测量结果");
         IGraphicsContainer pDeletElement = axMapControl.ActiveView.FocusMap as IGraphicsContainer;
         pDeletElement.DeleteAllElements();
         axMapControl.ActiveView.Refresh();
         //screenDisplay.RemoveAllCaches();
         // typeof(AxMapControl).GetEvent("OnMouseDown").RemoveEventHandler(axMapControl,);
     }
     catch
     {  }
 }
示例#4
0
        public void AddLineByWrite(AxMapControl axMapControl1, IFeatureLayer l, double x, double y)
        {
            ESRI.ArcGIS.Geometry.esriGeometryType featype = l.FeatureClass.ShapeType;
            if (featype == esriGeometryType.esriGeometryPolyline)//�жϲ��Ƿ�Ϊ�߲�
            {
                //IFeatureLayer l = MapCtr.Map.get_Layer(0) as IFeatureLayer;
                IFeatureClass fc = l.FeatureClass;
                IFeatureClassWrite fr = fc as IFeatureClassWrite;
                IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
                IFeature f;
                //��ѡ����������
                object Missing = Type.Missing;
                IPoint p = new PointClass();
                w.StartEditing(true);
                w.StartEditOperation();

                f = fc.CreateFeature();
                //����һ�������߶���
                IRgbColor color = new RgbColor();
                // ������ɫ����
                color.Red = 255;
                color.Transparency = 255;

                //ISimpleLineSymbol PlyLine = new SimpleLineSymbolClass();
                //PlyLine.Color = color;
                //PlyLine.Style = esriSimpleLineStyle.esriSLSInsideFrame;
                //PlyLine.Width = 1;

                IGeometry iGeom = axMapControl1.TrackLine();

                AddLine(axMapControl1, iGeom);

                f.Shape = iGeom;
                fr.WriteFeature(f);
                w.StopEditOperation();
                w.StopEditing(true);
            }
        }
示例#5
0
        private void axMapControlMainMap_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            int statusFlag = CommonLib.MapMouseFlag;

            if (statusFlag <= 1)
            {
                return;
            }

            AxMapControlMainMap.MousePointer = esriControlsMousePointer.esriPointerCrosshair;//鼠标指针:十字状
            IPoint pPoint = AxMapControlMainMap.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

            #region 11-19:空间查询(画点、线、面)
            if (statusFlag >= 11 && statusFlag <= 19)
            {
                object symbol = null;
                switch (statusFlag)
                {
                case 11:
                    IPoint point = new ESRI.ArcGIS.Geometry.Point();
                    point.X = e.mapX;
                    point.Y = e.mapY;
                    CommonLib.MapGeometry = point;
                    symbol = RenderOpt.GetSimpleMarkerSymbol("ff0000");
                    break;

                case 12:
                    CommonLib.MapGeometry = AxMapControlMainMap.TrackLine();
                    symbol = RenderOpt.GetSimpleLineSymbol("ff0000");
                    break;

                case 13:
                    CommonLib.MapGeometry = AxMapControlMainMap.TrackPolygon();
                    symbol = RenderOpt.GetSimpleFillSymbol("99ccff", "ff0000");
                    break;

                case 14:
                    CommonLib.MapGeometry = AxMapControlMainMap.TrackRectangle();
                    symbol = RenderOpt.GetSimpleFillSymbol("99ccff", "ff0000");
                    break;

                default:
                    CommonLib.MapGeometry = null;
                    break;
                }

                if (CommonLib.MapGeometry != null)
                {
                    //axMapControlMainMap.Map.SelectByShape(CommonLib.MapGeometry, null, false);
                    //axMapControlMainMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                    AxMapControlMainMap.DrawShape(CommonLib.MapGeometry, ref symbol);
                }
            }
            #endregion
            #region
            //#region 绘制图形
            //if (CommonLib.MapMouseFlag >= 1 && CommonLib.MapMouseFlag <= 4)
            //{
            //    //初始化Color
            //    IRgbColor rgbColor1 = new RgbColor();
            //    rgbColor1.Red = 255;
            //    rgbColor1.Green = 255;
            //    rgbColor1.Blue = 0;

            //    //初始化Symbol
            //    object symbol = null;
            //    if (geometry.GeometryType == esriGeometryType.esriGeometryPolyline) //线
            //    {
            //        ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol();
            //        simpleLineSymbol.Color = rgbColor1;
            //        simpleLineSymbol.Width = 5;
            //        symbol = simpleLineSymbol;
            //    }
            //    else
            //    {
            //        ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol();
            //        simpleFillSymbol.Color = rgbColor1;
            //        symbol = simpleFillSymbol;
            //    }

            //    axMapControlMainMap.DrawShape(geometry, ref symbol);
            //}
            //else if (CommonLib.MapMouseFlag == 5)
            //{
            //    //初始化Color
            //    IRgbColor rgbColor2 = new RgbColor();
            //    rgbColor2.Red = 255;
            //    rgbColor2.Green = 0;
            //    rgbColor2.Blue = 0;

            //    //初始化Symbol
            //    object symbol = null;
            //    ITextSymbol textSymbol = new TextSymbol();
            //    textSymbol.Color = rgbColor2;
            //    symbol = textSymbol;

            //    axMapControlMainMap.DrawText(geometry, "顶你个肺", ref symbol);
            //}
            //#endregion

            //#region 空间选择
            //if (CommonLib.MapMouseFlag >= 11 && CommonLib.MapMouseFlag <= 15)
            //{
            //    axMapControlMainMap.Map.SelectByShape(geometry, null, false);
            //}
            //axMapControlMainMap.Refresh();

            //#endregion
            #endregion
        }