|
本帖最后由 就是那个胖子 于 2013-12-31 09:34 编辑
用EventHandler方法获取鼠标位置,然后转换成经纬度显示,有时候出现值不准确的问题,请各位帮忙看看问题出在哪儿,指点下,谢谢了,代码如下:
void QueryPosHandler::Update(float fXPos, float fYPos, float fHeight, osgViewer::View* pViewer)
{
bool yes = false;
osg::Vec3d world;
if (m_pTerrain->getWorldCoordsUnderMouse(pViewer, fXPos, fYPos, world))
{
GeoPoint mapPoint;
mapPoint.fromWorld(m_pTerrain->getSRS(), world);
double query_resolution = 0.1;
double out_hamsl = 0.0;
double out_resolution = 0.0;
bool ok = m_pQuery->getElevation(mapPoint, out_hamsl, query_resolution, &out_resolution);
if (ok)
{
mapPoint.z() = out_hamsl;
GeoPoint mapPointGeodetic(m_pMapNode->getMapSRS()->getGeodeticSRS(), mapPoint);
CString strPos = "";
CString strLat = "";
CString strLon = "";
CString strHeight = "";
strLon.Format("%lf", mapPoint.x());
strLat.Format("%lf", mapPoint.y());
strHeight.Format("%lf", mapPoint.z());
strPos = "Lon:" + strLon + " Lat:" + strLat + " Height:" + strHeight;
m_pMousePosCtrl->setText(strPos.GetBuffer());
yes = true;
}
}
if(!yes)
{
m_pMousePosCtrl->setText("");
}
}
bool QueryPosHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE)
{
osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
Update(ea.getX(), ea.getY(), 0, view);
}
return false;
}
结果如图所示:我加载影像范围,纬度最大值是29.2,但是鼠标在影像范围内,显示的坐标却是30多:
鼠标在中国区域内,坐标显示为负值:
|
|