wmsmapadapter.cpp 3.88 KB
Newer Older
pixhawk's avatar
pixhawk committed
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
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL   : http://qmapcontrol.sourceforge.net/
*
*/

#include "wmsmapadapter.h"
namespace qmapcontrol
{
    WMSMapAdapter::WMSMapAdapter(QString host, QString serverPath, int tilesize)
        : MapAdapter(host, serverPath, tilesize, 0, 17)
    {
        // param1 = serverPath.indexOf("%1");
        // param2 = serverPath.indexOf("%2");
        // param3 = serverPath.indexOf("%3");
        // param4 = serverPath.indexOf("%4");
        // param5 = serverPath.indexOf("%5");
        // param6 = serverPath.lastIndexOf("%5");

        // this->serverPath = serverPath.replace(param6, 2, QString().setNum(tilesize)).replace(param5, 2, QString().setNum(tilesize));

        // sub1 = serverPath.mid(0, param1);
        // sub2 = serverPath.mid(param1+2, param2-param1-2);
        // sub3 = serverPath.mid(param2+2, param3-param2-2);
        // sub4 = serverPath.mid(param3+2, param4-param3-2);
        // sub5 = serverPath.mid(param4+2);

        this->serverPath.append("&WIDTH=").append(loc.toString(tilesize))
                .append("&HEIGHT=").append(loc.toString(tilesize))
                .append("&BBOX=");
        numberOfTiles = pow(2, current_zoom);
        coord_per_x_tile = 360. / numberOfTiles;
        coord_per_y_tile = 180. / numberOfTiles;
    }


    WMSMapAdapter::~WMSMapAdapter()
    {
    }

    QPoint WMSMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
    {
        qreal x = (coordinate.x()+180) * (numberOfTiles*mytilesize)/360.; // coord to pixel!
        qreal y = -1*(coordinate.y()-90) * (numberOfTiles*mytilesize)/180.; // coord to pixel!
        return QPoint(int(x), int(y));
    }
    QPointF WMSMapAdapter::displayToCoordinate(const QPoint& point) const
    {
        qreal lon = (point.x()*(360./(numberOfTiles*mytilesize)))-180;
        qreal lat = -(point.y()*(180./(numberOfTiles*mytilesize)))+90;
        return QPointF(lon, lat);
    }
    void WMSMapAdapter::zoom_in()
    {
        current_zoom+=1;
        numberOfTiles = pow(2, current_zoom);
        coord_per_x_tile = 360. / numberOfTiles;
        coord_per_y_tile = 180. / numberOfTiles;
    }
    void WMSMapAdapter::zoom_out()
    {
        current_zoom-=1;
        numberOfTiles = pow(2, current_zoom);
        coord_per_x_tile = 360. / numberOfTiles;
        coord_per_y_tile = 180. / numberOfTiles;
    }

    bool WMSMapAdapter::isValid(int /*x*/, int /*y*/, int /*z*/) const
    {
        // if (x>0 && y>0 && z>0)
        {
            return true;
        }
        // return false;
    }
    QString WMSMapAdapter::query(int i, int j, int /*z*/) const
    {
        return getQ(-180+i*coord_per_x_tile,
                    90-(j+1)*coord_per_y_tile,
                    -180+i*coord_per_x_tile+coord_per_x_tile,
                    90-(j+1)*coord_per_y_tile+coord_per_y_tile);
    }
    QString WMSMapAdapter::getQ(qreal ux, qreal uy, qreal ox, qreal oy) const
    {
        return QString().append(serverPath)
                .append(loc.toString(ux)).append(",")
                .append(loc.toString(uy)).append(",")
                .append(loc.toString(ox)).append(",")
                .append(loc.toString(oy));
    }
}