void CMeasuredGrid::CalLabels(Display::IDisplayPtr pDisplay, std::vector<stGridLabel>& vecVerticalLabel, std::vector<stGridLabel>& vecHorizontalLabel, std::vector<std::pair<GEOMETRY::geom::Envelope, std::string>>& vecVerLabels, std::vector<std::pair<GEOMETRY::geom::Envelope, std::string>>& vecHorLabels, double labelOffset, Display::CTextSymbol* pVerticalTextSym, Display::CTextSymbol* pHorizontalTextSym, double tickSpacePage) { int labelStep=1; char labelText[100]; memset(labelText,0 , 100*sizeof(char)); DIS_RECT maxRect, textRect; GEOMETRY::geom::Envelope maxEnv, textEnv; maxRect.left = maxRect.right = maxRect.top = maxRect.bottom = 0; GEOMETRY::geom::Coordinate coordLabelPos, coordLabelGeo; double x[2]; int nFind = 0; //bottom if(m_bLabelBottom) { //计算最大的文字尺寸 for(int i=0; i<vecVerticalLabel.size(); i++) { if(!vecVerticalLabel[i].bStartValid) continue; coordLabelGeo = vecVerticalLabel[i].geoCoordStart; sprintf(labelText, "%.2f", coordLabelGeo.x); textRect = CalculateTextSize(pDisplay, pVerticalTextSym, labelText); if(maxRect.Width()<textRect.Width()) maxRect = textRect; } pDisplay->GetDisplayTransformation().TransformToGeo(maxRect, &maxEnv); //计算互不重叠文字的间隔 nFind = 0; for(int i=0; i<vecVerticalLabel.size(); i++) { if(nFind == 2) break; if( vecVerticalLabel[i].bStartValid) { x[nFind] = vecVerticalLabel[i].pageCoordStart.x; nFind++; } } if(nFind==2) { double interval = abs(x[1]- x[0]); if(maxEnv.getWidth()+4>interval) labelStep = (int)((maxEnv.getWidth()+4)/interval + 0.9999); } //保存文字 for(int i=0; i<vecVerticalLabel.size(); i+=labelStep) { coordLabelGeo = vecVerticalLabel[i].geoCoordStart; coordLabelPos = vecVerticalLabel[i].pageCoordStart; textEnv.init(coordLabelPos.x/* - maxEnv.getWidth()/2*/, coordLabelPos.x/* + maxEnv.getWidth()/2*/, coordLabelPos.y - tickSpacePage - labelOffset - maxEnv.getHeight()/2, coordLabelPos.y - tickSpacePage - labelOffset - maxEnv.getHeight()/2); sprintf(labelText, "%.2f", coordLabelGeo.x); std::pair<GEOMETRY::geom::Envelope, std::string> label; label.first = textEnv; label.second = labelText; vecVerLabels.push_back(label); } } //top if(m_bLabelTop) { maxRect.left = maxRect.right = maxRect.top = maxRect.bottom = 0; for(int i=0; i<vecVerticalLabel.size(); i++) { if(!vecVerticalLabel[i].bEndValid) continue; coordLabelGeo = vecVerticalLabel[i].geoCoordEnd; sprintf(labelText, "%.2f", coordLabelGeo.x); textRect = CalculateTextSize(pDisplay, pVerticalTextSym, labelText); if(maxRect.Width()<textRect.Width()) maxRect = textRect; } pDisplay->GetDisplayTransformation().TransformToGeo(maxRect, &maxEnv); nFind = 0; for(int i=0; i<vecVerticalLabel.size(); i++) { if(nFind == 2) break; if( vecVerticalLabel[i].bEndValid) { x[nFind] = vecVerticalLabel[i].pageCoordEnd.x; nFind++; } } if(nFind==2) { double interval = abs(x[1]- x[0]); if(maxEnv.getWidth()+4>interval) labelStep = (int)((maxEnv.getWidth()+4)/interval + 0.9999); } for(int i=0; i<vecVerticalLabel.size(); i+=labelStep) { coordLabelGeo = vecVerticalLabel[i].geoCoordEnd; coordLabelPos = vecVerticalLabel[i].pageCoordEnd; textEnv.init(coordLabelPos.x/* - maxEnv.getWidth()/2*/, coordLabelPos.x/* + maxEnv.getWidth()/2*/, coordLabelPos.y + tickSpacePage + labelOffset + maxEnv.getHeight()/2, coordLabelPos.y + tickSpacePage + labelOffset + maxEnv.getHeight()/2); sprintf(labelText, "%.2f", coordLabelGeo.x); std::pair<GEOMETRY::geom::Envelope, std::string> label; label.first = textEnv; label.second = labelText; vecVerLabels.push_back(label); } } //left double y[2]; if(m_bLabelLeft) { maxRect.left = maxRect.right = maxRect.top = maxRect.bottom = 0; for(int i=0; i<vecHorizontalLabel.size(); i++) { if(!vecHorizontalLabel[i].bStartValid) continue; coordLabelGeo = vecHorizontalLabel[i].geoCoordStart; sprintf(labelText, "%.2f", coordLabelGeo.y); textRect = CalculateTextSize(pDisplay, pHorizontalTextSym, labelText); if(maxRect.Width()<textRect.Width()) maxRect = textRect; } pDisplay->GetDisplayTransformation().TransformToGeo(maxRect, &maxEnv); nFind = 0; for(int i=0; i<vecHorizontalLabel.size(); i++) { if(nFind == 2) break; if( vecHorizontalLabel[i].bStartValid) { y[nFind] = vecHorizontalLabel[i].pageCoordStart.y; nFind++; } } if(nFind==2) { double interval = abs(y[1]- y[0]); if(maxEnv.getHeight()+4>interval) labelStep = (int)((maxEnv.getHeight()+4)/interval + 0.9999); } for(int i=0; i<vecHorizontalLabel.size(); i+=labelStep) { coordLabelGeo = vecHorizontalLabel[i].geoCoordStart; coordLabelPos = vecHorizontalLabel[i].pageCoordStart; textEnv.init(coordLabelPos.x - tickSpacePage - labelOffset - maxEnv.getWidth()/2 , coordLabelPos.x - tickSpacePage - labelOffset - maxEnv.getWidth()/2, coordLabelPos.y , coordLabelPos.y); sprintf(labelText, "%.2f", coordLabelGeo.y); std::pair<GEOMETRY::geom::Envelope, std::string> label; label.first = textEnv; label.second = labelText; vecHorLabels.push_back(label); } } if(m_bLabelRight) { //right maxRect.left = maxRect.right = maxRect.top = maxRect.bottom = 0; for(int i=0; i<vecHorizontalLabel.size(); i++) { if(!vecHorizontalLabel[i].bEndValid) continue; coordLabelGeo = vecHorizontalLabel[i].geoCoordEnd; sprintf(labelText, "%.2f", coordLabelGeo.y); textRect = CalculateTextSize(pDisplay, pHorizontalTextSym, labelText); if(maxRect.Width()<textRect.Width()) maxRect = textRect; } pDisplay->GetDisplayTransformation().TransformToGeo(maxRect, &maxEnv); nFind = 0; for(int i=0; i<vecHorizontalLabel.size(); i++) { if(nFind == 2) break; if( vecHorizontalLabel[i].bEndValid) { y[nFind] = vecHorizontalLabel[i].pageCoordEnd.y; nFind++; } } if(nFind==2) { double interval = abs(y[1]- y[0]); if(maxEnv.getHeight()+4>interval) labelStep = (int)((maxEnv.getHeight()+4)/interval + 0.9999); } for(int i=0; i<vecHorizontalLabel.size(); i+=labelStep) { coordLabelGeo = vecHorizontalLabel[i].geoCoordEnd; coordLabelPos = vecHorizontalLabel[i].pageCoordEnd; textEnv.init(coordLabelPos.x + tickSpacePage + labelOffset + maxEnv.getWidth()/2 , coordLabelPos.x + tickSpacePage + labelOffset + maxEnv.getWidth()/2, coordLabelPos.y, coordLabelPos.y); sprintf(labelText, "%.2f", coordLabelGeo.y); std::pair<GEOMETRY::geom::Envelope, std::string> label; label.first = textEnv; label.second = labelText; vecHorLabels.push_back(label); } } }
void Button::SetTextParameters(){ CalculateTextSize(); CalculateTextPosition(); };