Marble

ViewportParams.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
4// SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
5//
6
7#ifndef MARBLE_VIEWPORTPARAMS_H
8#define MARBLE_VIEWPORTPARAMS_H
9
10/** @file
11 * This file contains the headers for ViewportParams.
12 *
13 * @author Inge Wallin <inge@lysator.liu.se>
14 */
15
16#include <QSize>
17
18#include "GeoDataCoordinates.h"
19#include "MarbleGlobal.h"
20#include "Quaternion.h"
21#include "marble_export.h"
22
23class QPolygonF;
24class QPainterPath;
25
26namespace Marble
27{
28
29class GeoDataLatLonAltBox;
30class GeoDataLatLonBox;
31class GeoDataLineString;
32class AbstractProjection;
33class ViewportParamsPrivate;
34
35/**
36 * @short A public class that controls what is visible in the viewport of a Marble map.
37 *
38 */
39
40class MARBLE_EXPORT ViewportParams
41{
42public:
44 explicit ViewportParams(Projection projection, qreal centerLongitude = 0, qreal centerLatitude = 0, int radius = 2000, const QSize &size = QSize(100, 100));
46
47 // Getters and setters
48 Projection projection() const;
49 const AbstractProjection *currentProjection() const;
50 void setProjection(Projection newProjection);
51
52 int polarity() const;
53
54 const GeoDataLatLonAltBox &viewLatLonAltBox() const;
55
56 GeoDataLatLonAltBox latLonAltBox(const QRect &screenRect) const;
57
58 // Calculates an educated guess for the average angle in radians covered per pixel.
59 // Given a certain resolution it doesn't make much sense
60 // - to display an object that covers an angle that is smaller than that.
61 // - to display two points as distinct points if they are separated by a
62 // an angular distance that is smaller. Instead only one point should be shown.
63 // So this method helps to filter out details.
64 // It's somewhat related to https://en.wikipedia.org/wiki/Angular_resolution
65
66 qreal angularResolution() const;
67
68 // Determines whether a geographical feature is big enough so that it should
69 // represent a single point on the screen already.
70 // See angularResolution()
71
72 bool resolves(const GeoDataLatLonBox &latLonBox, qreal pixel = 2.0) const;
73
74 bool resolves(const GeoDataLatLonAltBox &latLonAltBox, qreal pixel = 2.0, qreal altitude = 10000.0) const;
75
76 // Determines whether two points are located enough apart so that it makes
77 // sense to display them as distinct points. If this is not the case
78 // calculation and drawing of one point can be skipped as only a single
79 // point will be displayed on the screen.
80
81 bool resolves(const GeoDataCoordinates &coord1, const GeoDataCoordinates &coord2) const;
82
83 int radius() const;
84
85 /**
86 * @brief Change the radius of the planet
87 * @param radius Size of the planet radius in pixel. Non-positive values are ignored.
88 */
89 void setRadius(int radius);
90
91 void centerOn(qreal lon, qreal lat);
92 void setHeading(qreal heading);
93
94 Quaternion planetAxis() const;
95 const matrix &planetAxisMatrix() const;
96
97 int width() const;
98 int height() const;
99 QSize size() const;
100
101 void setWidth(int newWidth);
102 void setHeight(int newHeight);
103 void setSize(const QSize &newSize);
104
105 qreal centerLongitude() const;
106 qreal centerLatitude() const;
107
108 /**
109 * @brief Get the screen coordinates corresponding to geographical coordinates in the map.
110 * @param lon the lon coordinate of the requested pixel position in radians
111 * @param lat the lat coordinate of the requested pixel position in radians
112 * @param x the x coordinate of the pixel is returned through this parameter
113 * @param y the y coordinate of the pixel is returned through this parameter
114 * @return @c true if the geographical coordinates are visible on the screen
115 * @c false if the geographical coordinates are not visible on the screen
116 *
117 * @see ViewportParams
118 */
119 bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const;
120
121 /**
122 * @brief Get the screen coordinates corresponding to geographical coordinates in the map.
123 *
124 * @param geopoint the point on earth, including altitude, that we want the coordinates for.
125 * @param x the x coordinate of the pixel is returned through this parameter
126 * @param y the y coordinate of the pixel is returned through this parameter
127 * @param globeHidesPoint whether the point gets hidden on the far side of the earth
128 *
129 * @return @c true if the geographical coordinates are visible on the screen
130 * @c false if the geographical coordinates are not visible on the screen
131 *
132 * @see ViewportParams
133 */
134 bool screenCoordinates(const GeoDataCoordinates &geopoint, qreal &x, qreal &y, bool &globeHidesPoint) const;
135
136 // Will just call the virtual version with a dummy globeHidesPoint.
137 bool screenCoordinates(const GeoDataCoordinates &geopoint, qreal &x, qreal &y) const;
138
139 /**
140 * @brief Get the coordinates of screen points for geographical coordinates in the map.
141 *
142 * @param coordinates the point on earth, including altitude, that we want the coordinates for.
143 * @param x the x coordinates of the pixels are returned through this parameter
144 * @param y the y coordinate of the pixel is returned through this parameter
145 * @param pointRepeatNum the amount of times that a single geographical
146 point gets represented on the map
147 * @param size the size of the point
148 * @param globeHidesPoint whether the point gets hidden on the far side of the earth
149 *
150 * @return @c true if the geographical coordinates are visible on the screen
151 * @c false if the geographical coordinates are not visible on the screen
152 *
153 * @see ViewportParams
154 */
155 bool screenCoordinates(const GeoDataCoordinates &coordinates, qreal *x, qreal &y, int &pointRepeatNum, const QSizeF &size, bool &globeHidesPoint) const;
156
157 bool screenCoordinates(const GeoDataLineString &lineString, QList<QPolygonF *> &polygons) const;
158
159 /**
160 * @brief Get the earth coordinates corresponding to a pixel in the map.
161 * @param x the x coordinate of the pixel
162 * @param y the y coordinate of the pixel
163 * @param lon the longitude angle is returned through this parameter
164 * @param lat the latitude angle is returned through this parameter
165 * @param unit the unit of the angles for lon and lat.
166 * @return @c true if the pixel (x, y) is within the globe
167 * @c false if the pixel (x, y) is outside the globe, i.e. in space.
168 */
169 bool geoCoordinates(const int x, const int y, qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Degree) const;
170
171 qreal heading() const;
172 bool mapCoversViewport() const;
173
174 QPainterPath mapShape() const;
175
176 QRegion mapRegion() const;
177
178 /**
179 * @return The current point of focus, e.g. the point that is not moved
180 * when changing the zoom level. If not set, it defaults to the
181 * center point.
182 * @see centerCoordinates setFocusPoint resetFocusPoint
183 */
184 GeoDataCoordinates focusPoint() const;
185
186 /**
187 * @brief Change the point of focus, overridding any previously set focus point.
188 * @param focusPoint New focus point
189 * @see focusPoint resetFocusPoint
190 */
191 void setFocusPoint(const GeoDataCoordinates &focusPoint);
192
193 /**
194 * @brief Invalidate any focus point set with @ref setFocusPoint.
195 * @see focusPoint setFocusPoint
196 */
197 void resetFocusPoint();
198
199private:
200 Q_DISABLE_COPY(ViewportParams)
201 ViewportParamsPrivate *const d;
202};
203
204}
205
206#endif
A base class for all projections in Marble.
A 3d point representation.
Unit
enum used constructor to specify the units used
A class that defines a 3D bounding box for geographic data.
A class that defines a 2D bounding box for geographic data.
A LineString that allows to store a contiguous set of line segments.
A public class that controls what is visible in the viewport of a Marble map.
Q_INVOKABLE void setProjection(uint proj)
Binds a QML item to a specific geodetic location in screen coordinates.
Projection
This enum is used to choose the projection shown in the view.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.