Qt prepare 25 offline map of security video monitoring system

Keywords: github Linux IE Qt

I. Preface

The function of offline map has only been completed recently. Many people have asked if there is any function of offline map for a long time ago. They have also roughly learned how to make offline map before. In fact, the core is not the code, but how to get free offline map files. Most of the offline map downloaders are charged online, and it seems that they are not cheap. After finding many, they finally find out A simple and available one can be downloaded in a designated city. Most of the offline maps are Baidu or Goude. In fact, if you are proficient in using online maps, those methods are completely the same. In theory, the api interface made by the manufacturer will also be unified. The only difference is that the js file introduced is different, and the use method and processing flow are completely different In the same way, I spent some time reorganizing and encapsulating a Baidu map class, and supported both online map and offline map modes.

Map function features:

  1. Both online map and offline map are supported.
  2. It also supports webkit kernel, webengine kernel and IE kernel.
  3. It supports setting multiple annotation points, including name, address, longitude and latitude.
  4. You can set whether the map can be clicked, dragged, and zoomed by the mouse wheel.
  5. You can set the protocol version, secret key, theme style, center coordinate, center city, geocoding location, etc.
  6. The zoom scale and level of the map can be set, and the thumbnail, scale bar, traffic information and other controls can be visible.
  7. Support map interaction, such as mouse click to obtain the latitude and longitude of the corresponding position.
  8. It supports query of routes, and can set start position, end position, route mode, route mode, route scheme (minimum time, minimum transfer, minimum walking, no subway, minimum distance, avoiding high-speed).
  9. It can display point, line and surface tools, and can directly draw lines, points, rectangles, circles, etc. on the map.
  10. Administrative divisions can be set up, a certain city area drawing layer can be specified, and online map can automatically output boundary points of administrative divisions to js file for offline map.
  11. Multiple coverings can be added. Support points, polylines, polygons, rectangles, circles, arcs, etc.
  12. Function interface is friendly and unified, easy to use, just one class.
  13. Support any Qt version, any system, any compiler.

Open source address of video control: https://gitee.com/feiyangqingyun/QWidgetDemo https://github.com/feiyangqingyun/QWidgetDemo File name: Video widget

Experience address: https://gitee.com/feiyangqingyun/QWidgetExe https://github.com/feiyangqingyun/QWidgetExe File name: Bin video system.zip

2, Functional features

  1. Support 16 screen switching, full screen switching, etc., including 1 + 4 + 6 + 8 + 9 + 13 + 16 screen switching.
  2. Support alt+enter full screen, esc exit full screen.
  3. Custom message box + error box + inquiry box + prompt box at the bottom right corner.
  4. 17 sets of skin styles are changed at will, all styles are unified, including menu, etc.
  5. Move the mouse on the dashboard of the platform to highlight and identify eight directions accurately.
  6. The bottom screen toolbar (screen segmentation switch + screenshot sound and other settings) is moved up to highlight.
  7. You can change the logo + Chinese software name + English software name in the upper left corner of the configuration file.
  8. Package Baidu map, three-dimensional switching, equipment point, mouse click to get latitude and longitude.
  9. Stack form, each form is a separate qwidget, convenient to write their own code.
  10. The top right mouse button menu can dynamically control the display and hide of time CPU + upper left corner panel + lower left corner panel + upper right corner panel + lower right corner panel, and support to restore the default layout.
  11. The toolbar can place multiple small icons and close icons.
  12. The left and right sides can be dragged and stretched, and the width and height positions can be memorized automatically, which can be recovered after restart.
  13. Double click the camera node to automatically play the video, double-click the node to automatically add the video in turn, and it will automatically jump to the next one, double-click the parent node to automatically add all the videos under the node.
  14. The camera node can be dragged to the corresponding form to play the video, and the local file can be dragged to play directly.
  15. The video window supports drag switching and instant response.
  16. Double click the node + drag the node + drag the form exchange location, and the url.txt will be updated automatically.
  17. It supports loading 16 channels of video from url.txt to play, automatically remembering the corresponding video of the last channel, and automatically opening and playing after the software is started.
  18. The volume bar control in the lower right corner automatically hides when the focus is lost, and the volume bar mute icon.
  19. Integrated with Baidu map, you can add the corresponding location of the device, automatically generate the map, support zoom and 3D map, and provide the choice of map style, a total of 12 styles.
  20. Drag the video outside the channel form to automatically delete the video.
  21. Right click to delete current + all videos, screenshot current + all videos.
  22. VCR management, camera management, can add, delete, modify, import, export and print information, apply new device information to generate tree list immediately, without restart.
  23. Whether to load the map can be opened freely in pro file.
  24. Four kinds of cores can be selected for video playback, vlc+ffmpeg+easyplayer + Haikang sdk, which can be set in pro.
  25. 1 + 4 + 9 + 16 screen polling can be set, polling interval and polling code stream type can be set. Click the start polling button directly on the right side of the toolbar at the bottom of the main interface, and then click stop polling again.
  26. The mouse pointer is not automatically hidden by default for more than 10 seconds.
  27. Support the onvif search equipment, support any onvif camera, including but not limited to the Huawei of Haikang Dahua Yushi Tiandi Weiye, etc., and support the onvif PTZ control.
  28. Highly customizable, users can easily derive their own functions on this basis, supporting linux system.

3, Renderings

4, Core code

#include "frmmaplocal.h"
#include "frmmapweb.h"
#include "ui_frmmaplocal.h"
#include "quiwidget.h"
#include "iconfont.h"
#include "mapbaidu.h"

