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

📄 mapxmobileviewerview.cpp

📁 mapx嵌入式插件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	m_ctrlMapX.SetCurrentTool(miAddRegionTool);
}

void CMapXMobileViewerView::OnUpdateToolAddpolygon(CCmdUI* pCmdUI) 
{
	TRY {
		CMapXLayer lyrInsertion = m_ctrlMapX.GetLayers().GetInsertionLayer();
		pCmdUI->Enable(lyrInsertion.m_lpDispatch!=NULL);
		pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miAddRegionTool);
	}
	CATCH (COleDispatchException,e) {
		//e->Delete();
	}
	AND_CATCH (COleException,e) {
		e->ReportError();
		//e->Delete();
	}
	END_CATCH
}

void CMapXMobileViewerView::OnToolAddpolyline() 
{
	m_ctrlMapX.SetCurrentTool(miAddPolylineTool);
}

void CMapXMobileViewerView::OnUpdateToolAddpolyline(CCmdUI* pCmdUI) 
{
	TRY {
		CMapXLayer lyrInsertion = m_ctrlMapX.GetLayers().GetInsertionLayer();
		pCmdUI->Enable(lyrInsertion.m_lpDispatch!=NULL);
		pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miAddPolylineTool);
	}
	CATCH (COleDispatchException,e) {
		//e->Delete();
	}
	AND_CATCH (COleException,e) {
		e->ReportError();
		//e->Delete();
	}
	END_CATCH
}

void CMapXMobileViewerView::OnMapClosealltables() 
{
	m_ctrlMapX.SetGeoSet(_T(""));
}

void CMapXMobileViewerView::OnUpdateMapClosealltables(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CMapXMobileViewerView::OnUpdateMapCreatetemplayer(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CMapXMobileViewerView::OnToolsEditoptionsNewobjectstyles() 
{
	long nTool = m_ctrlMapX.GetCurrentTool();
	switch(nTool) {
		case miAddPointTool:
			m_ctrlMapX.GetDefaultStyle().PickSymbol();
			break;
		case miAddPolylineTool:
			m_ctrlMapX.GetDefaultStyle().PickLine();
			break;
		case miAddRegionTool:
		default:
			m_ctrlMapX.GetDefaultStyle().PickRegion();
			break;
	}
}

void CMapXMobileViewerView::OnToolsObjecteditingFeatureeditmode() 
{
	m_ctrlMapX.SetFeatureEditMode(miEditModeFeature);
}

void CMapXMobileViewerView::OnUpdateToolsObjecteditingFeatureeditmode(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CMapXMobileViewerView::OnToolsObjecteditingNodemode() 
{
	m_ctrlMapX.SetFeatureEditMode(miEditModeNode);
}

void CMapXMobileViewerView::OnUpdateToolsObjecteditingNodemode(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CMapXMobileViewerView::OnToolsObjecteditingSetinsertionlayer() 
{
	CSetInsertionDlg dlg(this);
	dlg.m_pMap = GetMap();
	if (dlg.DoModal() == IDCANCEL) {
		return;
	}
	TRY {
		if (dlg.GetLayerIndex() <= 0) {
			m_ctrlMapX.GetLayers().SetInsertionLayer(NULL);
		}
		else {
			m_ctrlMapX.GetLayers().SetInsertionLayer(m_ctrlMapX.GetLayers().Item(dlg.GetLayerIndex()));
		}
	}
	CATCH (COleDispatchException,e) {
		//e->Delete();
	}
	AND_CATCH (COleException,e) {
		//e->Delete();
	}
  END_CATCH
}

void CMapXMobileViewerView::OnUpdateToolsObjecteditingSetinsertionlayer(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

bool CMapXMobileViewerView::MapHasSelection()
{
	int n = m_ctrlMapX.GetLayers().GetCount();
	CMapXSelection sel;
	bool bSelFound=false;

	for (int i=1; i <= n; i++) {
		TRY {
			sel = m_ctrlMapX.GetLayers().Item(i).GetSelection();
			if (sel.GetCount() > 0) {
				bSelFound=true;
				break;
			}
		}
		CATCH (COleDispatchException,e) {
			e->Delete();
			// move on to next layer
		}
		AND_CATCH (COleException,e) {
			e->ReportError();
			e->Delete();
		}
		END_CATCH
	}
	return bSelFound;
}

void CMapXMobileViewerView::OnToolsSelectionsBufferselectedobjects() 
{
	CBufferDlg dlg(this);

	dlg.m_dDistance = 100;
	dlg.m_nType = 0;
	dlg.m_nUnit = m_ctrlMapX.GetMapUnit();

	// this only makes sense if there is a selection
	if (!MapHasSelection()) {
		AfxMessageBox(IDS_NOSELECTION);
		return;
	}

	if (dlg.DoModal() == IDCANCEL) return;


	int n = m_ctrlMapX.GetLayers().GetCount();

	for (int i=1; i <= n; i++) {
		CMapXSelection sel;
		CMapXFeature fSel;
		CMapXFeature fNew;
		TRY {
			sel = m_ctrlMapX.GetLayers().Item(i).GetSelection();
			int nObjects = sel.GetCount();
			if (nObjects > 0) {
				if (dlg.m_nType == 0) { // buffer each object separately
					for (int j=1; j <= nObjects; j++) {
						fSel = sel.Item(j);
						fNew = m_ctrlMapX.GetFeatureFactory().BufferFeatures(fSel, dlg.m_dDistance, dlg.m_nUnit);
						m_ctrlMapX.GetLayers().GetInsertionLayer().AddFeature(fNew);
					}
				}
				else { // buffer entire selection into one object
					fNew = m_ctrlMapX.GetFeatureFactory().BufferFeatures(sel, dlg.m_dDistance, dlg.m_nUnit);
					m_ctrlMapX.GetLayers().GetInsertionLayer().AddFeature(fNew);
				}
			}
		}
		CATCH (COleDispatchException,e) {
			e->Delete();
		}
		AND_CATCH (COleException,e) {
			e->ReportError();
			e->Delete();
		}
		END_CATCH
	}
}

void CMapXMobileViewerView::OnUpdateToolsSelectionsBufferselectedobjects(CCmdUI* pCmdUI) 
{
	// too expensive to check for a selection each time here, so the check is done
	// in the command handler
}

void CMapXMobileViewerView::OnToolsSelectionsClearselection() 
{
	m_ctrlMapX.GetLayers().ClearSelection();
}

void CMapXMobileViewerView::OnUpdateToolsSelectionsClearselection(CCmdUI* pCmdUI) 
{
	// possibly too expensive to check for a selection each time here
	// no harm done if called with no selection anyway
}

void CMapXMobileViewerView::OnToolsSelectionsDeleteselectedobjects() 
{
	if (!MapHasSelection()) {
		AfxMessageBox(IDS_NOSELECTION);
		return;
	}

	keybd_event(VK_DELETE, 0, 0, 0);
	keybd_event(VK_DELETE, 0, KEYEVENTF_KEYUP, 0);
}

void CMapXMobileViewerView::OnUpdateToolsSelectionsDeleteselectedobjects(CCmdUI* pCmdUI) 
{
	// too expensive to check for a selection each time here, so the check is done
	// in the command handler
}

void CMapXMobileViewerView::OnToolsSelectionsPolygonselecttool() 
{
	m_ctrlMapX.SetCurrentTool(miPolygonSelectTool);
}

void CMapXMobileViewerView::OnUpdateToolsSelectionsPolygonselecttool(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miPolygonSelectTool);
}

void CMapXMobileViewerView::OnToolsSelectionsRectselecttool() 
{
	m_ctrlMapX.SetCurrentTool(miRectSelectTool);
}

void CMapXMobileViewerView::OnUpdateToolsSelectionsRectselecttool(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miRectSelectTool);
}

void CMapXMobileViewerView::OnToolsSelectionsSetobjectstyles() 
{
	if (!MapHasSelection()) {
		AfxMessageBox(IDS_NOSELECTION);
		return;
	}

	// we will put up a style picker based on the style of the first item
	// in the selection, then we will apply the style to all selected features
	// of the same type
	TRY {
		int n = m_ctrlMapX.GetLayers().GetCount();

		for (int i=1; i <= n; i++) {
			CMapXLayer layer = m_ctrlMapX.GetLayers().Item(i);
			CMapXSelection sel = layer.GetSelection();
			CMapXFeature f1, f;

			int n = sel.GetCount();
			if (n <= 0) {
				return;
			}
			// set style of first feature in list
			f1 = sel.Item(1);
			short nType = f1.GetType();
			BOOL bOK = FALSE;
			switch(nType) {
			case miFeatureTypeSymbol:
				bOK = f1.GetStyle().PickSymbol();
				break;
			case miFeatureTypeLine:
				bOK = f1.GetStyle().PickLine();
				break;
			case miFeatureTypeRegion:
				bOK = f1.GetStyle().PickRegion();
				break;
			case miFeatureTypeText:
				bOK = f1.GetStyle().PickText();
				break;
			default:
				return; // unknown feature type
			}
			if (!bOK) { // user cancelled
				continue;
			}
			// update first feature
			f1.Update();

			for (int i=2;i<=n;i++) {
				f = sel.Item(i);
				if (f.GetType() == nType) {
					f.SetStyle(f1.GetStyle());
					f.Update();
				}
			}
		}
	}
	CATCH (COleDispatchException, e) {
		e->ReportError();
		e->Delete();
	}
	AND_CATCH (COleException, e) {
		e->ReportError();
		e->Delete();
	}
	END_CATCH
	
}

void CMapXMobileViewerView::OnUpdateToolsSelectionsSetobjectstyles(CCmdUI* pCmdUI) 
{
}

void CMapXMobileViewerView::OnToolsObjecteditingAddnodemode() 
{
	m_ctrlMapX.SetFeatureEditMode(miEditModeNode | miEditModeAddNode);
}

void CMapXMobileViewerView::OnUpdateToolsObjecteditingAddnodemode(CCmdUI* pCmdUI) 
{
}

void CMapXMobileViewerView::OnToolbarInfo() 
{
	m_ctrlMapX.SetCurrentTool(MY_INFOTOOL);
}

void CMapXMobileViewerView::OnUpdateToolbarInfo(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == MY_INFOTOOL);
}

void CMapXMobileViewerView::OnToolUsed(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, VARIANT* EnableDefault)
{
	if (ToolNum == MY_INFOTOOL) {
		CInfoToolDlg dlg(m_ctrlMapX.GetLayers(), X1, Y1, this);

		dlg.DoModal();
	}
}
void CMapXMobileViewerView::OnViewFind() 
{
	CSetInsertionDlg dlgLayer(this);
	CFindDlg dlg(this);

	// use insertion dlgbox to get layer to find on
	dlgLayer.m_pMap = GetMap();
	dlgLayer.m_strTitle.LoadString(IDS_FINDLAYER);
	if (dlgLayer.DoModal() == IDCANCEL) {
		return;
	}
	TRY {
		if (dlgLayer.GetLayerIndex() <= 0) {
			return;
		}
		dlg.m_pReferenceMapX = &m_ctrlMapX;
		dlg.m_nLayerIndex = dlgLayer.GetLayerIndex();
		dlg.DoModal();	
	}
	CATCH (COleDispatchException,e) {
		//e->Delete();
	}
	AND_CATCH (COleException,e) {
		//e->Delete();
	}
  END_CATCH
}

void CMapXMobileViewerView::OnUpdateViewFind(CCmdUI* pCmdUI) 
{
	BOOL b=FALSE;
	TRY {
		if (m_ctrlMapX.GetLayers().GetCount() > 0) {
			b = TRUE;
		}
	}
	CATCH (COleDispatchException,e) {
		//e->Delete();
	}
	AND_CATCH (COleException,e) {
		//e->Delete();
	}
  END_CATCH
	pCmdUI->Enable(b);
}

void CMapXMobileViewerView::OnViewProjection() 
{
	TRY {
		m_ctrlMapX.GetDisplayCoordSys().PickCoordSys();
	}
	CATCH (COleDispatchException,e) {
		//e->Delete();
	}
	AND_CATCH (COleException,e) {
		//e->Delete();
	}
  END_CATCH
}

void CMapXMobileViewerView::OnMapExportmap() 
{
	CFileDialog dlgFile(FALSE, _T("gst"), NULL, 0, szFilterBmp, this);
	dlgFile.m_ofn.lpstrTitle = _T("Export");
	TCHAR buf[_MAX_PATH]=_T("\\");
	//GetCurrentDirectory( _MAX_PATH, buf);

	dlgFile.m_ofn.lpstrInitialDir = buf;

	if (dlgFile.DoModal() == IDCANCEL)
		return;

	TRY {
		CString strFile = dlgFile.GetPathName();
		m_ctrlMapX.ExportMap(strFile, miFormatBMP);
	}
	CATCH (COleDispatchException,e) {
		e->ReportError();
		//e->Delete();
	}
	AND_CATCH (COleException,e) {
		e->ReportError();
		//e->Delete();
	}
	END_CATCH
}

void CMapXMobileViewerView::OnToolsMoretools() 
{
  CMenu menu;            // top-level menu 
  CMenu *pMenu=NULL;  // pop-up menu 

  // Load the menu resource. 
	menu.LoadMenu(IDR_MENUBAR1); 

  // get the handle of the map menu. 
  pMenu = menu.GetSubMenu(0);
	if (!pMenu)
		return;

  // Display the floating pop-up menu. Track the right mouse 
  // button on the assumption that this function is called 
  // during WM_CONTEXTMENU processing. 
	POINT pt;
	GetCursorPos(&pt);

	pMenu->TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this, NULL); 

  // Destroy the menu. 
  menu.DestroyMenu(); 
}

void CMapXMobileViewerView::OnToolsArrow() 
{
	m_ctrlMapX.SetCurrentTool(miArrowTool);
}

void CMapXMobileViewerView::OnUpdateToolsArrow(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_ctrlMapX.GetCurrentTool() == miArrowTool);
}

void CMapXMobileViewerView::OnMapCreatetheme() 
{
	CAddThemeDlg dlgTheme(this);

	dlgTheme.m_pMapX = &m_ctrlMapX;

	dlgTheme.DoModal();
}

void CMapXMobileViewerView::OnUpdateMapCreatetheme(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CMapXMobileViewerView::OnMapModifytheme() 
{
	CModifyThemeDlg dlg(this);

	dlg.m_pMapX = &m_ctrlMapX;

	dlg.DoModal();
	
}

// bring up theme dialog (or legend dialog) if user double clicks on legend
void CMapXMobileViewerView::OnThemeModifyRequested(LPDISPATCH Theme)
{
	TRY {
		CMapXTheme theme;
		VARIANT vHelpFile, vHelpID;		// mark as optional since we don't have a helpfile
		vHelpFile.vt = VT_ERROR;
		vHelpFile.scode = DISP_E_PARAMNOTFOUND;
		vHelpID.vt = VT_ERROR;
		vHelpID.scode = DISP_E_PARAMNOTFOUND;
		
		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();
	}
	AND_CATCH (COleException, e) {
		e->ReportError();
		e->Delete();
	}
	END_CATCH
}

void CMapXMobileViewerView::OnOpen() 
{
  CMenu menu;            // top-level menu 
  CMenu *pMenu=NULL;  // pop-up menu 

  // Load the menu resource. 
	menu.LoadMenu(IDR_MENUBAR1); 

  // get the handle of the map menu. 
  pMenu = menu.GetSubMenu(0);
	if (!pMenu)
		return;

  // Display the floating pop-up menu. Track the right mouse 
  // button on the assumption that this function is called 
  // during WM_CONTEXTMENU processing. 
	POINT pt;
	GetCursorPos(&pt);

	pMenu->TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this, NULL); 

  // Destroy the menu. 
  menu.DestroyMenu(); 	
}

⌨️ 快捷键说明

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