📄 bufferdlg.cpp
字号:
// BufferDlg.cpp : implementation file
//
/*
* This sample application and corresponding sample code is provided for
* example purposes only. It has not undergone rigorous testing and as
* such should not be shipped as part of a final application without
* extensive testing on the part of the organization releasing the
* end-user product.
*/
#include "stdafx.h"
#include "MapTest.h"
#include "BufferDlg.h"
#include "Mapx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBufferDlg dialog
CBufferDlg::CBufferDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBufferDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBufferDlg)
m_Distance = 0;
//}}AFX_DATA_INIT
}
void CBufferDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBufferDlg)
DDX_Text(pDX, IDC_EDITDISTANCE, m_Distance);
DDV_MinMaxInt(pDX, m_Distance, 1, 1000);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_LISTOUTLETS, m_chkListBox);
}
BEGIN_MESSAGE_MAP(CBufferDlg, CDialog)
//{{AFX_MSG_MAP(CBufferDlg)
ON_BN_CLICKED(IDC_MILES, OnMiles)
ON_BN_CLICKED(IDC_KILOMETERS, OnKilometers)
ON_NOTIFY(UDN_DELTAPOS, IDC_SPINDISTANCE, OnDeltaposSpindistance)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBufferDlg message handlers
void CBufferDlg::InitListBox()
{
CMapXLayer outletLyr;
m_chkListBox.ResetContent(); //Empty the contents of the list box.
if (!m_pMap->GetLayers().Item("Outlets")){//If the "Outlets" layer isn't there, do not
return; //go any further.
}
try {
m_outletFtrs = m_pMap->GetLayers().Item("Outlets").AllFeatures();
//m_outletFtrs is set equal to the features of the "Outlets" layer
outletLyr = m_pMap->GetLayers().Item("Outlets");
//outletLyr is set equal to the "Outlets" layer
outletLyr.SetKeyField("Store_Name");
//Change the keyfield of outletLyr equal to "Store_Name" the second column
// in the Outlets.tab file
for (int i = 1; i <= m_outletFtrs.GetCount(); i++){
CString ftrName = m_outletFtrs.Item(i).GetKeyValue(); //Get the keyvalue
int n = m_chkListBox.AddString(ftrName); //Add it to the listbox
m_chkListBox.SetItemData(n, (DWORD)i);
}
} catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
} catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
BOOL CBufferDlg::OnInitDialog()
{
CSpinButtonCtrl* pSpin;
CDialog::OnInitDialog();
ASSERT(m_pMap);
InitListBox();
CheckDlgButton(IDC_MILES, 1);
m_Units = miUnitMile;
pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_SPINDISTANCE);
pSpin->SetRange(1, 1000);
pSpin->SetPos(140);
m_Distance = 140;
UpdateData(true);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBufferDlg::OnMiles()
{
m_Units = miUnitMile; //Sets the units variable equal to miles.
}
void CBufferDlg::OnKilometers()
{
m_Units = miUnitKilometer;
}
void CBufferDlg::OnOK()
{
CCheckListBox* pLstOutlets = (CCheckListBox*)GetDlgItem(IDC_LISTOUTLETS); // The list of outlets
if(!CBufferDlg::UpdateData(TRUE))
return;
//This layer will hold the buffers that the user creates around the outlets.
CMapXLayer outletBuffLyr = m_pMap->GetLayers().CreateLayer("Outlet Buffer",NULL,3);
for(int counter = 0; counter < pLstOutlets->GetCount(); counter++) {
if(pLstOutlets->GetCheck(counter) == BST_CHECKED) {
//"outletFtr" is the buffer we create around our outlet. Since the indexes of the items selected from the list box
// are 1 less than the actual outlet item #'s, we need to increment the counter.
CMapXFeature outletFtr = m_pMap->GetFeatureFactory().BufferFeatures(m_outletFtrs.Item(counter+1), m_Distance, m_Units);
outletBuffLyr.AddFeature(outletFtr); //Add the buffer feature, outletFtr, to the outletBuffLyr.
}
}
CMapXStyle lyrStyle = outletBuffLyr.GetStyle();
//"lyrStyle" will hold the style of the newly created "Outlet Buffer" layer
outletBuffLyr.SetOverrideStyle(TRUE); //Allow us to override the style of the "Outlet Buffer" layer
lyrStyle.SetRegionTransparent(TRUE); //Sets the region created by the buffer to be transparent
lyrStyle.SetRegionBorderWidth(5); //Set the border width of the buffer to be 5
lyrStyle.SetRegionPattern(0); //Set the region pattern to be no fill
lyrStyle.SetRegionBorderColor(miColorBlue); //Set the color of the border to be Blue
m_pMap->Refresh(); //display the changes we made
CDialog::OnOK();
}
void CBufferDlg::OnDeltaposSpindistance(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
if(!UpdateData(true))
return;
m_Distance += pNMUpDown->iDelta;
if(m_Distance > 1000)
m_Distance = 1000;
if(m_Distance < 1)
m_Distance = 1;
UpdateData(false);
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -