32 &QgsQuickPositionKit::onSimulatePositionLongLatRadChanged );
37 QGeoPositionInfoSource *QgsQuickPositionKit::gpsSource()
41 std::unique_ptr<QGeoPositionInfoSource>
source( QGeoPositionInfoSource::createDefaultSource(
nullptr ) );
42 if ( ( !
source ) || (
source->error() != QGeoPositionInfoSource::NoError ) )
45 .arg( tr(
"Unable to create default GPS Position Source" ) )
46 .arg( QString::number( (
long )
source->error() ) )
47 , QStringLiteral(
"QgsQuick" )
57 QGeoPositionInfoSource *QgsQuickPositionKit::simulatedSource(
double longitude,
double latitude,
double radius )
59 return new QgsQuickSimulatedPositionSource(
this, longitude, latitude, radius );
69 std::unique_ptr<QGeoPositionInfoSource>
source( simulatedSource( longitude, latitude, radius ) );
71 replacePositionSource(
source.release() );
74 void QgsQuickPositionKit::updateScreenPosition()
87 void QgsQuickPositionKit::updateScreenAccuracy()
102 QGeoPositionInfoSource *
source = gpsSource();
103 mIsSimulated =
false;
104 replacePositionSource(
source );
107 void QgsQuickPositionKit::replacePositionSource( QGeoPositionInfoSource *source )
109 if ( mSource.get() ==
source )
114 mSource->disconnect();
122 connect( mSource.get(), &QGeoPositionInfoSource::positionUpdated,
this, &QgsQuickPositionKit::onPositionUpdated );
123 connect( mSource.get(), &QGeoPositionInfoSource::updateTimeout,
this, &QgsQuickPositionKit::onUpdateTimeout );
125 mSource->startUpdates();
127 QgsDebugMsg( QStringLiteral(
"Position source changed: %1" ).arg( mSource->sourceName() ) );
136 void QgsQuickPositionKit::updateProjectedPosition()
159 void QgsQuickPositionKit::onPositionUpdated(
const QGeoPositionInfo &info )
170 info.coordinate().longitude(),
171 info.coordinate().latitude(),
172 info.coordinate().altitude() );
181 if ( info.hasAttribute( QGeoPositionInfo::HorizontalAccuracy ) )
182 accuracy = info.attribute( QGeoPositionInfo::HorizontalAccuracy );
193 if ( info.hasAttribute( QGeoPositionInfo::Direction ) )
194 direction = info.attribute( QGeoPositionInfo::Direction );
204 onMapSettingsUpdated();
207 void QgsQuickPositionKit::onMapSettingsUpdated()
209 updateProjectedPosition();
211 updateScreenAccuracy();
212 updateScreenPosition();
215 void QgsQuickPositionKit::onSimulatePositionLongLatRadChanged( QVector<double> simulatePositionLongLatRad )
222 QgsDebugMsg( QStringLiteral(
"Use simulated position around longlat: %1, %2, %3" ).arg( longitude ).arg( latitude ).arg( radius ) );
225 else if ( mIsSimulated )
227 QgsDebugMsg( QStringLiteral(
"Switching from simulated to GPS location" ) );
232 double QgsQuickPositionKit::calculateScreenAccuracy()
248 void QgsQuickPositionKit::onUpdateTimeout()
252 mHasPosition =
false;
259 return mScreenPosition;
264 return mScreenAccuracy;
269 return mSimulatePositionLongLatRad;
285 return mProjectedPosition;
325 mMapSettings->disconnect();
This class represents a coordinate reference system (CRS).
static Q_INVOKABLE QgsCoordinateReferenceSystem fromEpsgId(long epsg)
Creates a CRS from a given EPSG ID.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
void extentChanged()
Geographical coordinates of the rectangle that should be rendered.
void outputSizeChanged()
The size of the resulting map image.
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void outputDpiChanged()
Output DPI used for conversion between real world units (e.g.
void destinationCrsChanged()
CRS of destination coordinate reference system.
void visibleExtentChanged()
Returns the actual extent derived from requested extent that takes takes output image size into accou...
void mapUnitsPerPixelChanged()
Returns the distance in geographical coordinates that equals to one pixel in the map.
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
Q_INVOKABLE QPointF coordinateToScreen(const QgsPoint &point) const
Convert a map coordinate to screen pixel coordinates.
QgsPoint projectedPosition
GPS position in map coords.
bool isSimulated
GPS position and accuracy is simulated (not real from GPS sensor).
double directionChanged() const
GPS direction, bearing in degrees clockwise from north to direction of travel.
void positionChanged()
GPS position in WGS84 coords.
QGeoPositionInfoSource * source
Internal source of GPS location data.
void simulatePositionLongLatRadChanged(QVector< double > simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
double screenAccuracyChanged() const
Screen horizontal accuracy, 2 if not available or resolution is too small.
Q_INVOKABLE void useGpsLocation()
Use real GPS source (not simulated)
Q_INVOKABLE void useSimulatedLocation(double longitude, double latitude, double radius)
Use simulated GPS source.
void hasPositionChanged()
hasPosition changed
void mapSettingsChanged()
Associated map settings.
bool hasPosition
GPS position is available (position property is a valid number).
double screenAccuracy
Screen horizontal accuracy, 2 if not available or resolution is too small.
double accuracyChanged() const
GPS horizontal accuracy in accuracyUnits, -1 if not available.
QgsQuickPositionKit(QObject *parent=nullptr)
Creates new position kit.
Q_INVOKABLE QgsCoordinateReferenceSystem positionCRS() const
Coordinate reference system of position - WGS84 (constant)
QPointF screenPosition
GPS position in device coords (pixels).
void sourceChanged()
Emitted when the internal source of GPS location data has been replaced.
void setSimulatePositionLongLatRad(const QVector< double > &simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
void setMapSettings(QgsQuickMapSettings *mapSettings)
Associated map settings.
double direction
GPS direction, bearing in degrees clockwise from north to direction of travel.
void projectedPositionChanged()
GPS position in map coords.
QgsQuickMapSettings * mapSettings
Associated map settings.
QVector< double > simulatePositionLongLatRad
Uses of GPS and simulated position and sets its parameters.
QgsPoint position
GPS position in WGS84 coords.
void screenPositionChanged()
GPS position in device coords (pixels).
double accuracy
GPS horizontal accuracy in accuracyUnits, -1 if not available.
QgsUnitTypes::DistanceUnit accuracyUnits() const
GPS horizontal accuracy units - meters (constant)
static Q_INVOKABLE double screenUnitsToMeters(QgsQuickMapSettings *mapSettings, int baseLengthPixels)
Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the curr...
static Q_INVOKABLE QgsPointXY transformPoint(const QgsCoordinateReferenceSystem &srcCrs, const QgsCoordinateReferenceSystem &destCrs, const QgsCoordinateTransformContext &context, const QgsPointXY &srcPoint)
Transforms point between different crs from QML.
DistanceUnit
Units of distance.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)