Technology Sharing

Qt/C programming map application/offline map download/path planning/track playback/massive points/coordinate conversion

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1. Introduction

This map component has been written for many years. The initial design was relatively rough. It was originally just to meet the needs of the project and did not consider too much scalability. For example, it was originally written in the code according to Baidu Maps. After a lot of practical applications in the field in recent years, and a large number of improvement suggestions put forward by users, the idea of ​​completely rewriting the corresponding map-related codes gradually emerged, such as the design of base classes and subclasses, and the interaction of various functional interfaces through js functions, rather than a bunch of code written on the web page.

The previous map examples were written rather roughly. I wrote whatever I thought of, and the functions were piled up seriously. I kept adding more and more functions, which made it more and more bloated. The function demonstrations on the interface were also not intuitive. So this time I took some time to refactor them all, including all the examples. For the excessive number of example demonstrations, I set up a separate directory to store the codes of each small example, and split them up, making it very convenient to learn the functions of the group. Before, a bunch of example codes were piled up in a class, and it took time to find them. What programmers hate most is a lot of code in a code file, so if you can split them into groups, do so.

2. Features

  1. Supports multiple map kernels, and Baidu Maps is used by default.
  2. It supports both online map and offline map modes. Offline maps are convenient for use in scenarios where there is no Internet connection.
  3. Supports the activation of various map controls, such as map navigation, map type, thumbnail, scale, panoramic navigation, real-time traffic conditions, drawing tools, result panel, etc.
  4. Supports dynamic enabling and disabling of various map functions, such as map dragging, keyboard operation, scroll wheel zooming, double-click zooming, and map distance measurement.
  5. It provides numerous js function interfaces for interaction with extremely rich parameters, covering all conceivable application scenarios.
  6. Unified signal slot mechanism, the results in the map are sent out as a unified signal, and after receiving, they are distinguished according to type.
  7. Supports map interaction, such as obtaining the longitude and latitude of the corresponding location by pressing the mouse. Clicking a marked point pops up the information of the corresponding point.
  8. Supports adding annotations, deleting annotations, moving annotations, and clearing annotations.
  9. Annotation points can specify icon images, set rotation angles, and have rich text prompts.
  10. The annotation point event supports single-click signal notification and pop-up box display of information.
  11. Provides interfaces for converting addresses to coordinates and converting coordinates to addresses.
  12. Supports various graphics drawing, including line graphs, polygons, rectangles, circles, arcs, etc.
  13. You can display a floating drawing toolbar to draw lines, mark points, rectangles, circles, etc. directly on the map.
  14. It supports various area searches, such as rectangular areas and circular areas, and can display search results on the map according to keyword matching.
  15. You can dynamically add offline administrative district boundary point data. You can search for administrative divisions and obtain boundary point data for that area. Data can be saved to a file for offline use.
  16. Supports point aggregation function, merging multiple small annotation points into one large annotation point to prevent dense points from causing unfriendly interaction.
  17. A large number of points can be added, and each point can be clicked to obtain the corresponding coordinates and information.
  18. All coverage information, such as annotation points, rectangles, polygons, line graphs, etc., can be actively obtained.
  19. It supports route planning, including bus routes, driving routes, walking routes, and cycling routes. Different queries support different strategies, including the minimum time, minimum transfers, and no elevated routes.
  20. The path planning results are displayed on the map, and the path point coordinates can also be obtained. This data can be saved to a file and sent to a robot or drone for navigation and trajectory movement.
  21. You can set different map views such as street map, satellite map, and hybrid map.
  22. Different styles can be set, such as midnight blue, grass green and other styles.
  23. It provides an offline map download module, you can choose different map kernels such as Baidu Maps or Google Maps, different map types such as downloading street maps or satellite maps, different map levels, and multi-threaded high-speed download.
  24. The table row displays the corresponding tile download progress in real time, including download timeout and number of retries. A signal notification is sent when each tile is downloaded, and the parameters include download time.
  25. Provides a provincial and municipal outline map download module to automatically download outline maps of various regions and save them to script files or text files.
  26. It supports manual adjustment of the contour boundaries of different areas, and after adjustment, the adjusted boundary point set can be actively obtained.
  27. Provides dynamic point examples, manually select points on the map and add annotations, with custom information such as speed and time.
  28. Provides a large number of point examples, batch adding of annotation points, point aggregation, and large number of points. It is used to test the maximum point performance supported in the environment.
  29. Supports GPS coordinate conversion, and provides both online and offline modes. Generally, the device receives standard GPS coordinates, which need to be converted into Baidu coordinates on Baidu Maps.
  30. Provides a dynamic track example. After selecting the starting point and the end point on the map, the route is queried, the path track points are obtained, and the timer simulates the track movement. Data can be filtered to filter too many path points to the set number of points.
  31. Provides track playback examples, playback according to the specified track point list, and can also import track point data for playback. It also supports playback of tracks in street maps, satellite maps, and mixed maps.
  32. Provides examples of provincial and municipal regional maps, using echart components, and supports flashing point maps, migration maps, regional maps, world maps, dashboards, etc. You can set various colors such as title, prompt information, background color, text color, line color, and regional color.
  33. Examples of provincial and municipal regional maps, with built-in world maps, national maps, provincial maps, and regional maps, which can be accurate to the county level, and all maps can be used offline. You can set the name, value, and longitude and latitude of the city.
  34. Built-in universal browser component, supports webkit/webengine/miniblink and other kernels. Provides web control examples to demonstrate opening web pages and local web files.
  35. Supports any Qt version, any system, and any compiler.

3. Code Usage

  1. Copy the two component directories of core_map (map component) and core_webview (browser component) to your project directory, and fill in the import code in pro to add it to your project. $PWD/…/ indicates the parent directory.
include ($$PWD/../core_map/core_map.pri)
include ($$PWD/../core_webview/core_webview.pri)
  1. To enable the map kernel in pro, for example, the Baidu map kernel requires adding a line of definition DEFINES = baidux in the pro file.
  2. Import header files.
#include "webview.h"
#include "mapbase.h"
  1. Create a new form and put a layout on it. It is recommended to use gridlayout, which can hold multiple browser controls.
  2. Instantiate the browser class and the map class.
//实例化浏览器控件
WebView *webView = new WebView(this);
//加入到布局
webView-