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

KDE's Doxygen guidelines are available online.