32 &QgsQuickPositionKit::onSimulatePositionLongLatRadChanged );
37 QGeoPositionInfoSource *QgsQuickPositionKit::gpsSource()
41 std::unique_ptr<QGeoPositionInfoSource> source( QGeoPositionInfoSource::createDefaultSource(
nullptr ) );
42 if ( source->error() != QGeoPositionInfoSource::NoError )
45 .arg( tr(
"Unable to create default GPS Position Source" ) )
46 .arg( QString::number( (
long )source->error() ) )
47 , QStringLiteral(
"QgsQuick" )
53 return source.release();
57 QGeoPositionInfoSource *QgsQuickPositionKit::simulatedSource(
double longitude,
double latitude,
double radius )
59 return new QgsQuickSimulatedPositionSource(
this, longitude, latitude, radius );
64 std::unique_ptr<QGeoPositionInfoSource> source( simulatedSource( longitude, latitude, radius ) );
66 replacePositionSource( source.release() );
69 void QgsQuickPositionKit::updateScreenPosition()
75 if ( screenPosition != mScreenPosition )
82 void QgsQuickPositionKit::updateScreenAccuracy()
97 QGeoPositionInfoSource *source = gpsSource();
99 replacePositionSource( source );
102 void QgsQuickPositionKit::replacePositionSource( QGeoPositionInfoSource *source )
104 if ( mSource.get() == source )
109 mSource->disconnect();
112 mSource.reset( source );
116 connect( mSource.get(), &QGeoPositionInfoSource::positionUpdated,
this, &QgsQuickPositionKit::onPositionUpdated );
117 connect( mSource.get(), &QGeoPositionInfoSource::updateTimeout,
this, &QgsQuickPositionKit::onUpdateTimeout );
119 mSource->startUpdates();
121 QgsDebugMsg( QStringLiteral(
"Position source changed: %1" ).arg( mSource->sourceName() ) );
130 void QgsQuickPositionKit::updateProjectedPosition()
143 projectedPosition.addZValue( mPosition.
z() );
145 if ( projectedPosition != mProjectedPosition )
152 void QgsQuickPositionKit::onPositionUpdated(
const QGeoPositionInfo &info )
155 if ( hasPosition != mHasPosition )
163 info.coordinate().longitude(),
164 info.coordinate().latitude(),
165 info.coordinate().altitude() );
167 if ( position != mPosition )
174 if ( info.hasAttribute( QGeoPositionInfo::HorizontalAccuracy ) )
175 accuracy = info.attribute( QGeoPositionInfo::HorizontalAccuracy );
186 if ( info.hasAttribute( QGeoPositionInfo::Direction ) )
187 direction = info.attribute( QGeoPositionInfo::Direction );
197 onMapSettingsUpdated();
200 void QgsQuickPositionKit::onMapSettingsUpdated()
202 updateProjectedPosition();
204 updateScreenAccuracy();
205 updateScreenPosition();
210 if ( simulatePositionLongLatRad.size() > 2 )
212 double longitude = simulatePositionLongLatRad[0];
213 double latitude = simulatePositionLongLatRad[1];
214 double radius = simulatePositionLongLatRad[2];
215 QgsDebugMsg( QStringLiteral(
"Use simulated position around longlat: %1, %2, %3" ).arg( longitude ).arg( latitude ).arg( radius ) );
220 QgsDebugMsg( QStringLiteral(
"Unable to set simulated position due to the input errors." ) );
225 double QgsQuickPositionKit::calculateScreenAccuracy()
241 void QgsQuickPositionKit::onUpdateTimeout()
245 mHasPosition =
false;
252 return mScreenPosition;
257 return mScreenAccuracy;
262 return mSimulatePositionLongLatRad;
278 return mProjectedPosition;
313 if ( mMapSettings == mapSettings )
318 mMapSettings->disconnect();
void visibleExtentChanged()
Returns the actual extent derived from requested extent that takes takes output image size into accou...
void positionChanged()
GPS position in WGS84 coords.
void setMapSettings(QgsQuickMapSettings *mapSettings)
Associated map settings.
double screenAccuracyChanged() const
Screen horizontal accuracy, 2 if not available or resolution is too small.
QgsQuickPositionKit(QObject *parent=nullptr)
Creates new position kit.
Q_INVOKABLE void useGpsLocation()
Use real GPS source (not simulated)
void extentChanged()
Geographical coordinates of the rectangle that should be rendered.
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double direction() const
GPS direction, bearing in degrees clockwise from north to direction of travel.
void setSimulatePositionLongLatRad(const QVector< double > &simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
static Q_INVOKABLE double screenUnitsToMeters(QgsQuickMapSettings *mapSettings, int baseLengthPixels)
Calculates the distance in meter representing baseLengthPixels pixels on the screen based on the curr...
void projectedPositionChanged()
GPS position in map coords.
void outputDpiChanged()
Output DPI used for conversion between real world units (e.g.
void mapUnitsPerPixelChanged()
Returns the distance in geographical coordinates that equals to one pixel in the map.
QgsQuickMapSettings * mapSettings() const
Associated map settings.
static Q_INVOKABLE QgsPointXY transformPoint(const QgsCoordinateReferenceSystem &srcCrs, const QgsCoordinateReferenceSystem &destCrs, const QgsCoordinateTransformContext &context, const QgsPointXY &srcPoint)
Transforms point between different crs from QML.
static Q_INVOKABLE QgsCoordinateReferenceSystem fromEpsgId(long epsg)
Creates a CRS from a given EPSG ID.
double accuracy() const
GPS horizontal accuracy in accuracyUnits, -1 if not available.
bool hasPosition() const
GPS position in WGS84 coords.
QgsUnitTypes::DistanceUnit accuracyUnits() const
GPS horizontal accuracy units - meters (constant)
Q_INVOKABLE void useSimulatedLocation(double longitude, double latitude, double radius)
Use simulated GPS source.
void screenPositionChanged()
GPS position in device coords (pixels).
QgsPoint position() const
GPS position in WGS84 coords.
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).
void destinationCrsChanged()
CRS of destination coordinate reference system.
Point geometry type, with support for z-dimension and m-values.
double directionChanged() const
GPS direction, bearing in degrees clockwise from north to direction of travel.
DistanceUnit
Units of distance.
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
QgsPoint projectedPosition() const
GPS position in map coords.
void outputSizeChanged()
The size of the resulting map image.
bool isSimulated() const
GPS position and accuracy is simulated (not real from GPS sensor).
This class represents a coordinate reference system (CRS).
Q_INVOKABLE QPointF coordinateToScreen(const QgsPoint &point) const
Convert a map coordinate to screen pixel coordinates.
void simulatePositionLongLatRadChanged(QVector< double > simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
void mapSettingsChanged()
Associated map settings.
Q_INVOKABLE QgsCoordinateReferenceSystem positionCRS() const
Coordinate reference system of position - WGS84 (constant)
double screenAccuracy() const
Screen horizontal accuracy, 2 if not available or resolution is too small.
QVector< double > simulatePositionLongLatRad() const
Uses of GPS and simulated position and sets its parameters.
double accuracyChanged() const
GPS horizontal accuracy in accuracyUnits, -1 if not available.
void hasPositionChanged()
hasPosition changed
QPointF screenPosition() const
GPS position in device coords (pixels).