#include #include #include #include #include #include #include "common/rectc.h" #include "osm.h" #include "config.h" #include "mbtilesmap.h" #define META_TYPE(type) static_cast(type) static double index2mercator(int index, int zoom) { return rad2deg(-M_PI + 2 * M_PI * ((double)index / (1< _zooms.max()) return _zooms.max(); return zoom; } int MBTilesMap::zoomFit(const QSize &size, const RectC &rect) { if (!rect.isValid()) _zoom = _zooms.max(); else { QRectF tbr(osm::ll2m(rect.topLeft()), osm::ll2m(rect.bottomRight())); QPointF sc(tbr.width() / size.width(), tbr.height() / size.height()); _zoom = limitZoom(osm::scale2zoom(qMax(sc.x(), -sc.y()) / coordinatesRatio(), _tileSize)); } return _zoom; } qreal MBTilesMap::resolution(const QRectF &rect) { return osm::resolution(rect.center(), _zoom, _tileSize); } int MBTilesMap::zoomIn() { _zoom = qMin(_zoom + 1, _zooms.max()); return _zoom; } int MBTilesMap::zoomOut() { _zoom = qMax(_zoom - 1, _zooms.min()); return _zoom; } qreal MBTilesMap::coordinatesRatio() const { return _deviceRatio > 1.0 ? _deviceRatio / _tileRatio : 1.0; } qreal MBTilesMap::imageRatio() const { return _deviceRatio > 1.0 ? _deviceRatio : _tileRatio; } qreal MBTilesMap::tileSize() const { return (_tileSize / coordinatesRatio()); } QByteArray MBTilesMap::tileData(int zoom, const QPoint &tile) const { QSqlQuery query(_db); query.prepare("SELECT tile_data FROM tiles " "WHERE zoom_level=:zoom AND tile_column=:x AND tile_row=:y"); query.bindValue(":zoom", zoom); query.bindValue(":x", tile.x()); query.bindValue(":y", (1<drawPixmap(tp, pm); } } } } QPointF MBTilesMap::ll2xy(const Coordinates &c) { qreal scale = osm::zoom2scale(_zoom, _tileSize); QPointF m = osm::ll2m(c); return QPointF(m.x() / scale, m.y() / -scale) / coordinatesRatio(); } Coordinates MBTilesMap::xy2ll(const QPointF &p) { qreal scale = osm::zoom2scale(_zoom, _tileSize); return osm::m2ll(QPointF(p.x() * scale, -p.y() * scale) * coordinatesRatio()); }