QRectF GdalAdapter::getBoundingbox() const { QRectF projBbox = theBbox; if (isLatLon) projBbox = QRectF(angToRad(theBbox.left()), angToRad(theBbox.top()), angToRad(theBbox.width()), angToRad(theBbox.height())); return projBbox; }
QPointF mercatorProject(const QPointF& c) const { qreal x = c.x() / 180. * EQUATORIALMETERHALFCIRCUMFERENCE; qreal y = log(tan(angToRad(c.y())) + 1/cos(angToRad(c.y()))) / M_PI * (EQUATORIALMETERHALFCIRCUMFERENCE); return QPointF(x, y); }
QPointF mercatorProject(const QPointF& c) { double x = angToRad(c.x()) / M_PI * 20037508.34; double y = log(tan(angToRad(c.y())) + 1/cos(angToRad(c.y()))) / M_PI * (20037508.34); return QPointF(x, y); }
QPointF Projection::projProject(const QPointF & Map) const { qreal x = angToRad(Map.x()); qreal y = angToRad(Map.y()); projTransformFromWGS84(1, 0, &x, &y, NULL); return QPointF(x, y); }
void PrimitivePainter::drawLabel(QPainterPath* R, QPainter* thePainter, qreal PixelPerM, QString str, QString strBg) const { if (!DrawLabel) return; if (str.isEmpty() && strBg.isEmpty()) return; thePainter->save(); if (getLabelArea()) { QPointF C(R->boundingRect().center()); drawPointLabel(C, str, strBg, thePainter, PixelPerM); thePainter->restore(); return; } LineParameters lp = labelBoundary(); qreal WW = PixelPerM*lp.Proportional+lp.Fixed; if (WW < 10) return; //qreal WWR = qMax(PixelPerM*R->widthOf()*BackgroundScale+BackgroundOffset, PixelPerM*R->widthOf()*ForegroundScale+ForegroundOffset); QPainterPath textPath; QPainterPath tranformedRoadPath = *R; QFont font = getLabelFont(); if (!str.isEmpty()) { QRegion rg = thePainter->clipRegion(); font.setPixelSize(int(WW)); QFontMetrics metrics(font); if (font.pixelSize() >= 5 && tranformedRoadPath.length() > metrics.width(str)) { thePainter->setFont(font); int repeat = int((tranformedRoadPath.length() / ((metrics.width(str) * LABEL_PATH_DISTANCE))) - 0.5); int numSegment = repeat+1; qreal lenSegment = tranformedRoadPath.length() / numSegment; qreal startSegment = 0; QPainterPath textPath; do { QRegion rg = thePainter->clipRegion(); qreal curLen = startSegment + ((lenSegment - metrics.width(str)) / 2); int modIncrement = 1; qreal modAngle = 0; int modY = 0; if (cos(angToRad(tranformedRoadPath.angleAtPercent((startSegment+(lenSegment/2))/tranformedRoadPath.length()))) < 0) { modIncrement = -1; modAngle = 180.0; curLen += metrics.width(str); } for (int i = 0; i < str.length(); ++i) { qreal t = tranformedRoadPath.percentAtLength(curLen); QPointF pt = tranformedRoadPath.pointAtPercent(t); qreal angle = tranformedRoadPath.angleAtPercent(t); modY = (metrics.ascent()/2)-3; QMatrix m; m.translate(pt.x(), pt.y()); m.rotate(-angle+modAngle); QPainterPath charPath; charPath.addText(0, modY, font, str.mid(i, 1)); charPath = charPath * m; textPath.addPath(charPath); qreal incremenet = metrics.width(str[i]); curLen += (incremenet * modIncrement); } startSegment += lenSegment; } while (--repeat >= 0); if (getLabelHalo()) { thePainter->setPen(QPen(Qt::white, font.pixelSize()/6)); thePainter->drawPath(textPath); } thePainter->setPen(Qt::NoPen); thePainter->setBrush(LabelColor); thePainter->drawPath(textPath); thePainter->setClipRegion(rg); } } if (DrawLabelBackground && !strBg.isEmpty()) { QRegion rg = thePainter->clipRegion(); font.setPixelSize(int(WW)); QFontMetrics metrics(font); int repeat = int((tranformedRoadPath.length() / (metrics.width(strBg) * LABEL_STRAIGHT_DISTANCE)) - 0.5); int numSegment = repeat+1; qreal lenSegment = tranformedRoadPath.length() / numSegment; qreal startSegment = 0; do { int modX = 0; int modY = 0; qreal curLen = startSegment + (lenSegment / 2); qreal t = tranformedRoadPath.percentAtLength(curLen); QPointF pt = tranformedRoadPath.pointAtPercent(t); modX = - (metrics.width(strBg)/2); //modX = WW; modY = (metrics.ascent()/2); QPainterPath textPath, bgPath; textPath.addText(modX, modY, font, strBg); bgPath.addRect(textPath.boundingRect().adjusted(-BG_SPACING, -BG_SPACING, BG_SPACING, BG_SPACING)); bool rgContains = false; for (int i=0; i<rg.rects().size(); i++) { if (rg.rects()[i].contains(bgPath.boundingRect().toRect().translated(pt.toPoint()))) { rgContains = true; break; } } if (rgContains) { thePainter->translate(pt); thePainter->setPen(QPen(LabelColor, BG_PEN_SZ)); thePainter->setBrush(LabelBackgroundColor); thePainter->drawPath(bgPath); if (getLabelHalo()) { thePainter->setPen(QPen(Qt::white, font.pixelSize()/5)); thePainter->drawPath(textPath); } thePainter->setPen(Qt::NoPen); thePainter->setBrush(LabelColor); thePainter->drawPath(textPath); rg -= bgPath.boundingRect().toRect().translated(pt.toPoint()); } startSegment += lenSegment; } while (--repeat >= 0); thePainter->setClipRegion(rg); } thePainter->restore(); }