VC+MO实现地图的放大,缩小和漫游

 首先设置几个常量:ZOOMIN   ZOOMOUT  PAN通过工具栏或其它选择来改变 CurrentOperation

void CTestMapView::OnMouseDownMap1(short Button, short Shift, long X, long Y)
{
  SetCapture();
  //放大
 
  if(m_CurrentOperation==ZOOMIN)
  {
      CMoRectangle rect(m_map.TrackRectangle());
      double m_TrackRectangle_Height;
      double m_TrackRectangle_Width;
   m_TrackRectangle_Height=rect.GetHeight();
      m_TrackRectangle_Width=rect.GetWidth();

      //拉框放大
      if(LPDISPATCH(rect)&&m_TrackRectangle_Height!=0&&m_TrackRectangle_Width!=0)
      m_map.SetExtent(rect);

      //定点放大
      else
   {
       CMoPoint m_CenterPoint;
       m_CenterPoint=m_map.ToMapPoint(float(X),float(Y));
       double m_CenterPointX;
       double m_CenterPointY;
       m_CenterPointX=m_CenterPoint.GetX();
          m_CenterPointY=m_CenterPoint.GetY();
       CMoRectangle rect_Extent(m_map.GetExtent());
       //设置放大系数
       rect_Extent.ScaleRectangle(0.5);
       m_map.SetExtent(rect_Extent);
       //使图形居中
       m_map.CenterAt(m_CenterPointX,m_CenterPointY);

   }
  }
  //缩小
  
  else if(m_CurrentOperation==ZOOMOUT)
  {
  CMoPoint m_CenterPoint;
   CMoRectangle rect_Mouse(m_map.TrackRectangle());
   CMoRectangle rect_Extent;
   rect_Extent=m_map.GetExtent();
   double m_CenterPointX;
   double m_CenterPointY;
   //拉框缩小
   if(LPDISPATCH(rect_Mouse)&&rect_Mouse.GetHeight()!=0&&rect_Mouse.GetWidth()!=0)
   {
    m_CenterPoint=rect_Mouse.GetCenter();
    m_CenterPointX=m_CenterPoint.GetX();
    m_CenterPointY=m_CenterPoint.GetY();
    //求解并设置缩小系数
    double X_Scale;
    double Y_Scale;
    X_Scale=rect_Extent.GetHeight()/rect_Mouse.GetHeight();
    Y_Scale=rect_Extent.GetWidth()/rect_Mouse.GetWidth();
    double m_Scale=X_Scale;
    if(X_Scale     m_Scale=Y_Scale;
    rect_Extent.ScaleRectangle(m_Scale);
   }
    ///定点缩小
      else
   {
       m_CenterPoint=m_map.ToMapPoint(float(X),float(Y));
       m_CenterPointX=m_CenterPoint.GetX();
       m_CenterPointY=m_CenterPoint.GetY();
    设置缩小系数
       rect_Extent.ScaleRectangle(2);

   }
   m_map.SetExtent(rect_Extent);
   //居中
   m_map.CenterAt(m_CenterPointX,m_CenterPointY);
  }
   //漫游
   else if(m_CurrentOperation==PAN)
    m_map.Pan();
   else;
   ReleaseCapture();

 
 
}

你可能感兴趣的:(VC+MO实现地图的放大,缩小和漫游)