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

📄 viewlegend.cpp

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

   // Draw box around key if has focus

   if (GetFocus() == this && !m_bCopy && !pDC->IsPrinting())
   {
      CRect rect = m_rect;
      rect.right--;
      rect.bottom--;
      DrawBorder(pDC, rect);
   }   

   // Store new bottom position for scrollbar

   m_nBottomY = cy + nViewY;
}

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

BOOL CViewLegend::DrawMapLineLegend(CDC* pDC, CMapLayer* pMapLayer, int& cy, 
                                    LPCSTR s, CMapStyle mapstyle)
{

   CPen pen(mapstyle.m_nLineStyle, CViewMap::GetLineWidth(pDC,mapstyle.m_nLineStyle, mapstyle.m_nLineWidth), mapstyle.m_crLine);
   CPen* pPenOld = pDC->SelectObject(&pen);

   // Create brush

   CBrush brush;
   CComboBoxPattern::CreateBrush(brush, mapstyle.m_nPattern, mapstyle.m_nHatch, mapstyle.m_crFill);   
   CBrush* pBrushOld = pDC->SelectObject(&brush);
   
   // Output line or polygon

   int cx = m_rect.left + m_nBorder/2;

   if (!pMapLayer->GetAutoColour())
   {
      // Draw filled polygon
      if (pMapLayer->GetPolygon())
      {
         POINT aPoints[4];
         aPoints[0].x = cx + m_nBorder;
         aPoints[0].y = cy + m_nHeight/4;
         aPoints[1].x = cx + m_nBorder;
         aPoints[1].y = cy + (m_nHeight*3)/4;
         aPoints[2].x = cx + m_nTextPos-m_nBorder;
         aPoints[2].y = cy + (m_nHeight*3)/4;
         aPoints[3].x = cx + m_nTextPos-m_nBorder;
         aPoints[3].y = cy + m_nHeight/4;         
         pDC->Polygon(aPoints, sizeof(aPoints)/sizeof(POINT));
      } 
      // Draw sample line
      else
      {
         pDC->MoveTo(cx + m_nBorder, cy + m_nHeight/2);
         pDC->LineTo(cx + m_nTextPos-m_nBorder, cy + m_nHeight/2);
      }
   };

   // Set text color and draw the text

   if (!m_pDoc->GetLayers()->GetLegend1Font())
   {
      pDC->SetTextColor(pMapLayer->GetTextColour());
   };
   if (s == NULL) s = pMapLayer->GetName();   

   if (!pMapLayer->GetAutoColour()) cx += m_nTextPos;
   else cx += m_nBorder;

   BOOL bOK = DrawText(pDC, cx, cy, s);   

   pDC->SelectObject(pPenOld);
   pDC->SelectObject(pBrushOld);

   return bOK;
}

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

BOOL CViewLegend::DrawCoordLegend(CDC* pDC, CMapLayer* pMapLayer, int& cy, 
                                  LPCSTR s, CMapStyle mapstyle)
{            
   // Draw symbol

   int cx = m_rect.left + m_nBorder/2;

   CSize sz = CComboBoxSymbol::GetSymSize(pDC, pMapLayer->GetSymSize());   

   if (pMapLayer->GetSize() != 0)
   {
   

      if (!pMapLayer->GetAutoSize())
      {   
         CComboBoxSymbol::DrawSymbol(pDC, cx + m_nTextPos/2, cy + max(sz.cy, m_nHeight/2), mapstyle);         
      };
   };

   // Set text color

   if (!m_pDoc->GetLayers()->GetLegend1Font())
   {
      pDC->SetTextColor(pMapLayer->GetTextColour());
   };

   // Draw text

   if (s == NULL) s = pMapLayer->GetName();

   if (pMapLayer->GetSymbol() == CComboBoxSymbol::none) cx += m_nBorder;
   else  cx += m_nTextPos;   

   int cyOld = cy;
   BOOL bRet =  DrawText(pDC, cx, cy, s);   

   // Make room for custom symbols

   if (cyOld + sz.cy*2 > cy) cy = cyOld + sz.cy*2;

   return bRet;
}

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

