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

📄 viewlegend.cpp

📁 一个英国人写的GIS查看/编辑工具。支持标准的shapefile地图文件格式和coverage地图文件格式。同时可以编辑相应的dbf文件。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
         nScale *= 10;
      }
      while (nRange > 5)
      {
         nRange /= 2;
         nScale *= 2;
      }

      // Remove text height from scale bar height

      rectS.top += sz.cy;

      // Convert the range back up, but rounded

       int nScaleRange = nRange*nScale;
       if (nScaleRange == 0) return;

       int nScaleDiv = nScaleRange / nScale;
       bKM = nScaleRange / nScaleDiv > 1000;
    
       for (int i = 0; i <= nScaleDiv; i ++)
       {
          // Determine position of bar

          rect = rectS;
          rect.left = rectS.left + (int)((((rectS.right-rectS.left) * i) * (double)nScaleRange) / (nDist)) / nScaleDiv;
          rect.right = rectS.left + (int)((((rectS.right-rectS.left) * (i+1)) * (double)nScaleRange) / (nDist)) / nScaleDiv;
       
          if (i < nScaleDiv)
          {
             // Draw rectange

             if (i % 2)
             {
                pDC->FillRect(&rect, &brush);
             } else
             {
                GetDoc()->GetViewMap()->DrawRect(pDC, &rect, RGB(0,0,0));
             };

             // Draw text

             int n = (nScaleRange * i) / nScaleDiv;
             if (bKM) n = n / 1000;
             s.Format("%i",n);
             rect.bottom = rect.top;
             rect.top = rect.bottom - sz.cy;
             pDC->DrawText(s, &rect, DT_BOTTOM|DT_LEFT|DT_SINGLELINE); 
          } else
          {
             // Display units         
    
             s = BDString(IDS_METERS);
             if (bKM) s = BDString(IDS_KM); 
             rect.bottom = rect.top;
             rect.top = rect.bottom - sz.cy;
             pDC->DrawText(s, &rect, DT_BOTTOM|DT_LEFT|DT_SINGLELINE); 
          }
       }
   
       // Tidy up

      pDC->SelectObject(pFontOld);        

      // Update position

      cy += rectS.Height();
   };
}

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

void CViewLegend::DrawComments(CDC* pDC, int& cy)
{
   LOGFONT lf;   
    
   // Set the font
     
   pDC->SetTextColor(RGB(0,0,0));  

   cy += m_nHeight;

   CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::source);
   CRect rectLegend = layoutobj.m_rect;   
   if (pDC->IsPrinting() && !BDGetApp()->GetLayout().IsAuto())
   {         
      m_rect = CMapLayout::RectFromPercent(GetDoc()->GetViewMap()->GetRectPrint(), rectLegend);
      cy = m_rect.top;
   }
 
   // If outputing to screen or rectangle, draw to a rectangle

   if (m_rect.Width() > 0)
   {
      CString s;

      for (int i = 0; i < m_pDoc->GetLayers()->GetSize(); i++)
      {         
         CFont font;
         lf = m_pDoc->GetLayers()->GetAt(i)->GetFontC();

         ScaleFont(pDC, &lf);         
         font.CreateFontIndirect(&lf);  
         CFont* pFontOld = pDC->SelectObject(&font);           
         DrawText(pDC, m_rect.left + m_nBorder, cy, m_pDoc->GetLayers()->GetAt(i)->GetComment());   

         pDC->SelectObject(pFontOld);        
     
      }  
   };
        
}

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

void CViewLegend::DrawNorthArrow(CDC* pDC, int& cy)
{
   CRect rect = m_rect;

   CPen pen(PS_SOLID, 2, RGB(0,0,0));
   CPen* pPenOld = pDC->SelectObject(&pen);   
   int cx = 0;

// Determine the default position for the title

   CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::arrow);
   CRect& rectNorthArrow = layoutobj.m_rect;

   if (pDC->IsPrinting() && !BDGetApp()->GetLayout().IsAuto())
   {         
      m_rect = CMapLayout::RectFromPercent(GetDoc()->GetViewMap()->GetRectPrint(), rectNorthArrow);
      rect = m_rect;
      cy = m_rect.top;
   }
      
   // Ensure space if portrait

   if (m_rect.Width() > 0)
   {
      int cy1 = cy;
      int nColumn = m_nColumn;
      for (int i = 0; i < 4; i++) 
      {
         DrawText(pDC, cx, cy1, " ");
         if (m_nColumn != nColumn) 
         {
            cy = cy1;
            break;
         }
      };      
      cx = (rect.right + rect.left)/2;         
      if (cy + m_nBorder* 5 > GetDoc()->GetViewMap()->GetRectPrint().bottom) return;
 
      // Draw Arrow
   
      pDC->MoveTo(cx, cy);
      pDC->LineTo(cx-m_nBorder/2, cy+m_nBorder*2);
      pDC->LineTo(cx, cy+(m_nBorder*3)/2);
      pDC->LineTo(cx+m_nBorder/2, cy+m_nBorder*2);
      pDC->LineTo(cx, cy);
      cy += m_nBorder*2;

      // Draw N

      pDC->MoveTo(cx+m_nBorder/4, cy);
      pDC->LineTo(cx+m_nBorder/4, cy+m_nBorder);
      pDC->LineTo(cx-m_nBorder/4, cy);
      pDC->LineTo(cx-m_nBorder/4, cy+m_nBorder);
      cy += m_nBorder*2;

      pDC->SelectObject(pPenOld);        
   };   
}



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

void CViewLegend::OnSize(UINT nType, int cx, int cy) 
{
	CBDView::OnSize(nType, cx, cy);
}

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

void CViewLegend::DrawBorder(CDC* pDC, CRect rect, int nPen, int nWidth, int nColour)
{
   CPen pen(nPen, nWidth, nColour);
   CPen* pPenOld = pDC->SelectObject(&pen);
   pDC->MoveTo(rect.left, rect.bottom); 
   pDC->LineTo(rect.right, rect.bottom);
   pDC->LineTo(rect.right, rect.top);
   pDC->LineTo(rect.left, rect.top);
   pDC->LineTo(rect.left, rect.bottom);
   pDC->SelectObject(pPenOld);
}

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

void CViewLegend::OnSetFocus(CWnd* pOldWnd) 
{
	CBDView::OnSetFocus(pOldWnd);
	
	Invalidate(TRUE);
   UpdateWindow();  
	
}

void CViewLegend::OnKillFocus(CWnd* pNewWnd) 
{
	CBDView::OnKillFocus(pNewWnd);
	
	Invalidate(TRUE);
   UpdateWindow();  
	
}

///////////////////////////////////////////////////////////////////////////////
//
// Override functions so that they can be accessed when the key window has
// input focus
//

void CViewLegend::OnFilePrintPreview() 
{
   m_pDoc->GetViewMap()->OnFilePrintPreview();
}

void CViewLegend::OnFilePrint() 
{
	m_pDoc->GetViewMap()->OnFilePrint();
}

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

void CViewLegend::OnViewZoomin() 
{
	m_pDoc->GetViewMap()->OnViewZoomin();	
}

void CViewLegend::OnViewZoomnormal() 
{
	m_pDoc->GetViewMap()->OnViewZoomnormal();	
}

void CViewLegend::OnViewZoomout() 
{
   m_pDoc->GetViewMap()->OnViewZoomout();		
}

void CViewLegend::OnMapPan() 
{
	m_pDoc->GetViewMap()->OnMapPan();	
}

///////////////////////////////////////////////////////////////////////////////
//
// Update the current layer according to which point was clicked on
//

void CViewLegend::OnLButtonDown(UINT nFlags, CPoint point) 
{
   int nLayer = GetLayer(point.y);

   if (nLayer >= 0)
   {
      // Activate the drag layer mode

      m_nDragLayer = nLayer;

      m_hCursorOld = SetCursor(m_hCursorKey);

     // Set the active layer if changed and redraw

	   if (nLayer != m_pDoc->GetLayers()->GetDefault())
      {
         m_pDoc->GetLayers()->SetDefault(nLayer);      

         Invalidate(TRUE);
         UpdateWindow();  
      }
   };
	
	
	CBDView::OnLButtonDown(nFlags, point);
}

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

void CViewLegend::OnLButtonUp(UINT nFlags, CPoint point) 
{
   int nLayer = GetLayer(point.y);

   if (nLayer == start) nLayer = 0;
   if (nLayer == end) nLayer = m_pDoc->GetLayers()->GetSize()-1;

   // Swap layers

   if (nLayer != m_nDragLayer && m_nDragLayer >= 0)
   {            
      CMapLayer* pMapLayer = (CMapLayer*)m_pDoc->GetLayers()->GetAt(m_nDragLayer);
      
      // Shift layers up
      
      for (int i = m_nDragLayer; i < nLayer; i++)
      {
         m_pDoc->GetLayers()->SetAt(i, m_pDoc->GetLayers()->GetAt(i+1));
      }            

      // Shift layers down

      for (i = m_nDragLayer; i > nLayer; i--)
      {
         m_pDoc->GetLayers()->SetAt(i, m_pDoc->GetLayers()->GetAt(i-1));
      }             

      // Set this layer the default

      m_pDoc->GetLayers()->SetAt(nLayer, pMapLayer);
      m_pDoc->GetLayers()->SetDefault(nLayer); 

      // Redraw the windows, key first

      Invalidate(TRUE);
      UpdateWindow();  
      m_pDoc->UpdateAllViews(this);   

      
   }
 
  // Reset cursor

   if (m_nDragLayer >= 0)
   {
      SetCursor(m_hCursorOld);
   }

   // Reset drag item

   m_nDragLayer = null;   

	CBDView::OnLButtonUp(nFlags, point);
}

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

void CViewLegend::OnMouseMove(UINT nFlags, CPoint point) 
{   
	if (m_nDragLayer != null)
   {
      SetCursor(m_hCursorKey);
   } 
	
	CBDView::OnMouseMove(nFlags, point);
}


///////////////////////////////////////////////////////////////////////////////
//
// Display the properties dialog for the current layer
//

void CViewLegend::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	int nLayer = GetLayer(point.y);
	if (nLayer >= 0)
   {
      m_pDoc->GetLayers()->SetDefault(nLayer);
      CMapLayer* pMapLayer = m_pDoc->GetLayers()->GetAt(nLayer);

      CSheetMapProp dlg(m_pDoc->GetLayers(), pMapLayer, BDString(IDS_MAPPROP));
      if (dlg.DoModal())
      {
         m_pDoc->UpdateAllViews(NULL);   
      } else
      {
         Invalidate(TRUE);
         UpdateWindow();  
      }
   }
		
	CBDView::OnLButtonDblClk(nFlags, point);
}

///////////////////////////////////////////////////////////////////////////////
//
// Determine which layer has been clicked on
//

int CViewLegend::GetLayer(int cy)
{
   int nPos = GetScrollPos(SB_VERT);
   int nViewY = (m_nBottomY * nPos)/SCROLLRANGE;

   for (int i = 0; i < m_anLayerPos.GetSize()-1; i++)
   {
      if (cy + nViewY >= m_anLayerPos[i] && cy + nViewY <= m_anLayerPos[i+1])
      {
         return i;
      }
   }

   if (m_anLayerPos.GetSize() == 0) return null;
   else if (cy + nViewY < m_anLayerPos[0]) return start;

   ASSERT (cy + nViewY > m_anLayerPos[m_anLayerPos.GetSize()-1]);
   
   return end;   
}

///////////////////////////////////////////////////////////////////////////////
// 
// If right button is pressed, display map layer dialog
//

void CViewLegend::OnRButtonDown(UINT nFlags, CPoint point) 
{
   int nLayer = GetLayer(point.y);
	if (nLayer >= 0)
   {
      if (nLayer != m_pDoc->GetLayers()->GetDefault())
      {
         m_pDoc->GetLayers()->SetDefault(nLayer);

         Invalidate(TRUE);
         UpdateWindow();  
      };      
   }
   m_pDoc->OnViewLayers();
	      	
	CBDView::OnRButtonDown(nFlags, point);
}

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

void CViewLegend::CreateFont(CDC* pDC, CFont& font, int nHeight)
{
   LOGFONT lf;
   memset(&lf,0,sizeof(LOGFONT));
   lf.lfHeight = nHeight;
   lf.lfPitchAndFamily = 34;
   lf.lfCharSet = NRDB_CHARSET;
   strcpy(lf.lfFaceName, BDString(IDS_DEFAULTFONT));      
   ScaleFont(pDC, &lf);         
   font.CreateFontIndirect(&lf);  
}

///////////////////////////////////////////////////////////////////////////////
//
// Allow scrolling down
//

void CViewLegend::OnVScroll(UINT nSBCode, UINT uPos, CScrollBar* pScrollBar) 
{
   CRect rect;
   GetClientRect(&rect);

   int nPos = uPos;
   if (nSBCode != SB_THUMBPOSITION)
   {
      nPos = GetScrollPos(SB_VERT);
   };

   switch(nSBCode)
   {   
      case SB_LINEDOWN:      
         nPos += SCROLLRANGE/10;
      break;            

      case SB_LINEUP:
         nPos -= SCROLLRANGE/10;
      break;
            
      case SB_PAGEDOWN:        
         nPos += SCROLLRANGE/2;
      break;            
      
      case SB_PAGEUP:                            
         nPos -= SCROLLRANGE/10;
      break;         
     
      case SB_THUMBPOSITION:
         // Skip default
      break; 
  
      default:
         CBDView::OnVScroll(nSBCode, nPos, pScrollBar);
         return;
   }
   
   // Redraw the map
        
    nPos = min(SCROLLRANGE, nPos);
    nPos = max(0, nPos);
    uPos = nPos;

    SetScrollPos(SB_VERT, nPos);
    Invalidate();
    
	
	 CBDView::OnVScroll(nSBCode, uPos, pScrollBar);
}

⌨️ 快捷键说明

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