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

📄 navigatorview.cpp

📁 基于超图sne开发的一个详细的例子。提供查询
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		UGGraphics *pGraphics = UGGraphicsManager::NewGraphics();
		if(pGraphics != NULL)
		{
			SetCapture();
			UGGraphics::UGGraphicsData data;
			data.pNative = pDC;
			pGraphics->SetGraphicsData(data);
			UGPoint pntTmp(point.x, point.y);
			
			// 按下鼠标左键
			m_pMapWnd->OnLButtonDown(pGraphics, nFlags, pntTmp);
			delete pGraphics;
		}
		ReleaseDC(pDC);
		
		CView::OnLButtonDown(nFlags, point);
	}
}

void CNavigatorView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_pMapWnd)
	{
		CDC* pDC = GetDC();
		UGGraphics *pGraphics = UGGraphicsManager::NewGraphics();
		if(pGraphics != NULL)
		{
			UGGraphics::UGGraphicsData data;
			data.pNative = pDC;
			pGraphics->SetGraphicsData(data);
			UGPoint pntTmp(point.x, point.y);
			
			m_pMapWnd->OnLButtonUp(pGraphics, nFlags, pntTmp);
			delete pGraphics;
		}
		ReleaseDC(pDC);
		ReleaseCapture();
		
		CView::OnLButtonUp(nFlags, point);
	}
}

void CNavigatorView::OnMapPan() 
{
	// TODO: Add your command handler code here
	if (m_pMapWnd)
	{
		m_pMapWnd->SetUserAction(UGDrawParamaters::uaPan);
	}	
}


void CNavigatorView::OnMapViewentire() 
{
	// TODO: Add your command handler code here
	if ( m_pMapWnd ) 
	{
		m_pMapWnd->ViewEntire();
		m_pMapWnd->Refresh();
	}	
	
}

void CNavigatorView::OnPOIQuery() 
{
	if (m_pMapWnd)
	{
 		m_bPOIQuery = TRUE;
		// TODO: Add your command handler code here
		// 获取用于POI检索的数据源
		UGDataSource* pDataSource = NULL;	
		pDataSource = (UGDataSource*)GetDataSource(0);
		
		if (pDataSource)
		{
			m_POIQuery.SetDatasource( pDataSource);
		}
		
		// 设置地图窗口
		if (m_pMapWnd)
		{
			m_POIQuery.SetMapWnd( m_pMapWnd );
		}
		// 弹出“分类查询”对话框
		m_POIQuery.DoModal();
		
		UpdateData(FALSE);	
	}	
}

void CNavigatorView::OnSetDeparture() 
{
	// 清空起点数组,目前支持设置一个起点
	if (m_pMapWnd)
	{
		m_pathPlanning.m_arrPntStart.RemoveAll();
		
		OnPOIQuery();
		m_bPOIQuery = FALSE;
		
		
		UGPoint2D pntStartAnchor;
		
		// 获取查询结果目标点
		pntStartAnchor = m_POIQuery.GetDrawPoint();
		// 添加起点
		m_pathPlanning.AddDeparture(pntStartAnchor);		
		
		//////////////////////////////////////////////////////////////////////////
		// 跟踪层上写文本START
		UGRect2D rcBound = m_pMapWnd->GetBounds();
		m_pMapWnd->m_Map.m_TrackingLayer.SetBound(rcBound);
		
		// 构造文本对象
		UGGeoText startText;	
		UGString strStart = "S";		
		startText.Make(strStart, pntStartAnchor);
		
		//设置文本的风格
		UGTextStyle textStyle;
		UGString strFont = "宋体";
		textStyle.SetFaceName(strFont);
		textStyle.SetSizeForFixed(5);		
		textStyle.SetForeColor( UGRGBA(0,50,155,0) );
		textStyle.SetBackColor( UGRGBA(255,155,0,0) );
		textStyle.SetHalo( true );
		textStyle.SetBold( true );
		textStyle.SetBackOpaque( false );
		textStyle.SetFixedSize(TRUE);
		
		startText.SetTextStyle(textStyle);
		
		// 如果原来跟踪层上有“S”,则首先擦除
		m_pMapWnd->m_Map.m_TrackingLayer.DeleteEvent(m_nStartID);
		m_nStartID = m_pMapWnd->m_Map.m_TrackingLayer.AddEvent(&startText, "STARTPOINT");

		m_pMapWnd->Refresh();
		//////////////////////////////////////////////////////////////////////////
	}		
}

void CNavigatorView::OnSetDestination() 
{
	// TODO: Add your command handler code here
	
	// 清空起点数组, 目前支持设置一个终点	
	if (m_pMapWnd)
	{
		m_pathPlanning.m_arrPntEnd.RemoveAll();
		
		OnPOIQuery();
		m_bPOIQuery = FALSE;
		
		UGPoint2D pntEndAnchor;
		
		// 获取查询结果目标点		
		pntEndAnchor = m_POIQuery.GetDrawPoint();
		// 添加终点
		m_pathPlanning.AddDestination(pntEndAnchor);
		
		//////////////////////////////////////////////////////////////////////////
		// 跟踪层上写文本END
		UGGeoText endText;	
		UGString strEnd = "E";
		
		endText.Make(strEnd, pntEndAnchor);
		//设置文本的风格
		UGTextStyle textStyle;
		UGString strFont = "宋体";
		textStyle.SetFaceName(strFont);
		textStyle.SetSizeForFixed(5);
		
		textStyle.SetForeColor( UGRGBA(0,50,155,0) );
		textStyle.SetBackColor( UGRGBA(255,155,0,0) );
		textStyle.SetHalo( true );
		textStyle.SetBold( true );
		textStyle.SetBackOpaque( false );
		textStyle.SetFixedSize(TRUE);
		
		endText.SetTextStyle(textStyle);
		
		// 如果原来跟踪层上有“E”,则首先擦除
		m_pMapWnd->m_Map.m_TrackingLayer.DeleteEvent(m_nEndID);		
		m_nEndID = m_pMapWnd->m_Map.m_TrackingLayer.AddEvent(&endText, "ENDPOINT");
		
		m_pMapWnd->Refresh();
		//////////////////////////////////////////////////////////////////////////
	}		
}

void CNavigatorView::OnPathplanningDo() 
{
	if (m_pMapWnd)
	{
		// 获取用于路径规划的数据源
		UGNdfDataSource* pNdfDataSource = NULL;
		pNdfDataSource = (UGNdfDataSource*)GetDataSource(0);		
		if (pNdfDataSource)
		{
			m_pathPlanning.SetDatasource(pNdfDataSource);
		}
		
		// 路径规划初始化
		UGbool bInit = m_pathPlanning.Init();
		if (bInit)
		{
			// 执行路径规划
			UGbool	bSearch = m_pathPlanning.pathPlanning();			
			if (bSearch)
			{
				// 高亮路径规划结果
				m_pathPlanning.OnDrawRoute(m_pMapWnd);
				m_pathPlanning.HightLightRoute(m_pMapWnd);

 				m_bPathPlanning = TRUE;
				m_bInitGuide = FALSE;
			}
			else
			{
				MessageBox(TEXT("Route Analysis failed!"), NULL, MB_OK);
				return;
			}
		}
	}
	return;
}

// 擦除规划路线
void CNavigatorView::OnPathplanningClean() 
{
	// TODO: Add your command handler code here
	if (m_pMapWnd)
	{
		m_pathPlanning.OnClean(m_pMapWnd);	
	}
}

void CNavigatorView::OnSimulateNavi() 
{
	if (!m_bPathPlanning||!m_pMapWnd)
	{
		return;
	}
	if ( !m_bInitGuide )
	{
		// 获取用于导航的数据源
		UGNdfDataSource* pNdfDataSource = NULL;	
		pNdfDataSource = (UGNdfDataSource*)GetDataSource(0);		
		if (pNdfDataSource)
		{
			m_Guide.SetDatasource(pNdfDataSource);
		}
		
		// 设置导航的起点、终点
		m_Guide.m_pntStart = m_pathPlanning.m_arrPntStart.GetAt(0);
		m_Guide.m_pntEnd = m_pathPlanning.m_arrPntEnd.GetAt(0);	
		
		// 获取路径规划结果
		m_Guide.m_searchOutput = m_pathPlanning.m_searchOutput;		
	}
	
	// 引导初始化
	m_bInitGuide = m_Guide.OnInitGuide();
	if (m_bInitGuide)
	{
		m_pMapWnd->SetScale(1.0/10000);
		m_pMapWnd->SetCenter(m_Guide.m_pntStart);
		// 启动时钟
		SetTimer(1, 50, 0);
		m_pMapWnd->Refresh();
	}		
	return;
}


void CNavigatorView::OnTimer(UINT nIDEvent) 
{
    // 模拟导航
	UGlong lG = m_Guide.OnSimulateNavi(m_pMapWnd);
	
	// 导航成功
	if (lG == UG_GUIDANCE_GUIDEBYSPEED_SUCCEEDED)
	{
		m_bGuiding = TRUE;
		m_pntGuide = m_Guide.m_pntNext;
		m_strRouteInfo = m_Guide.GetRouteInfo();
	}
	// 导航至终点
	if (lG == UG_GUIDANCE_GUIDEBYSPEED_ARRIVE_DESTINATION)
	{
		m_pMapWnd->m_Map.SetCenter(m_pathPlanning.m_arrPntEnd.GetAt(0));
		m_pMapWnd->m_Map.SetAngle(0);
		m_bGuiding = FALSE;

		m_strRouteInfo = m_Guide.GetRouteInfo();
		KillTimer(1);
	}
	CView::OnTimer(nIDEvent);
}

void CNavigatorView::OnCancleNavi() 
{
	if (m_pMapWnd)
	{
		KillTimer(1);

		// 状态变量复位
		m_bInitGuide = FALSE;
		m_bGuiding = FALSE;		
		m_bPathPlanning = FALSE;
		m_strRouteInfo = "";
		
		// 地图转回原位置
		m_pMapWnd->m_Map.SetAngle(0);
		
		// 清除规划路线
		m_pathPlanning.OnClean(m_pMapWnd);		
		m_pMapWnd->Refresh();
	}
}

void CNavigatorView::OnUpdateFileOpen(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}	
}

void CNavigatorView::OnUpdateFileClose(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}	
}

void CNavigatorView::OnUpdatePoiQuery(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}	
}

void CNavigatorView::OnUpdateQueryDeparture(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}	
}

void CNavigatorView::OnUpdateQueryDestination(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}	
}

void CNavigatorView::OnUpdateRaDo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}	
}

void CNavigatorView::OnUpdateRaClean(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}	
}

void CNavigatorView::OnUpdateNaviSimulate(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bGuiding)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}
	
}

⌨️ 快捷键说明

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