void LightMap::drawMarks(QPainter& painter) { // QList<QSharedPointer<DataMark> > marks = m_marks.values(); double tdim=256.; QPointF center=tileForCoordinate(m_normalMap->latitude,m_normalMap->longitude,m_normalMap->zoom); QPointF pos,posOnMap,winCenter(m_normalMap->width/2,m_normalMap->height/2); //Add here time and count filter QSettings settings(QSettings::SystemScope,"osll","libs"); int markAge=0; int maxAgeOfMark=settings.value("timeLimit").toInt(); int marksCount=settings.value("marksCount").toInt(); //Getting list of all channels, wich marks are in request QList<QSharedPointer<DataMark> > marks; QList<QSharedPointer<Channel> > channels=m_marks.uniqueKeys(); for (int j=0;j<channels.size();j++) { marks=m_marks.values(channels.at(j)); qSort(marks.begin(), marks.end(), qGreater<QSharedPointer<DataMark> >()); for (int i=0; i < qMin(marksCount, marks.size()) ; i++) { markAge=marks.at(i)->getTime().toUTC().secsTo(QDateTime::currentDateTime())/60; qDebug() << "current mark age "<< markAge; if( markAge<maxAgeOfMark) { pos=center-tileForCoordinate(marks.at(i)->getLatitude(),marks.at(i)->getLongitude(),m_normalMap->zoom); posOnMap=winCenter-pos*qreal(tdim); this->drawMarkIco(painter, posOnMap, marks.at(i),channels.at(j)); } } } }
QPointF MapWidget::getMarkerScreenCoordinate(const MapMarker &marker) const { QPointF center = tileForCoordinate(latitude, longitude, ZOOM); qreal hCenter = width()/2.0; qreal vCenter = height()/2.0; QPointF latLong = marker.getLatLong(); QPointF tile = tileForCoordinate(latLong.x(), latLong.y(), ZOOM); qreal x = hCenter - ((center.x() - tile.x()) * TILES_SIZE); qreal y = vCenter - ((center.y() - tile.y()) * TILES_SIZE); return QPointF(x, y); }
QRectF MapWidget::computeMinimumRect(int zoom) const { QPointF center = tileForCoordinate(latitude, longitude, zoom); QPointF min = tileForCoordinate(getMinimumLatLongInMarkers(), zoom); QPointF max = tileForCoordinate(getMaximumLatLongInMarkers(), zoom); qreal hCenter = width()/2.0; qreal vCenter = height()/2.0; qreal left = hCenter - ((center.x() - min.x()) * TILES_SIZE); qreal top = vCenter - ((center.y() - min.y()) * TILES_SIZE); qreal right = hCenter - ((center.x() - max.x()) * TILES_SIZE); qreal bottom = vCenter - ((center.y() - max.y()) * TILES_SIZE); return QRectF(QPointF(left, top), QPointF(right, bottom)); }
void MapWidget::invalidate() { if (width() <= 0 || height() <= 0) return; QPointF center = tileForCoordinate(latitude, longitude, ZOOM); qreal tileX = center.x(); qreal tileY = center.y(); // top-left corner of the center tile int xp = width() / 2 - (tileX - floor(tileX)) * TILES_SIZE; int yp = height() / 2 - (tileY - floor(tileY)) * TILES_SIZE; // first tile vertical and horizontal int xa = (xp + TILES_SIZE - 1) / TILES_SIZE; int ya = (yp + TILES_SIZE - 1) / TILES_SIZE; int xs = static_cast<int>(tileX) - xa; int ys = static_cast<int>(tileY) - ya; // offset for top-left tile offset = QPoint(xp - xa * TILES_SIZE, yp - ya * TILES_SIZE); // last tile vertical and horizontal int xe = static_cast<int>(tileX) + (width() - xp - 1) / TILES_SIZE; int ye = static_cast<int>(tileY) + (height() - yp - 1) / TILES_SIZE; // build a rect tilesRect = QRect(xs, ys, xe - xs + 1, ye - ys + 1); update(); }
void SlippyMap::invalidate() { if (width <= 0 || height <= 0) return; const QPointF ct = tileForCoordinate(latitude, longitude, zoom); const qreal tx = ct.x(); const qreal ty = ct.y(); // top-left corner of the center tile const int xp = width / 2 - (tx - floor(tx)) * tdim; const int yp = height / 2 - (ty - floor(ty)) * tdim; // first tile vertical and horizontal const int xa = (xp + tdim - 1) / tdim; const int ya = (yp + tdim - 1) / tdim; const int xs = static_cast<int>(tx) - xa; const int ys = static_cast<int>(ty) - ya; // offset for top-left tile m_offset = QPoint(xp - xa * tdim, yp - ya * tdim); // last tile vertical and horizontal const int xe = static_cast<int>(tx) + (width - xp - 1) / tdim; const int ye = static_cast<int>(ty) + (height - yp - 1) / tdim; // build a rect m_tilesRect = QRect(xs, ys, xe - xs + 1, ye - ys + 1); if (m_url.isEmpty()) download(); emit updated(QRect(0, 0, width, height)); }
void SlippyMap::pan(const QPoint &delta) { const QPointF dx = QPointF(delta) / qreal(tdim); const QPointF center = tileForCoordinate(latitude, longitude, zoom) - dx; latitude = latitudeFromTile(center.y(), zoom); longitude = longitudeFromTile(center.x(), zoom); invalidate(); }
void TilesMap::calcTilesRect() { QPointF ct = tileForCoordinate(m_center); qreal tx = ct.x(); qreal ty = ct.y(); m_tileCenter = QPoint(floor(tx), floor(ty)); int xp = m_width / 2 - (tx - floor(tx)) * TILE_SIZE; int yp = m_height / 2 - (ty - floor(ty)) * TILE_SIZE; int xa = (xp + TILE_SIZE - 1) / TILE_SIZE; int ya = (yp + TILE_SIZE - 1) / TILE_SIZE; int xs = static_cast<int>(tx) - xa; int ys = static_cast<int>(ty) - ya; m_offset = QPoint(xp - xa * TILE_SIZE, yp - ya * TILE_SIZE); int xe = static_cast<int>(tx) + (m_width - xp - 1) / TILE_SIZE; int ye = static_cast<int>(ty) + (m_height - yp - 1) / TILE_SIZE; m_tilesRect = QRect(xs, ys, xe - xs + 1, ye - ys + 1); }
QPointF tileForCoordinate(QPointF latLong, int zoom) { return tileForCoordinate(latLong.x(), latLong.y(), zoom); }