1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2023-05-15
 * Description : geolocation engine based on Marble.
 *               (c) 2007-2022 Marble Team
 *               https://invent.kde.org/education/marble/-/raw/master/data/credits_authors.html
 *
 * SPDX-FileCopyrightText: 2023-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * ============================================================ */

/**
 * This file contains the headers for MercatorProjection.
 */

#pragma once

// Local includes

#include "CylindricalProjection.h"

namespace Marble
{

/**
 * @short A class to implement the Mercator projection.
 */

class MercatorProjection : public CylindricalProjection
{
    // Not a QObject so far because we don't need to send signals.

public:

    /**
     * @brief Construct a new MercatorProjection.
     */
    MercatorProjection();

    ~MercatorProjection() override;

    /**
     * @brief Returns the user-visible name of the projection.
     */
    QString name() const override;

    /**
     * @brief Returns a short user description of the projection
     * that can be used in tooltips or dialogs.
     */
    QString description() const override;

    /**
     * @brief Returns an icon for the projection.
     */
    QIcon icon() const override;

    qreal  maxValidLat() const override;<--- maxValidLat is a virtual function
    qreal  minValidLat() const override;<--- minValidLat is a virtual function

    PreservationType preservationType() const override
    {
        return Conformal;
    }

    /**
     * @brief Get the screen coordinates corresponding to geographical coordinates in the map.
     * @param coordinates  the coordinates of the requested pixel position
     * @param params the viewport parameters
     * @param x      the x coordinate of the pixel is returned through this parameter
     * @param y      the y coordinate of the pixel is returned through this parameter
     * @param globeHidesPoint whether the globe hides the point
     * @return @c true  if the geographical coordinates are visible on the screen
     *         @c false if the geographical coordinates are not visible on the screen
     */
    bool screenCoordinates(const GeoDataCoordinates& coordinates,
                           const ViewportParams* params,
                           qreal& x, qreal& y, bool& globeHidesPoint) const override;

    bool screenCoordinates(const GeoDataCoordinates& coordinates,
                           const ViewportParams* viewport,
                           qreal* x, qreal& y, int& pointRepeatNum,
                           const QSizeF& size,
                           bool& globeHidesPoint) const override;

    using CylindricalProjection::screenCoordinates;

    /**
      * @brief Get the earth coordinates corresponding to a pixel in the map.
      *
      * If the pixel (x, y) is outside the globe, only @p lon will be calculated,
      * and lat will be unchanged.
      *
      * @param x      the x coordinate of the pixel
      * @param y      the y coordinate of the pixel
      * @param params the viewport parameters
      * @param lon    the longitude angle is returned through this parameter
      * @param lat    the latitude angle is returned through this parameter
      * @param unit   the unit
      * @return @c true  if the pixel (x, y) is within the globe
      *         @c false if the pixel (x, y) is outside the globe, i.e. in space.
      */
    bool geoCoordinates(const int x, const int y,
                        const ViewportParams* params,
                        qreal& lon, qreal& lat,
                        GeoDataCoordinates::Unit = GeoDataCoordinates::Degree) const override;

    GeoDataLatLonAltBox latLonAltBox(const QRect& screenRect,
                                     const ViewportParams* viewport) const override;

    bool  mapCoversViewport(const ViewportParams* viewport) const override;

private:

    Q_DISABLE_COPY(MercatorProjection)

private:

    mutable qreal m_lastCenterLat;
    mutable qreal m_lastCenterLatInv;
};

} // namespace Marble