source: ntrip/branches/BNC_2.12/src/map/bncmapwin.cpp@ 8929

Last change on this file since 8929 was 6446, checked in by mervart, 10 years ago
File size: 5.3 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncMapWin
30 *
31 * Purpose: Displays the Google Map
32 *
33 * Author: L. Mervart
34 *
35 * Created: 08-Jun-2013
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include "map/bncmapwin.h"
42#include "bncsettings.h"
43#include "bncutils.h"
44
45// Constructor
46////////////////////////////////////////////////////////////////////////////
47bncMapWin::bncMapWin(QWidget* parent) : QDialog(parent) {
48
49 const int ww = QFontMetrics(font()).width('w');
50
51 setWindowTitle("BNC: Map View");
52
53 // Current Coordinates
54 // -------------------
55 _currLat = 50.09057949; // BKG latitude
56 _currLon = 8.66496871; // BKG longitude
57
58 _webView = new QWebView(this);
59 connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(slotInitMap(bool)));
60
61 // Plot Required Station
62 // ---------------------
63 bncSettings settings;
64 _staID = settings.value("PPP/plotCoordinates").toByteArray();
65
66 // Proxy Settings
67 // --------------
68 QString proxyHost = settings.value("proxyHost").toString();
69 int proxyPort = settings.value("proxyPort").toInt();
70 if (!proxyHost.isEmpty()) {
71 QNetworkProxy proxy(QNetworkProxy::HttpProxy, proxyHost, proxyPort);
72 _webView->page()->networkAccessManager()->setProxy(proxy);
73 }
74
75 loadHtmlPage();
76
77 _webView->show();
78
79 _statusLabel = new QLabel;
80
81 // Layout
82 // ------
83 QHBoxLayout* statusLayout = new QHBoxLayout;
84 statusLayout->addWidget(_statusLabel);
85
86 QVBoxLayout* mainLayout = new QVBoxLayout(this);
87 mainLayout->addWidget(_webView);
88 mainLayout->addLayout(statusLayout);
89
90 setLayout(mainLayout);
91 resize(60*ww, 60*ww);
92
93 show();
94}
95
96// Destructor
97////////////////////////////////////////////////////////////////////////////
98bncMapWin::~bncMapWin() {
99}
100
101//
102////////////////////////////////////////////////////////////////////////////
103void bncMapWin::loadHtmlPage() {
104
105 bncSettings settings;
106
107 QFile htmlFile;
108 if (settings.value("PPP/useOpenStreetMap").toBool()) {
109 htmlFile.setFileName(":/map/map_osm.html");
110 }
111 else {
112 htmlFile.setFileName(":/map/map_gm.html");
113 }
114 if (!htmlFile.open(QFile::ReadOnly)) {
115 qDebug() << "bncMapWin:: cannot open html file";
116 return;
117 }
118
119 QTextStream stream(&htmlFile);
120 QString html = stream.readAll();
121
122 _webView->setHtml(html);
123}
124
125//
126////////////////////////////////////////////////////////////////////////////
127void bncMapWin::slotInitMap(bool isOk) {
128 if (!isOk) {
129 return;
130 }
131 bncSettings settings;
132 int mapWinDotSize = settings.value("PPP/mapWinDotSize").toInt();
133 int mapWinDotColor = 1;
134 if (settings.value("PPP/mapWinDotColor").toString() == "yellow") {
135 mapWinDotColor = 2;
136 }
137 QString location = QString("%1, %2, %3, %4").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8).arg(mapWinDotSize).arg(mapWinDotColor);
138 _webView->page()->mainFrame()->evaluateJavaScript(QString("initialize( %1 )").arg(location));
139}
140
141//
142////////////////////////////////////////////////////////////////////////////
143void bncMapWin::gotoLocation(double lat, double lon) {
144 _currLat = lat;
145 _currLon = lon;
146 //// beg test
147 // _currLat += 0.00001;
148 // _currLon += 0.00001;
149 //// end test
150
151 int latDeg, latMin;
152 double latSec;
153 deg2DMS(lat, latDeg, latMin, latSec);
154
155 int lonDeg, lonMin;
156 double lonSec;
157 deg2DMS(lon, lonDeg, lonMin, lonSec);
158
159 QString lblStr=QString("Latitude: %1 %2 %3 Longitude: %4 %5 %6")
160 .arg(latDeg).arg(latMin).arg(latSec,0,'f',4)
161 .arg(lonDeg).arg(lonMin).arg(lonSec,0,'f',4);
162 _statusLabel->setText(lblStr);
163
164 QString location = QString("%1, %2").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8);
165 _webView->page()->mainFrame()->evaluateJavaScript(QString("gotoLocation( %1 )").arg(location));
166}
167
168//
169////////////////////////////////////////////////////////////////////////////
170void bncMapWin::slotNewPosition(QByteArray staID, bncTime /* time */, QVector<double> xx) {
171 if (!_staID.isEmpty() && _staID != staID) {
172 return;
173 }
174 double ell[3];
175 xyz2ell(xx.data(), ell);
176 gotoLocation(ell[0]*180.0/M_PI, ell[1]*180.0/M_PI);
177}
178
179// Close Dialog gracefully
180////////////////////////////////////////////////////////////////////////////
181void bncMapWin::closeEvent(QCloseEvent* event) {
182 emit mapClosed();
183 QDialog::closeEvent(event);
184}
Note: See TracBrowser for help on using the repository browser.