⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewmaplayout.cpp

📁 一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和coverage地图文件格式。同时可以编辑相应的dbf文件。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
           // Snap to grid

           int ix = m_rect.Width() / (m_nWidth/SNAPSIZE);
           int iy = m_rect.Height() / (m_nHeight/SNAPSIZE);
           rectT.left = (rectT.left + ix/2)/ ix * ix;
           rectT.right = (rectT.right + ix/2) / ix * ix;
           rectT.top = (rectT.top + iy/2) / iy * iy;
           rectT.bottom = (rectT.bottom + iy/2) / iy * iy;

           // Convert to percent
           
           CRect rect = CMapLayout::RectAsPercent(m_rect, rectT);                      

           // Adjust to edges

           int nWidth = rect.Width();
           int nHeight = rect.Height();

           rect.left = max(rect.left, 0);
           rect.right = min(rect.right, 1000);           
           rect.top = max(rect.top, 0);
           rect.bottom = min(rect.bottom, 1000);                     

           rect.left = min(rect.left, rect.right);
           rect.right = max(rect.right, rect.left);
           rect.top = min(rect.top, rect.bottom);
           rect.bottom = max(rect.bottom, rect.top);           

           // Save the position back

           m_pLayoutObj->m_rect = rect;
                                              
           Invalidate(FALSE);

           // Check for changes
           
           CreateTracker();
           
           return;
      }
   }
      
   // If outside the track area then check if another component of the map has 
   // been clicked on

   CMapLayoutObj *pLayoutObj = HitTest(point);
            
   // Set the new component

   if (pLayoutObj != NULL)
   {
      m_pLayoutObj = pLayoutObj;
      CreateTracker();            
   } else
   {
      OnLayoutSelect();
   }
	
	CView::OnLButtonDown(nFlags, point);
}

///////////////////////////////////////////////////////////////////////////////
//
// Determines which rectangle the point lies within
//

