pursuedream
成功=水平+业务+沟通+判断
在MapObject控件的基础上画扇型,保存画的轨迹,并得到扇型内的数据。由于MapObject不提供画扇型的Track方法,所以只能借助System.Drawing.Graphic来画,正好Graphic有方法DrawPie()。
1.先考虑如何画
  用户第一次点击MapObject上任意一点时,设为圆心,第二此点击时候,便确立半径,接着用户可以拉动鼠标到任意位置,呈现出扇型。
如果角度大于180,那么将画出相反方向的扇型。
为了让用户有操作体验,也就是在确立圆心时候,拉动鼠标时候,产生一条线以此来提示用户,那么可以借助MapObject中画线方法来进行。
在mapojbect_MouseDownEvent事件下
//定义类成员变量
        private ESRI.MapObjects2.Core.Line radiusLine;

        
private ESRI.MapObjects2.Core.Points collectPoints;
private int sumTotal = 0;//控制点的数量
if(e.button == 1)
{
  StartSector(e.x,e.y);
}

        
/// <summary>
        
/// start sector
        
/// </summary>
        
/// <param name="pointX"></param>
        
/// <param name="pointY"></param>
        private void StartSector(int pointX, int pointY)
        {
            
if (radiusLine == null)
            {
                radiusLine 
= new LineClass();
            }
            
if (collectPoints == null)
            {
                collectPoints 
= new PointsClass();
            }
            ESRI.MapObjects2.Core.Point anyPoint 
= axMap.ToMapPoint(pointX,pointY);
            
// use radiusLine to draw variety line.
            if (collectPoints.Count == 2)
            {
                
// because point has increased on mouse move event.
                collectPoints.Remove(1);
                radiusLine.Parts.Remove(
1);
            }
            collectPoints.Add(anyPoint);
            radiusLine.Parts.Add(collectPoints); 
//draw a fixed line.
            sumTotal++;

            
if (collectPoints.Count == 2 && sumTotal == 2)
            {
                
//store two points. 
                StoreSectorRadiusPoint(collectPoints.Item(0),collectPoints.Item(1));
            }
           
            
if (sumTotal == 3)
            {    
                ClearSectorIdentity();
                SectorSelect(anyPoint);
            }
        }

        
/// <summary>
        
/// clear sector indentifier to do next. v3.1
        
/// </summary>
        public void ClearSectorIdentity()
        {
            sumTotal 
= 0;
            
int pTotal = 0;
            
if (collectPoints != null)
            {
                pTotal 
= collectPoints.Count;
                
for (int i=0 ; i<pTotal; i++)
                {
                    collectPoints.Remove(
0);
                }
            }
            
if (radiusLine != null)
            {
                pTotal 
= radiusLine.Parts.Count;
                
for (short i=0 ; i<pTotal; i++)
                {
                    radiusLine.Parts.Remove(
0);
                }
                axMap.CtlRefresh();
            }
            
        }

        
/// <summary>
        
/// move mouse to draw line    
        
/// </summary>
        
/// <param name="pointX"></param>
        
/// <param name="pointY"></param>
        private void MoveDrawLine(int pointX,int pointY)
        {
            axMap.Refresh();
            
if (collectPoints.Count > 1)
            {
                collectPoints.Remove(
1); // just two points
            }
            
if (radiusLine.Parts.Count > 1)
            {
                radiusLine.Parts.Remove(
1);
            }
            ESRI.MapObjects2.Core.Point anyPoint 
= axMap.ToMapPoint(pointX,pointY);
            collectPoints.Add(anyPoint);
            radiusLine.Parts.Add(collectPoints); 
//draw a line.
        }

        
/// <summary>
        
/// determine three point and show to do next.
        
/// </summary>
        
/// <param name="thirdPoint"></param>
        private void SectorSelect(ESRI.MapObjects2.Core.Point thirdPoint)
        {
            axMap.MousePointer 
= MousePointerConstants.moHourglass;
            
try
            {
                mapTool.SectorSelect(thirdPoint);
                
//stat and show form
                StartSelection(true);
            }
            
catch(Exception ep)
            {
                IdgpTrace.IdgpTraceError(
"RectSelect error. " + ep.Message,ModuleName.GISWINDOW);
            }

        }

另外在MouseMoveEvent事件(主要是为画线,因为移动鼠标可以确认一点,那么可以就可以画线)
            if ( sumTotal >= 1)
            {
               
if (sumTotal == 1// draw line
               {
                  MoveDrawLine(e.x,e.y);
               }
               
else  // draw sector
               {
                  ESRI.MapObjects2.Core.Point varietyPoint 
= axMap.ToMapPoint(e.x,e.y);
                 //draw sector            
                 DrawVarietySector(axMap,varietyPoint);                  

               }
            }
画线必须使用drawShape()方法,该方法必须在AfterTrackingLayerDraw这样的事件下写
                if (radiusLine.Parts.Count == 2)   //draw line
                {
                    ESRI.MapObjects2.Core.Symbol symLine 
= new SymbolClass();
                    symLine.SymbolType 
= ESRI.MapObjects2.Core.SymbolTypeConstants.moLineSymbol;
                    symLine.Color 
= System.Convert.ToUInt32(ESRI.MapObjects2.Core.ColorConstants.moBlack);
                    axMap.DrawShape(radiusLine,symLine);
                }


posted on 2007-08-28 17:36  pursuedream  阅读(602)  评论(2)    收藏  举报