frmMapLocal::frmMapLocal(QWidget *parent) : QWidget(parent), ui(new Ui::frmMapLocal)

    delete ui;

void frmMapLocal::showEvent(QShowEvent *)
    static bool isShow = false;
    if (!isShow) {
        isShow = true;
        QTimer::singleShot(100, this, SLOT(loadMap()));

void frmMapLocal::initForm()
    connect(AppEvent::Instance(), SIGNAL(saveIpcInfo()), this, SLOT(loadMap()));

    ui->navTitle1->setText("Information setup");
    ui->navTitle2->setText("Layer management");

void frmMapLocal::initTree()

    QStringList texts;
    texts << "A" << "B" << "C" << "D";

    for (int i = 0; i < texts.count(); i++) {
        //Add parent node
        QTreeWidgetItem *itemParent = new QTreeWidgetItem(ui->treeWidget);
        itemParent->setText(0, QString("layer%1").arg(texts.at(i)));

        //Loop add child
        for (int j = 0; j < 5; j++) {
            QTreeWidgetItem *itemChild = new QTreeWidgetItem(itemParent);
            itemChild->setText(0, QString("%1%2").arg((j % 2 == 0) ? "terrain" : "Mountain range").arg(j + 1));
            QPixmap iconNormal = IconFont::Instance()->getPixmap(QUIConfig::TextColor, (j % 2 == 0) ? 0xe6f2 : 0xe6ed, 18, 20, 20);
            itemChild->setIcon(0, iconNormal);


void frmMapLocal::initMap()
#ifdef webkit
    QWebSettings *webSetting = QWebSettings::globalSettings();
    webSetting->setAttribute(QWebSettings::JavascriptEnabled, true);
    webSetting->setAttribute(QWebSettings::PluginsEnabled, true);
    webSetting->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);

    webView = new QWebView;
    connect(webView->page(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
#elif webengine
    QWebEngineSettings *webSetting = QWebEngineSettings::globalSettings();
    webSetting->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
    webSetting->setAttribute(QWebEngineSettings::PluginsEnabled, true);
    webSetting->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true);

    webView = new QWebEngineView;

    QWebChannel *channel = new QWebChannel(this);
    channel->registerObject("objName", MapData::Instance());
    connect(MapData::Instance(), SIGNAL(receiveDataFromJs(QVariant)), this, SLOT(receiveData(QVariant)));
    connect(webView->page(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
#elif webie
    webView = new QAxWidget;

void frmMapLocal::loadMap()
    QString fileName = QUIHelper::appPath() + "/config/deviceall.html";
    QString url = "file:///" + fileName;


    //Set the default center point coordinate. It is recommended to use the center point coordinate method
    //Set the default central city. Online map can be set
    //Mapbaidu:: instance() - > setmapcentercity ("Shanghai");

#ifndef webie

    QStringList deviceNames, deviceAddrs, devicePoints;
#if 0
    for (int i = 1; i <= 100; i++) {
        deviceNames << QString("Camera%1").arg(i);
        deviceAddrs << QString("Test address%1").arg(i);
        devicePoints << QString("121.%1,31.%2").arg(qrand() % 1000000).arg(qrand() % 1000000);
#elif 0
    deviceNames << "Camera 1" << "Camera 2" << "Camera 3" << "Camera 4" << "Camera 5";
    deviceAddrs << "Building 1, Lane 533, Anbo Road" << "8 Beixin Road" << "1200 Kangqiao Road, Kangqiao town(Yuqing Road)" << "JiZhai South Road, Zhuzhai Town, Minhang District" << "1080 Guanglan Road, Pudong New Area(Crape myrtle junction)";
    devicePoints << "121.534942,31.307706" << "121.572075,31.188825" << "121.57987,31.155795" << "121.292628,31.215278" << "121.626992,31.211056";
    //Load from database
    deviceNames = DBData::IpcInfo_IpcName;
    deviceAddrs = DBData::IpcInfo_IpcAddr;
    devicePoints = DBData::IpcInfo_IpcPosition;

    MapBaiDu::Instance()->setMarkerInfo(deviceNames, deviceAddrs, devicePoints);
    QString content = MapBaiDu::Instance()->newMap();

    //Here are two ways to load a web page. If the content is empty, load the web page file. Otherwise, load the content
    //Generally, it is recommended to load content for confidentiality, so that the generated web page file cannot be seen
    //Maybe webkit kernel on linux needs to be loaded by load
    if (MapBaiDu::Instance()->getSaveFile()) {
#ifdef webkit
#elif webengine
#elif webie
        webView->dynamicCall("Navigate(const QString&)", url);
    } else {
        QUrl baseUrl(QString("%1/config/").arg(QUIHelper::appPath()));
#ifdef webkit
        webView->setHtml(content, baseUrl);
#elif webengine
        webView->setHtml(content, baseUrl);

void frmMapLocal::receiveData(const QVariant &data)
    //Show me how to get the latitude and longitude from the marked points on the map
    if (!data.isNull()) {
        QStringList list = data.toString().split(",");
        double longitude = list.at(0).toDouble();
        double latitude = list.at(1).toDouble();

        //Take 6 decimal places
        QString strLongitude = QString::number(longitude, 'f', 6);
        QString strLatitude = QString::number(latitude, 'f', 6);

void frmMapLocal::loadFinished()
#ifdef webkit
    webView->page()->mainFrame()->addToJavaScriptWindowObject("objName", this);

Posted by Henaro on Tue, 07 Jan 2020 23:02:39 -0800