📄 maptestview.cpp
字号:
dlg.m_Zip = custZip;
dlg.m_pZip = &custZip;
m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("Order_amt");
custAmt = f.GetKeyValue();
dlg.m_Amt = custAmt;
dlg.m_pAmt = &custAmt;
m_ctrlMapX.GetLayers().Item("Us_custg").SetKeyField("Lname");
dlg.DoModal();
}
catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
}
catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
}
void CMapTestView::OnUpdateMapToolInfotool(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == CUST_INFO);
//Place a check by the info tool in the menu
// Enable the info tool if the customers layer has been added.
// If it has been added, it will be on the top, and so will have index 1
if (m_ctrlMapX.GetLayers().Item(1).GetName() == "Us_custg")
pCmdUI->Enable(1);
else
pCmdUI->Enable(0);
}
void CMapTestView::OnThemeModifyRequested(LPDISPATCH Theme)
{
try {
CMapXTheme theme;
COptionalVariant vHelpFile, vHelpID; // mark as optional since we don't have a helpfile
theme.AttachDispatch(Theme, FALSE); // don't auto release
theme.ThemeDlg(vHelpFile, vHelpID);
// could decide to bring up legend dlg here instead
//CMapXLegend leg(theme.GetLegend());
//leg.LegendDlg(vHelpFile, vHelpID);
}
catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
}
catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
void CMapTestView::OnEditCopy()
{
//Here we'll simply send the current displayed map to the clipboard.
//We send it there in bitmap format
m_ctrlMapX.ExportMap("Clipboard", miFormatBMP);
}
void CMapTestView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
try {
// get paper width in cm and convert to HIMETRIC (100th of a mm)
m_ctrlMapX.SetPaperUnit(miUnitCentimeter);
double pw = m_ctrlMapX.GetMapPaperWidth() * 10 * 100;
double ph = m_ctrlMapX.GetMapPaperHeight()* 10 * 100;
m_ctrlMapX.PrintMap((long)pDC->m_hDC, pInfo->m_rectDraw.left, pInfo->m_rectDraw.top, (long)pw, (long)ph);
}
catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
}
catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
void CMapTestView::OnInfoTool()
{
try{ //Set the current tool to the Custom tool CUST_INFO
m_ctrlMapX.SetCurrentTool(CUST_INFO);
} catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
} catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
void CMapTestView::OnUpdateInfoTool(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == CUST_INFO);
//Place a check by the info tool in the menu
// Enable the info tool if the customer layer has been added.
// If it has, it will be the topmost layer, so it will have index 1.
if (m_ctrlMapX.GetLayers().Item(1).GetName() == "Us_custg")
pCmdUI->Enable(1);
else
pCmdUI->Enable(0);
}
void CMapTestView::OnMapAddcustomerlayer()
{
char buffer[_MAX_PATH];
CString custPath;
//Get the current working directory
if(_getcwd(buffer, _MAX_PATH ) == NULL )
perror( "_getcwd error");
else //If there isn't an error, then concatenate the name of the .tab file
// that we want. Now outletPath will hold the correct path to the
// layer we wish to create.
custPath = strcat(buffer, "\\Data\\Us_custg.tab");
//This actually adds the layer to the map
m_ctrlMapX.GetLayers().Add(custPath,1);
}
void CMapTestView::OnUpdateMapAddcustomerlayer(CCmdUI* pCmdUI)
{
// If the customer layer has been added, it will be the top layer. So, check
// to see if we've added it.
pCmdUI->SetCheck(m_ctrlMapX.GetLayers().Item(1).GetName() == "Us_custg");
//Disable the menu item if the customer layer has been added
pCmdUI->Enable(m_ctrlMapX.GetLayers().Item(1).GetName() != "Us_custg");
}
void CMapTestView::OnMapRemovecustomerlayer()
{
//Remove the customer layer located in layer position 1
m_ctrlMapX.GetLayers().Remove("Us_custg");
m_ctrlMapX.GetDatasets().RemoveAll();
}
void CMapTestView::OnUpdateMapRemovecustomerlayer(CCmdUI* pCmdUI)
{
//Enable the menu item if the customer layer has been added
pCmdUI->Enable(m_ctrlMapX.GetLayers().Item(1).GetName() == "Us_custg");
}
void CMapTestView::OnMapAdddatasetfromlayer()
{
try {
CMapXLayer layer = m_ctrlMapX.GetLayers().Item("Us_custg");
COleVariant vtLayer;
vtLayer.vt = VT_DISPATCH;
vtLayer.pdispVal = layer.m_lpDispatch;
vtLayer.pdispVal->AddRef();
//Add in the dataset for the Us_custg layer and call it "Us_custg Layer"
CMapXDataset dataSet = m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vtLayer, "Us_custg Layer");
AfxMessageBox("Now you can go to Add Theme...., and create a theme based on the Customer Layer!!");
} catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
} catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
void CMapTestView::OnUpdateMapAdddatasetfromlayer(CCmdUI* pCmdUI)
{
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
BOOL enableFlag = FALSE;
for (int count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Us_custg" && (m_ctrlMapX.GetDatasets().GetCount() == 1)){
pCmdUI->Enable(0); //If any of the layers names is Us_custg and there is one
return; // dataset, then turn off the option to add the dataset
}
else
if (lyr.GetName() == "Us_custg"){ //If at least the layers name is Us_custg,
enableFlag = TRUE; //then set the flag to true.
}
else
pCmdUI->Enable(0); //If we get to here then turn off the menu because the layer
//Us_custg and its dataset are unavailable.
}
if (enableFlag)
pCmdUI->Enable(1); //If we arrived here, then at least we the proper layer to add the
// dataset from.
}
void CMapTestView::OnMapAddtheme()
{
CThemeDlg dlgTheme;
dlgTheme.m_pMapX = &m_ctrlMapX;//Set the variable m_pMapX to point at our map on
//the child window
dlgTheme.DoModal();
}
void CMapTestView::OnUpdateMapAddtheme(CCmdUI* pCmdUI)
{
//This turns on and of the Add Theme selection off of this menu. The decision is based
//on the # of datasets, the # of layers, and finally the # of themes.
if (m_ctrlMapX.GetDatasets().GetCount() == 1 ){
pCmdUI->Enable(1);
if(m_ctrlMapX.GetDatasets().Item(1).GetThemes().GetCount() == 1)
pCmdUI->Enable(0);} //Disables after there has been one Theme added
else
pCmdUI->Enable(0); //Disabled when there isn't a dataset to create a theme.
}
void CMapTestView::OnMapAddoutletlayer()
{
char buffer[_MAX_PATH];
CString outletPath;
//Get the current working directory
if(_getcwd(buffer, _MAX_PATH ) == NULL )
perror( "_getcwd error");
else //If there isn't an error, then concatenate the name of the .tab file
// that we want. Now outletPath will hold the correct path to the
// layer we wish to create.
outletPath = strcat(buffer, "\\Data\\Outlets.tab");
//This actually adds the layer to the map
m_ctrlMapX.GetLayers().Add(outletPath,2);
//***************************************************************************
//Before the layer is actually displayed, we will change the default symbol
// of our outlets. Right now, without changes, it is a very small gray star.
// We will change the symbol to a large red warehouse symbol. Below this
// is the code to accomplish this task.
//**************************************************************************
CMapXFeatures fs = m_ctrlMapX.GetLayers().Item("Outlets").AllFeatures();
//"fs" holds the features of the Outlets layer
CMapXStyle ftrStyle = m_ctrlMapX.GetLayers().Item("Outlets").GetStyle();
//"ftrStyle" holds the style of the feature for the
// Outlet layer.
try {
ftrStyle.SetSymbolCharacter(54); //Changes the symbol to a warehouse
ftrStyle.SetSymbolFontColor(255); //Changes the color of the symbol to red
ftrStyle.SetSymbolBitmapSize(24); //Changes the symbol font size
m_ctrlMapX.GetLayers().Item("Outlets").SetOverrideStyle(TRUE);
//To have these changes take effect, you must set the override style to TRUE
// for the layer you are working on
} catch (COleDispatchException *e) {
e->ReportError();
e->Delete();
} catch (COleException *e) {
e->ReportError();
e->Delete();
}
}
void CMapTestView::OnUpdateMapAddoutletlayer(CCmdUI* pCmdUI)
{
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
int count;
// If any of the layers names are equal to "Outlets" then disable
// this menu option.
for ( count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Outlets"){
pCmdUI->Enable(0);
return;
}
}
}
void CMapTestView::OnMapRemoveoutletlayer()
{
m_ctrlMapX.GetLayers().Remove("Outlets");//Remove the layer named "Outlets"
}
void CMapTestView::OnUpdateMapRemoveoutletlayer(CCmdUI* pCmdUI)
{
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
//If any of the layers names are equal to "Outlets" then enable
// this menu option.
for (int count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Outlets"){ //If there is an Outlets layer then enable this
pCmdUI->Enable(1); //menu option.
return;
}
else
pCmdUI->Enable(0);
}
}
void CMapTestView::OnMapBuffersBufferthecustomers()
{
CMapXFeatures allCustomers; // "allCustomers" will hold all the features of the customer layer
CMapXFeature custBuffFtr; // "custBuffFtr" will hold the buffer feature
// created from the Feature Factory
CMapXLayer lyr; // This will be the temporary layer we create to hold the buffers
// we create around each of the customers.
allCustomers = m_ctrlMapX.GetLayers().Item("Us_custg").AllFeatures();
lyr = m_ctrlMapX.GetLayers().CreateLayer("Buffer Layer",NULL,3);
//"lyr" is set to be the newly created layer "Buffer Layer". It is
// created and place in position 3 in the layers collection.
AfxMessageBox("This creates a 50 mile buffer around each of the customers. It will be a minute.");
custBuffFtr = m_ctrlMapX.GetFeatureFactory().BufferFeatures(allCustomers, 50, miUnitMile);
lyr.AddFeature(custBuffFtr);
}
void CMapTestView::OnUpdateMapBuffersBufferthecustomers(CCmdUI* pCmdUI)
{
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
//If any of the layers names are equal to "Buffer Layer" then enable
// this menu option.
for (int count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Buffer Layer" && (m_ctrlMapX.GetLayers().Item(1).GetName() == "Us_custg")){
pCmdUI->Enable(0);
return;
} else {
if (m_ctrlMapX.GetLayers().Item(1).GetName() == "Us_custg")
pCmdUI->Enable(1);
else
pCmdUI->Enable(0);
}
}
}
void CMapTestView::OnMapBuffersRemovecustomerbuffer()
{
m_ctrlMapX.GetLayers().Remove("Buffer Layer");
//Remove the layer of customer buffers off of the map
}
void CMapTestView::OnUpdateMapBuffersRemovecustomerbuffer(CCmdUI* pCmdUI)
{
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
//If any of the layers names are equal to "Buffer Layer" then enable
// this menu option.
for (int count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Buffer Layer"){
pCmdUI->Enable(1);
return;
}
else
pCmdUI->Enable(0);
}
}
void CMapTestView::OnMapBuffersBuffertheoutlets()
{
CBufferDlg buffDlg;
buffDlg.m_pMap = &m_ctrlMapX;
buffDlg.m_Distance = 140;
buffDlg.DoModal();
}
void CMapTestView::OnUpdateMapBuffersBuffertheoutlets(CCmdUI* pCmdUI)
{
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
BOOL enableFlag = FALSE;
for (int count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Outlet Buffer"){ //Disable if any of the layers
pCmdUI->Enable(0); //names is Outlet Buffer
return;
}
else
if (lyr.GetName() == "Outlets"){ //Check to see if the layers name is
enableFlag = TRUE; // Outlets, If it is, set the flag to TRUE.
}
else
pCmdUI->Enable(0); //If the above isn't true, disable
}
if (enableFlag) //Since we didn't return on finding "Outlet Buffer" and
pCmdUI->Enable(1); //the flag is TRUE, then at least we know the Outlets are
//there to buffer.
}
void CMapTestView::OnMapBuffersRemovetheoutletsbuffers()
{
// TODO: Add your command handler code here
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
int count;
m_ctrlMapX.GetLayers().Remove("Outlet Buffer"); //Remove the outlet buffer
for (count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Intersection Layer")
m_ctrlMapX.GetLayers().Remove("Intersection Layer");
}
}
void CMapTestView::OnUpdateMapBuffersRemovetheoutletsbuffers(CCmdUI* pCmdUI)
{
CMapXLayers lyrs = m_ctrlMapX.GetLayers();
CMapXLayer lyr;
for (int count = 1; count <= lyrs.GetCount(); count++){
lyr = lyrs.Item(count);
if (lyr.GetName() == "Outlet Buffer"){ //Disable if any of the layers
pCmdUI->Enable(1); //names is Outlet Buffer
return;
}
else
pCmdUI->Enable(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -