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

📄 mainfrm.cpp

📁 vc 和mapobjects地理信息系统组件开发 很有启发意义和参考价值
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	fini.SetFileName(theApp.m_sRunPath+"\\mapper.ini");
	CString sLastPath=fini.ReadString("PATH","ArcLast","");

	//增加图层,可以同时添加多个
	CFileDialog	fd(TRUE,NULL,NULL,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,
		"Arc/Info文件(*at.adf)|*at.adf||",this);

	fd.m_ofn.lpstrInitialDir=sLastPath;
	if(fd.DoModal()!=IDOK) 
		return;

	srand((unsigned)time(NULL));
	int n=0;
	CString sPathFile,sTitle;
	POSITION pos=fd.GetStartPosition();
	
	COLORREF color;
	int r,g,b;
	CMapperView *pMap=theApp.GetMapPane();
	CMapperLayerView *pLayer=theApp.GetLayerPane();
	while(pos!=NULL)
	{
		//需要检查重复的图层
		sPathFile=fd.GetNextPathName(pos);
		Eng_GetFileOfPathFile(sPathFile,sTitle);
		
		Eng_GetRandInt(0,255,r,g,b);
		color=RGB(r,g,b);
		Eng_GetFileOfPathFile(sPathFile,sTitle);
		Eng_AddLayerArc(pMap->m_map,sPathFile,color);
		n++;
	}

	//当选择了一个文件,返回文件和路径;如果多个则只返回路径
	if(n>1)
	{
		fini.WriteString("PATH","ArcLast",fd.GetPathName());
	}
	else
	{
		Eng_GetPathOfPathFile(fd.GetPathName(),sLastPath);
		fini.WriteString("PATH","ArcLast",sLastPath);
	}

	Eng_SetLegend(pMap->m_map,pLayer->m_legend);

	CMapperDoc *pDoc=(CMapperDoc*)GetActiveDocument();
	pDoc->SetModifiedFlag();

}

BOOL CMainFrame::CreateFloatBar()
{
	if (!m_wndViewBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
		CBRS_TOP | CBRS_TOOLTIPS, IDW_VIEW_BAR) ||!m_wndViewBar.LoadBitmap(IDR_TOOLBAR_VIEW) ||
		!m_wndViewBar.SetButtons(PaletteButtons,
		  sizeof(PaletteButtons)/sizeof(UINT)))
	{
		TRACE0("Failed to create toolbar\n");
		return FALSE;       // fail to create
	}

//	m_wndViewBar.SetWindowText(_T("显示"));
	m_wndViewBar.SetWindowText(_T("图形"));
	m_wndViewBar.EnableDocking(0);

	// Create the Palette.  We are using hardcoded numbers for ease here
	// normally the location would be read in from an ini file.
	CPoint pt(GetSystemMetrics(SM_CXSCREEN) - 100,100);
	m_wndViewBar.SetColumns(2);
	FloatControlBar(&m_wndViewBar, pt);

	{
		if (!m_wndQueryBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
				CBRS_TOP |CBRS_TOOLTIPS , IDW_QUERY_BAR) ||	!m_wndQueryBar.LoadBitmap(IDR_TOOLBAR_QUERY) ||
			!m_wndQueryBar.SetButtons(EditButtons, sizeof(EditButtons)/sizeof(UINT)))
		{
			TRACE0("Failed to create palettebar\n");
			return -1;      // fail to create
		}

		m_wndQueryBar.SetWindowText(_T("查询"));
		m_wndQueryBar.EnableDocking(0);

		CPoint pt(GetSystemMetrics(SM_CXSCREEN) - 100,350);

		m_wndQueryBar.SetColumns(2);
		FloatControlBar(&m_wndQueryBar, pt);
	}
	return TRUE;
}

void CMainFrame::OnMapClearLayer() 
{
	int nRes=AfxMessageBox("确定清除所有图层?",MB_ICONQUESTION|MB_YESNO);
	if(nRes==IDNO) return;

	CMapperView *pMap=theApp.GetMapPane();
	CMapperLayerView *pLayer=theApp.GetLayerPane();
	pMap->m_rsQuery.ReleaseDispatch();
	pMap->m_map.GetLayers().Clear();
	Eng_SetLegend(pMap->m_map,pLayer->m_legend);
}

void CMainFrame::OnMapExport() 
{
	CMapExportDlg	efd;
	if(efd.DoModal()!=IDOK)
		return;

	CString sFileExt,sExt;
	switch(efd.m_nFormat)
	{
	case 0:
		sExt="JPG";
		sFileExt="JPG图像文件(*.JPG)|*.JPG||";
		break;
	case 1:
		sExt="BMP";
		sFileExt="BMP图像文件(*.BMP)|*.BMP||";
		break;
	case 2:
		sExt="EMF";
		sFileExt="EMF图像文件(*.EMF)|*.EMF||";
		break;
	}

	CFileDialog	fd(FALSE,sExt,NULL,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,
		sFileExt,this);

	CMapperView *pMap=theApp.GetMapPane();
	switch(efd.m_nFormat)
	{
	case 0:
		if(fd.DoModal()==IDOK)
		{
			pMap->m_map.ExportMapToJpeg(fd.GetPathName(),85,FALSE,efd.m_nFactor,moAllSymbologyScaled);
		}
		break;
	case 1:
		if(fd.DoModal()==IDOK)
		{
			pMap->m_map.ExportMap(moExportBMP,fd.GetPathName(),efd.m_nFactor);
		}
		break;
	case 2:
		if(fd.DoModal()==IDOK)
		{
			pMap->m_map.ExportMap(moExportEMF,fd.GetPathName(),efd.m_nFactor);
		}
		break;
	case 3:
		pMap->m_map.ExportMap(moExportClipboardBMP,fd.GetPathName(),efd.m_nFactor);
		break;
	case 4:
		pMap->m_map.ExportMap(moExportClipboardEMF,fd.GetPathName(),efd.m_nFactor);
		break;
	}
}

void CMainFrame::OnDrawFull() 
{
	CMapperView *pMap=theApp.GetMapPane();
	CMoRectangle r(pMap->m_map.GetFullExtent());
	if(LPDISPATCH(r))
		pMap->m_map.SetExtent(r);

}

void CMainFrame::OnDrawPan() 
{
	m_uID=ID_DRAW_PAN;		
}

void CMainFrame::OnDrawRefresh() 
{
	CMapperView *pMap=theApp.GetMapPane();
	pMap->m_map.Refresh();
}

void CMainFrame::OnDrawZoomin() 
{
	m_uID=ID_DRAW_ZOOMIN;		
}

void CMainFrame::OnDrawZoomout() 
{
	m_uID=ID_DRAW_ZOOMOUT;		
}

void CMainFrame::OnUpdateDrawPan(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_uID==ID_DRAW_PAN);
}

void CMainFrame::OnUpdateDrawZoomin(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_uID==ID_DRAW_ZOOMIN);	
}

void CMainFrame::OnUpdateDrawZoomout(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_uID==ID_DRAW_ZOOMOUT);	
}

void CMainFrame::OnQueryPoint() 
{
	short nLayer=theApp.GetLayerPane()->m_legend.getActiveLayer();
	if(nLayer<0)
	{
		AfxMessageBox("必须先选择一个图层!");
		return;
	}

	m_uID=ID_QUERY_POINT;
}

void CMainFrame::OnQueryLine() 
{
	short nLayer=theApp.GetLayerPane()->m_legend.getActiveLayer();
	if(nLayer<0)
	{
		AfxMessageBox("必须先选择一个图层!");
		return;
	}

	m_uID=ID_QUERY_LINE;	
}

void CMainFrame::OnQueryRect() 
{
	short nLayer=theApp.GetLayerPane()->m_legend.getActiveLayer();
	if(nLayer<0)
	{
		AfxMessageBox("必须先选择一个图层!");
		return;
	}

	m_uID=ID_QUERY_RECT;
}

void CMainFrame::OnQueryPoly() 
{
	short nLayer=theApp.GetLayerPane()->m_legend.getActiveLayer();
	if(nLayer<0)
	{
		AfxMessageBox("必须先选择一个图层!");
		return;
	}

	m_uID=ID_QUERY_POLY;	
}

void CMainFrame::OnUpdateQueryPoint(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_uID==ID_QUERY_POINT);
}

void CMainFrame::OnUpdateQueryLine(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_uID==ID_QUERY_LINE);	
}

void CMainFrame::OnUpdateQueryRect(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_uID==ID_QUERY_RECT);
}

void CMainFrame::OnUpdateQueryPoly(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(m_uID==ID_QUERY_POLY);
}

void CMainFrame::OnQueryExport() 
{
	CMapperView *pMap=theApp.GetMapPane();
	if(LPDISPATCH(pMap->m_rsQuery)!=0)
	{
		CFileDialog	fd(FALSE,"shp",NULL,OFN_EXPLORER|OFN_HIDEREADONLY,"SHP文件(*.shp)|*.shp||",this);
		if(fd.DoModal()!=IDOK)
			return;
		CString sPathFile=fd.GetPathName();
		
		short n=theApp.GetLayerPane()->m_legend.getActiveLayer();
		if(n<0) 
			return;

		CMoMapLayer layer(pMap->m_map.GetLayers().Item(COleVariant(n)));
		pMap->m_rsQuery.Export(sPathFile,COleVariant((short)1));
//		pMap->m_rsQuery.Export(sPathFile,layer.GetCoordinateSystem());
		AfxMessageBox("输出完成!");
	}
	else
	{
		AfxMessageBox("无查询结果,不能进行保存操作!");
	}
}

void CMainFrame::OnQueryStatistic() 
{
	CMapperView *pMap=theApp.GetMapPane();

/*
	//获得图层名称,可能因为图层active更改而出现错误
	short iLayer=theApp.GetLayerPane()->m_legend.getActiveLayer();
	if(iLayer<0) 
		return;
	CMoLayers layers(pMap->m_map.GetLayers());
	CMoMapLayer layer(layers.Item(COleVariant(iLayer)));
*/
	if(LPDISPATCH(pMap->m_rsQuery)!=0)
	{
		CLayerStatisticDlg ssd;
		Eng_GetRsStatistic(pMap->m_rsQuery,ssd.m_taLayerField);
//		ssd.m_sLayer="图层:"+layer.GetName();
		ssd.m_sLayer="";
		ssd.DoModal();
	}
	else
	{
		AfxMessageBox("无查询结果,不能进行统计操作!");
	}
}

void CMainFrame::OnMapSetup() 
{
	CMapSetupDlg msd;

	msd.m_nMapPickTol=theApp.m_tMapSetup.nPickTol;
	msd.m_dFontSize=theApp.m_tMapSetup.dFontSize;
	msd.m_oMapColorBack.SetColor(theApp.m_tMapSetup.MapColor);
	msd.m_oQueryColor.SetColor(theApp.m_tMapSetup.QueryColor);
	msd.m_oSelectColor.SetColor(theApp.m_tMapSetup.SelectColor);
	msd.m_nLieduShp=theApp.m_tMapSetup.nLieduShp;

	if(msd.DoModal()!=IDOK)
		return;

	theApp.m_tMapSetup.nPickTol=msd.m_nMapPickTol;
	theApp.m_tMapSetup.dFontSize=msd.m_dFontSize;
	theApp.m_tMapSetup.MapColor=msd.m_oMapColorBack.GetColor();
	theApp.m_tMapSetup.QueryColor=msd.m_oQueryColor.GetColor();
	theApp.m_tMapSetup.SelectColor=msd.m_oSelectColor.GetColor();
	theApp.m_tMapSetup.nLieduShp=msd.m_nLieduShp;

	theApp.GetMapPane()->m_map.SetBackColor(theApp.m_tMapSetup.MapColor);
	
	//save
	{
		CIniFile f;
		f.SetFileName(theApp.m_sRunPath+"\\mapper.ini");
		f.WriteInt("MAP SETUP","MapPickTol",theApp.m_tMapSetup.nPickTol);
		f.WriteDouble("MAP SETUP","FontSize",theApp.m_tMapSetup.dFontSize);
		f.WriteLong("MAP SETUP","MapColorBack",theApp.m_tMapSetup.MapColor);
		f.WriteLong("MAP SETUP","QueryColorBack",theApp.m_tMapSetup.QueryColor);
		f.WriteLong("MAP SETUP","SelectColor",theApp.m_tMapSetup.SelectColor);
		f.WriteInt("MAP SETUP","LieduShp",theApp.m_tMapSetup.nLieduShp);
	}
}

void CMainFrame::OnMapLayerInfo() 
{
	CLayerInfoDlg lid;
	lid.DoModal();
}

void CMainFrame::OnQueryRecord() 
{
	if(LPDISPATCH(theApp.GetMapPane()->m_rsQuery)==0)
	{
		AfxMessageBox("没有查询结果!必须先执行查询操作!");
		return;
	}

	CLayerRecordDlg lrd;
	lrd.m_rs=theApp.GetMapPane()->m_rsQuery;
	lrd.m_sLayer="查询";
	lrd.DoModal();
}

void CMainFrame::OnMapQuery() 
{
	CEdit* pEdit=(CEdit*)m_wndDlgBar.GetDlgItem(IDC_QUERY_TEXT);
	CString text,sExp;
	pEdit->GetWindowText(text);
	
	if(text=="")
	{
		AfxMessageBox("必须输入有效字符!");
		return;
	}
	
	short n=theApp.GetLayerPane()->m_legend.getActiveLayer();
	if(n<0)
		return;
	CMoLayers layers(theApp.GetMapPane()->m_map.GetLayers());
	CMoMapLayer layer(layers.Item(COleVariant(n)));

	sExp.Format("(state_name Like '%%%s%%')",text);
	AfxMessageBox(sExp);
	theApp.GetMapPane()->m_rsQuery=layer.SearchExpression(sExp);

	theApp.GetMapPane()->m_map.Refresh();
/*
	if(!theApp.GetMapPane()->m_rsQuery.GetEof())
	{
		CMoFields fields(theApp.GetMapPane()->m_rsQuery.GetFields());
		CMoField shapeField(fields.Item(COleVariant(TEXT("Shape"))));
		CMoPolygon shape(shapeField.GetValue().pdispVal);
		CMoRectangle r(shape.GetExtent());

//变换大小
//		r.ScaleRectangle(2);
//		theApp.GetMapPane()->m_map.SetExtent(r);

//不变化大小,移动到中心
//		theApp.GetMapPane()->m_map.CenterAt(r.GetCenter().GetX(),r.GetCenter().GetY());

		theApp.GetMapPane()->m_map.Refresh();
//		theApp.GetMapPane()->m_map.FlashShape(shape,2);
	}
*/	
}

void CMainFrame::OnQueryExpression() 
{
	short nLayer=theApp.GetLayerPane()->m_legend.getActiveLayer();
	if(nLayer<0)
	{
		AfxMessageBox("必须先选择一个图层!");
		return;
	}

	CLayerQueryDlg lqd;
	lqd.m_nLayer=nLayer;
	lqd.m_sLayer=theApp.GetLayerPane()->m_legend.GetEntryName(&nLayer);
	if(lqd.DoModal()!=IDOK)
		return;

	CMoLayers layers(theApp.GetMapPane()->m_map.GetLayers());
	CMoMapLayer layer(layers.Item(COleVariant(nLayer)));
	
	theApp.GetMapPane()->m_rsQuery=layer.SearchExpression(lqd.m_sText);
	theApp.GetMapPane()->m_map.Refresh();
}

⌨️ 快捷键说明

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