Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
801 - 1
/*
2
*
3
* This file is part of QMapControl,
4
* an open-source cross-platform map widget
5
*
6
* Copyright (C) 2007 - 2008 Kai Winter
7
*
8
* This program is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
* GNU Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
20
*
21
* Contact e-mail: kaiwinter@gmx.de
22
* Program URL   : http://qmapcontrol.sourceforge.net/
23
*
24
*/
25
 
26
#include "emptymapadapter.h"
27
namespace qmapcontrol
28
{
29
    EmptyMapAdapter::EmptyMapAdapter(int tileSize, int minZoom, int maxZoom)
30
        :MapAdapter("", "", 256, minZoom, maxZoom)
31
    {
32
        PI = acos(-1.0);
33
 
34
        numberOfTiles = tilesonzoomlevel(minZoom);
35
    }
36
 
37
    EmptyMapAdapter::~EmptyMapAdapter()
38
    {
39
    }
40
 
41
    void EmptyMapAdapter::zoom_in()
42
    {
43
        if (current_zoom < max_zoom)
44
        {
45
            current_zoom = current_zoom + 1;
46
        }
47
        numberOfTiles = tilesonzoomlevel(current_zoom);
48
    }
49
 
50
    void EmptyMapAdapter::zoom_out()
51
    {
52
        if (current_zoom > min_zoom)
53
        {
54
            current_zoom = current_zoom - 1;
55
        }
56
        numberOfTiles = tilesonzoomlevel(current_zoom);
57
    }
58
 
59
    qreal EmptyMapAdapter::deg_rad(qreal x) const
60
    {
61
        return x * (PI/180.0);
62
    }
63
    qreal EmptyMapAdapter::rad_deg(qreal x) const
64
    {
65
        return x * (180/PI);
66
    }
67
 
68
    QString EmptyMapAdapter::query(int x, int y, int z) const
69
    {
70
        return "";
71
    }
72
 
73
    QPoint EmptyMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
74
    {
75
        qreal x = (coordinate.x()+180) * (numberOfTiles*mytilesize)/360.; // coord to pixel!
76
        qreal y = (1-(log(tan(PI/4+deg_rad(coordinate.y())/2)) /PI)) /2  * (numberOfTiles*mytilesize);
77
 
78
        return QPoint(int(x), int(y));
79
    }
80
 
81
    QPointF EmptyMapAdapter::displayToCoordinate(const QPoint& point) const
82
    {
83
        qreal longitude = (point.x()*(360/(numberOfTiles*mytilesize)))-180;
84
        qreal latitude = rad_deg(atan(sinh((1-point.y()*(2/(numberOfTiles*mytilesize)))*PI)));
85
 
86
        return QPointF(longitude, latitude);
87
 
88
    }
89
 
90
    bool EmptyMapAdapter::isValid(int x, int y, int z) const
91
    {
92
        if (max_zoom < min_zoom)
93
        {
94
            z= min_zoom - z;
95
        }
96
 
97
        if (x<0 || x>pow(2,z)-1 ||
98
            y<0 || y>pow(2,z)-1)
99
        {
100
            return false;
101
        }
102
        return true;
103
 
104
    }
105
    int EmptyMapAdapter::tilesonzoomlevel(int zoomlevel) const
106
    {
107
        return int(pow(2, zoomlevel));
108
    }
109
    int EmptyMapAdapter::xoffset(int x) const
110
    {
111
        return x;
112
    }
113
    int EmptyMapAdapter::yoffset(int y) const
114
    {
115
        return y;
116
    }
117
}