Qt compile map comprehensive application 14-offline map download

I. Introduction

In fact, there are many different offline map downloaders on the Internet, most of which are charged. The free ones either limit the number or level of tiles downloaded, or the downloaded tile maps are watermarked and look very It's ugly. I often need to use offline maps to get rid of this limitation. I deliberately spent some time re-examining the principle of tile maps and made an offline map downloader. In fact, tile map download is not so complicated. Several server addresses form the address of the tile map to be requested. After sending the request, the picture will be automatically returned to you. You only need to get the picture data and save it as a picture.

The steps of downloading the tile map are as follows:

  1. Get the scope of the visible area or administrative area
  2. Get the latitude and longitude coordinates of the lower left corner and upper right corner of the area
  3. Calculate the number of tiles at the corresponding level according to the number of levels
  4. Automatically generate an address to download the tile map and issue a request
  5. Parse the received data and save it as a picture
  6. Update the download quantity and progress of the corresponding interface
  7. You can select the corresponding saved directory, select all levels, stop downloading halfway, etc.
  8. Choose whether to download street maps or satellite maps, etc.

2. Features

  1. Both online and offline map modes are supported.
  2. At the same time support webkit kernel, webengine kernel, IE kernel.
  3. Support to set multiple labeling points, information includes name, address, latitude and longitude.
  4. You can set whether the map can be clicked, dragged, or zoomed with the mouse wheel.
  5. You can set the protocol version, secret key, theme style, center coordinates, center city, geocoding location, etc.
  6. You can set the zoom level and level of the map, and the visibility of the thumbnails, scales, and traffic information.
  7. Support map interaction, such as pressing the mouse to get the latitude and longitude of the corresponding location.
  8. Support query route, you can set the starting position, end position, route mode, route mode, route plan (minimum time, least transfer, least walking, no subway, shortest distance, avoid high speed).
  9. It can display point, line and surface tools, and can directly draw lines, points, rectangles and circles on the map.
  10. You can set administrative divisions, specify a city area to draw layers, and online maps automatically output the collection of administrative division boundary points to js files for offline maps.
  11. Multiple covers can be added statically or dynamically. Support points, polylines, polygons, rectangles, circles, arcs, point aggregation, etc.
  12. The function interface is friendly and unified, simple and convenient to use, just one class.
  13. Support js dynamic interactive add point, delete point, clear point, reset point, no need to refresh the page.
  14. Support any Qt version, any system, any compiler.

3. Experience address

  1. Experience address: https://pan.baidu.com/s/1uQsDQO5E5crUBN2J-nPeLQ extraction code: 1jkp File name: bin_map.zip
  2. Domestic site: https://gitee.com/feiyangqingyun
  3. International site: https://github.com/feiyangqingyun
  4. Personal homepage: https://blog.csdn.net/feiyangqingyun
  5. Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/

Four, renderings

V. Related codes

void MapDownload::download(const QString &url, const QString &dirName, const QString &fileName, int zoom)
{
    if (url.isEmpty()) {
        return;
    }

    //启动计时
    QTime time;
    time.start();

    //先判断文件夹是否存在,不存在则新建
    QDir dir(dirName);
    if (!dir.exists()) {
        dir.mkpath(dirName);
    }

    //局部的事件循环,不卡主界面
    QEventLoop eventLoop;
    QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
    connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));

    //设置下载超时
    QTimer timer;
    connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));
    timer.setSingleShot(true);
    timer.start(timeout);
    eventLoop.exec();

    bool error = false;
    if (reply->bytesAvailable() > 0 && reply->error() == QNetworkReply::NoError) {
        //读取所有数据保存成文件
        QByteArray data = reply->readAll();
        QFile file(dirName + fileName);
        if (file.open(QFile::WriteOnly | QFile::Truncate)) {
            file.write(data);
            file.close();
        }
    } else {
        //可以自行增加下载失败的统计
        error = true;
        qDebug() << TIMEMS << "下载出错" << reply->errorString();
    }

    int useTime = time.elapsed();
    emit finsh(url, fileName, zoom, useTime, error);
}

Guess you like

Origin www.cnblogs.com/feiyangqingyun/p/12717511.html
Map
map
map
Map