AmonRaNet / QGeoView

QGeoView is a Qt / C ++ widget for visualizing geographic data.
GNU Lesser General Public License v3.0
155 stars 60 forks source link

How to draw a curve line, the red dot moving on the red curve #27

Closed wangdemon closed 2 years ago

wangdemon commented 2 years ago

As shown in the figure below 微信截图_20220329153611

embeddedmz commented 2 years ago

There's some web sites that can help you to draw stuff on a map and get the list of the geo coords related to what you have drawn (GeoJSON, CSV). I forgot ! You can use QGIS to display a map and add points or draw stuff on it, there's a lot of tutorials on the web. Be ware that QGIS can be finicky to use and that the tutorials are out-dated. If you work on a GIS project, QGIS can be very useful.

Once you have a list of points, you will just have to load them (CSV/GeoJSON), iterate over them and change the position of the red dot redraw the map, make a pause etc... (don't make a blocking code, use QTimer or QEventLoop).

By the way, in the past, I have already worked on a code that generates N points for a path that have less than N points (e.g. a path defined using 30 points but we want to have the same path but with 1000 points. It uses scalar products and wasn't easy to code), so if someone needs it, I will make a demo and share it in this branch where I have already shared some interesting demos : https://github.com/embeddedmz/QGeoView/tree/draft (there's a GeoJSON reader under demo/samples/polyline.cpp, it is not complete but it will work for simple files) I have used it back then to color a path with data (color map).

AmonRaNet commented 2 years ago
  1. Draw curve. For this you can create your custom Polyline. To make your curve smooth you can consider this article: https://www.toptal.com/c-plus-plus/rounded-corners-bezier-curves-qpainter . I would also recommend to check example from @embeddedmz
  2. Draw circle. You can use existing example in demo. Also you will need to add method or property to control position of circle (will be needed for animation control): https://github.com/AmonRaNet/QGeoView/blob/master/demo/samples/ellipse.cpp
  3. Moving circle along curve. With QPainterPath you can get list of points along curve.
  4. Animation: here is several solutions, probably easiest is based on QAnimation. You can simple iterate over values from 0.0 to 1.0, where value is percentage from start to end along the line.

Most closest to your case: https://github.com/AmonRaNet/QGeoView/blob/master/demo/samples/utilities.cpp https://github.com/AmonRaNet/QGeoView/blob/master/demo/samples/waveanimation.cpp

It is not one-to-one to your case, but very close to it. It is demo with animated "QQeoView" text on map.

wangdemon commented 2 years ago

Thank you very much