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.

44 lines
963 B

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "mapViewWidget.h"
  2. sdlMapView::sdlMapView(int x, int y, int w, int h, bool decor, sdlCoreWidget* pParent) :sdlCoreWidget(x, y, w, h, decor, pParent) {
  3. };
  4. sdlMapView::~sdlMapView() {
  5. };
  6. void sdlMapView::setCenter(double lat, double lng) {
  7. double x = (lng + 180.0f) / 360.0f;
  8. double y = (1.0f - log(tan(lat * M_PI / 180.0f) + 1.0f / cos(lat * M_PI / 180.0f)) / M_PI) / 2.0f;
  9. offsetx = x * (TILESIZE << zoom) - width / 2;
  10. offsety = y * (TILESIZE << zoom) - height / 2;
  11. };
  12. void sdlMapView::moveBy(int dx, int dy) {
  13. offsetx += dx;
  14. offsety += dy;
  15. };
  16. void sdlMapView::zoomAt(int x, int y) {
  17. if (zoom < 22) {
  18. zoom++;
  19. offsetx = offsetx * 2 + x;
  20. offsety = offsety * 2 + y;
  21. };
  22. };
  23. void sdlMapView::zoomIn() {
  24. zoomAt(width / 2, height / 2);
  25. };
  26. void sdlMapView::zoomOut() {
  27. if (zoom > 3) {
  28. zoom--;
  29. offsetx = (offsetx - width / 2) / 2;
  30. offsety = (offsety - height / 2) / 2;
  31. };
  32. };
  33. void sdlMapView::drawBefore(SDL_Renderer* pRenderer){
  34. };