void MainWindow::test() { QMap<int,UGString>::iterator it; for(it=m_Trackstr.begin();it!=m_Trackstr.end();) { qMapControl->GetMap()->m_TrackingLayer.RemoveTag(it.value()); // m_qMapControl->GetMap()->m_TrackingLayer.Remove(it.value()); it++; } m_Trackstr.clear(); UGPoint2D trackGeograph;//地图坐标 double m_RabarB=30.563; double m_RararL=103.479; transBLtoGeOGraphic(m_RabarB,m_RararL,trackGeograph); UGPoint2D Target2D; double R,A;
UGStyle* pStyle = new UGStyle(); pStyle->SetMarkerSize(1);//点大小,5 pStyle->SetLineColor(UGRGB(0,255,0));//设置点颜色为红色 pStyle->SetMarkerHeight(2); // 设置符号高度 pStyle->SetMarkerWidth(1); // 设置符号宽 pStyle->SetMarkerSize(2); UGGeoPoint *pt = new UGGeoPoint(); int ilen=10; for(int j=0;j<ilen;j++) { R=30000-incdo*200; if(R<0) { R=30000; incdo=0; } A=45+j*20; QString str=QString::number(j+1);//取出批号 Target2D.x=trackGeograph.x+R*sin(A*(PITD/180)); Target2D.y=trackGeograph.y+R*cos(A*(PITD/180)); pt->SetPoint(Target2D); UGString Tracktag=Translator::QStr2UGStr("Tracktag"+str); m_Trackstr.insert(j+1,Tracktag); UGPoint2D qpt1,qpt2,qpt3,qpt4; double detal=R/30000.0; qpt1=Target2D+UGPoint2D(100*detal,0); qpt2=Target2D+UGPoint2D(-100*detal,0); qpt3=Target2D+UGPoint2D(0,100*detal); qpt4=Target2D+UGPoint2D(0,-100*detal); UGGeoLine *pLine =new UGGeoLine(); UGPoint2Ds *pts1 = new UGPoint2Ds(); pts1->Add(qpt1); pts1->Add(qpt2); pLine->AddSub(pts1->GetData(),2); pLine->SetStyle(pStyle); qMapControl->GetMap()->m_TrackingLayer.Add(pLine, Tracktag);//画点十字 pts1->RemoveAll(); pLine->Clear(); pts1->Add(qpt3); pts1->Add(qpt4); pLine->AddSub(pts1->GetData(),2); pLine->SetStyle(pStyle); qMapControl->GetMap()->m_TrackingLayer.Add(pLine, Tracktag);//画点 delete pLine; pLine=NULL; delete pts1; pts1=NULL;
} delete pt; pt=NULL; delete pStyle; pStyle=NULL; qMapControl->refreshDynamicLayer(); incdo++; }这个函数是用100ms的定时器在调用
void MainWindow::transBLtoGeOGraphic(double B, double L, UGPoint2D &pt) { const UGPrjCoordSys& pSrcPrj= qMapControl->GetMap()->GetPrjCoordSys(); UGPrjCoordSys* pTargetPrj = new UGPrjCoordSys(4326);//WSG84 UGRefTranslator* pUGRefTranslator = new UGRefTranslator();
pUGRefTranslator->SetPrjCoordSysSrc(pSrcPrj); // 被转换点的坐标系 pUGRefTranslator->SetPrjCoordSysDes(*pTargetPrj); // 转换后点的坐标系 pUGRefTranslator->SetGeoTransMethod(EmGeoTransMethod::MTH_GEOCENTRIC_TRANSLATION); // 转换方法:三参数
// 转换参数,根据设置的转换方法,有旋转,平移等时设置对应参数,没有需要就创建空对象 UGGeoTransParams* pTempParams = new UGGeoTransParams(); pUGRefTranslator->SetGeoTransParams(*pTempParams); delete pTempParams; pTempParams = NULL;
// 构造点串, pt为一个屏幕上的点 UGPoint2D p1; p1.x=L; p1.y=B; UGArray<UGPoint2D> ugArray; ugArray.Add(p1);
int count = ugArray.GetSize(); UGPoint2D p; bool result = pUGRefTranslator->Translate(ugArray.GetData(), 1,false);//监视是否转换成功
p=ugArray.GetAt(0); pt.x=p.x; pt.y=p.y; delete pTargetPrj; pTargetPrj=nullptr; delete pUGRefTranslator; pUGRefTranslator=nullptr; } 这是坐标转换
修改一下代码逻辑,改为每次去修改对应点的坐标,不将原来的删除
修改跟踪图层对象代码如下,: