Subversion Repositories Projects

Rev

Rev 315 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
305 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
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  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
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 General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
#include "dlg_Map.h"
20
 
21
dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent)
22
{
23
    setupUi(this);
24
 
306 KeyOz 25
    // Kartenwahl ausschalten
334 KeyOz 26
    //lb_Maps->setVisible(false);
27
    //cb_Maps->setVisible(false);
306 KeyOz 28
 
334 KeyOz 29
    cb_Maps->removeItem(5);
30
    cb_Maps->removeItem(4);
31
    cb_Maps->removeItem(3);
32
    cb_Maps->removeItem(2);
33
 
306 KeyOz 34
    // Noch nicht eingebaut also Button weg.
35
    pb_SendWaypoints->setVisible(false);
36
 
37
    pb_Add->setEnabled(false);
38
    pb_Goto->setEnabled(false);
39
}
40
 
41
// Karte erstellen und anzeigen
42
void dlg_Map::create_Map(cSettings *t_Settings)
43
{
44
    o_Settings = t_Settings;
45
 
46
    cb_CenterPos->setChecked(o_Settings->Map.GotoPosition);
47
    cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack);
48
 
305 KeyOz 49
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
306 KeyOz 50
    connect(pb_Add,    SIGNAL(clicked()), this, SLOT(slot_AddWayPoint()));
51
    connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints()));
52
    connect(pb_Goto,   SIGNAL(clicked()), this, SLOT(slot_GotoTarget()));
305 KeyOz 53
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
306 KeyOz 54
    connect(this,      SIGNAL(rejected()), this, SLOT(slot_Close()));
305 KeyOz 55
 
56
    o_Map = new MapControl(w_Map->size());
306 KeyOz 57
    o_Map->enablePersistentCache(o_Settings->DIR.Cache);
58
    o_Map->showScale(true);
305 KeyOz 59
 
60
    o_Adapter = new OSMMapAdapter();
61
 
62
    o_Layer = new MapLayer("MapLayer", o_Adapter);
63
    o_Click = new GeometryLayer("Click", o_Adapter);
64
    o_Route = new GeometryLayer("Poute", o_Adapter);
65
 
66
    o_Map->addLayer(o_Layer);
67
    o_Map->addLayer(o_Click);
68
    o_Map->addLayer(o_Route);
69
 
70
    o_Map->setZoom(17);
71
//    o_Map->setView(QPointF(13.85615670,52.50787020));
72
    o_Map->setView(QPointF(13.5,52.5));
73
 
74
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
75
 
76
    l_Map->addWidget(o_Map);
77
 
78
    sl_Zoom->setValue(17);
79
 
80
    Pen[0] = new QPen(QColor(0,0,255,255));
81
    Pen[0]->setWidth(2);
82
    Pen[1] = new QPen(QColor(255,0,0,255));
83
    Pen[1]->setWidth(2);
84
}
85
 
306 KeyOz 86
// Position zum Flug-Track hinzufügen
305 KeyOz 87
void dlg_Map::add_Position(double x, double y)
88
{
306 KeyOz 89
    sWayPoint WayPoint;
90
 
91
    WayPoint.Longitude = x;
92
    WayPoint.Latitude = y;
93
    WayPoint.Time = sb_Time->value();
94
 
95
    l_WayPoint.append(WayPoint);
96
 
305 KeyOz 97
    o_Route->removeGeometry(l_RouteFL);
98
    p_RouteFL.append(new Point(x,y));
99
 
100
    o_Click->removeGeometry(LastPos);
101
 
102
    Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]);
103
    LastPos = P;
104
    P->setBaselevel(17);
105
    o_Click->addGeometry(P);
106
 
107
    if (cb_CenterPos->isChecked())
108
    {
109
        o_Map->setView(QPointF(x, y));
110
    }
111
 
112
    if (cb_ShowRoute->isChecked())
113
    {
114
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
115
 
116
        o_Route->addGeometry(l_RouteFL);
117
    }
118
    o_Map->updateRequestNew();
119
}
120
 
306 KeyOz 121
// Zoom der Karte ändern
122
void dlg_Map::slot_Zoom(int t_Zoom)
305 KeyOz 123
{
306 KeyOz 124
    o_Map->setZoom(t_Zoom);
305 KeyOz 125
}
126
 
306 KeyOz 127
// Waypoint zur Liste hinzufügen
128
void dlg_Map::slot_AddWayPoint()
305 KeyOz 129
{
130
    o_Route->removeGeometry(l_RouteWP);
131
 
132
    p_RouteWP.append(LastClick);
133
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
134
 
135
    o_Route->addGeometry(l_RouteWP);
136
    o_Map->updateRequestNew();
137
}
138
 
306 KeyOz 139
// Waypoint-Liste löschen
140
void dlg_Map::slot_DeleteWayPoints()
305 KeyOz 141
{
142
    o_Route->removeGeometry(l_RouteWP);
143
    p_RouteWP.clear();
306 KeyOz 144
    l_WayPoint.clear();
305 KeyOz 145
    o_Map->updateRequestNew();
146
}
147
 
306 KeyOz 148
// Zum Zielpunkt fliegen
149
void dlg_Map::slot_GotoTarget()
150
{
151
    sWayPoint Target;
152
 
153
    Target.Longitude = LastClick->longitude();
154
    Target.Latitude = LastClick->latitude();
155
    Target.Time = sb_Time->value();
156
 
157
    emit(set_Target(Target));
158
}
159
 
160
// Click in der Karte
305 KeyOz 161
void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord)
162
{
163
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
164
    {
165
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
166
    }
167
 
306 KeyOz 168
    // Überwachen ob Karte verschoben wird
305 KeyOz 169
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
170
    {
306 KeyOz 171
        MapCenter = o_Map->currentCoordinate();
172
    }
305 KeyOz 173
 
306 KeyOz 174
    // Nur wenn nicht Verschoben dann einen Punkt setzen
175
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
176
    {
177
        if (o_Map->currentCoordinate() == MapCenter)
178
        {
179
            pb_Add->setEnabled(true);
180
            pb_Goto->setEnabled(true);
305 KeyOz 181
 
306 KeyOz 182
            o_Click->removeGeometry(ClickPoint);
305 KeyOz 183
 
306 KeyOz 184
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]);
185
//            LastPoint = P;
186
 
187
            LastClick = new Point(Coord.x(), Coord.y());
188
 
189
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
190
            o_Click->addGeometry(ClickPoint);
191
        }
305 KeyOz 192
    }
306 KeyOz 193
 
305 KeyOz 194
    o_Map->updateRequestNew();
306 KeyOz 195
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
196
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
305 KeyOz 197
}
198
 
306 KeyOz 199
// auf Veränderung der Fenstergröße reagieren
305 KeyOz 200
void dlg_Map::resizeEvent ( QResizeEvent * event )
201
{
306 KeyOz 202
    event = event;
305 KeyOz 203
    o_Map->resize(w_Map->size() - QSize(20,20));
204
}
205
 
306 KeyOz 206
// Karte wechseln
207
void dlg_Map::slot_ChangeMap(int t_Set)
305 KeyOz 208
{
306 KeyOz 209
    int zoom = o_Adapter->adaptedZoom();
210
    QPointF a = o_Map->currentCoordinate();
305 KeyOz 211
 
306 KeyOz 212
    o_Map->setZoom(0);
213
 
214
    switch(t_Set)
215
    {
216
        case 0 : // OpenStreetMap
217
        {
305 KeyOz 218
            o_Adapter = new OSMMapAdapter();
306 KeyOz 219
        }
220
        break;
334 KeyOz 221
        case 1 : // Yahoo Sat
306 KeyOz 222
        {
334 KeyOz 223
            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);
224
        }
225
        break;
226
        case 2 : // Google Maps
227
        {
306 KeyOz 228
            o_Adapter = new GoogleMapAdapter();
229
        }
230
        break;
334 KeyOz 231
        case 3 : // Google Sat
306 KeyOz 232
        {
233
            o_Adapter = new GoogleSatMapAdapter();
234
        }
235
        break;
334 KeyOz 236
        case 4 : // Yahoo Maps
306 KeyOz 237
        {
305 KeyOz 238
            o_Adapter = new YahooMapAdapter();
306 KeyOz 239
        }
240
        break;
334 KeyOz 241
        case 5 : // Yahoo Sat
306 KeyOz 242
        {
305 KeyOz 243
            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");
306 KeyOz 244
        }
245
        break;
246
    }
305 KeyOz 247
 
306 KeyOz 248
    o_Layer->setMapAdapter(o_Adapter);
249
    o_Click->setMapAdapter(o_Adapter);
250
    o_Route->setMapAdapter(o_Adapter);
305 KeyOz 251
 
306 KeyOz 252
    o_Map->updateRequestNew();
253
    o_Map->setZoom(zoom);
254
}
305 KeyOz 255
 
306 KeyOz 256
// Fenster wird geschlossen.
257
void dlg_Map::slot_Close()
258
{
259
    o_Settings->Map.GotoPosition = cb_CenterPos->isChecked();
260
    o_Settings->Map.ShowTrack    = cb_ShowRoute->isChecked();
261
    emit set_Settings(o_Settings);
262
}
305 KeyOz 263