Commit d058acae authored by dogmaphobic's avatar dogmaphobic

Handle proper current google map version.

Added Bing Hybrid Map
Added Open Street Map
Set map selection menu checks (exclusive check)
Handle proper image type otherwise disk caching fails
parent 86f9a219
......@@ -93,7 +93,7 @@ ProviderStrings::ProviderStrings()
UrlFactory::UrlFactory()
: _isCorrectedGoogleVersions(false)
, _correctGoogleVersions(false)
, _correctGoogleVersions(true)
, _timeout(5 * 1000)
{
Proxy.setType(QNetworkProxy::NoProxy);
......@@ -177,9 +177,9 @@ void UrlFactory::_tryCorrectGoogleVersions()
reg = QRegExp("\"*https://khms0.google.com/kh/v=(\\d*)", Qt::CaseInsensitive);
if (reg.indexIn(html) != -1) {
QStringList gc = reg.capturedTexts();
VersionGoogleSatellite = gc[1];
VersionGoogleSatellite = "s@" + gc[1];
VersionGoogleSatelliteKorea = VersionGoogleSatellite;
VersionGoogleSatelliteChina = "s@" + VersionGoogleSatellite;
VersionGoogleSatelliteChina = VersionGoogleSatellite;
}
reg = QRegExp("\"*https://mts0.google.com/vt/lyrs=t@(\\d*),r@(\\d*)", Qt::CaseInsensitive);
if (reg.indexIn(html) != -1) {
......
......@@ -91,25 +91,36 @@ void QGeoMapReplyQGC::networkReplyFinished()
if (m_reply->error() != QNetworkReply::NoError)
return;
// qDebug() << "Map OK: " << m_reply->url().toString();
QByteArray a = m_reply->readAll();
setMapImageData(a);
switch ((OpenPilot::MapType)tileSpec().mapId()) {
case OpenPilot::GoogleMap:
case OpenPilot::GoogleSatellite:
case OpenPilot::GoogleLabels:
case OpenPilot::GoogleTerrain:
case OpenPilot::GoogleHybrid:
case OpenPilot::BingMap:
if(a.size() > 2)
{
if((char)a[0] == (char)0xff && (char)a[1] == (char)0xd8)
setMapImageFormat("jpg");
else if((char)a[0] == (char)0x89 && (char)a[1] == (char)0x50)
setMapImageFormat("png");
break;
case OpenPilot::BingSatellite:
setMapImageFormat("jpeg");
break;
default:
qWarning("Unknown map id %d", tileSpec().mapId());
break;
else
{
switch ((OpenPilot::MapType)tileSpec().mapId()) {
case OpenPilot::GoogleMap:
case OpenPilot::GoogleLabels:
case OpenPilot::GoogleTerrain:
case OpenPilot::GoogleHybrid:
case OpenPilot::BingMap:
case OpenPilot::OpenStreetMap:
setMapImageFormat("png");
break;
case OpenPilot::GoogleSatellite:
case OpenPilot::BingSatellite:
case OpenPilot::BingHybrid:
setMapImageFormat("jpg");
break;
default:
qWarning("Unknown map id %d", tileSpec().mapId());
break;
}
}
}
setFinished(true);
......@@ -122,8 +133,6 @@ void QGeoMapReplyQGC::networkReplyError(QNetworkReply::NetworkError error)
if (!m_reply)
return;
// qDebug() << "Map error: " << m_reply->url().toString();
if (error != QNetworkReply::OperationCanceledError)
setError(QGeoTiledMapReply::CommunicationError, m_reply->errorString());
......
......@@ -76,6 +76,8 @@ QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVarian
// Bing
mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Bing Street Map"), tr("Bing street map"), false, false, OpenPilot::BingMap);
mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Bing Satellite Map"), tr("Bing satellite map"), false, false, OpenPilot::BingSatellite);
mapTypes << QGeoMapType(QGeoMapType::HybridMap, tr("Bing Hybrid Map"), tr("Bing hybrid map"), false, false, OpenPilot::BingHybrid);
mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Open Street Map"), tr("Open Street map"), false, false, OpenPilot::OpenStreetMap);
setSupportedMapTypes(mapTypes);
QGeoTileFetcherQGC *tileFetcher = new QGeoTileFetcherQGC(this);
......
......@@ -75,8 +75,6 @@ QGeoTiledMapReply *QGeoTileFetcherQGC::getTileImage(const QGeoTileSpec &spec)
QNetworkRequest request;
QString url = m_UrlFactory.makeImageUrl((OpenPilot::MapType)spec.mapId(), QPoint(spec.x(), spec.y()), spec.zoom(), m_Language);
// qDebug() << "Request x" << spec.x() << "y" << spec.y() << "URL:" << url;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", m_userAgent);
request.setRawHeader("Accept", "*/*");
......
......@@ -214,6 +214,7 @@ Rectangle {
Menu {
id: mapTypeMenu
title: "Map Type..."
ExclusiveGroup { id: currentMapType }
function setCurrentMap(map) {
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
if (map === mapBackground.mapItem.supportedMapTypes[i].name) {
......@@ -223,20 +224,24 @@ Rectangle {
}
}
}
function addMap(map) {
function addMap(map, checked) {
var mItem = mapTypeMenu.addItem(map);
mItem.checkable = true
mItem.checked = checked
mItem.exclusiveGroup = currentMapType
var menuSlot = function() {setCurrentMap(map);};
mItem.triggered.connect(menuSlot);
}
function update() {
clear()
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
addMap(mapBackground.mapItem.supportedMapTypes[i].name);
}
var map = ''
if (mapBackground.mapItem.supportedMapTypes.length > 0)
map = mapBackground.mapItem.activeMapType.name;
map = flightDisplay.loadSetting("currentMapType", map);
for (var i = 0; i < mapBackground.mapItem.supportedMapTypes.length; i++) {
var name = mapBackground.mapItem.supportedMapTypes[i].name;
addMap(name, map === name);
}
if(map != '')
setCurrentMap(map);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment