Subversion Repositories Projects

Rev

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