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 );
69 std::unique_ptr<QGeoPositionInfoSource>
source( simulatedSource( longitude, latitude, radius ) );
71 replacePositionSource( source.release() );
74 void QgsQuickPositionKit::updateScreenPosition()
80 if ( screenPosition != mScreenPosition )
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();
117 mSource.reset( source );
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()
149 projectedPosition.addZValue( mPosition.
z() );
151 if ( projectedPosition != mProjectedPosition )
158 void QgsQuickPositionKit::onPositionUpdated(
const QGeoPositionInfo &info )
161 if ( hasPosition != mHasPosition )
169 info.coordinate().longitude(),
170 info.coordinate().latitude(),
171 info.coordinate().altitude() );
173 if ( position != mPosition )
180 if ( info.hasAttribute( QGeoPositionInfo::HorizontalAccuracy ) )
181 accuracy = info.attribute( QGeoPositionInfo::HorizontalAccuracy );
192 if ( info.hasAttribute( QGeoPositionInfo::Direction ) )
193 direction = info.attribute( QGeoPositionInfo::Direction );
203 onMapSettingsUpdated();
206 void QgsQuickPositionKit::onMapSettingsUpdated()
208 updateProjectedPosition();
210 updateScreenAccuracy();
211 updateScreenPosition();
216 if ( simulatePositionLongLatRad.size() > 2 )
218 double longitude = simulatePositionLongLatRad[0];
219 double latitude = simulatePositionLongLatRad[1];
220 double radius = simulatePositionLongLatRad[2];
221 QgsDebugMsg( QStringLiteral(
"Use simulated position around longlat: %1, %2, %3" ).arg( longitude ).arg( latitude ).arg( radius ) );
226 QgsDebugMsg( QStringLiteral(
"Unable to set simulated position due to the input errors." ) );
231 double QgsQuickPositionKit::calculateScreenAccuracy()
247 void QgsQuickPositionKit::onUpdateTimeout()
251 mHasPosition =
false;
258 return mScreenPosition;
263 return mScreenAccuracy;
268 return mSimulatePositionLongLatRad;
284 return mProjectedPosition;
319 if ( mMapSettings == mapSettings )
324 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 accuracy() const
GPS horizontal accuracy in accuracyUnits, -1 if not available.
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)
QPointF screenPosition() const
GPS position in device coords (pixels).
void setSimulatePositionLongLatRad(const QVector< double > &simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
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.
Q_INVOKABLE QPointF coordinateToScreen(const QgsPoint &point) const
Convert a map coordinate to screen pixel coordinates.
void mapUnitsPerPixelChanged()
Returns the distance in geographical coordinates that equals to one pixel in the map.
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.
Q_INVOKABLE QgsCoordinateReferenceSystem positionCRS() const
Coordinate reference system of position - WGS84 (constant)
QGeoPositionInfoSource * source() const
Returns pointer to the internal QGeoPositionInfoSource object used to receive GPS location...
Q_INVOKABLE void useSimulatedLocation(double longitude, double latitude, double radius)
Use simulated GPS source.
void screenPositionChanged()
GPS position in device coords (pixels).
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).
QgsPoint projectedPosition() const
GPS position in map coords.
QVector< double > simulatePositionLongLatRad() const
Uses of GPS and simulated position and sets its parameters.
bool isSimulated() const
GPS position and accuracy is simulated (not real from GPS sensor).
void destinationCrsChanged()
CRS of destination coordinate reference system.
Point geometry type, with support for z-dimension and m-values.
bool hasPosition() const
GPS position in WGS84 coords.
DistanceUnit
Units of distance.
QgsCoordinateReferenceSystem destinationCrs
CRS of destination coordinate reference system.
double accuracyChanged() const
GPS horizontal accuracy in accuracyUnits, -1 if not available.
void sourceChanged()
Emitted when the internal source of GPS location data has been replaced.
double directionChanged() const
GPS direction, bearing in degrees clockwise from north to direction of travel.
void outputSizeChanged()
The size of the resulting map image.
QgsUnitTypes::DistanceUnit accuracyUnits() const
GPS horizontal accuracy units - meters (constant)
This class represents a coordinate reference system (CRS).
void simulatePositionLongLatRadChanged(QVector< double > simulatePositionLongLatRad)
Uses of GPS and simulated position and sets its parameters.
QgsPoint position() const
GPS position in WGS84 coords.
double direction() const
GPS direction, bearing in degrees clockwise from north to direction of travel.
void mapSettingsChanged()
Associated map settings.
Q_INVOKABLE QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void hasPositionChanged()
hasPosition changed
double screenAccuracy() const
Screen horizontal accuracy, 2 if not available or resolution is too small.
QgsQuickMapSettings * mapSettings() const
Associated map settings.
double screenAccuracyChanged() const
Screen horizontal accuracy, 2 if not available or resolution is too small.