[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 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 47 | bncMapWin::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 |
|
---|
[5321] | 61 | MyWebPage* webPage = new MyWebPage();
|
---|
| 62 | _webView->setPage(webPage);
|
---|
| 63 |
|
---|
[5269] | 64 | // Proxy Settings
|
---|
| 65 | // --------------
|
---|
| 66 | bncSettings settings;
|
---|
| 67 | QString proxyHost = settings.value("proxyHost").toString();
|
---|
| 68 | int proxyPort = settings.value("proxyPort").toInt();
|
---|
| 69 | if (!proxyHost.isEmpty()) {
|
---|
| 70 | QNetworkProxy proxy(QNetworkProxy::HttpProxy, proxyHost, proxyPort);
|
---|
| 71 | _webView->page()->networkAccessManager()->setProxy(proxy);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[5166] | 74 | loadHtmlPage();
|
---|
| 75 |
|
---|
[5161] | 76 | _webView->show();
|
---|
| 77 |
|
---|
[5228] | 78 | _statusLabel = new QLabel;
|
---|
[5161] | 79 |
|
---|
[5180] | 80 | // Layout
|
---|
| 81 | // ------
|
---|
[5228] | 82 | QHBoxLayout* statusLayout = new QHBoxLayout;
|
---|
| 83 | statusLayout->addWidget(_statusLabel);
|
---|
| 84 |
|
---|
[5180] | 85 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
| 86 | mainLayout->addWidget(_webView);
|
---|
[5228] | 87 | mainLayout->addLayout(statusLayout);
|
---|
[5180] | 88 |
|
---|
| 89 | setLayout(mainLayout);
|
---|
[5161] | 90 | resize(60*ww, 60*ww);
|
---|
[5180] | 91 |
|
---|
[5161] | 92 | show();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | // Destructor
|
---|
| 96 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 97 | bncMapWin::~bncMapWin() {
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[5166] | 100 | //
|
---|
| 101 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 102 | void bncMapWin::loadHtmlPage() {
|
---|
| 103 |
|
---|
[5232] | 104 | bncSettings settings;
|
---|
| 105 |
|
---|
| 106 | QFile htmlFile;
|
---|
| 107 | if (settings.value("useOsmMap").toBool()) {
|
---|
| 108 | htmlFile.setFileName(":/map/map_osm.html");
|
---|
| 109 | }
|
---|
| 110 | else {
|
---|
| 111 | htmlFile.setFileName(":/map/map_gm.html");
|
---|
| 112 | }
|
---|
[5166] | 113 | if (!htmlFile.open(QFile::ReadOnly)) {
|
---|
[5213] | 114 | qDebug() << "bncMapWin:: cannot open html file";
|
---|
[5166] | 115 | return;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | QTextStream stream(&htmlFile);
|
---|
| 119 | QString html = stream.readAll();
|
---|
| 120 |
|
---|
| 121 | _webView->setHtml(html);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[5167] | 124 | //
|
---|
| 125 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 126 | void bncMapWin::slotInitMap(bool isOk) {
|
---|
| 127 | if (!isOk) {
|
---|
| 128 | return;
|
---|
| 129 | }
|
---|
[5246] | 130 | bncSettings settings;
|
---|
[5296] | 131 | int mapWinDotSize = settings.value("mapWinDotSize").toInt();
|
---|
[5305] | 132 | int mapWinDotColor = 1;
|
---|
| 133 | if (settings.value("mapWinDotColor").toString() == "yellow") {
|
---|
| 134 | mapWinDotColor = 2;
|
---|
| 135 | }
|
---|
| 136 | QString location = QString("%1, %2, %3, %4").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8).arg(mapWinDotSize).arg(mapWinDotColor);
|
---|
[5167] | 137 | _webView->page()->mainFrame()->evaluateJavaScript(QString("initialize( %1 )").arg(location));
|
---|
[5177] | 138 | }
|
---|
[5175] | 139 |
|
---|
[5177] | 140 | //
|
---|
| 141 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5187] | 142 | void bncMapWin::gotoLocation(double lat, double lon) {
|
---|
[5180] | 143 | _currLat = lat;
|
---|
| 144 | _currLon = lon;
|
---|
[5253] | 145 | //// beg test
|
---|
| 146 | // _currLat += 0.00001;
|
---|
| 147 | // _currLon += 0.00001;
|
---|
| 148 | //// end test
|
---|
[5230] | 149 |
|
---|
| 150 | int latDeg, latMin;
|
---|
| 151 | double latSec;
|
---|
| 152 | deg2DMS(lat, latDeg, latMin, latSec);
|
---|
| 153 |
|
---|
| 154 | int lonDeg, lonMin;
|
---|
| 155 | double lonSec;
|
---|
| 156 | deg2DMS(lon, lonDeg, lonMin, lonSec);
|
---|
| 157 |
|
---|
| 158 | QString lblStr=QString("Latitude: %1 %2 %3 Longitude: %4 %5 %6")
|
---|
[5231] | 159 | .arg(latDeg).arg(latMin).arg(latSec,0,'f',4)
|
---|
| 160 | .arg(lonDeg).arg(lonMin).arg(lonSec,0,'f',4);
|
---|
[5230] | 161 | _statusLabel->setText(lblStr);
|
---|
| 162 |
|
---|
[5177] | 163 | QString location = QString("%1, %2").arg(_currLat,0,'f',8).arg(_currLon,0,'f',8);
|
---|
| 164 | _webView->page()->mainFrame()->evaluateJavaScript(QString("gotoLocation( %1 )").arg(location));
|
---|
[5180] | 165 | }
|
---|
| 166 |
|
---|
| 167 | //
|
---|
| 168 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5188] | 169 | void bncMapWin::slotNewPosition(bncTime /* time */, double xx, double yy, double zz) {
|
---|
| 170 | double xyz[3];
|
---|
| 171 | xyz[0] = xx;
|
---|
| 172 | xyz[1] = yy;
|
---|
| 173 | xyz[2] = zz;
|
---|
| 174 | double ell[3];
|
---|
| 175 | xyz2ell(xyz, ell);
|
---|
| 176 | gotoLocation(ell[0]*180.0/M_PI, ell[1]*180.0/M_PI);
|
---|
[5187] | 177 | }
|
---|
[5234] | 178 |
|
---|
| 179 | // Close Dialog gracefully
|
---|
| 180 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 181 | void bncMapWin::closeEvent(QCloseEvent* event) {
|
---|
| 182 | emit mapClosed();
|
---|
| 183 | QDialog::closeEvent(event);
|
---|
| 184 | }
|
---|