CMapLayoutObj* CViewMapLayout::HitTest(CPoint pt)
{
   int iRect = -1;
   int iSize = 0;

   // Determine if user has clicked in any of the rectangles bounding
   // the components of the map

   for (int i = 0; i < GetLayout()->m_aLayout.GetSize(); i++)
   {
      // Convert the rectangle to screen coordinates

      CRect rectP = GetLayout()->m_aLayout[i].m_rect;
      CRect rect = CMapLayout::RectFromPercent(m_rect, rectP);

      if (rect.left <= pt.x && pt.x <= rect.right && 
          rect.top <= pt.y && pt.y <= rect.bottom)
      {               
         // Smaller rectangles take priority

         if (iRect == -1 || rect.Height() * rect.Width() < iSize)
         {
            iRect = i;
            iSize = rect.Height() * rect.Width();
         }               
      }
   }

   if (iRect != -1)
   {
      return &GetLayout()->m_aLayout[iRect];
   };
   return NULL;
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnLayoutMap() 
{   
   CreateLayoutObj(CMapLayout::map);	
}

void CViewMapLayout::OnLayoutArrow() 
{	
   CreateLayoutObj(CMapLayout::arrow);	
}

void CViewMapLayout::OnLayoutLegend() 
{	
	CreateLayoutObj(CMapLayout::legend);
}

void CViewMapLayout::OnLayoutProjection() 
{	
   CreateLayoutObj(CMapLayout::projection);
}

void CViewMapLayout::OnLayoutScalebar() 
{	
   CreateLayoutObj(CMapLayout::scalebar);
}

void CViewMapLayout::OnLayoutTitle() 
{   
   CreateLayoutObj(CMapLayout::title);
}

void CViewMapLayout::OnLayoutSource() 
{
   CreateLayoutObj(CMapLayout::source);
}

void CViewMapLayout::OnLayoutScale() 
{
	CreateLayoutObj(CMapLayout::scale);
	
}

///////////////////////////////////////////////////////////////////////////////
 
void CViewMapLayout::CreateLayoutObj(int nType)
{
   m_pLayoutObj = GetLayout()->GetLayoutObjPtr(nType);
   if (m_pLayoutObj == NULL)
   {
      CMapLayoutObj layoutobj;
      layoutobj.m_nType = nType;
      int index = GetLayout()->m_aLayout.Add(layoutobj);
      m_pLayoutObj = GetLayout()->m_aLayout.GetData() + index;
   }
   CreateTracker();			
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::CreateLayoutObjMult(int nType)
{
   // Add a new object of type box

   CMapLayoutObj layoutobj;
   layoutobj.m_nType = nType;

   int index = GetLayout()->m_aLayout.Add(layoutobj);

   m_pLayoutObj = GetLayout()->m_aLayout.GetData() + index;
   CreateTracker();	
}

///////////////////////////////////////////////////////////////////////////////
//
// Reset selection
//

void CViewMapLayout::OnLayoutSelect() 
{
   m_pLayoutObj = NULL;   

   if (m_pRectTracker != NULL) delete m_pRectTracker;
   m_pRectTracker = NULL;

   Invalidate(FALSE);
	
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnLayoutBorder() 
{  
   CreateLayoutObjMult(CMapLayout::box);

   // Set the default box style to transparent

   m_pLayoutObj->m_style.m_nPattern = BS_NULL;
   m_pLayoutObj->m_style.m_nHatch = 0;
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnLayoutPicture() 
{
	CreateLayoutObjMult(CMapLayout::picture);
	
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnLayoutText() 
{
	CreateLayoutObjMult(CMapLayout::text);	
}

///////////////////////////////////////////////////////////////////////////////
//
// Support deleting of objects
//

void CViewMapLayout::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar == VK_DELETE)
   {
      if (m_pLayoutObj != NULL)
      {
         for (int i = 0; i < GetLayout()->m_aLayout.GetSize(); i++)
         {
            if (GetLayout()->m_aLayout.GetData() + i == m_pLayoutObj)
            {
               GetLayout()->m_aLayout.RemoveAt(i);
               break;
            }
         }
         m_pLayoutObj = NULL;
         Invalidate(FALSE);

         if (m_pRectTracker != NULL) delete m_pRectTracker;
         m_pRectTracker = NULL;
      }      
   }
	
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

///////////////////////////////////////////////////////////////////////////////
//
// Display properties of the layout object
//

void CViewMapLayout::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
  // Determine which layout object is selected
 
   CMapLayoutObj *pLayoutObj = HitTest(point);
   if (pLayoutObj != NULL)
   {
      // Edit the style for a box

      if (pLayoutObj->m_nType == CMapLayout::box)
      {
         // Create maplayer

         CMapLayer maplayer;
         CMapLayerObj* pMapObj = new CMapLayerObj;
         pMapObj->SetDataType(BDMAPLINES);
         maplayer.Add(pMapObj);

         // Create map property

         CMapProperties mapprop;
         (CMapStyle&)mapprop = pLayoutObj->m_style;
         mapprop.m_bPolygon = TRUE;         

         // Create dialog

         CSheetMapStyle dlg(&maplayer, &mapprop, BDString(IDS_STYLE));            
         if (dlg.DoModal() == IDOK)
         {  
            pLayoutObj->m_style = mapprop;            
            Invalidate(FALSE);
         }
      }
      // Image

      else if (pLayoutObj->m_nType == CMapLayout::picture)
      {
         CString sType = BDString(IDS_JPGFILE) + "|*.jpg|" + 
                   BDString(IDS_PNGFILE) + "|*.png||";
   
         CFileDialog dlg(TRUE,"jpg",NULL,OFN_FILEMUSTEXIST, sType);
         if (dlg.DoModal() == IDOK)
         {
            pLayoutObj->m_sImageFile = dlg.GetPathName();
            Invalidate(FALSE);
         }
      }

      // Text

      else if (pLayoutObj->m_nType == CMapLayout::text)
      {
         CDlgLayoutText dlg(pLayoutObj->m_sText, pLayoutObj->m_logfont);
         if (dlg.DoModal() == IDOK)
         {
            pLayoutObj->m_sText = dlg.GetString();
            pLayoutObj->m_logfont = dlg.GetFont();

         }
      }
   }
	
	CView::OnLButtonDblClk(nFlags, point);
}

///////////////////////////////////////////////////////////////////////////////
//
// Toggles preview map mode
//

void CViewMapLayout::OnLayoutPreview() 
{   
   m_bOverlayMap = !m_bOverlayMap;   

   Invalidate(FALSE);
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnUpdateLayoutPreview(CCmdUI* pCmdUI) 
{
   pCmdUI->SetCheck(m_bOverlayMap);
	
}

///////////////////////////////////////////////////////////////////////////////

BOOL CViewMapLayout::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
   if (m_pRectTracker != NULL)
   {
	   if (m_pRectTracker->SetCursor(pWnd, nHitTest))
      {
         return TRUE;
      }
   };
	
	return CView::OnSetCursor(pWnd, nHitTest, message);
}

///////////////////////////////////////////////////////////////////////////////

BOOL CViewMapLayout::OnPreparePrinting(CPrintInfo* pInfo) 
{
	// default preparation
	return DoPreparePrinting(pInfo);   
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
   // Initialise the printing of the first map view   

   CViewMap* pViewMap = BDGetDocMap()->GetViewMap();
   if (pViewMap != NULL)
   {
      pViewMap->OnPrint(pDC, pInfo);
   };
	
	//CView::OnPrint(pDC, pInfo);
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
   // Reset the default map

   CViewMap* pViewMap = BDGetDocMap()->GetViewMap();
   if (pViewMap != NULL) pViewMap->OnEndPrinting(pDC, pInfo);
	
	CView::OnEndPrinting(pDC, pInfo);
}

///////////////////////////////////////////////////////////////////////////////

void CViewMapLayout::OnUpdateFilePrintPreview(CCmdUI* pCmdUI) 
{   
   CDocMap* pDocMap = BDGetDocMap();
	pCmdUI->Enable(pDocMap != NULL && pDocMap->GetViewMap() != NULL);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -