Пример #1
0
/* TODO: relative2coord could be split off this */
void SlippyMapWidget::makeSelection(const QRect& relative) {
    /* Compute viewport boundingbox */
    qreal X1 = p->Lon - (width()/2.0)/TILESIZE;
    qreal Y1 = p->Lat - (height()/2.0)/TILESIZE;
    qreal X2 = p->Lon + (width()/2.0)/TILESIZE;
    qreal Y2 = p->Lat + (height()/2.0)/TILESIZE;

    /* Actual difference per pixel */
    qreal xpixel = (X2-X1)/width();
    qreal ypixel = (Y2-Y1)/height();

    /* Shift the border according to relative */
    X1 += xpixel * relative.topLeft().x();
    Y1 += ypixel * relative.topLeft().y();
    X2 -= xpixel * (width() - relative.bottomRight().x());
    Y2 -= ypixel * (height() - relative.bottomRight().y());

    qreal Lon1 = tile2lon(X1, p->Zoom);
    qreal Lat1 = tile2lat(Y1, p->Zoom);

    qreal Lon2 = tile2lon(X2, p->Zoom);
    qreal Lat2 = tile2lat(Y2, p->Zoom);

    /* Save the selection */
    p->CurrentSelectionCoord =  QRectF(Lon1, Lat2, Lon2-Lon1, Lat1-Lat2);

    qDebug() << "Selection rectangle: " << p->CurrentSelectionCoord;
}
Пример #2
0
QRectF SlippyMapWidget::viewArea() const
{
    qreal X1 = p->Lat - (width()/2.0)/TILESIZE;
    qreal Y1 = p->Lon - (height()/2.0)/TILESIZE;
    qreal X2 = p->Lat + (width()/2.0)/TILESIZE;
    qreal Y2 = p->Lon + (height()/2.0)/TILESIZE;

    qreal Lon1 = tile2lon(X1, p->Zoom);
    qreal Lat1 = tile2lat(Y1, p->Zoom);

    qreal Lon2 = tile2lon(X2, p->Zoom);
    qreal Lat2 = tile2lat(Y2, p->Zoom);

    return QRectF(Lon1, Lat2, Lon2-Lon1, Lat1-Lat2);
}