void CViewLegend::DrawLegendValues(CDC* pDC, CMapLayer* pMapLayer, int& cy, CString s, CMapStyle mapstyle)
{
   int cx = m_rect.left;

   // Draw value

   CString s1 = s.Left(s.Find('\n'));
   CString s2 = s.Mid(s.Find('\n')+1);
   
   int cyt = cy;   

   // Draw Legend Values
      
   
   DrawText(pDC, cx + m_nBorder, cyt, s1, MAP_UPDATEY);   

   CSize sz = pDC->GetTextExtent(s2);
   DrawText(pDC, m_rect.right - m_nBorder - sz.cx, cy, s2);   

   // Handles case where no legend values!
   cy = max(cy, cyt);
}

/////////////////////////////////////////////////////////////////////////////
//
// Draws a scale indicating the range of values in the auto color scale
//

void CViewLegend::DrawAutoColour(CDC* pDC, CMapLayer* pMapLayer, int& cy, CMapStyle mapstyle)
{
   CRect rectA;   
     
   int y = cy + m_nHeight/2;
   int cx = m_rect.left;

   // Draw the lines
   
   int nPenWidth = m_nBorder/2;

   for (int i = 0; i < RANGECOLOR; i++)
   {
      // Select pen of the appropriate color

      double d = pMapLayer->GetAutoMin() + 
                 (pMapLayer->GetAutoMax()-pMapLayer->GetAutoMin())*i/RANGECOLOR;

      CViewMap::GetStyle(pMapLayer, NULL, d, mapstyle);            

     CPen pen(mapstyle.m_nLineStyle, CViewMap::GetLineWidth(pDC,mapstyle.m_nLineStyle, mapstyle.m_nLineWidth), mapstyle.m_crLine);
     CPen* pPenOld = pDC->SelectObject(&pen);

      CBrush brush;
      CComboBoxPattern::CreateBrush(brush, mapstyle.m_nPattern, mapstyle.m_nHatch, mapstyle.m_crFill);      

      int x1 = cx + m_nBorder + (m_rect.Width()-m_nBorder-m_nBorder)*i/RANGECOLOR;
      int x2 = cx + m_nBorder + (m_rect.Width()-m_nBorder-m_nBorder)*(i+1)/RANGECOLOR;

      CRect rect;
      rect.left = x1;
      rect.right = x2;
      rect.top = y-nPenWidth/2;
      rect.bottom = y+nPenWidth/2;

      pDC->FillRect(&rect, &brush);      

      // Draw bounding lines

    if (i == 0) 
    {
       pDC->MoveTo(x1, y-nPenWidth/2);
       pDC->LineTo(x1, y+nPenWidth/2);
    } else if (i+1 == RANGECOLOR)
    {
       pDC->MoveTo(x2, y-nPenWidth/2);
       pDC->LineTo(x2, y+nPenWidth/2);
    }

    pDC->MoveTo(x1, y-nPenWidth/2);
    pDC->LineTo(x2, y-nPenWidth/2);
    pDC->MoveTo(x1, y+nPenWidth/2);
    pDC->LineTo(x2, y+nPenWidth/2);

   pDC->SelectObject(pPenOld);


   }

   cy += m_nHeight;      
}

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

void CViewLegend::DrawAutoSize(CDC* pDC, CMapLayer* pMapLayer, int& cy)
{      
   int nPenWidth = 1;
   int crPen = RGB(0,0,0);
   int nPenStyle = PS_SOLID;
   int nPattern = BS_SOLID;
   int nHatch = 0;

   // Determine the maximum height of the symbols

   CSize sz = CComboBoxSymbol::GetSymSize(pDC, pMapLayer->GetSymSize() * AUTOSCALE);         

   cy += sz.cy;   
   
   for (int i = 0; i <= RANGESIZE; i++)
   {
      // Determine color of symbol

      double d = pMapLayer->GetAutoMin() + 
                 (pMapLayer->GetAutoMax()-pMapLayer->GetAutoMin())*i/RANGESIZE;

      CMapStyle mapstyle;
      CViewMap::GetStyle(pMapLayer, NULL, d, mapstyle);            

      // Determine position

      int x = m_rect.left + m_nBorder + (m_rect.Width()-m_nTextPos-m_nBorder)*i/RANGESIZE;

      mapstyle.m_dSymSize = (int)(((pMapLayer->GetSymSize() *AUTOSCALE)*i)/RANGESIZE);

      CComboBoxSymbol::DrawSymbol(pDC, x, cy, mapstyle);
   };

   cy += sz.cy;   
}

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

void CViewLegend::DrawAutoScale(CDC* pDC, CMapLayer* pMapLayer, int& cy)
{
   CSize sz(0,20);       
   strstream str1, str2;   

   str1.precision(10);
   str2.precision(10);

   double dMin = pMapLayer->GetAutoMin();
   double dMax = pMapLayer->GetAutoMax();
   
   if (dMin < dMax)
   {
      str1 << dMin << ends;   
      str2 << dMax << ends;
   } else
   {           
      if ((int)dMin % 10 == 1 && (int)dMin % 100 != 11) str1 << dMin << "st" << ends;
      else if ((int)dMin % 10 == 2 && (int)dMin % 100 != 12) str1 << dMin << "nd" << ends;
      else str1 << dMin << "th" << ends;

      if ((int)dMax % 10 == 1 && (int)dMax % 100 != 11) str2 << dMax << "st" << ends;
      else if ((int)dMax % 10 == 2 && (int)dMax % 100 != 12) str2 << dMax << "nd" << ends;
      else str2 << dMax << "th" << ends;      
   }
   
   sz = pDC->GetTextExtent(str2.str());         
            	
   pDC->TextOut(m_rect.left + m_nBorder - sz.cy/2, cy, str1.str());                         	
   pDC->TextOut(m_rect.right-m_nBorder-sz.cx, cy, str2.str());                         	

	str1.rdbuf()->freeze(0);
   str2.rdbuf()->freeze(0);
   
   cy += sz.cy;   
}

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

BOOL CViewLegend::DrawText(CDC* pDC, int cx, int& cy, LPCSTR sText,  int nFlags)
{
   CRect rect = m_rect;   
   rect.left = cx;
   rect.right = m_rect.right;
   rect.top = cy;      
   int y = pDC->DrawText(sText, &rect, DT_LEFT|DT_WORDBREAK|DT_TOP|DT_NOPREFIX|DT_NOCLIP);         

   if (nFlags & MAP_UPDATEY) cy += y;

  // If reached the bottom of the page and portrait then shift to the next column

   if (cy > m_rect.bottom - m_nBorder*2 && nFlags & MAP_UPDATEY)
   {
	  if (m_nColumn < m_nCols)
	  {
		  if (pDC->IsPrinting())   
		  {
			 m_nColumn++;			 

          int nWidth = m_rect.Width();
          m_rect.left = m_rect.right + m_nBorder;
          m_rect.right = m_rect.left + nWidth - m_nBorder;
          
          cy = m_rect.top;

          CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::map);
          if (BDGetApp()->GetLayout().IsAuto()) cy += m_nBorder*2;
		  } 
	  } else
	  {
         m_bCancel = TRUE;

         if (pDC->IsPrinting())
         {
            return FALSE;
         };
	  }
   };
   return TRUE;
}

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

void CViewLegend::OnEditCopy() 
{
	CBDView::OnEditCopy();	
}

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

void CViewLegend::DrawProjection(CDC* pDC, int& cy)
{   
   CFont font;

// Initialise layout

   CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::projection);
   CRect rectComments = layoutobj.m_rect;   
   if (!BDGetApp()->GetLayout().IsAuto() && pDC->IsPrinting())
   {      
      m_rect = CMapLayout::RectFromPercent(GetDoc()->GetViewMap()->GetRectPrint(), rectComments);
      cy = m_rect.top;
   }

   CString s = BDProjection()->GetProjectionName();
   CRect rect;   
   rect = m_rect;

   // Set the font

   if (rect.Width() > 0)
   {   
      CreateFont(pDC, font, -9);      
      CFont* pFontOld = pDC->SelectObject(&font);           

      pDC->SetTextColor(RGB(0,0,0));

      cy += m_nHeight;
 
      // If outputing to screen or rectangle, draw to a rectangle

      DrawText(pDC, m_rect.left + m_nBorder, cy, s);   

      // Tidy up

      pDC->SelectObject(pFontOld);        
   };
}

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

