You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.8 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "emptymapadapter.h"
  26. EmptyMapAdapter::EmptyMapAdapter(int tileSize, int minZoom, int maxZoom)
  27. :MapAdapter("", "", 256, minZoom, maxZoom)
  28. {
  29. Q_UNUSED(tileSize)
  30. PI = acos(-1.0);
  31. mNumberOfTiles = tilesonzoomlevel(minZoom);
  32. }
  33. EmptyMapAdapter::~EmptyMapAdapter()
  34. {
  35. }
  36. void EmptyMapAdapter::zoom_in()
  37. {
  38. if (mCurrent_zoom < mMax_zoom)
  39. {
  40. mCurrent_zoom = mCurrent_zoom + 1;
  41. }
  42. mNumberOfTiles = tilesonzoomlevel(mCurrent_zoom);
  43. }
  44. void EmptyMapAdapter::zoom_out()
  45. {
  46. if (mCurrent_zoom > mMin_zoom)
  47. {
  48. mCurrent_zoom = mCurrent_zoom - 1;
  49. }
  50. mNumberOfTiles = tilesonzoomlevel(mCurrent_zoom);
  51. }
  52. qreal EmptyMapAdapter::deg_rad(qreal x) const
  53. {
  54. return x * (PI/180.0);
  55. }
  56. qreal EmptyMapAdapter::rad_deg(qreal x) const
  57. {
  58. return x * (180/PI);
  59. }
  60. QString EmptyMapAdapter::query(int x, int y, int z) const
  61. {
  62. Q_UNUSED(x)
  63. Q_UNUSED(y)
  64. Q_UNUSED(z)
  65. return QString();
  66. }
  67. QPoint EmptyMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
  68. {
  69. qreal x = (coordinate.x()+180) * (mNumberOfTiles*mTileSize)/360.; // coord to pixel!
  70. qreal y = (1-(log(tan(PI/4+deg_rad(coordinate.y())/2)) /PI)) /2 * (mNumberOfTiles*mTileSize);
  71. return QPoint(int(x), int(y));
  72. }
  73. QPointF EmptyMapAdapter::displayToCoordinate(const QPoint& point) const
  74. {
  75. qreal longitude = (point.x()*(360/(mNumberOfTiles*mTileSize)))-180;
  76. qreal latitude = rad_deg(atan(sinh((1-point.y()*(2/(mNumberOfTiles*mTileSize)))*PI)));
  77. return QPointF(longitude, latitude);
  78. }
  79. bool EmptyMapAdapter::isTileValid(int x, int y, int z) const
  80. {
  81. if (mMax_zoom < mMin_zoom)
  82. {
  83. z= mMin_zoom - z;
  84. }
  85. bool result = true;
  86. if (x<0 || x>pow(2.0,z)-1 ||
  87. y<0 || y>pow(2.0,z)-1)
  88. {
  89. result = false;
  90. }
  91. return result;
  92. }
  93. int EmptyMapAdapter::tilesonzoomlevel(int zoomlevel) const
  94. {
  95. return int(pow(2.0, zoomlevel));
  96. }
  97. int EmptyMapAdapter::xoffset(int x) const
  98. {
  99. return x;
  100. }
  101. int EmptyMapAdapter::yoffset(int y) const
  102. {
  103. return y;
  104. }