One, foreword
Offline maps of the loading and loading method is almost the same as online map actually, the only difference is that may be a js file can be introduced before, now need more local js file import, and js file version of the Internet is old, means that now unable to support the new form of support opengl maps, Later go to the Internet search to see if you can get the latest version.
Offline map loads depend on a pile of js file, you can customize the entire folder placed the location of the web page code into line with the specified location, general advice on executable file to create a new directory under the special deposit, such management convenient, offline maps corresponding image file directory is also configurable, also suggested in this directory.
Two, functional characteristics
- Multi-thread synchronous download multi-level tile map, card interface.
- Built-in multiple offline map download request address, automatically select a random send request.
- Download map types support both street maps and satellite maps.
- Automatically calculates the number of downloaded tiles in the viewable area or administrative area.
- The level of download can be custom scoped and selected.
- Signal notification is sent for each tile download completion, and parameters include download time.
- You can set the maximum timeout time for downloading. If the timeout time is exceeded, it will be discarded and skip to the next download task.
- Real-time display of the download progress, as well as the number of tiles downloaded at the current level and total number of tiles.
- The download can be stopped during the download process, and the total time is automatically counted after the download is completed.
- Built-in latitude and longitude and screen coordinate conversion function.
- Baidu Map is currently supported, and other maps such as Google Map, Tencent Map and Autonavi map can be customized.
- Function interface friendly and unified, easy to use, a class.
- Support any Qt version, any system, any compiler.
3. Experience address
- Experience address: pan.baidu.com/s/1ZxG-oyUK… Extraction code: O05q File name: bin_map.zip
- Domestic site: gitee.com/feiyangqing…
- International site: github.com/feiyangqing…
- Profile: blog.csdn.net/feiyangqing…
- Zhihu homepage: www.zhihu.com/people/feiy…
Four, effect drawing
5. Relevant codes
void frmMapDownload::getCount(a)
{
// Count tiles
QString pointLeftBottom = ui->txtPointLeftBottom->text(a); QString pointRightTop = ui->txtPointRightTop->text(a); QStringList listLeftBottom = pointLeftBottom.split(",");
QStringList listRightTop = pointRightTop.split(",");
double lngLeftBottom = listLeftBottom.at(0).toDouble(a);double latLeftBottom = listLeftBottom.at(1).toDouble(a);double lngRightTop = listRightTop.at(0).toDouble(a);double latRightTop = listRightTop.at(1).toDouble(a);//mapType=0 = baidu map =4 = Google Map
int mapType = ui->cboxMapType->currentIndex(a);for (int zoom = indexMin; zoom <= indexMax; zoom++) {
int index = zoom - indexMin;
// Different maps calculate different coordinates
QPoint pt1, pt2;
if (mapType == 3) {
pt1 = WebHelper::lngLatToTileTian(lngLeftBottom, latLeftBottom, zoom);
pt2 = WebHelper::lngLatToTileTian(lngRightTop, latRightTop, zoom);
} else if (mapType == 4) {
pt1 = WebHelper::lngLatToTileGoogle(lngLeftBottom, latLeftBottom, zoom);
pt2 = WebHelper::lngLatToTileGoogle(lngRightTop, latRightTop, zoom);
} else {
pt1 = WebHelper::lngLatToTileBaiDu(lngLeftBottom, latLeftBottom, zoom);
pt2 = WebHelper::lngLatToTileBaiDu(lngRightTop, latRightTop, zoom);
}
// Calculate the maximum and minimum XY coordinates
int xmin = qMin(pt1.x(), pt2.x());
int xmax = qMax(pt1.x(), pt2.x());
int ymin = qMin(pt1.y(), pt2.y());
int ymax = qMax(pt1.y(), pt2.y());
pt1 = QPoint(xmin, ymin);
pt2 = QPoint(xmax, ymax);
// It is convenient to print the result of calculation
if (zoom == 20) {
qDebug() << lngLeftBottom << latLeftBottom << lngRightTop << latRightTop << pt1 << pt2;
}
// The number of tiles at the current level
int count = 0;
for (int j = xmin; j <= xmax; j++) {
for (intk = ymin; k <= ymax; k++) { count++; }}// Display the corresponding total number of tiles, set the progress bar parameters, and update the corresponding value
if (count > 0) {
bars.at(index)->setRange(0, count);
}
bars.at(index)->setValue(0);
labs.at(index)->setText(QString::number(count)); pointLeftBottoms[index] = pt1; pointRightTops[index] = pt2; }}void frmMapDownload::clear(a)
{
// Set the advanced bar to 0
currentCount = 0;
foreach (QProgressBar *bar, bars) {
bar->setValue(0); }}void frmMapDownload::receiveDataFromJs(const QString &type, const QVariant &data)
{
if (data.isNull()) {
return;
}
//qDebug() << "frmMapDownload" << type << data;
QString result = data.toString(a);if (type == "zoom") {
float zoom = result.toFloat(a); QString strZoom = QString::number(zoom, 'f'.3);
ui->txtZoom->setText(strZoom);
} else if (type == "bounds") {
QStringList list = result.split(",");
if (list.count() = =7) {
QString lat, lng, point;
lng = WebHelper::getLngLat1(list.at(0));
lat = WebHelper::getLngLat1(list.at(1));
point = QString("% 1 and % 2").arg(lng).arg(lat);
ui->txtPointLeftBottom->setText(point);
lng = WebHelper::getLngLat1(list.at(2));
lat = WebHelper::getLngLat1(list.at(3));
point = QString("% 1 and % 2").arg(lng).arg(lat);
ui->txtPointRightTop->setText(point);
lng = WebHelper::getLngLat1(list.at(4));
lat = WebHelper::getLngLat1(list.at(5));
point = QString("% 1 and % 2").arg(lng).arg(lat);
ui->txtPointCenter->setText(point);
float zoom = list.at(6).toFloat(a); QString strZoom = QString::number(zoom, 'f'.3);
ui->txtZoom->setText(strZoom);
// Automatically count tiles
this->getCount(a);// The scroll bar is rolled to the bottom, usually requires a large download level
ui->tableWidget->scrollToBottom();
}
} else if (type == "point") {
QString point = WebHelper::getLngLat2(result);
ui->txtPointCenter->setText(point); }}Copy the code