1 | /* |
---|
2 | Copyright (C) 2005 Nick Whitelegg, Hogweed Software, nick@hogweed.org |
---|
3 | |
---|
4 | This program is free software; you can redistribute it and/or modify |
---|
5 | it under the terms of the GNU Lesser General Public License as published by |
---|
6 | the Free Software Foundation; either version 2 of the License, or |
---|
7 | (at your option) any yer version. |
---|
8 | |
---|
9 | This program is distributed in the hope that it will be useful, |
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | GNU Lesser General Public License for more details. |
---|
13 | |
---|
14 | You should have received a copy of the GNU Lesser General Public License |
---|
15 | axg with this program; if not, write to the Free Software |
---|
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA |
---|
17 | |
---|
18 | */ |
---|
19 | #ifndef MAP_H |
---|
20 | #define MAP_H |
---|
21 | |
---|
22 | #include "EarthPoint.h" |
---|
23 | #include <iostream> |
---|
24 | using namespace std; |
---|
25 | |
---|
26 | struct ScreenPos |
---|
27 | { |
---|
28 | int x,y; |
---|
29 | |
---|
30 | ScreenPos() { x=y=0; } |
---|
31 | ScreenPos(int x1,int y1) { x=x1; y=y1; } |
---|
32 | }; |
---|
33 | |
---|
34 | |
---|
35 | class Map |
---|
36 | { |
---|
37 | private: |
---|
38 | EarthPoint bottomLeft, topRight; |
---|
39 | double scale; |
---|
40 | |
---|
41 | public: |
---|
42 | Map(double scale) { this->scale=scale; } |
---|
43 | |
---|
44 | void setBBOX(double w,double s,double e,double n) |
---|
45 | { |
---|
46 | bottomLeft=EarthPoint(w,s); |
---|
47 | topRight=EarthPoint(e,n); |
---|
48 | } |
---|
49 | |
---|
50 | void print() { |
---|
51 | EarthPoint p = getTopRight(); |
---|
52 | cout << "bottomLeft: "<< bottomLeft.x << ","<<bottomLeft.y<< |
---|
53 | " topright:" << p.x<<","<<p.y << endl; |
---|
54 | } |
---|
55 | |
---|
56 | ScreenPos getScreenPos(const EarthPoint& pos) |
---|
57 | { |
---|
58 | return ScreenPos ( |
---|
59 | (pos.x-bottomLeft.x)*scale, |
---|
60 | (topRight.y-pos.y)*scale |
---|
61 | ); |
---|
62 | } |
---|
63 | |
---|
64 | ScreenPos getScreenPos(double x,double y) |
---|
65 | { return getScreenPos(EarthPoint(x,y)); } |
---|
66 | |
---|
67 | EarthPoint getEarthPoint(const ScreenPos& pos) |
---|
68 | { return getEarthPoint(pos.x,pos.y); } |
---|
69 | |
---|
70 | EarthPoint getEarthPoint(int x, int y) |
---|
71 | { return EarthPoint( bottomLeft.x+(((double)x)/scale), |
---|
72 | topRight.y-(((double)y)/scale)); } |
---|
73 | |
---|
74 | EarthPoint getTopLeft() { return EarthPoint(bottomLeft.x,topRight.y); } |
---|
75 | EarthPoint getBottomRight() |
---|
76 | { return EarthPoint(topRight.x,bottomLeft.y); } |
---|
77 | EarthPoint getTopRight() { return topRight; } |
---|
78 | |
---|
79 | void extend(double factor) |
---|
80 | { |
---|
81 | double dx = topRight.x-bottomLeft.x, |
---|
82 | dy = topRight.y-bottomLeft.y; |
---|
83 | bottomLeft.x -= dx * factor; |
---|
84 | bottomLeft.y -= dy * factor; |
---|
85 | topRight.x += dx * factor; |
---|
86 | topRight.y += dy * factor; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | EarthPoint getBottomLeft() |
---|
91 | { return bottomLeft; } |
---|
92 | |
---|
93 | double getScale() |
---|
94 | { return scale; } |
---|
95 | |
---|
96 | bool pt_within_map(const EarthPoint& ep) |
---|
97 | { |
---|
98 | return ep.x>=bottomLeft.x && ep.y>=bottomLeft.y&& |
---|
99 | ep.x<=topRight.x && ep.y<=topRight.y; |
---|
100 | } |
---|
101 | |
---|
102 | int getWidth(){return (topRight.x-bottomLeft.x)*scale;} |
---|
103 | int getHeight(){return (topRight.y-bottomLeft.y)*scale;} |
---|
104 | |
---|
105 | double earthDist(double pixelDist) |
---|
106 | { return pixelDist/scale; } |
---|
107 | |
---|
108 | EarthPoint getCentre(int w,int h) |
---|
109 | { |
---|
110 | return getEarthPoint(ScreenPos(w/2,h/2)); |
---|
111 | } |
---|
112 | }; |
---|
113 | |
---|
114 | |
---|
115 | #endif |
---|