I want to display a huge number of points on a map with Qt/QML. These points are detailled in a .txt file.
I'm looking for the process to use but, unfortunately, I only find a query method via a plugin to display places from a server (osm, google...). I can't use it, these points being very specific.
What is the best way to achieve this task ?
Also, is it necessary to use "plugin itemsoverlay" in addition to the "osm plugin" to show these points on a specific layer ?
Thanks for help.
Ok, back to fight with code now.
Here is the main .cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QObject>
#include <QGeoCoordinate>
#include <QDebug>
class NavaidsPoint: public QObject
{
Q_OBJECT
Q_PROPERTY(QGeoCoordinate position READ position WRITE setPosition NOTIFY positionChanged)
public:
NavaidsPoint(QString code, double latitude, double longitude, QString country = "")
{
m_code = code;
m_latitude = latitude;
m_longitude = longitude;
m_country = country;
m_position.setLatitude(latitude);
m_position.setLongitude(longitude);
}
void setPosition(const QGeoCoordinate &c) { //Affectation des nouvelles coordonnées de position
if (m_position == c)
return;
m_position = c;
emit positionChanged(); //Emission du signal de changement de position
}
QGeoCoordinate position() const
{
return m_position; //Lecture des coordonnées de position
}
Q_INVOKABLE QString oaciCode() const {
return m_code;
}
Q_INVOKABLE QString countryCode() const {
return m_country;
}
signals:
void positionChanged();
private:
QGeoCoordinate m_position;
double m_latitude;
double m_longitude;
double m_altitude;
QString m_code;
QString m_country;
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
NavaidsPoint oslo("Oslo", 59.9154, 10.7425, "NG");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("oslo", &oslo);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
#include "main.moc"
And the main.qml
import QtQuick 2.6
import QtQuick.Window 2.2
import QtPositioning 5.5
import QtLocation 5.6
Window {
width: 700
height: 500
visible: true
title: qsTr("Test implantation coordonnées")
property variant topLeftEurope: QtPositioning.coordinate(60.5, 0.0)
property variant bottomRightEurope: QtPositioning.coordinate(51.0, 14.0)
property variant viewOfEurope:
QtPositioning.rectangle(topLeftEurope, bottomRightEurope)
Map {
id: mapOfEurope
anchors.centerIn: parent;
anchors.fill: parent
plugin: Plugin {
name: "osm"
}
MapCircle {
center: oslo.position
radius: 5000.0
color: 'green'
border.width: 3
MouseArea {
anchors.fill: parent
onDoubleClicked: {
console.log("Doubleclick on " + oslo.oaciCode())
}
onClicked: {
console.log("Point : " + oslo.oaciCode() + " " + oslo.position + " " + oslo.countryCode())
}
}
}
visibleRegion: viewOfEurope
}
}
everything works fine with this unique point Oslo. Now I need to place thousands of points. This structure cannot work like that, because I need to implement one NavaidsPoint for each of them and setContextProperty for each of them again. Likewise, in the main.QML the circle is tied with the object :
center : oslo.position
and in addition, I nead the oaciCode and the countryCode. So this part of the code must be generic, not specific to a single object.
So, what could be the best way to solve this problem ?
I hope to be in the SO scope with these precisions.
Thanks again for help.