Rev 338 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 338 | Rev 358 | ||
---|---|---|---|
1 | /*************************************************************************** |
1 | /*************************************************************************** |
2 | * Copyright (C) 2009 by Manuel Schrape * |
2 | * Copyright (C) 2009 by Manuel Schrape * |
3 | * manuel.schrape@gmx.de * |
3 | * manuel.schrape@gmx.de * |
4 | * * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License. * |
7 | * the Free Software Foundation; either version 2 of the License. * |
8 | * * |
8 | * * |
9 | * This program is distributed in the hope that it will be useful, * |
9 | * This program is distributed in the hope that it will be useful, * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
12 | * GNU General Public License for more details. * |
12 | * GNU General Public License for more details. * |
13 | * * |
13 | * * |
14 | * You should have received a copy of the GNU General Public License * |
14 | * You should have received a copy of the GNU General Public License * |
15 | * along with this program; if not, write to the * |
15 | * along with this program; if not, write to the * |
16 | * Free Software Foundation, Inc., * |
16 | * Free Software Foundation, Inc., * |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 | ***************************************************************************/ |
18 | ***************************************************************************/ |
19 | #include "dlg_Map.h" |
19 | #include "dlg_Map.h" |
20 | 20 | ||
21 | dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent) |
21 | dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent) |
22 | { |
22 | { |
23 | setupUi(this); |
23 | setupUi(this); |
24 | 24 | ||
25 | cb_Maps->removeItem(5); |
25 | cb_Maps->removeItem(5); |
26 | cb_Maps->removeItem(4); |
26 | cb_Maps->removeItem(4); |
27 | cb_Maps->removeItem(3); |
27 | cb_Maps->removeItem(3); |
28 | cb_Maps->removeItem(2); |
28 | cb_Maps->removeItem(2); |
29 | - | ||
30 | // Noch nicht eingebaut also Button weg. |
- | |
31 | pb_SendWaypoints->setVisible(false); |
- | |
32 | 29 | ||
33 | pb_Add->setEnabled(false); |
30 | pb_Add->setEnabled(false); |
34 | pb_Goto->setEnabled(false); |
31 | pb_Goto->setEnabled(false); |
35 | } |
32 | } |
36 | 33 | ||
37 | // Karte erstellen und anzeigen |
34 | // Karte erstellen und anzeigen |
38 | void dlg_Map::create_Map(cSettings *t_Settings) |
35 | void dlg_Map::create_Map(cSettings *t_Settings) |
39 | { |
36 | { |
40 | o_Settings = t_Settings; |
37 | o_Settings = t_Settings; |
41 | 38 | ||
42 | cb_CenterPos->setChecked(o_Settings->Map.GotoPosition); |
39 | cb_CenterPos->setChecked(o_Settings->Map.GotoPosition); |
43 | cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack); |
40 | cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack); |
44 | 41 | ||
45 | connect(sl_Zoom, SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int))); |
42 | connect(sl_Zoom, SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int))); |
46 | connect(pb_Add, SIGNAL(clicked()), this, SLOT(slot_AddWayPoint())); |
43 | connect(pb_Add, SIGNAL(clicked()), this, SLOT(slot_AddWayPoint())); |
47 | connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints())); |
44 | connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints())); |
48 | connect(pb_Goto, SIGNAL(clicked()), this, SLOT(slot_GotoTarget())); |
45 | connect(pb_Goto, SIGNAL(clicked()), this, SLOT(slot_GotoTarget())); |
- | 46 | connect(pb_SendWaypoints, SIGNAL(clicked()), this, SLOT(slot_SendWayPoints())); |
|
49 | connect(cb_Maps, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int))); |
47 | connect(cb_Maps, SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int))); |
50 | connect(this, SIGNAL(rejected()), this, SLOT(slot_Close())); |
48 | connect(this, SIGNAL(rejected()), this, SLOT(slot_Close())); |
51 | 49 | ||
52 | o_Map = new MapControl(w_Map->size()); |
50 | o_Map = new MapControl(w_Map->size()); |
53 | o_Map->enablePersistentCache(o_Settings->DIR.Cache); |
51 | o_Map->enablePersistentCache(o_Settings->DIR.Cache); |
54 | o_Map->showScale(true); |
52 | o_Map->showScale(true); |
55 | 53 | ||
56 | o_Adapter = new OSMMapAdapter(); |
54 | o_Adapter = new OSMMapAdapter(); |
57 | 55 | ||
58 | o_Layer = new MapLayer("MapLayer", o_Adapter); |
56 | o_Layer = new MapLayer("MapLayer", o_Adapter); |
59 | o_Click = new GeometryLayer("Click", o_Adapter); |
57 | o_Click = new GeometryLayer("Click", o_Adapter); |
60 | o_Route = new GeometryLayer("Poute", o_Adapter); |
58 | o_Route = new GeometryLayer("Poute", o_Adapter); |
61 | 59 | ||
62 | o_Map->addLayer(o_Layer); |
60 | o_Map->addLayer(o_Layer); |
63 | o_Map->addLayer(o_Click); |
61 | o_Map->addLayer(o_Click); |
64 | o_Map->addLayer(o_Route); |
62 | o_Map->addLayer(o_Route); |
65 | 63 | ||
66 | o_Map->setZoom(17); |
64 | o_Map->setZoom(17); |
67 | o_Map->setView(QPointF(13.5,52.5)); |
65 | o_Map->setView(QPointF(13.5,52.5)); |
68 | 66 | ||
69 | connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF))); |
67 | connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF))); |
70 | 68 | ||
71 | l_Map->addWidget(o_Map); |
69 | l_Map->addWidget(o_Map); |
72 | 70 | ||
73 | sl_Zoom->setValue(17); |
71 | sl_Zoom->setValue(17); |
74 | 72 | ||
75 | Pen[0] = new QPen(QColor(0,0,255,255)); |
73 | Pen[0] = new QPen(QColor(0,0,255,255)); |
76 | Pen[0]->setWidth(2); |
74 | Pen[0]->setWidth(2); |
77 | Pen[1] = new QPen(QColor(255,0,0,255)); |
75 | Pen[1] = new QPen(QColor(255,0,0,255)); |
78 | Pen[1]->setWidth(2); |
76 | Pen[1]->setWidth(2); |
79 | } |
77 | } |
80 | 78 | ||
81 | // Position zum Flug-Track hinzufügen |
79 | // Position zum Flug-Track hinzufügen |
82 | void dlg_Map::add_Position(double x, double y) |
80 | void dlg_Map::add_Position(double x, double y) |
83 | { |
81 | { |
84 | sWayPoint WayPoint; |
82 | sWayPoint WayPoint; |
85 | 83 | ||
86 | WayPoint.Longitude = x; |
84 | WayPoint.Longitude = x; |
87 | WayPoint.Latitude = y; |
85 | WayPoint.Latitude = y; |
88 | WayPoint.Time = sb_Time->value(); |
86 | // WayPoint.Time = sb_Time->value(); |
89 | 87 | ||
90 | l_WayPoint.append(WayPoint); |
88 | l_Track.append(WayPoint); |
91 | 89 | ||
92 | o_Route->removeGeometry(l_RouteFL); |
90 | o_Route->removeGeometry(l_RouteFL); |
93 | p_RouteFL.append(new Point(x,y)); |
91 | p_RouteFL.append(new Point(x,y)); |
94 | 92 | ||
95 | o_Click->removeGeometry(LastPos); |
93 | o_Click->removeGeometry(LastPos); |
96 | 94 | ||
97 | Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]); |
95 | Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]); |
98 | LastPos = P; |
96 | LastPos = P; |
99 | P->setBaselevel(17); |
97 | P->setBaselevel(17); |
100 | o_Click->addGeometry(P); |
98 | o_Click->addGeometry(P); |
101 | 99 | ||
102 | if (cb_CenterPos->isChecked()) |
100 | if (cb_CenterPos->isChecked()) |
103 | { |
101 | { |
104 | o_Map->setView(QPointF(x, y)); |
102 | o_Map->setView(QPointF(x, y)); |
105 | } |
103 | } |
106 | 104 | ||
107 | if (cb_ShowRoute->isChecked()) |
105 | if (cb_ShowRoute->isChecked()) |
108 | { |
106 | { |
109 | l_RouteFL = new LineString(p_RouteFL, "", Pen[1]); |
107 | l_RouteFL = new LineString(p_RouteFL, "", Pen[1]); |
110 | 108 | ||
111 | o_Route->addGeometry(l_RouteFL); |
109 | o_Route->addGeometry(l_RouteFL); |
112 | } |
110 | } |
113 | o_Map->updateRequestNew(); |
111 | o_Map->updateRequestNew(); |
114 | } |
112 | } |
115 | 113 | ||
116 | // Zoom der Karte ändern |
114 | // Zoom der Karte ändern |
117 | void dlg_Map::slot_Zoom(int t_Zoom) |
115 | void dlg_Map::slot_Zoom(int t_Zoom) |
118 | { |
116 | { |
119 | o_Map->setZoom(t_Zoom); |
117 | o_Map->setZoom(t_Zoom); |
120 | } |
118 | } |
121 | 119 | ||
122 | // Waypoint zur Liste hinzufügen |
120 | // Waypoint zur Liste hinzufügen |
123 | void dlg_Map::slot_AddWayPoint() |
121 | void dlg_Map::slot_AddWayPoint() |
124 | { |
122 | { |
- | 123 | sWayPoint WayPoint; |
|
- | 124 | ||
- | 125 | WayPoint.Longitude = LastClick->longitude(); |
|
- | 126 | WayPoint.Latitude = LastClick->latitude(); |
|
- | 127 | WayPoint.Time = sb_Time->value(); |
|
- | 128 | ||
- | 129 | l_WayPoints.append(WayPoint); |
|
- | 130 | ||
125 | o_Route->removeGeometry(l_RouteWP); |
131 | o_Route->removeGeometry(l_RouteWP); |
126 | 132 | ||
127 | p_RouteWP.append(LastClick); |
133 | p_RouteWP.append(LastClick); |
128 | l_RouteWP = new LineString(p_RouteWP, "", Pen[0]); |
134 | l_RouteWP = new LineString(p_RouteWP, "", Pen[0]); |
129 | 135 | ||
130 | o_Route->addGeometry(l_RouteWP); |
136 | o_Route->addGeometry(l_RouteWP); |
131 | o_Map->updateRequestNew(); |
137 | o_Map->updateRequestNew(); |
- | 138 | ||
- | 139 | pb_SendWaypoints->setEnabled(true); |
|
132 | } |
140 | } |
133 | 141 | ||
134 | // Waypoint-Liste löschen |
142 | // Waypoint-Liste löschen |
135 | void dlg_Map::slot_DeleteWayPoints() |
143 | void dlg_Map::slot_DeleteWayPoints() |
136 | { |
144 | { |
137 | o_Route->removeGeometry(l_RouteWP); |
145 | o_Route->removeGeometry(l_RouteWP); |
138 | p_RouteWP.clear(); |
146 | p_RouteWP.clear(); |
139 | l_WayPoint.clear(); |
147 | l_WayPoints.clear(); |
140 | o_Map->updateRequestNew(); |
148 | o_Map->updateRequestNew(); |
141 | } |
149 | } |
- | 150 | ||
- | 151 | void dlg_Map::slot_SendWayPoints() |
|
- | 152 | { |
|
- | 153 | emit(set_WayPoints(l_WayPoints)); |
|
- | 154 | } |
|
142 | 155 | ||
143 | // Zum Zielpunkt fliegen |
156 | // Zum Zielpunkt fliegen |
144 | void dlg_Map::slot_GotoTarget() |
157 | void dlg_Map::slot_GotoTarget() |
145 | { |
158 | { |
146 | sWayPoint Target; |
159 | sWayPoint Target; |
147 | 160 | ||
148 | Target.Longitude = LastClick->longitude(); |
161 | Target.Longitude = LastClick->longitude(); |
149 | Target.Latitude = LastClick->latitude(); |
162 | Target.Latitude = LastClick->latitude(); |
150 | Target.Time = sb_Time->value(); |
163 | Target.Time = sb_Time->value(); |
151 | 164 | ||
152 | emit(set_Target(Target)); |
165 | emit(set_Target(Target)); |
153 | } |
166 | } |
154 | 167 | ||
155 | // Click in der Karte |
168 | // Click in der Karte |
156 | void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord) |
169 | void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord) |
157 | { |
170 | { |
158 | if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton))) |
171 | if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton))) |
159 | { |
172 | { |
160 | sl_Zoom->setValue(o_Adapter->adaptedZoom()); |
173 | sl_Zoom->setValue(o_Adapter->adaptedZoom()); |
161 | } |
174 | } |
162 | 175 | ||
163 | // Überwachen ob Karte verschoben wird |
176 | // Überwachen ob Karte verschoben wird |
164 | if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton)) |
177 | if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton)) |
165 | { |
178 | { |
166 | MapCenter = o_Map->currentCoordinate(); |
179 | MapCenter = o_Map->currentCoordinate(); |
167 | } |
180 | } |
168 | 181 | ||
169 | // Nur wenn nicht Verschoben dann einen Punkt setzen |
182 | // Nur wenn nicht Verschoben dann einen Punkt setzen |
170 | if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton)) |
183 | if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton)) |
171 | { |
184 | { |
172 | if (o_Map->currentCoordinate() == MapCenter) |
185 | if (o_Map->currentCoordinate() == MapCenter) |
173 | { |
186 | { |
174 | pb_Add->setEnabled(true); |
187 | pb_Add->setEnabled(true); |
175 | pb_Goto->setEnabled(true); |
188 | pb_Goto->setEnabled(true); |
176 | 189 | ||
177 | o_Click->removeGeometry(ClickPoint); |
190 | o_Click->removeGeometry(ClickPoint); |
178 | 191 | ||
179 | ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]); |
192 | ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]); |
180 | // LastPoint = P; |
193 | // LastPoint = P; |
181 | 194 | ||
182 | LastClick = new Point(Coord.x(), Coord.y()); |
195 | LastClick = new Point(Coord.x(), Coord.y()); |
183 | 196 | ||
184 | ClickPoint->setBaselevel(o_Adapter->adaptedZoom()); |
197 | ClickPoint->setBaselevel(o_Adapter->adaptedZoom()); |
185 | o_Click->addGeometry(ClickPoint); |
198 | o_Click->addGeometry(ClickPoint); |
186 | } |
199 | } |
187 | } |
200 | } |
188 | 201 | ||
189 | o_Map->updateRequestNew(); |
202 | o_Map->updateRequestNew(); |
190 | // qDebug(QString("%1").arg(Coord.x()).toLatin1().data()); |
203 | // qDebug(QString("%1").arg(Coord.x()).toLatin1().data()); |
191 | // qDebug(QString("%1").arg(Coord.y()).toLatin1().data()); |
204 | // qDebug(QString("%1").arg(Coord.y()).toLatin1().data()); |
192 | } |
205 | } |
193 | 206 | ||
194 | // auf Veränderung der Fenstergröße reagieren |
207 | // auf Veränderung der Fenstergröße reagieren |
195 | void dlg_Map::resizeEvent ( QResizeEvent * event ) |
208 | void dlg_Map::resizeEvent ( QResizeEvent * event ) |
196 | { |
209 | { |
197 | event = event; |
210 | event = event; |
198 | o_Map->resize(w_Map->size() - QSize(20,20)); |
211 | o_Map->resize(w_Map->size() - QSize(20,20)); |
199 | } |
212 | } |
200 | 213 | ||
201 | // Karte wechseln |
214 | // Karte wechseln |
202 | void dlg_Map::slot_ChangeMap(int t_Set) |
215 | void dlg_Map::slot_ChangeMap(int t_Set) |
203 | { |
216 | { |
204 | int zoom = o_Adapter->adaptedZoom(); |
217 | int zoom = o_Adapter->adaptedZoom(); |
205 | QPointF a = o_Map->currentCoordinate(); |
218 | QPointF a = o_Map->currentCoordinate(); |
206 | 219 | ||
207 | o_Map->setZoom(0); |
220 | o_Map->setZoom(0); |
208 | 221 | ||
209 | switch(t_Set) |
222 | switch(t_Set) |
210 | { |
223 | { |
211 | case 0 : // OpenStreetMap |
224 | case 0 : // OpenStreetMap |
212 | { |
225 | { |
213 | o_Adapter = new OSMMapAdapter(); |
226 | o_Adapter = new OSMMapAdapter(); |
214 | } |
227 | } |
215 | break; |
228 | break; |
216 | case 1 : // Yahoo Sat |
229 | case 1 : // Yahoo Sat |
217 | { |
230 | { |
218 | // o_Adapter = new WMSMapAdapter("openaerialmap.org", "/wms/wms.asp?wms=WorldMap&LAYERS=world&FORMAT=image/png&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&TRANSPARENT=FALSE", 256); |
- | |
219 | o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17); |
231 | o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17); |
220 | } |
232 | } |
221 | break; |
233 | break; |
222 | case 2 : // Google Maps |
234 | case 2 : // Google Maps |
223 | { |
235 | { |
224 | o_Adapter = new GoogleMapAdapter(); |
236 | o_Adapter = new GoogleMapAdapter(); |
225 | } |
237 | } |
226 | break; |
238 | break; |
227 | case 3 : // Google Sat |
239 | case 3 : // Google Sat |
228 | { |
240 | { |
229 | o_Adapter = new GoogleSatMapAdapter(); |
241 | o_Adapter = new GoogleSatMapAdapter(); |
230 | } |
242 | } |
231 | break; |
243 | break; |
232 | case 4 : // Yahoo Maps |
244 | case 4 : // Yahoo Maps |
233 | { |
245 | { |
234 | o_Adapter = new YahooMapAdapter(); |
246 | o_Adapter = new YahooMapAdapter(); |
235 | } |
247 | } |
236 | break; |
248 | break; |
237 | case 5 : // Yahoo Sat |
249 | case 5 : // Yahoo Sat |
238 | { |
250 | { |
239 | o_Adapter = new YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=1.7&t=a&s=256&x=%2&y=%3&z=%1"); |
251 | o_Adapter = new YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=1.7&t=a&s=256&x=%2&y=%3&z=%1"); |
240 | } |
252 | } |
241 | break; |
253 | break; |
242 | } |
254 | } |
243 | 255 | ||
244 | o_Layer->setMapAdapter(o_Adapter); |
256 | o_Layer->setMapAdapter(o_Adapter); |
245 | o_Click->setMapAdapter(o_Adapter); |
257 | o_Click->setMapAdapter(o_Adapter); |
246 | o_Route->setMapAdapter(o_Adapter); |
258 | o_Route->setMapAdapter(o_Adapter); |
247 | 259 | ||
248 | o_Map->updateRequestNew(); |
260 | o_Map->updateRequestNew(); |
249 | o_Map->setZoom(zoom); |
261 | o_Map->setZoom(zoom); |
250 | } |
262 | } |
251 | 263 | ||
252 | // Fenster wird geschlossen. |
264 | // Fenster wird geschlossen. |
253 | void dlg_Map::slot_Close() |
265 | void dlg_Map::slot_Close() |
254 | { |
266 | { |
255 | o_Settings->Map.GotoPosition = cb_CenterPos->isChecked(); |
267 | o_Settings->Map.GotoPosition = cb_CenterPos->isChecked(); |
256 | o_Settings->Map.ShowTrack = cb_ShowRoute->isChecked(); |
268 | o_Settings->Map.ShowTrack = cb_ShowRoute->isChecked(); |
257 | emit set_Settings(o_Settings); |
269 | emit set_Settings(o_Settings); |
258 | } |
270 | } |
259 | 271 | ||
260 | 272 |