void CViewLegend::DrawScale(CDC* pDC, int& cy)
{

   CFont font;  
   CRect rect;
   
// Initialise layout

   CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::scale);
   CRect rectComments = layoutobj.m_rect;   
   if (!BDGetApp()->GetLayout().IsAuto() && pDC->IsPrinting())
   {      
      m_rect = CMapLayout::RectFromPercent(GetDoc()->GetViewMap()->GetRectPrint(), rectComments);
      cy = m_rect.top;
   }

   rect = m_rect;

   if (rect.Width() > 0)
   {
      // Set the font

      CreateFont(pDC, font, -9);
      CFont* pFontOld = pDC->SelectObject(&font);           

      pDC->SetTextColor(RGB(0,0,0));

      cy += m_nHeight;
 
      // If outputing to screen or rectangle, draw to a rectangle
      // If the scale is almost the set value then use this

      int nScale = GetDoc()->GetViewMap()->GetScale(pDC);
      if (abs(nScale - GetDoc()->GetScale() < 10)) nScale = GetDoc()->GetScale();
      CString s;
      s.Format("%s 1:%i", (LPCSTR)BDString(IDS_SCALE), nScale);   
      DrawText(pDC, m_rect.left + m_nBorder, cy, s);   

      // Tidy up

      pDC->SelectObject(pFontOld);        
   };
}

///////////////////////////////////////////////////////////////////////////////
//
// Draw the scale bar
//

void CViewLegend::DrawScaleBar(CDC* pDC, int& cy)
{
   CRect rect;
   CString s;
   BOOL bKM = FALSE;
   LOGFONT lf;
   CFont font;

   // Create font

   memset(&lf,0,sizeof(LOGFONT));
   lf.lfHeight = -8;
   lf.lfPitchAndFamily = 12;
   lf.lfCharSet = NRDB_CHARSET;
   strcpy(lf.lfFaceName, BDString(IDS_DEFAULTFONT));      
   ScaleFont(pDC, &lf);         
   font.CreateFontIndirect(&lf);  
   CFont* pFontOld = pDC->SelectObject(&font);           
   pDC->SetTextColor(RGB(0,0,0));
   CSize sz = pDC->GetTextExtent("ABC");

   // Draw the scale bar

    CBrush brush(RGB(0,0,0));

// Determine position of scale bar

    CRect rectS = m_rect;    
    rectS.left += m_nBorder;
    rectS.right = rectS.left + (rectS.Width() * 4)/5;
    rectS.top = cy;
    rectS.bottom = cy + (sz.cy*3)/2;
    
// Determine the layout position for the scalebar

   CMapLayoutObj layoutobj = GetDoc()->GetLayers()->GetMapLayout().GetLayoutObj(CMapLayout::scalebar);
   CRect rectScaleBar = layoutobj.m_rect;

   if (pDC->IsPrinting() && !BDGetApp()->GetLayout().IsAuto())
   {         
      rectS = CMapLayout::RectFromPercent(GetDoc()->GetViewMap()->GetRectPrint(), rectScaleBar);

      // Adjust to prevent fat scale bars
      rectS.bottom = rectS.top + (sz.cy*3)/2;
   }
 
   if (rectS.Width() > 0)
   {
     // Determine the scale range in meters
     // For lat/lon, based on bottom of map so assume linear
   
      CLongCoord coord1, coord2;

      coord1.x = GetDoc()->GetViewMap()->GetfXInv(rectS.left);   
      coord1.y = GetDoc()->GetViewMap()->GetfYInv(rectS.bottom);    

      coord2.x = GetDoc()->GetViewMap()->GetfXInv(rectS.right);   
      coord2.y = GetDoc()->GetViewMap()->GetfYInv(rectS.bottom);   

      int nDist = BDProjection()->GetDistance(coord1, coord2);
      int nRange = nDist;

      int nScale = 1;

      // Round the scale down to a value between 5 and 10

      while (nRange > 50)
      {
         nRange /= 10;

⌨️ 快捷键说明

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