Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
674 | KeyOz | 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 "wmsmapadapter.h" |
||
27 | namespace qmapcontrol |
||
28 | { |
||
29 | WMSMapAdapter::WMSMapAdapter(QString host, QString serverPath, int tilesize) |
||
30 | : MapAdapter(host, serverPath, tilesize, 0, 17) |
||
31 | { |
||
32 | // param1 = serverPath.indexOf("%1"); |
||
33 | // param2 = serverPath.indexOf("%2"); |
||
34 | // param3 = serverPath.indexOf("%3"); |
||
35 | // param4 = serverPath.indexOf("%4"); |
||
36 | // param5 = serverPath.indexOf("%5"); |
||
37 | // param6 = serverPath.lastIndexOf("%5"); |
||
38 | |||
39 | // this->serverPath = serverPath.replace(param6, 2, QString().setNum(tilesize)).replace(param5, 2, QString().setNum(tilesize)); |
||
40 | |||
41 | // sub1 = serverPath.mid(0, param1); |
||
42 | // sub2 = serverPath.mid(param1+2, param2-param1-2); |
||
43 | // sub3 = serverPath.mid(param2+2, param3-param2-2); |
||
44 | // sub4 = serverPath.mid(param3+2, param4-param3-2); |
||
45 | // sub5 = serverPath.mid(param4+2); |
||
46 | |||
47 | this->serverPath.append("&WIDTH=").append(loc.toString(tilesize)) |
||
48 | .append("&HEIGHT=").append(loc.toString(tilesize)) |
||
49 | .append("&BBOX="); |
||
50 | numberOfTiles = pow(2, current_zoom); |
||
51 | coord_per_x_tile = 360. / numberOfTiles; |
||
52 | coord_per_y_tile = 180. / numberOfTiles; |
||
53 | } |
||
54 | |||
55 | |||
56 | WMSMapAdapter::~WMSMapAdapter() |
||
57 | { |
||
58 | } |
||
59 | |||
60 | QPoint WMSMapAdapter::coordinateToDisplay(const QPointF& coordinate) const |
||
61 | { |
||
62 | qreal x = (coordinate.x()+180) * (numberOfTiles*mytilesize)/360.; // coord to pixel! |
||
63 | qreal y = -1*(coordinate.y()-90) * (numberOfTiles*mytilesize)/180.; // coord to pixel! |
||
64 | return QPoint(int(x), int(y)); |
||
65 | } |
||
66 | QPointF WMSMapAdapter::displayToCoordinate(const QPoint& point) const |
||
67 | { |
||
68 | qreal lon = (point.x()*(360./(numberOfTiles*mytilesize)))-180; |
||
69 | qreal lat = -(point.y()*(180./(numberOfTiles*mytilesize)))+90; |
||
70 | return QPointF(lon, lat); |
||
71 | } |
||
72 | void WMSMapAdapter::zoom_in() |
||
73 | { |
||
74 | current_zoom+=1; |
||
75 | numberOfTiles = pow(2, current_zoom); |
||
76 | coord_per_x_tile = 360. / numberOfTiles; |
||
77 | coord_per_y_tile = 180. / numberOfTiles; |
||
78 | } |
||
79 | void WMSMapAdapter::zoom_out() |
||
80 | { |
||
81 | current_zoom-=1; |
||
82 | numberOfTiles = pow(2, current_zoom); |
||
83 | coord_per_x_tile = 360. / numberOfTiles; |
||
84 | coord_per_y_tile = 180. / numberOfTiles; |
||
85 | } |
||
86 | |||
87 | bool WMSMapAdapter::isValid(int /*x*/, int /*y*/, int /*z*/) const |
||
88 | { |
||
89 | // if (x>0 && y>0 && z>0) |
||
90 | { |
||
91 | return true; |
||
92 | } |
||
93 | // return false; |
||
94 | } |
||
95 | QString WMSMapAdapter::query(int i, int j, int /*z*/) const |
||
96 | { |
||
97 | return getQ(-180+i*coord_per_x_tile, |
||
98 | 90-(j+1)*coord_per_y_tile, |
||
99 | -180+i*coord_per_x_tile+coord_per_x_tile, |
||
100 | 90-(j+1)*coord_per_y_tile+coord_per_y_tile); |
||
101 | } |
||
102 | QString WMSMapAdapter::getQ(qreal ux, qreal uy, qreal ox, qreal oy) const |
||
103 | { |
||
104 | return QString().append(serverPath) |
||
105 | .append(loc.toString(ux)).append(",") |
||
106 | .append(loc.toString(uy)).append(",") |
||
107 | .append(loc.toString(ox)).append(",") |
||
108 | .append(loc.toString(oy)); |
||
109 | } |
||
110 | } |