How to add Qt dynamically

1 Introduction

When adding device points or area shapes, it will be considered whether to directly write to the web page in a static way or to load asynchronously with dynamic js functions. This needs to be done according to the actual needs of the site. If you only need to load once, it is recommended to be static That’s it, if you need to add it dynamically during running, you can use the dynamic js function interaction method. Most of the scenes are added dynamically. After all, this is executed asynchronously, and it is more flexible. It is written into the webpage in a static way and loaded. It’s rather stupid to open, the data can be seen on the web page, there is no confidentiality at all, when doing administrative division and point aggregation in the previous two articles, both methods are supported, and the specific site is as convenient as possible.

If it is added dynamically, it is equivalent to making all the demos on the official website into the form of js function calls. The demos on the official website are mainly statically coded as demonstrations. In order to be more intuitive and easy to understand, if you are a Qt programmer Or for c++ programs, it takes a little time to learn how to encapsulate them into js function calls. After all, there is no concept of data type in js, and they are all var, which is equivalent to the QVariant type in Qt. The so-called everything is var. Arrays and array objects are directly handled with [], which is quite convenient.

2. Features

  1. It supports both online map and offline map modes.
  2. It also supports webkit kernel, webengine kernel, and IE kernel.
  3. Support setting multiple label points, the 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. Protocol version, secret key, theme style, center coordinates, center city, geocoding location, etc. can be set.
  6. You can set the zoom scale and level of the map, and the visibility of controls such as 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 route query, you can set the start location, end location, route mode, route method, route plan (least time, least transfer, least walking, no subway, shortest distance, avoid high speed).
  9. Point, line and surface tools can be displayed, and lines, points, rectangles, circles, etc. can be drawn directly on the map.
  10. You can set administrative divisions, specify a city area to draw a layer, and the online map will automatically output a collection of administrative division boundary points to a js file for use in offline maps.
  11. Multiple overlays can be added statically or dynamically. Support points, polylines, polygons, rectangles, circles, arcs, point aggregation, etc.
  12. The function interface is friendly and unified, and it is simple and convenient to use, just one class.
  13. Support js dynamic interaction to add points, delete points, clear points, reset points, no need to refresh the page.
  14. Support any Qt version, any system, any compiler.

3. Rendering

 

4. Related codes

void MapBaiDu::addPolyline(QStringList &list)
{
    //覆盖物通用属性,包括颜色线条粗细等,可以自行更改
    QString property = getOverlayProperty();

    //动态添加折线
    list << QString("  function addPolyline(points) {");
    list << QString("    var pts = getPoints(points);");
    list << QString("    var polyline = new BMap.Polyline(pts, %1);").arg(property);
    list << QString("    map.addOverlay(polyline);");
    list << QString("  }");
}

void MapBaiDu::addPolygon(QStringList &list)
{
    //覆盖物通用属性,包括颜色线条粗细等,可以自行更改
    QString property = getOverlayProperty();

    //动态添加多边形
    list << QString("  function addPolygon(points) {");
    list << QString("    var pts = getPoints(points);");
    list << QString("    var polygon = new BMap.Polygon(pts, %1);").arg(property);
    list << QString("    map.addOverlay(polygon);");
    list << QString("  }");
}

void MapBaiDu::addRectangle(QStringList &list)
{
    //覆盖物通用属性,包括颜色线条粗细等,可以自行更改
    QString property = getOverlayProperty();

    //动态添加矩形
    list << QString("  function addRectangle(points) {");
    list << QString("    var listPoint = points.split(\"|\");");
    list << QString("    if (listPoint.length != 2) {");
    list << QString("      return;");
    list << QString("    }");

    //将两个坐标拆分成四个点
    list << QString("    var list1 = listPoint[0].split(\",\");");
    list << QString("    var list2 = listPoint[1].split(\",\");");
    list << QString("    var ptStart = new BMap.Point(list1[0], list1[1]);");
    list << QString("    var ptEnd = new BMap.Point(list2[0], list2[1]);");
    list << QString("    var pt1 = new BMap.Point(ptStart.lng, ptStart.lat);");
    list << QString("    var pt2 = new BMap.Point(ptEnd.lng, ptStart.lat);");
    list << QString("    var pt3 = new BMap.Point(ptEnd.lng, ptEnd.lat);");
    list << QString("    var pt4 = new BMap.Point(ptStart.lng, ptEnd.lat);");
    list << QString("    var rectangle = new BMap.Polygon([pt1,pt2,pt3,pt4], %1);").arg(property);
    list << QString("    map.addOverlay(rectangle);");
    list << QString("  }");
}

void MapBaiDu::addCircle(QStringList &list)
{
    //覆盖物通用属性,包括颜色线条粗细等,可以自行更改
    QString property = getOverlayProperty();

    //动态添加圆形
    list << QString("  function addCircle(points, radius) {");
    list << QString("    var listPoint = points.split(\"|\");");
    list << QString("    var list = listPoint[0].split(\",\");");
    list << QString("    var ptCenter = new BMap.Point(list[0], list[1]);");
    list << QString("    var circle = new BMap.Circle(ptCenter, radius, %1);").arg(property);
    list << QString("    map.addOverlay(circle);");
    list << QString("  }");
}

The benefits of this article, free to receive Qt development learning materials package, technical video, including (C++ language foundation, C++ design pattern, introduction to Qt programming, QT signal and slot mechanism, QT interface development-image drawing, QT network, QT database programming, QT project actual combat, QSS, OpenCV, Quick module, interview questions, etc.) ↓↓↓↓↓↓See below↓↓Click on the bottom of the article to receive the fee↓↓

Guess you like

Origin blog.csdn.net/m0_60259116/article/details/130091770