source: ntrip/trunk/BNC/src/map/bncmapwin.cpp@ 6292

Last change on this file since 6292 was 5956, checked in by mervart, 10 years ago
File size: 5.2 KB
RevLine 
[5161]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 *
[5188]31 * Purpose: Displays the Google Map
[5161]32 *
33 * Author: L. Mervart
34 *
35 * Created: 08-Jun-2013
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include "map/bncmapwin.h"
[5232]42#include "bncsettings.h"
[5188]43#include "bncutils.h"
[5161]44
45// Constructor
46////////////////////////////////////////////////////////////////////////////
47bncMapWin::bncMapWin(QWidget* parent) : QDialog(parent) {
48
49 const int ww = QFontMetrics(font()).width('w');
50
[5180]51 setWindowTitle("BNC: Map View");
[5161]52
[5229]53 // Current Coordinates
54 // -------------------
55 _currLat = 50.09057949; // BKG latitude
56 _currLon = 8.66496871; // BKG longitude
[5180]57
[5161]58 _webView = new QWebView(this);
[5167]59 connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(slotInitMap(bool)));
60
[5269]61 // Proxy Settings
62 // --------------
63 bncSettings settings;
64 QString proxyHost = settings.value("proxyHost").toString();
65 int proxyPort = settings.value("proxyPort").toInt();
66 if (!proxyHost.isEmpty()) {
67 QNetworkProxy proxy(QNetworkProxy::HttpProxy, proxyHost, proxyPort);
68 _webView->page()->networkAccessManager()->setProxy(proxy);
69 }
70
[5166]71 loadHtmlPage();
72
[5161]73 _webView->show();
74
[5228]75 _statusLabel = new QLabel;
[5161]76
[5180]77 // Layout
78 // ------
[5228]79 QHBoxLayout* statusLayout = new QHBoxLayout;
80 statusLayout->addWidget(_statusLabel);
81
[5180]82 QVBoxLayout* mainLayout = new QVBoxLayout(this);
83 mainLayout->addWidget(_webView);
[5228]84 mainLayout->addLayout(statusLayout);
[5180]85
86 setLayout(mainLayout);
[5161]87 resize(60*ww, 60*ww);
[5180]88
[5161]89 show();
90}
91
92// Destructor
93////////////////////////////////////////////////////////////////////////////
94bncMapWin::~bncMapWin() {
95}
96
[5166]97//
98////////////////////////////////////////////////////////////////////////////
99void bncMapWin::loadHtmlPage() {
100
[5232]101 bncSettings settings;
102
103 QFile htmlFile;
[5956]104 if (settings.value("PPP/useOpenStreetMap").toBool()) {
[5232]105 htmlFile.setFileName(":/map/map_osm.html");
106 }
107 else {
108 htmlFile.setFileName(":/map/map_gm.html");
109 }
[5166]110 if (!htmlFile.open(QFile::ReadOnly)) {
[5213]111 qDebug() << "bncMapWin:: cannot open html file";
[5166]112 return;
113 }
114
115 QTextStream stream(&htmlFile);
116 QString html = stream.readAll();
117
118 _webView->setHtml(html);
119}
120
[5167]121//
122////////////////////////////////////////////////////////////////////////////
123void bncMapWin::slotInitMap(bool isOk) {
124 if (!isOk) {
125 return;
126 }
[5246]127 bncSettings settings;
[5956]128 int mapWinDotSize = settings.value("PPP/mapWinDotSize").toInt();
[5305]129 int mapWinDotColor = 1;
[5956]130 if (settings.value("PPP/mapWinDotColor").toString() == "yellow") {
[5305]131 mapWinDotColor = 2;
132 }
133 QString location = QString("%1, %2, %3, %4").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8).arg(mapWinDotSize).arg(mapWinDotColor);
[5167]134 _webView->page()->mainFrame()->evaluateJavaScript(QString("initialize( %1 )").arg(location));
[5177]135}
[5175]136
[5177]137//
138////////////////////////////////////////////////////////////////////////////
[5187]139void bncMapWin::gotoLocation(double lat, double lon) {
[5180]140 _currLat = lat;
141 _currLon = lon;
[5253]142 //// beg test
143 // _currLat += 0.00001;
144 // _currLon += 0.00001;
145 //// end test
[5230]146
147 int latDeg, latMin;
148 double latSec;
149 deg2DMS(lat, latDeg, latMin, latSec);
150
151 int lonDeg, lonMin;
152 double lonSec;
153 deg2DMS(lon, lonDeg, lonMin, lonSec);
154
155 QString lblStr=QString("Latitude: %1 %2 %3 Longitude: %4 %5 %6")
[5231]156 .arg(latDeg).arg(latMin).arg(latSec,0,'f',4)
157 .arg(lonDeg).arg(lonMin).arg(lonSec,0,'f',4);
[5230]158 _statusLabel->setText(lblStr);
159
[5177]160 QString location = QString("%1, %2").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8);
161 _webView->page()->mainFrame()->evaluateJavaScript(QString("gotoLocation( %1 )").arg(location));
[5180]162}
163
164//
165////////////////////////////////////////////////////////////////////////////
[5954]166void bncMapWin::slotNewPosition(QByteArray /* staID */, bncTime /* time */, QVector<double> xx) {
[5188]167 double ell[3];
[5879]168 xyz2ell(xx.data(), ell);
[5188]169 gotoLocation(ell[0]*180.0/M_PI, ell[1]*180.0/M_PI);
[5187]170}
[5234]171
172// Close Dialog gracefully
173////////////////////////////////////////////////////////////////////////////
174void bncMapWin::closeEvent(QCloseEvent* event) {
175 emit mapClosed();
176 QDialog::closeEvent(event);
177}
Note: See TracBrowser for help on using the repository browser.