mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-19 09:54:15 +01:00
OP37/GCS MapLib - Various fixes to improve stability, created diagnostics screen available from maps context menu.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2674 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
12cdec0ae7
commit
8c5fe506b3
@ -15,7 +15,8 @@ SOURCES += opmaps.cpp \
|
||||
placemark.cpp \
|
||||
point.cpp \
|
||||
size.cpp \
|
||||
kibertilecache.cpp
|
||||
kibertilecache.cpp \
|
||||
diagnostics.cpp
|
||||
HEADERS += opmaps.h \
|
||||
size.h \
|
||||
maptype.h \
|
||||
@ -35,4 +36,5 @@ HEADERS += opmaps.h \
|
||||
placemark.h \
|
||||
point.h \
|
||||
kibertilecache.h \
|
||||
debugheader.h
|
||||
debugheader.h \
|
||||
diagnostics.h
|
||||
|
@ -0,0 +1,31 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file diagnostics.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "diagnostics.h"
|
||||
|
||||
diagnostics::diagnostics():networkerrors(0),emptytiles(0),timeouts(0),runningThreads(0)
|
||||
{
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file diagnostics.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef DIAGNOSTICS_H
|
||||
#define DIAGNOSTICS_H
|
||||
#include <QString>
|
||||
struct diagnostics
|
||||
{
|
||||
diagnostics();
|
||||
int networkerrors;
|
||||
int emptytiles;
|
||||
int timeouts;
|
||||
int runningThreads;
|
||||
QString toString()
|
||||
{
|
||||
return QString("Network errors:%1\nEmpty Tiles:%2\nTimeOuts:%3\nRunningThreads:%4").arg(networkerrors).arg(emptytiles).arg(timeouts).arg(runningThreads);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // DIAGNOSTICS_H
|
@ -1,250 +1,274 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file OPMaps.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "opmaps.h"
|
||||
|
||||
|
||||
namespace core {
|
||||
OPMaps* OPMaps::m_pInstance=0;
|
||||
|
||||
OPMaps* OPMaps::Instance()
|
||||
{
|
||||
if(!m_pInstance)
|
||||
m_pInstance=new OPMaps;
|
||||
return m_pInstance;
|
||||
}
|
||||
OPMaps::OPMaps():RetryLoadTile(2),useMemoryCache(true)
|
||||
{
|
||||
accessmode=AccessMode::ServerAndCache;
|
||||
Language=LanguageType::PortuguesePortugal;
|
||||
LanguageStr=LanguageType().toShortString(Language);
|
||||
Cache::Instance();
|
||||
|
||||
}
|
||||
|
||||
|
||||
OPMaps::~OPMaps()
|
||||
{
|
||||
TileDBcacheQueue.wait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QByteArray OPMaps::GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom)
|
||||
{
|
||||
#ifdef DEBUG_TIMINGS
|
||||
QTime time;
|
||||
time.restart();
|
||||
#endif
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Entered GetImageFrom";
|
||||
#endif //DEBUG_GMAPS
|
||||
QByteArray ret;
|
||||
|
||||
if(useMemoryCache)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Try Tile from memory:Size="<<TilesInMemory.MemoryCacheSize();
|
||||
#endif //DEBUG_GMAPS
|
||||
ret=GetTileFromMemoryCache(RawTile(type,pos,zoom));
|
||||
|
||||
}
|
||||
if(ret.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Tile not in memory";
|
||||
#endif //DEBUG_GMAPS
|
||||
if(accessmode != (AccessMode::ServerOnly))
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Try tile from DataBase";
|
||||
#endif //DEBUG_GMAPS
|
||||
ret=Cache::Instance()->ImageCache.GetImageFromCache(type,pos,zoom);
|
||||
if(!ret.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Tile found in Database";
|
||||
#endif //DEBUG_GMAPS
|
||||
if(useMemoryCache)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Add Tile to memory";
|
||||
#endif //DEBUG_GMAPS
|
||||
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if(accessmode!=AccessMode::CacheOnly)
|
||||
{
|
||||
QEventLoop q;
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
QTimer tT;
|
||||
tT.setSingleShot(true);
|
||||
connect(&network, SIGNAL(finished(QNetworkReply*)),
|
||||
&q, SLOT(quit()));
|
||||
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
|
||||
network.setProxy(Proxy);
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Try Tile from the Internet";
|
||||
#endif //DEBUG_GMAPS
|
||||
#ifdef DEBUG_TIMINGS
|
||||
qDebug()<<"opmaps before make image url"<<time.elapsed();
|
||||
#endif
|
||||
QString url=MakeImageUrl(type,pos,zoom,LanguageStr);
|
||||
#ifdef DEBUG_TIMINGS
|
||||
qDebug()<<"opmaps after make image url"<<time.elapsed();
|
||||
#endif //url "http://vec02.maps.yandex.ru/tiles?l=map&v=2.10.2&x=7&y=5&z=3" string
|
||||
//"http://map3.pergo.com.tr/tile/02/000/000/007/000/000/002.png"
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
qheader.setRawHeader("Accept","*/*");
|
||||
switch(type)
|
||||
{
|
||||
case MapType::GoogleMap:
|
||||
case MapType::GoogleSatellite:
|
||||
case MapType::GoogleLabels:
|
||||
case MapType::GoogleTerrain:
|
||||
case MapType::GoogleHybrid:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://maps.google.com/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::GoogleMapChina:
|
||||
case MapType::GoogleSatelliteChina:
|
||||
case MapType::GoogleLabelsChina:
|
||||
case MapType::GoogleTerrainChina:
|
||||
case MapType::GoogleHybridChina:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://ditu.google.cn/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::BingHybrid:
|
||||
case MapType::BingMap:
|
||||
case MapType::BingSatellite:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.bing.com/maps/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YahooHybrid:
|
||||
case MapType::YahooLabels:
|
||||
case MapType::YahooMap:
|
||||
case MapType::YahooSatellite:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://maps.yahoo.com/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::ArcGIS_MapsLT_Map_Labels:
|
||||
case MapType::ArcGIS_MapsLT_Map:
|
||||
case MapType::ArcGIS_MapsLT_OrtoFoto:
|
||||
case MapType::ArcGIS_MapsLT_Map_Hybrid:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.maps.lt/map_beta/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::OpenStreetMapSurfer:
|
||||
case MapType::OpenStreetMapSurferTerrain:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.mapsurfer.net/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::OpenStreetMap:
|
||||
case MapType::OpenStreetOsm:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.openstreetmap.org/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YandexMapRu:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://maps.yandex.ru/");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
reply=network.get(qheader);
|
||||
tT.start(Timeout);
|
||||
q.exec();
|
||||
|
||||
if(!tT.isActive()){
|
||||
return ret;
|
||||
}
|
||||
tT.stop();
|
||||
ret=reply->readAll();
|
||||
reply->deleteLater();//TODO can't this be global??
|
||||
if(ret.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Invalid Tile";
|
||||
#endif //DEBUG_GMAPS
|
||||
return ret;
|
||||
}
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Received Tile from the Internet";
|
||||
#endif //DEBUG_GMAPS
|
||||
if (useMemoryCache)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Add Tile to memory cache";
|
||||
#endif //DEBUG_GMAPS
|
||||
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
|
||||
}
|
||||
if(accessmode!=AccessMode::ServerOnly)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Add tile to DataBase";
|
||||
#endif //DEBUG_GMAPS
|
||||
CacheItemQueue * item=new CacheItemQueue(type,pos,ret,zoom);
|
||||
TileDBcacheQueue.EnqueueCacheTask(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Entered GetImageFrom";
|
||||
#endif //DEBUG_GMAPS
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool OPMaps::ExportToGMDB(const QString &file)
|
||||
{
|
||||
return Cache::Instance()->ImageCache.ExportMapDataToDB(Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb",file);
|
||||
}
|
||||
bool OPMaps::ImportFromGMDB(const QString &file)
|
||||
{
|
||||
return Cache::Instance()->ImageCache.ExportMapDataToDB(file,Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb");
|
||||
}
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file OPMaps.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "opmaps.h"
|
||||
|
||||
|
||||
namespace core {
|
||||
OPMaps* OPMaps::m_pInstance=0;
|
||||
|
||||
OPMaps* OPMaps::Instance()
|
||||
{
|
||||
if(!m_pInstance)
|
||||
m_pInstance=new OPMaps;
|
||||
return m_pInstance;
|
||||
}
|
||||
OPMaps::OPMaps():RetryLoadTile(2),useMemoryCache(true)
|
||||
{
|
||||
accessmode=AccessMode::ServerAndCache;
|
||||
Language=LanguageType::PortuguesePortugal;
|
||||
LanguageStr=LanguageType().toShortString(Language);
|
||||
Cache::Instance();
|
||||
|
||||
}
|
||||
|
||||
|
||||
OPMaps::~OPMaps()
|
||||
{
|
||||
TileDBcacheQueue.wait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QByteArray OPMaps::GetImageFrom(const MapType::Types &type,const Point &pos,const int &zoom)
|
||||
{
|
||||
#ifdef DEBUG_TIMINGS
|
||||
QTime time;
|
||||
time.restart();
|
||||
#endif
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Entered GetImageFrom";
|
||||
#endif //DEBUG_GMAPS
|
||||
QByteArray ret;
|
||||
|
||||
if(useMemoryCache)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Try Tile from memory:Size="<<TilesInMemory.MemoryCacheSize();
|
||||
#endif //DEBUG_GMAPS
|
||||
ret=GetTileFromMemoryCache(RawTile(type,pos,zoom));
|
||||
|
||||
}
|
||||
if(ret.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Tile not in memory";
|
||||
#endif //DEBUG_GMAPS
|
||||
if(accessmode != (AccessMode::ServerOnly))
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Try tile from DataBase";
|
||||
#endif //DEBUG_GMAPS
|
||||
ret=Cache::Instance()->ImageCache.GetImageFromCache(type,pos,zoom);
|
||||
if(!ret.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Tile found in Database";
|
||||
#endif //DEBUG_GMAPS
|
||||
if(useMemoryCache)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Add Tile to memory";
|
||||
#endif //DEBUG_GMAPS
|
||||
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
if(accessmode!=AccessMode::CacheOnly)
|
||||
{
|
||||
QEventLoop q;
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
QTimer tT;
|
||||
tT.setSingleShot(true);
|
||||
connect(&network, SIGNAL(finished(QNetworkReply*)),
|
||||
&q, SLOT(quit()));
|
||||
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
|
||||
network.setProxy(Proxy);
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Try Tile from the Internet";
|
||||
#endif //DEBUG_GMAPS
|
||||
#ifdef DEBUG_TIMINGS
|
||||
qDebug()<<"opmaps before make image url"<<time.elapsed();
|
||||
#endif
|
||||
QString url=MakeImageUrl(type,pos,zoom,LanguageStr);
|
||||
#ifdef DEBUG_TIMINGS
|
||||
qDebug()<<"opmaps after make image url"<<time.elapsed();
|
||||
#endif //url "http://vec02.maps.yandex.ru/tiles?l=map&v=2.10.2&x=7&y=5&z=3" string
|
||||
//"http://map3.pergo.com.tr/tile/02/000/000/007/000/000/002.png"
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
qheader.setRawHeader("Accept","*/*");
|
||||
switch(type)
|
||||
{
|
||||
case MapType::GoogleMap:
|
||||
case MapType::GoogleSatellite:
|
||||
case MapType::GoogleLabels:
|
||||
case MapType::GoogleTerrain:
|
||||
case MapType::GoogleHybrid:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://maps.google.com/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::GoogleMapChina:
|
||||
case MapType::GoogleSatelliteChina:
|
||||
case MapType::GoogleLabelsChina:
|
||||
case MapType::GoogleTerrainChina:
|
||||
case MapType::GoogleHybridChina:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://ditu.google.cn/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::BingHybrid:
|
||||
case MapType::BingMap:
|
||||
case MapType::BingSatellite:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.bing.com/maps/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YahooHybrid:
|
||||
case MapType::YahooLabels:
|
||||
case MapType::YahooMap:
|
||||
case MapType::YahooSatellite:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://maps.yahoo.com/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::ArcGIS_MapsLT_Map_Labels:
|
||||
case MapType::ArcGIS_MapsLT_Map:
|
||||
case MapType::ArcGIS_MapsLT_OrtoFoto:
|
||||
case MapType::ArcGIS_MapsLT_Map_Hybrid:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.maps.lt/map_beta/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::OpenStreetMapSurfer:
|
||||
case MapType::OpenStreetMapSurferTerrain:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.mapsurfer.net/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::OpenStreetMap:
|
||||
case MapType::OpenStreetOsm:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://www.openstreetmap.org/");
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YandexMapRu:
|
||||
{
|
||||
qheader.setRawHeader("Referrer", "http://maps.yandex.ru/");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
reply=network.get(qheader);
|
||||
tT.start(Timeout);
|
||||
q.exec();
|
||||
|
||||
if(!tT.isActive()){
|
||||
errorvars.lock();
|
||||
++diag.timeouts;
|
||||
errorvars.unlock();
|
||||
return ret;
|
||||
}
|
||||
tT.stop();
|
||||
if( (reply->error()!=QNetworkReply::NoError))
|
||||
{
|
||||
errorvars.lock();
|
||||
++diag.networkerrors;
|
||||
errorvars.unlock();
|
||||
reply->deleteLater();
|
||||
return ret;
|
||||
}
|
||||
ret=reply->readAll();
|
||||
reply->deleteLater();//TODO can't this be global??
|
||||
if(ret.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Invalid Tile";
|
||||
#endif //DEBUG_GMAPS
|
||||
errorvars.lock();
|
||||
++diag.emptytiles;
|
||||
errorvars.unlock();
|
||||
return ret;
|
||||
}
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Received Tile from the Internet";
|
||||
#endif //DEBUG_GMAPS
|
||||
if (useMemoryCache)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Add Tile to memory cache";
|
||||
#endif //DEBUG_GMAPS
|
||||
AddTileToMemoryCache(RawTile(type,pos,zoom),ret);
|
||||
}
|
||||
if(accessmode!=AccessMode::ServerOnly)
|
||||
{
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Add tile to DataBase";
|
||||
#endif //DEBUG_GMAPS
|
||||
CacheItemQueue * item=new CacheItemQueue(type,pos,ret,zoom);
|
||||
TileDBcacheQueue.EnqueueCacheTask(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_GMAPS
|
||||
qDebug()<<"Entered GetImageFrom";
|
||||
#endif //DEBUG_GMAPS
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool OPMaps::ExportToGMDB(const QString &file)
|
||||
{
|
||||
return Cache::Instance()->ImageCache.ExportMapDataToDB(Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb",file);
|
||||
}
|
||||
bool OPMaps::ImportFromGMDB(const QString &file)
|
||||
{
|
||||
return Cache::Instance()->ImageCache.ExportMapDataToDB(file,Cache::Instance()->ImageCache.GtileCache()+QDir::separator()+"Data.qmdb");
|
||||
}
|
||||
|
||||
diagnostics OPMaps::GetDiagnostics()
|
||||
{
|
||||
diagnostics i;
|
||||
errorvars.lock();
|
||||
i=diag;
|
||||
errorvars.unlock();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,92 +1,94 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file OPMaps.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef OPMaps_H
|
||||
#define OPMaps_H
|
||||
|
||||
|
||||
#include "debugheader.h"
|
||||
#include "memorycache.h"
|
||||
#include "rawtile.h"
|
||||
#include "cache.h"
|
||||
#include "accessmode.h"
|
||||
#include "languagetype.h"
|
||||
#include "cacheitemqueue.h"
|
||||
#include "tilecachequeue.h"
|
||||
#include "pureimagecache.h"
|
||||
#include "alllayersoftype.h"
|
||||
#include "urlfactory.h"
|
||||
|
||||
//#include "point.h"
|
||||
|
||||
|
||||
namespace core {
|
||||
class OPMaps: public MemoryCache,public AllLayersOfType,public UrlFactory
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
~OPMaps();
|
||||
|
||||
static OPMaps* Instance();
|
||||
bool ImportFromGMDB(const QString &file);
|
||||
bool ExportToGMDB(const QString &file);
|
||||
/// <summary>
|
||||
/// timeout for map connections
|
||||
/// </summary>
|
||||
|
||||
|
||||
QByteArray GetImageFrom(const MapType::Types &type,const core::Point &pos,const int &zoom);
|
||||
bool UseMemoryCache(){return useMemoryCache;}//TODO
|
||||
void setUseMemoryCache(const bool& value){useMemoryCache=value;}
|
||||
void setLanguage(const LanguageType::Types& language){Language=language;}//TODO
|
||||
LanguageType::Types GetLanguage(){return Language;}//TODO
|
||||
AccessMode::Types GetAccessMode()const{return accessmode;}
|
||||
void setAccessMode(const AccessMode::Types& mode){accessmode=mode;}
|
||||
int RetryLoadTile;
|
||||
private:
|
||||
bool useMemoryCache;
|
||||
LanguageType::Types Language;
|
||||
AccessMode::Types accessmode;
|
||||
// PureImageCache ImageCacheLocal;//TODO Criar acesso Get Set
|
||||
TileCacheQueue TileDBcacheQueue;
|
||||
OPMaps();
|
||||
|
||||
OPMaps(OPMaps const&){}
|
||||
OPMaps& operator=(OPMaps const&){ return *this; }
|
||||
static OPMaps* m_pInstance;
|
||||
|
||||
|
||||
protected:
|
||||
// MemoryCache TilesInMemory;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // OPMaps_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file OPMaps.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef OPMaps_H
|
||||
#define OPMaps_H
|
||||
|
||||
|
||||
#include "debugheader.h"
|
||||
#include "memorycache.h"
|
||||
#include "rawtile.h"
|
||||
#include "cache.h"
|
||||
#include "accessmode.h"
|
||||
#include "languagetype.h"
|
||||
#include "cacheitemqueue.h"
|
||||
#include "tilecachequeue.h"
|
||||
#include "pureimagecache.h"
|
||||
#include "alllayersoftype.h"
|
||||
#include "urlfactory.h"
|
||||
#include "diagnostics.h"
|
||||
|
||||
//#include "point.h"
|
||||
|
||||
|
||||
namespace core {
|
||||
class OPMaps: public MemoryCache,public AllLayersOfType,public UrlFactory
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
~OPMaps();
|
||||
|
||||
static OPMaps* Instance();
|
||||
bool ImportFromGMDB(const QString &file);
|
||||
bool ExportToGMDB(const QString &file);
|
||||
/// <summary>
|
||||
/// timeout for map connections
|
||||
/// </summary>
|
||||
|
||||
|
||||
QByteArray GetImageFrom(const MapType::Types &type,const core::Point &pos,const int &zoom);
|
||||
bool UseMemoryCache(){return useMemoryCache;}//TODO
|
||||
void setUseMemoryCache(const bool& value){useMemoryCache=value;}
|
||||
void setLanguage(const LanguageType::Types& language){Language=language;}//TODO
|
||||
LanguageType::Types GetLanguage(){return Language;}//TODO
|
||||
AccessMode::Types GetAccessMode()const{return accessmode;}
|
||||
void setAccessMode(const AccessMode::Types& mode){accessmode=mode;}
|
||||
int RetryLoadTile;
|
||||
diagnostics GetDiagnostics();
|
||||
|
||||
private:
|
||||
bool useMemoryCache;
|
||||
LanguageType::Types Language;
|
||||
AccessMode::Types accessmode;
|
||||
// PureImageCache ImageCacheLocal;//TODO Criar acesso Get Set
|
||||
TileCacheQueue TileDBcacheQueue;
|
||||
OPMaps();
|
||||
OPMaps(OPMaps const&){}
|
||||
OPMaps& operator=(OPMaps const&){ return *this; }
|
||||
static OPMaps* m_pInstance;
|
||||
diagnostics diag;
|
||||
QMutex errorvars;
|
||||
protected:
|
||||
// MemoryCache TilesInMemory;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // OPMaps_H
|
||||
|
@ -194,6 +194,7 @@ namespace core {
|
||||
qlonglong id=++ConnCounter;
|
||||
Mcounter.unlock();
|
||||
{
|
||||
Mcounter.lock();
|
||||
QSqlDatabase cn;
|
||||
cn = QSqlDatabase::addDatabase("QSQLITE",QString::number(id));
|
||||
QString db=gtilecache+"Data.qmdb";
|
||||
@ -219,30 +220,30 @@ namespace core {
|
||||
}
|
||||
cn.close();
|
||||
}
|
||||
Mcounter.unlock();
|
||||
}
|
||||
QSqlDatabase::removeDatabase(QString::number(id));
|
||||
return true;
|
||||
}
|
||||
QByteArray PureImageCache::GetImageFromCache(MapType::Types type, Point pos, int zoom)
|
||||
{
|
||||
bool ret=true;
|
||||
QByteArray ar;
|
||||
QString dir=gtilecache;
|
||||
Mcounter.lock();
|
||||
qlonglong id=++ConnCounter;
|
||||
Mcounter.unlock();
|
||||
#ifdef DEBUG_PUREIMAGECACHE
|
||||
// qDebug()<<"Cache dir="<<dir<<" Try to GET:"<<pos.X()+","+pos.Y();
|
||||
qDebug()<<"Cache dir="<<dir<<" Try to GET:"<<pos.X()+","+pos.Y();
|
||||
#endif //DEBUG_PUREIMAGECACHE
|
||||
|
||||
{
|
||||
QString db=dir+"Data.qmdb";
|
||||
ret=QFileInfo(db).exists();
|
||||
if(ret)
|
||||
{
|
||||
Mcounter.lock();
|
||||
QSqlDatabase cn;
|
||||
|
||||
cn = QSqlDatabase::addDatabase("QSQLITE",QString::number(id));
|
||||
|
||||
cn.setDatabaseName(db);
|
||||
if(cn.open())
|
||||
{
|
||||
@ -252,15 +253,12 @@ namespace core {
|
||||
query.next();
|
||||
if(query.isValid())
|
||||
{
|
||||
|
||||
ar=query.value(0).toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
cn.close();
|
||||
}
|
||||
|
||||
|
||||
Mcounter.unlock();
|
||||
}
|
||||
}
|
||||
QSqlDatabase::removeDatabase(QString::number(id));
|
||||
|
@ -1,66 +1,66 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pureimagecache.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef PUREIMAGECACHE_H
|
||||
#define PUREIMAGECACHE_H
|
||||
|
||||
#include <QtSql/QSqlDatabase>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QtSql/QSqlQuery>
|
||||
#include <QtSql/QSqlError>
|
||||
#include <QBuffer>
|
||||
#include "maptype.h"
|
||||
#include "point.h"
|
||||
#include <QVariant>
|
||||
#include "pureimage.h"
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
|
||||
namespace core {
|
||||
class PureImageCache
|
||||
{
|
||||
|
||||
public:
|
||||
PureImageCache();
|
||||
static bool CreateEmptyDB(const QString &file);
|
||||
bool PutImageToCache(const QByteArray &tile,const MapType::Types &type,const core::Point &pos, const int &zoom);
|
||||
QByteArray GetImageFromCache(MapType::Types type, core::Point pos, int zoom);
|
||||
QString GtileCache();
|
||||
void setGtileCache(const QString &value);
|
||||
static bool ExportMapDataToDB(QString sourceFile, QString destFile);
|
||||
void deleteOlderTiles(int const& days);
|
||||
private:
|
||||
QString gtilecache;
|
||||
QMutex Mcounter;
|
||||
static qlonglong ConnCounter;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // PUREIMAGECACHE_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pureimagecache.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef PUREIMAGECACHE_H
|
||||
#define PUREIMAGECACHE_H
|
||||
|
||||
#include <QtSql/QSqlDatabase>
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QtSql/QSqlQuery>
|
||||
#include <QtSql/QSqlError>
|
||||
#include <QBuffer>
|
||||
#include "maptype.h"
|
||||
#include "point.h"
|
||||
#include <QVariant>
|
||||
#include "pureimage.h"
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
|
||||
namespace core {
|
||||
class PureImageCache
|
||||
{
|
||||
|
||||
public:
|
||||
PureImageCache();
|
||||
static bool CreateEmptyDB(const QString &file);
|
||||
bool PutImageToCache(const QByteArray &tile,const MapType::Types &type,const core::Point &pos, const int &zoom);
|
||||
QByteArray GetImageFromCache(MapType::Types type, core::Point pos, int zoom);
|
||||
QString GtileCache();
|
||||
void setGtileCache(const QString &value);
|
||||
static bool ExportMapDataToDB(QString sourceFile, QString destFile);
|
||||
void deleteOlderTiles(int const& days);
|
||||
private:
|
||||
QString gtilecache;
|
||||
QMutex Mcounter;
|
||||
static qlonglong ConnCounter;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // PUREIMAGECACHE_H
|
||||
|
@ -1,695 +1,694 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file urlfactory.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "urlfactory.h"
|
||||
#include <QRegExp>
|
||||
|
||||
namespace core {
|
||||
|
||||
const double UrlFactory::EarthRadiusKm = 6378.137; // WGS-84
|
||||
|
||||
UrlFactory::UrlFactory()
|
||||
{
|
||||
/// <summary>
|
||||
/// timeout for map connections
|
||||
/// </summary>
|
||||
|
||||
Proxy.setType(QNetworkProxy::NoProxy);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the User-agent HTTP header.
|
||||
/// </summary>
|
||||
UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7";
|
||||
|
||||
Timeout = 5 * 1000;
|
||||
CorrectGoogleVersions=true;
|
||||
isCorrectedGoogleVersions = false;
|
||||
UseGeocoderCache=true;
|
||||
UsePlacemarkCache=true;
|
||||
// timer.setSingleShot(true);
|
||||
|
||||
|
||||
}
|
||||
UrlFactory::~UrlFactory()
|
||||
{
|
||||
}
|
||||
QString UrlFactory::TileXYToQuadKey(const int &tileX,const int &tileY,const int &levelOfDetail) const
|
||||
{
|
||||
QString quadKey;
|
||||
for(int i = levelOfDetail; i > 0; i--)
|
||||
{
|
||||
char digit = '0';
|
||||
int mask = 1 << (i - 1);
|
||||
if((tileX & mask) != 0)
|
||||
{
|
||||
digit++;
|
||||
}
|
||||
if((tileY & mask) != 0)
|
||||
{
|
||||
digit++;
|
||||
digit++;
|
||||
}
|
||||
quadKey.append(digit);
|
||||
}
|
||||
return quadKey;
|
||||
}
|
||||
int UrlFactory::GetServerNum(const Point &pos,const int &max) const
|
||||
{
|
||||
return (pos.X() + 2 * pos.Y()) % max;
|
||||
}
|
||||
void UrlFactory::setIsCorrectGoogleVersions(bool value)
|
||||
{
|
||||
isCorrectedGoogleVersions=value;
|
||||
|
||||
}
|
||||
|
||||
bool UrlFactory::IsCorrectGoogleVersions()
|
||||
{
|
||||
return isCorrectedGoogleVersions;
|
||||
}
|
||||
|
||||
void UrlFactory::TryCorrectGoogleVersions()
|
||||
{
|
||||
if(CorrectGoogleVersions && !IsCorrectGoogleVersions())
|
||||
{
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
network.setProxy(Proxy);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Correct GoogleVersion";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
setIsCorrectGoogleVersions(true);
|
||||
QString url = "http://maps.google.com";
|
||||
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
reply=network.get(qheader);
|
||||
QTime time;
|
||||
time.start();
|
||||
while( (!(reply->isFinished()) || (time.elapsed()>(6*Timeout))) ){QCoreApplication::processEvents(QEventLoop::AllEvents);}
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Finished?"<<reply->error()<<" abort?"<<(time.elapsed()>Timeout*6);
|
||||
#endif //DEBUG_URLFACTORY
|
||||
if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6))
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Try corrected version network error:";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
return;
|
||||
}
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Try corrected version withou abort or error:"<<reply->errorString();
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QString html=QString(reply->readAll());
|
||||
QRegExp reg("\"*http://mt0.google.com/vt/lyrs=m@(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleMap = QString("m@%1").arg(gc[1]);
|
||||
VersionGoogleMapChina = VersionGoogleMap;
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleMap: "<<VersionGoogleMap;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
|
||||
reg=QRegExp("\"*http://mt0.google.com/vt/lyrs=h@(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleLabels = QString("h@%1").arg(gc[1]);
|
||||
VersionGoogleLabelsChina = VersionGoogleLabels;
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleLabels: "<<VersionGoogleLabels;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
reg=QRegExp("\"*http://khm0.google.com/kh/v=(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleSatellite = gc[1];
|
||||
VersionGoogleSatelliteKorea = VersionGoogleSatellite;
|
||||
VersionGoogleSatelliteChina = "s@" + VersionGoogleSatellite;
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleSatellite: "<<VersionGoogleSatellite;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
reg=QRegExp("\"*http://mt0.google.com/vt/lyrs=t@(\\d*),r@(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleTerrain = QString("t@%1,r@%2").arg(gc[1]).arg(gc[2]);
|
||||
VersionGoogleTerrainChina = VersionGoogleTerrain;
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleTerrain: "<<VersionGoogleTerrain;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
}
|
||||
QString UrlFactory::MakeImageUrl(const MapType::Types &type,const Point &pos,const int &zoom,const QString &language)
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Entered MakeImageUrl";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
switch(type)
|
||||
{
|
||||
case MapType::GoogleMap:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
|
||||
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMap).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleSatellite:
|
||||
{
|
||||
QString server = "khm";
|
||||
QString request = "kh";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
return QString("http://%1%2.google.com/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatellite).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleLabels:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
|
||||
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabels).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleTerrain:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
return QString("http://%1%2.google.com/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleTerrain).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleMapChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
// http://mt0.google.cn/vt/v=w2.101&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.cn/%3/lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMapChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleSatelliteChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
// TryCorrectGoogleVersions();
|
||||
// http://khm0.google.cn/kh/v=46&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.cn/%3/lyrs=%4&gl=cn&x=%5%6&y=%7&z=%8&s=%9").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatelliteChina).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleLabelsChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
// http://mt0.google.cn/vt/v=w2t.110&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.cn/%3/imgtp=png32&lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabelsChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleTerrainChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
// http://mt0.google.cn/vt/v=w2p.110&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleTerrainChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleMapKorea:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "mt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
|
||||
//http://mt3.gmaptiles.co.kr/mt/v=kr1.11&hl=lt&x=109&y=49&z=7&s=
|
||||
|
||||
QString ret = QString("http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMapKorea).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleSatelliteKorea:
|
||||
{
|
||||
QString server = "khm";
|
||||
QString request = "kh";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
|
||||
// http://khm1.google.co.kr/kh/v=54&x=109&y=49&z=7&s=
|
||||
|
||||
return QString("http://%1%2.google.co.kr/%3/v=%4&x=%5%6&y=%7&z=%8&s=%9").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatelliteKorea).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleLabelsKorea:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "mt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
|
||||
// http://mt1.gmaptiles.co.kr/mt/v=kr1t.11&hl=lt&x=109&y=50&z=7&s=G
|
||||
|
||||
return QString("http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabelsKorea).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::YahooMap:
|
||||
{
|
||||
return QString("http://maps%1.yimg.com/hx/tl?v=%2&.intl=%3&x=%4&y=%5&z=%6&r=1").arg(((GetServerNum(pos, 2)) + 1)).arg(VersionYahooMap).arg(language).arg(pos.X()).arg((((1 << zoom) >> 1) - 1 - pos.Y())).arg((zoom + 1));
|
||||
}
|
||||
|
||||
case MapType::YahooSatellite:
|
||||
{
|
||||
return QString("http://maps%1.yimg.com/ae/ximg?v=%2&t=a&s=256&.intl=%3&x=%4&y=%5&z=%6&r=1").arg("3").arg(VersionYahooSatellite).arg(language).arg(pos.X()).arg(((1 << zoom) >> 1) - 1 - pos.Y()).arg(zoom + 1);
|
||||
}
|
||||
break;
|
||||
case MapType::YahooLabels:
|
||||
{
|
||||
return QString("http://maps%1.yimg.com/hx/tl?v=%2&t=h&.intl=%3&x=%4&y=%5&z=%6&r=1").arg("1").arg(VersionYahooLabels).arg(language).arg(pos.X()).arg(((1 << zoom) >> 1) - 1 - pos.Y()).arg(zoom + 1);
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetMap:
|
||||
{
|
||||
char letter= "abc"[GetServerNum(pos, 3)];
|
||||
return QString("http://%1.tile.openstreetmap.org/%2/%3/%4.png").arg(letter).arg(zoom).arg(pos.X()).arg(pos.Y());
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetOsm:
|
||||
{
|
||||
char letter = "abc"[GetServerNum(pos, 3)];
|
||||
return QString("http://%1.tah.openstreetmap.org/Tiles/tile/%2/%3/%4.png").arg(letter).arg(zoom).arg(pos.X()).arg(pos.Y());
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetMapSurfer:
|
||||
{
|
||||
// http://tiles1.mapsurfer.net/tms_r.ashx?x=37378&y=20826&z=16
|
||||
|
||||
return QString("http://tiles1.mapsurfer.net/tms_r.ashx?x=%1&y=%2&z=%3").arg(pos.X()).arg(pos.Y()).arg(zoom);
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetMapSurferTerrain:
|
||||
{
|
||||
// http://tiles2.mapsurfer.net/tms_t.ashx?x=9346&y=5209&z=14
|
||||
|
||||
return QString("http://tiles2.mapsurfer.net/tms_t.ashx?x=%1&y=%2&z=%3").arg(pos.X()).arg(pos.Y()).arg(zoom);
|
||||
}
|
||||
break;
|
||||
case MapType::BingMap:
|
||||
{
|
||||
QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom);
|
||||
return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/r%2.png?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString(""));
|
||||
}
|
||||
break;
|
||||
case MapType::BingSatellite:
|
||||
{
|
||||
QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom);
|
||||
return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/a%2.jpeg?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString(""));
|
||||
}
|
||||
break;
|
||||
case MapType::BingHybrid:
|
||||
{
|
||||
QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom);
|
||||
return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/h%2.jpeg?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString(""));
|
||||
}
|
||||
|
||||
case MapType::ArcGIS_Map:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/tile/0/0/0.jpg
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_Satellite:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/1/0/1.jpg
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_ShadedRelief:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer/tile/1/0/1.jpg
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_Terrain:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer/tile/4/3/15
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_MapsLT_OrtoFoto:
|
||||
{
|
||||
// http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L02/R0000001b/C00000028.jpg
|
||||
// http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/0/9/13
|
||||
// return string.Format("http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L{0:00}/R{1:x8}/C{2:x8}.jpg", zoom, pos.Y(), pos.X());
|
||||
// http://dc1.maps.lt/cache/mapslt_ortofoto_512/map/_alllayers/L03/R0000001c/C00000029.jpg
|
||||
// return string.Format("http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/{0}/{1}/{2}", zoom, pos.Y(), pos.X());
|
||||
// http://dc1.maps.lt/cache/mapslt_ortofoto_512/map/_alllayers/L03/R0000001d/C0000002a.jpg
|
||||
//TODO verificar
|
||||
return QString("http://dc1.maps.lt/cache/mapslt_ortofoto/map/_alllayers/L%1/R%2/C%3.jpg").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0');
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_MapsLT_Map:
|
||||
{
|
||||
// http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L02/R0000001b/C00000028.jpg
|
||||
// http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/0/9/13
|
||||
// return string.Format("http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L{0:00}/R{1:x8}/C{2:x8}.jpg", zoom, pos.Y(), pos.X());
|
||||
// http://arcgis.maps.lt/ArcGIS/rest/services/mapslt/MapServer/tile/7/1162/1684.png
|
||||
// http://dc1.maps.lt/cache/mapslt_512/map/_alllayers/L03/R0000001b/C00000029.png
|
||||
//TODO verificar
|
||||
// http://dc1.maps.lt/cache/mapslt/map/_alllayers/L02/R0000001c/C00000029.png
|
||||
return QString("http://dc1.maps.lt/cache/mapslt/map/_alllayers/L%1/R%2/C%3.png").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0');
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_MapsLT_Map_Labels:
|
||||
{
|
||||
//http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto_overlay/MapServer/tile/0/9/13
|
||||
//return string.Format("http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto_overlay/MapServer/tile/{0}/{1}/{2}", zoom, pos.Y(), pos.X());
|
||||
//http://dc1.maps.lt/cache/mapslt_ortofoto_overlay_512/map/_alllayers/L03/R0000001d/C00000029.png
|
||||
//TODO verificar
|
||||
return QString("http://dc1.maps.lt/cache/mapslt_ortofoto_overlay/map/_alllayers/L%1/R%2/C%3.png").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0');
|
||||
}
|
||||
break;
|
||||
case MapType::PergoTurkeyMap:
|
||||
{
|
||||
// http://{domain}/{layerName}/{zoomLevel}/{first3LetterOfTileX}/{second3LetterOfTileX}/{third3LetterOfTileX}/{first3LetterOfTileY}/{second3LetterOfTileY}/{third3LetterOfTileXY}.png
|
||||
|
||||
// http://map3.pergo.com.tr/tile/00/000/000/001/000/000/000.png
|
||||
// That means: Zoom Level: 0 TileX: 1 TileY: 0
|
||||
|
||||
// http://domain/tile/14/000/019/371/000/011/825.png
|
||||
// That means: Zoom Level: 14 TileX: 19371 TileY:11825
|
||||
|
||||
// string x = pos.X().ToString("000000000").Insert(3, "/").Insert(7, "/"); // - 000/000/001
|
||||
// string y = pos.Y().ToString("000000000").Insert(3, "/").Insert(7, "/"); // - 000/000/000
|
||||
QString x=QString("%1").arg(QString::number(pos.X()),9,(QChar)'0');
|
||||
x.insert(3,"/").insert(7,"/");
|
||||
QString y=QString("%1").arg(QString::number(pos.Y()),9,(QChar)'0');
|
||||
y.insert(3,"/").insert(7,"/");
|
||||
//"http://map03.pergo.com.tr/tile/2/000/000/003/000/000/002.png"
|
||||
return QString("http://map%1.pergo.com.tr/tile/%2/%3/%4.png").arg(GetServerNum(pos, 4)).arg(zoom,2,10,(QChar)'0').arg(x).arg(y);
|
||||
}
|
||||
break;
|
||||
case MapType::SigPacSpainMap:
|
||||
{
|
||||
return QString("http://sigpac.mapa.es/kmlserver/raster/%1@3785/%2.%3.%4.img").arg(levelsForSigPacSpainMap[zoom]).arg(zoom).arg(pos.X()).arg((2 << (zoom - 1)) - pos.Y() - 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YandexMapRu:
|
||||
{
|
||||
QString server = "vec";
|
||||
|
||||
//http://vec01.maps.yandex.ru/tiles?l=map&v=2.10.2&x=1494&y=650&z=11
|
||||
|
||||
return QString("http://%1").arg(server)+QString("0%2.maps.yandex.ru/tiles?l=map&v=%3&x=%4&y=%5&z=%6").arg(GetServerNum(pos, 4)+1).arg(VersionYandexMap).arg(pos.X()).arg(pos.Y()).arg(zoom);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QString::null;
|
||||
}
|
||||
void UrlFactory::GetSecGoogleWords(const Point &pos, QString &sec1, QString &sec2)
|
||||
{
|
||||
sec1 = ""; // after &x=...
|
||||
sec2 = ""; // after &zoom=...
|
||||
int seclen = ((pos.X() * 3) + pos.Y()) % 8;
|
||||
sec2 = SecGoogleWord.left(seclen);
|
||||
if(pos.Y() >= 10000 && pos.Y() < 100000)
|
||||
{
|
||||
sec1 = "&s=";
|
||||
}
|
||||
}
|
||||
QString UrlFactory::MakeGeocoderUrl(QString keywords)
|
||||
{
|
||||
QString key = keywords.replace(' ', '+');
|
||||
return QString("http://maps.google.com/maps/geo?q=%1&output=csv&key=%2").arg(key).arg(GoogleMapsAPIKey);
|
||||
}
|
||||
QString UrlFactory::MakeReverseGeocoderUrl(internals::PointLatLng &pt,const QString &language)
|
||||
{
|
||||
|
||||
return QString("http://maps.google.com/maps/geo?hl=%1&ll=%2,%3&output=csv&key=%4").arg(language).arg(QString::number(pt.Lat())).arg(QString::number(pt.Lng())).arg(GoogleMapsAPIKey);
|
||||
|
||||
}
|
||||
internals::PointLatLng UrlFactory::GetLatLngFromGeodecoder(const QString &keywords, GeoCoderStatusCode::Types &status)
|
||||
{
|
||||
return GetLatLngFromGeocoderUrl(MakeGeocoderUrl(keywords),UseGeocoderCache,status);
|
||||
}
|
||||
internals::PointLatLng UrlFactory::GetLatLngFromGeocoderUrl(const QString &url, const bool &useCache, GeoCoderStatusCode::Types &status)
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Entered GetLatLngFromGeocoderUrl:";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
status = GeoCoderStatusCode::Unknow;
|
||||
internals::PointLatLng ret(0,0);
|
||||
QString urlEnd = url.mid(url.indexOf("geo?q=")+6);
|
||||
urlEnd.replace( QRegExp(
|
||||
"[^"
|
||||
"A-Z,a-z,0-9,"
|
||||
"\\^,\\&,\\',\\@,"
|
||||
"\\{,\\},\\[,\\],"
|
||||
"\\,,\\$,\\=,\\!,"
|
||||
"\\-,\\#,\\(,\\),"
|
||||
"\\%,\\.,\\+,\\~,\\_"
|
||||
"]"), "_" );
|
||||
|
||||
QString geo = useCache ? Cache::Instance()->GetGeocoderFromCache(urlEnd) : "";
|
||||
|
||||
if(geo.isNull()|geo.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Not in cache going internet";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
network.setProxy(Proxy);
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
reply=network.get(qheader);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:URL="<<url;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QTime time;
|
||||
time.start();
|
||||
while( (!(reply->isFinished()) || (time.elapsed()>(6*Timeout))) ){QCoreApplication::processEvents(QEventLoop::AllEvents);}
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Finished?"<<reply->error()<<" abort?"<<(time.elapsed()>Timeout*6);
|
||||
#endif //DEBUG_URLFACTORY
|
||||
if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6))
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl::Network error";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
return internals::PointLatLng(0,0);
|
||||
}
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Reply ok";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
geo=reply->readAll();
|
||||
|
||||
|
||||
// cache geocoding
|
||||
if(useCache && geo.startsWith("200"))
|
||||
{
|
||||
Cache::Instance()->CacheGeocoder(urlEnd, geo);
|
||||
}
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
// parse values
|
||||
// true : 200,4,56.1451640,22.0681787
|
||||
// false: 602,0,0,0
|
||||
{
|
||||
QStringList values = geo.split(',');
|
||||
if(values.count() == 4)
|
||||
{
|
||||
status = (GeoCoderStatusCode::Types) QString(values[0]).toInt();
|
||||
if(status == GeoCoderStatusCode::G_GEO_SUCCESS)
|
||||
{
|
||||
double lat = QString(values[2]).toDouble();
|
||||
double lng = QString(values[3]).toDouble();
|
||||
|
||||
ret = internals::PointLatLng(lat, lng);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Lat="<<lat<<" Lng="<<lng;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Placemark UrlFactory::GetPlacemarkFromGeocoder(internals::PointLatLng location)
|
||||
{
|
||||
return GetPlacemarkFromReverseGeocoderUrl(MakeReverseGeocoderUrl(location, LanguageStr), UsePlacemarkCache);
|
||||
}
|
||||
|
||||
Placemark UrlFactory::GetPlacemarkFromReverseGeocoderUrl(const QString &url, const bool &useCache)
|
||||
{
|
||||
|
||||
Placemark ret("");
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Entered GetPlacemarkFromReverseGeocoderUrl:";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
// status = GeoCoderStatusCode::Unknow;
|
||||
QString urlEnd = url.right(url.indexOf("geo?hl="));
|
||||
urlEnd.replace( QRegExp(
|
||||
"[^"
|
||||
"A-Z,a-z,0-9,"
|
||||
"\\^,\\&,\\',\\@,"
|
||||
"\\{,\\},\\[,\\],"
|
||||
"\\,,\\$,\\=,\\!,"
|
||||
"\\-,\\#,\\(,\\),"
|
||||
"\\%,\\.,\\+,\\~,\\_"
|
||||
"]"), "_" );
|
||||
|
||||
QString reverse = useCache ? Cache::Instance()->GetPlacemarkFromCache(urlEnd) : "";
|
||||
|
||||
if(reverse.isNull()|reverse.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Not in cache going internet";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
network.setProxy(Proxy);
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
reply=network.get(qheader);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:URL="<<url;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QTime time;
|
||||
time.start();
|
||||
while( (!(reply->isFinished()) || (time.elapsed()>(6*Timeout))) ){QCoreApplication::processEvents(QEventLoop::AllEvents);}
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Finished?"<<reply->error()<<" abort?"<<(time.elapsed()>Timeout*6);
|
||||
#endif //DEBUG_URLFACTORY
|
||||
if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6))
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl::Network error";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
return ret;
|
||||
}
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Reply ok";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QByteArray a=(reply->readAll());
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
reverse = codec->toUnicode(a);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<reverse;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
// cache geocoding
|
||||
if(useCache && reverse.startsWith("200"))
|
||||
{
|
||||
Cache::Instance()->CachePlacemark(urlEnd, reverse);
|
||||
}
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
// parse values
|
||||
// true : 200,4,56.1451640,22.0681787
|
||||
// false: 602,0,0,0
|
||||
if(reverse.startsWith("200"))
|
||||
{
|
||||
QString acc = reverse.left(reverse.indexOf('\"'));
|
||||
ret = Placemark(reverse.remove(reverse.indexOf('\"')));
|
||||
ret.SetAccuracy ((int) (( (QString) acc.split(',')[1]).toInt()) );
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
double UrlFactory::GetDistance(internals::PointLatLng p1, internals::PointLatLng p2)
|
||||
{
|
||||
double dLat1InRad = p1.Lat() * (M_PI / 180);
|
||||
double dLong1InRad = p1.Lng() * (M_PI / 180);
|
||||
double dLat2InRad = p2.Lat() * (M_PI / 180);
|
||||
double dLong2InRad = p2.Lng() * (M_PI / 180);
|
||||
double dLongitude = dLong2InRad - dLong1InRad;
|
||||
double dLatitude = dLat2InRad - dLat1InRad;
|
||||
double a = pow(sin(dLatitude / 2), 2) + cos(dLat1InRad) * cos(dLat2InRad) * pow(sin(dLongitude / 2), 2);
|
||||
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
|
||||
double dDistance = EarthRadiusKm * c;
|
||||
return dDistance;
|
||||
}
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file urlfactory.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "urlfactory.h"
|
||||
#include <QRegExp>
|
||||
|
||||
namespace core {
|
||||
|
||||
const double UrlFactory::EarthRadiusKm = 6378.137; // WGS-84
|
||||
|
||||
UrlFactory::UrlFactory()
|
||||
{
|
||||
/// <summary>
|
||||
/// timeout for map connections
|
||||
/// </summary>
|
||||
|
||||
Proxy.setType(QNetworkProxy::NoProxy);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the User-agent HTTP header.
|
||||
/// </summary>
|
||||
UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7";
|
||||
|
||||
Timeout = 5 * 1000;
|
||||
CorrectGoogleVersions=true;
|
||||
isCorrectedGoogleVersions = false;
|
||||
UseGeocoderCache=true;
|
||||
UsePlacemarkCache=true;
|
||||
}
|
||||
UrlFactory::~UrlFactory()
|
||||
{
|
||||
}
|
||||
QString UrlFactory::TileXYToQuadKey(const int &tileX,const int &tileY,const int &levelOfDetail) const
|
||||
{
|
||||
QString quadKey;
|
||||
for(int i = levelOfDetail; i > 0; i--)
|
||||
{
|
||||
char digit = '0';
|
||||
int mask = 1 << (i - 1);
|
||||
if((tileX & mask) != 0)
|
||||
{
|
||||
digit++;
|
||||
}
|
||||
if((tileY & mask) != 0)
|
||||
{
|
||||
digit++;
|
||||
digit++;
|
||||
}
|
||||
quadKey.append(digit);
|
||||
}
|
||||
return quadKey;
|
||||
}
|
||||
int UrlFactory::GetServerNum(const Point &pos,const int &max) const
|
||||
{
|
||||
return (pos.X() + 2 * pos.Y()) % max;
|
||||
}
|
||||
void UrlFactory::setIsCorrectGoogleVersions(bool value)
|
||||
{
|
||||
isCorrectedGoogleVersions=value;
|
||||
|
||||
}
|
||||
|
||||
bool UrlFactory::IsCorrectGoogleVersions()
|
||||
{
|
||||
return isCorrectedGoogleVersions;
|
||||
}
|
||||
|
||||
void UrlFactory::TryCorrectGoogleVersions()
|
||||
{
|
||||
if(CorrectGoogleVersions && !IsCorrectGoogleVersions())
|
||||
{
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
QEventLoop q;
|
||||
QTimer tT;
|
||||
tT.setSingleShot(true);
|
||||
connect(&network, SIGNAL(finished(QNetworkReply*)),
|
||||
&q, SLOT(quit()));
|
||||
connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
|
||||
network.setProxy(Proxy);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Correct GoogleVersion";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
setIsCorrectGoogleVersions(true);
|
||||
QString url = "http://maps.google.com";
|
||||
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
reply=network.get(qheader);
|
||||
tT.start(Timeout);
|
||||
q.exec();
|
||||
if(!tT.isActive())
|
||||
return;
|
||||
tT.stop();
|
||||
if( (reply->error()!=QNetworkReply::NoError))
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Try corrected version withou abort or error:"<<reply->errorString();
|
||||
#endif //DEBUG_URLFACTORY
|
||||
return;
|
||||
}
|
||||
QString html=QString(reply->readAll());
|
||||
QRegExp reg("\"*http://mt0.google.com/vt/lyrs=m@(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleMap = QString("m@%1").arg(gc[1]);
|
||||
VersionGoogleMapChina = VersionGoogleMap;
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleMap: "<<VersionGoogleMap;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
|
||||
reg=QRegExp("\"*http://mt0.google.com/vt/lyrs=h@(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleLabels = QString("h@%1").arg(gc[1]);
|
||||
VersionGoogleLabelsChina = VersionGoogleLabels;
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleLabels: "<<VersionGoogleLabels;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
reg=QRegExp("\"*http://khm0.google.com/kh/v=(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleSatellite = gc[1];
|
||||
VersionGoogleSatelliteKorea = VersionGoogleSatellite;
|
||||
VersionGoogleSatelliteChina = "s@" + VersionGoogleSatellite;
|
||||
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleSatellite: "<<VersionGoogleSatellite;
|
||||
|
||||
}
|
||||
reg=QRegExp("\"*http://mt0.google.com/vt/lyrs=t@(\\d*),r@(\\d*)",Qt::CaseInsensitive);
|
||||
if(reg.indexIn(html)!=-1)
|
||||
{
|
||||
QStringList gc=reg.capturedTexts();
|
||||
VersionGoogleTerrain = QString("t@%1,r@%2").arg(gc[1]).arg(gc[2]);
|
||||
VersionGoogleTerrainChina = VersionGoogleTerrain;
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"TryCorrectGoogleVersions, VersionGoogleTerrain: "<<VersionGoogleTerrain;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
reply->deleteLater();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString UrlFactory::MakeImageUrl(const MapType::Types &type,const Point &pos,const int &zoom,const QString &language)
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Entered MakeImageUrl";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
switch(type)
|
||||
{
|
||||
case MapType::GoogleMap:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
|
||||
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMap).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleSatellite:
|
||||
{
|
||||
QString server = "khm";
|
||||
QString request = "kh";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
return QString("http://%1%2.google.com/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatellite).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleLabels:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
|
||||
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabels).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleTerrain:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
return QString("http://%1%2.google.com/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleTerrain).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleMapChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
// http://mt0.google.cn/vt/v=w2.101&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.cn/%3/lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMapChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleSatelliteChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
// TryCorrectGoogleVersions();
|
||||
// http://khm0.google.cn/kh/v=46&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.cn/%3/lyrs=%4&gl=cn&x=%5%6&y=%7&z=%8&s=%9").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatelliteChina).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleLabelsChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
// http://mt0.google.cn/vt/v=w2t.110&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.cn/%3/imgtp=png32&lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabelsChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleTerrainChina:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "vt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
TryCorrectGoogleVersions();
|
||||
// http://mt0.google.cn/vt/v=w2p.110&hl=zh-CN&gl=cn&x=12&y=6&z=4&s=Ga
|
||||
|
||||
return QString("http://%1%2.google.com/%3/lyrs=%4&hl=%5&gl=cn&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleTerrainChina).arg("zh-CN").arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleMapKorea:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "mt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
|
||||
//http://mt3.gmaptiles.co.kr/mt/v=kr1.11&hl=lt&x=109&y=49&z=7&s=
|
||||
|
||||
QString ret = QString("http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleMapKorea).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleSatelliteKorea:
|
||||
{
|
||||
QString server = "khm";
|
||||
QString request = "kh";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
|
||||
// http://khm1.google.co.kr/kh/v=54&x=109&y=49&z=7&s=
|
||||
|
||||
return QString("http://%1%2.google.co.kr/%3/v=%4&x=%5%6&y=%7&z=%8&s=%9").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleSatelliteKorea).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::GoogleLabelsKorea:
|
||||
{
|
||||
QString server = "mt";
|
||||
QString request = "mt";
|
||||
QString sec1 = ""; // after &x=...
|
||||
QString sec2 = ""; // after &zoom=...
|
||||
GetSecGoogleWords(pos, sec1, sec2);
|
||||
|
||||
// http://mt1.gmaptiles.co.kr/mt/v=kr1t.11&hl=lt&x=109&y=50&z=7&s=G
|
||||
|
||||
return QString("http://%1%2.gmaptiles.co.kr/%3/v=%4&hl=%5&x=%6%7&y=%8&z=%9&s=%10").arg(server).arg(GetServerNum(pos, 4)).arg(request).arg(VersionGoogleLabelsKorea).arg(language).arg(pos.X()).arg(sec1).arg(pos.Y()).arg(zoom).arg(sec2);
|
||||
}
|
||||
break;
|
||||
case MapType::YahooMap:
|
||||
{
|
||||
return QString("http://maps%1.yimg.com/hx/tl?v=%2&.intl=%3&x=%4&y=%5&z=%6&r=1").arg(((GetServerNum(pos, 2)) + 1)).arg(VersionYahooMap).arg(language).arg(pos.X()).arg((((1 << zoom) >> 1) - 1 - pos.Y())).arg((zoom + 1));
|
||||
}
|
||||
|
||||
case MapType::YahooSatellite:
|
||||
{
|
||||
return QString("http://maps%1.yimg.com/ae/ximg?v=%2&t=a&s=256&.intl=%3&x=%4&y=%5&z=%6&r=1").arg("3").arg(VersionYahooSatellite).arg(language).arg(pos.X()).arg(((1 << zoom) >> 1) - 1 - pos.Y()).arg(zoom + 1);
|
||||
}
|
||||
break;
|
||||
case MapType::YahooLabels:
|
||||
{
|
||||
return QString("http://maps%1.yimg.com/hx/tl?v=%2&t=h&.intl=%3&x=%4&y=%5&z=%6&r=1").arg("1").arg(VersionYahooLabels).arg(language).arg(pos.X()).arg(((1 << zoom) >> 1) - 1 - pos.Y()).arg(zoom + 1);
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetMap:
|
||||
{
|
||||
char letter= "abc"[GetServerNum(pos, 3)];
|
||||
return QString("http://%1.tile.openstreetmap.org/%2/%3/%4.png").arg(letter).arg(zoom).arg(pos.X()).arg(pos.Y());
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetOsm:
|
||||
{
|
||||
char letter = "abc"[GetServerNum(pos, 3)];
|
||||
return QString("http://%1.tah.openstreetmap.org/Tiles/tile/%2/%3/%4.png").arg(letter).arg(zoom).arg(pos.X()).arg(pos.Y());
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetMapSurfer:
|
||||
{
|
||||
// http://tiles1.mapsurfer.net/tms_r.ashx?x=37378&y=20826&z=16
|
||||
|
||||
return QString("http://tiles1.mapsurfer.net/tms_r.ashx?x=%1&y=%2&z=%3").arg(pos.X()).arg(pos.Y()).arg(zoom);
|
||||
}
|
||||
break;
|
||||
case MapType::OpenStreetMapSurferTerrain:
|
||||
{
|
||||
// http://tiles2.mapsurfer.net/tms_t.ashx?x=9346&y=5209&z=14
|
||||
|
||||
return QString("http://tiles2.mapsurfer.net/tms_t.ashx?x=%1&y=%2&z=%3").arg(pos.X()).arg(pos.Y()).arg(zoom);
|
||||
}
|
||||
break;
|
||||
case MapType::BingMap:
|
||||
{
|
||||
QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom);
|
||||
return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/r%2.png?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString(""));
|
||||
}
|
||||
break;
|
||||
case MapType::BingSatellite:
|
||||
{
|
||||
QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom);
|
||||
return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/a%2.jpeg?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString(""));
|
||||
}
|
||||
break;
|
||||
case MapType::BingHybrid:
|
||||
{
|
||||
QString key = TileXYToQuadKey(pos.X(), pos.Y(), zoom);
|
||||
return QString("http://ecn.t%1.tiles.virtualearth.net/tiles/h%2.jpeg?g=%3&mkt=%4%5").arg(GetServerNum(pos, 4)).arg(key).arg(VersionBingMaps).arg(language).arg(!(BingMapsClientToken.isNull()|BingMapsClientToken.isEmpty()) ? "&token=" + BingMapsClientToken : QString(""));
|
||||
}
|
||||
|
||||
case MapType::ArcGIS_Map:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/tile/0/0/0.jpg
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_Satellite:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/1/0/1.jpg
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_ShadedRelief:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer/tile/1/0/1.jpg
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_Terrain:
|
||||
{
|
||||
// http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer/tile/4/3/15
|
||||
|
||||
return QString("http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer/tile/%1/%2/%3").arg(zoom).arg(pos.Y()).arg(pos.X());
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_MapsLT_OrtoFoto:
|
||||
{
|
||||
// http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L02/R0000001b/C00000028.jpg
|
||||
// http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/0/9/13
|
||||
// return string.Format("http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L{0:00}/R{1:x8}/C{2:x8}.jpg", zoom, pos.Y(), pos.X());
|
||||
// http://dc1.maps.lt/cache/mapslt_ortofoto_512/map/_alllayers/L03/R0000001c/C00000029.jpg
|
||||
// return string.Format("http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/{0}/{1}/{2}", zoom, pos.Y(), pos.X());
|
||||
// http://dc1.maps.lt/cache/mapslt_ortofoto_512/map/_alllayers/L03/R0000001d/C0000002a.jpg
|
||||
//TODO verificar
|
||||
return QString("http://dc1.maps.lt/cache/mapslt_ortofoto/map/_alllayers/L%1/R%2/C%3.jpg").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0');
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_MapsLT_Map:
|
||||
{
|
||||
// http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L02/R0000001b/C00000028.jpg
|
||||
// http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto/MapServer/tile/0/9/13
|
||||
// return string.Format("http://www.maps.lt/ortofoto/mapslt_ortofoto_vector_512/map/_alllayers/L{0:00}/R{1:x8}/C{2:x8}.jpg", zoom, pos.Y(), pos.X());
|
||||
// http://arcgis.maps.lt/ArcGIS/rest/services/mapslt/MapServer/tile/7/1162/1684.png
|
||||
// http://dc1.maps.lt/cache/mapslt_512/map/_alllayers/L03/R0000001b/C00000029.png
|
||||
//TODO verificar
|
||||
// http://dc1.maps.lt/cache/mapslt/map/_alllayers/L02/R0000001c/C00000029.png
|
||||
return QString("http://dc1.maps.lt/cache/mapslt/map/_alllayers/L%1/R%2/C%3.png").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0');
|
||||
}
|
||||
break;
|
||||
case MapType::ArcGIS_MapsLT_Map_Labels:
|
||||
{
|
||||
//http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto_overlay/MapServer/tile/0/9/13
|
||||
//return string.Format("http://arcgis.maps.lt/ArcGIS/rest/services/mapslt_ortofoto_overlay/MapServer/tile/{0}/{1}/{2}", zoom, pos.Y(), pos.X());
|
||||
//http://dc1.maps.lt/cache/mapslt_ortofoto_overlay_512/map/_alllayers/L03/R0000001d/C00000029.png
|
||||
//TODO verificar
|
||||
return QString("http://dc1.maps.lt/cache/mapslt_ortofoto_overlay/map/_alllayers/L%1/R%2/C%3.png").arg(zoom,2,10,(QChar)'0').arg(pos.Y(),8,16,(QChar)'0').arg(pos.X(),8,16,(QChar)'0');
|
||||
}
|
||||
break;
|
||||
case MapType::PergoTurkeyMap:
|
||||
{
|
||||
// http://{domain}/{layerName}/{zoomLevel}/{first3LetterOfTileX}/{second3LetterOfTileX}/{third3LetterOfTileX}/{first3LetterOfTileY}/{second3LetterOfTileY}/{third3LetterOfTileXY}.png
|
||||
|
||||
// http://map3.pergo.com.tr/tile/00/000/000/001/000/000/000.png
|
||||
// That means: Zoom Level: 0 TileX: 1 TileY: 0
|
||||
|
||||
// http://domain/tile/14/000/019/371/000/011/825.png
|
||||
// That means: Zoom Level: 14 TileX: 19371 TileY:11825
|
||||
|
||||
// string x = pos.X().ToString("000000000").Insert(3, "/").Insert(7, "/"); // - 000/000/001
|
||||
// string y = pos.Y().ToString("000000000").Insert(3, "/").Insert(7, "/"); // - 000/000/000
|
||||
QString x=QString("%1").arg(QString::number(pos.X()),9,(QChar)'0');
|
||||
x.insert(3,"/").insert(7,"/");
|
||||
QString y=QString("%1").arg(QString::number(pos.Y()),9,(QChar)'0');
|
||||
y.insert(3,"/").insert(7,"/");
|
||||
//"http://map03.pergo.com.tr/tile/2/000/000/003/000/000/002.png"
|
||||
return QString("http://map%1.pergo.com.tr/tile/%2/%3/%4.png").arg(GetServerNum(pos, 4)).arg(zoom,2,10,(QChar)'0').arg(x).arg(y);
|
||||
}
|
||||
break;
|
||||
case MapType::SigPacSpainMap:
|
||||
{
|
||||
return QString("http://sigpac.mapa.es/kmlserver/raster/%1@3785/%2.%3.%4.img").arg(levelsForSigPacSpainMap[zoom]).arg(zoom).arg(pos.X()).arg((2 << (zoom - 1)) - pos.Y() - 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YandexMapRu:
|
||||
{
|
||||
QString server = "vec";
|
||||
|
||||
//http://vec01.maps.yandex.ru/tiles?l=map&v=2.10.2&x=1494&y=650&z=11
|
||||
|
||||
return QString("http://%1").arg(server)+QString("0%2.maps.yandex.ru/tiles?l=map&v=%3&x=%4&y=%5&z=%6").arg(GetServerNum(pos, 4)+1).arg(VersionYandexMap).arg(pos.X()).arg(pos.Y()).arg(zoom);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QString::null;
|
||||
}
|
||||
void UrlFactory::GetSecGoogleWords(const Point &pos, QString &sec1, QString &sec2)
|
||||
{
|
||||
sec1 = ""; // after &x=...
|
||||
sec2 = ""; // after &zoom=...
|
||||
int seclen = ((pos.X() * 3) + pos.Y()) % 8;
|
||||
sec2 = SecGoogleWord.left(seclen);
|
||||
if(pos.Y() >= 10000 && pos.Y() < 100000)
|
||||
{
|
||||
sec1 = "&s=";
|
||||
}
|
||||
}
|
||||
QString UrlFactory::MakeGeocoderUrl(QString keywords)
|
||||
{
|
||||
QString key = keywords.replace(' ', '+');
|
||||
return QString("http://maps.google.com/maps/geo?q=%1&output=csv&key=%2").arg(key).arg(GoogleMapsAPIKey);
|
||||
}
|
||||
QString UrlFactory::MakeReverseGeocoderUrl(internals::PointLatLng &pt,const QString &language)
|
||||
{
|
||||
|
||||
return QString("http://maps.google.com/maps/geo?hl=%1&ll=%2,%3&output=csv&key=%4").arg(language).arg(QString::number(pt.Lat())).arg(QString::number(pt.Lng())).arg(GoogleMapsAPIKey);
|
||||
|
||||
}
|
||||
internals::PointLatLng UrlFactory::GetLatLngFromGeodecoder(const QString &keywords, GeoCoderStatusCode::Types &status)
|
||||
{
|
||||
return GetLatLngFromGeocoderUrl(MakeGeocoderUrl(keywords),UseGeocoderCache,status);
|
||||
}
|
||||
internals::PointLatLng UrlFactory::GetLatLngFromGeocoderUrl(const QString &url, const bool &useCache, GeoCoderStatusCode::Types &status)
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Entered GetLatLngFromGeocoderUrl:";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
status = GeoCoderStatusCode::Unknow;
|
||||
internals::PointLatLng ret(0,0);
|
||||
QString urlEnd = url.mid(url.indexOf("geo?q=")+6);
|
||||
urlEnd.replace( QRegExp(
|
||||
"[^"
|
||||
"A-Z,a-z,0-9,"
|
||||
"\\^,\\&,\\',\\@,"
|
||||
"\\{,\\},\\[,\\],"
|
||||
"\\,,\\$,\\=,\\!,"
|
||||
"\\-,\\#,\\(,\\),"
|
||||
"\\%,\\.,\\+,\\~,\\_"
|
||||
"]"), "_" );
|
||||
|
||||
QString geo = useCache ? Cache::Instance()->GetGeocoderFromCache(urlEnd) : "";
|
||||
|
||||
if(geo.isNull()|geo.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Not in cache going internet";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
network.setProxy(Proxy);
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
reply=network.get(qheader);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:URL="<<url;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QTime time;
|
||||
time.start();
|
||||
while( (!(reply->isFinished()) || (time.elapsed()>(6*Timeout))) ){QCoreApplication::processEvents(QEventLoop::AllEvents);}
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Finished?"<<reply->error()<<" abort?"<<(time.elapsed()>Timeout*6);
|
||||
#endif //DEBUG_URLFACTORY
|
||||
if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6))
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl::Network error";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
return internals::PointLatLng(0,0);
|
||||
}
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Reply ok";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
geo=reply->readAll();
|
||||
|
||||
|
||||
// cache geocoding
|
||||
if(useCache && geo.startsWith("200"))
|
||||
{
|
||||
Cache::Instance()->CacheGeocoder(urlEnd, geo);
|
||||
}
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
// parse values
|
||||
// true : 200,4,56.1451640,22.0681787
|
||||
// false: 602,0,0,0
|
||||
{
|
||||
QStringList values = geo.split(',');
|
||||
if(values.count() == 4)
|
||||
{
|
||||
status = (GeoCoderStatusCode::Types) QString(values[0]).toInt();
|
||||
if(status == GeoCoderStatusCode::G_GEO_SUCCESS)
|
||||
{
|
||||
double lat = QString(values[2]).toDouble();
|
||||
double lng = QString(values[3]).toDouble();
|
||||
|
||||
ret = internals::PointLatLng(lat, lng);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Lat="<<lat<<" Lng="<<lng;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Placemark UrlFactory::GetPlacemarkFromGeocoder(internals::PointLatLng location)
|
||||
{
|
||||
return GetPlacemarkFromReverseGeocoderUrl(MakeReverseGeocoderUrl(location, LanguageStr), UsePlacemarkCache);
|
||||
}
|
||||
|
||||
Placemark UrlFactory::GetPlacemarkFromReverseGeocoderUrl(const QString &url, const bool &useCache)
|
||||
{
|
||||
|
||||
Placemark ret("");
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Entered GetPlacemarkFromReverseGeocoderUrl:";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
// status = GeoCoderStatusCode::Unknow;
|
||||
QString urlEnd = url.right(url.indexOf("geo?hl="));
|
||||
urlEnd.replace( QRegExp(
|
||||
"[^"
|
||||
"A-Z,a-z,0-9,"
|
||||
"\\^,\\&,\\',\\@,"
|
||||
"\\{,\\},\\[,\\],"
|
||||
"\\,,\\$,\\=,\\!,"
|
||||
"\\-,\\#,\\(,\\),"
|
||||
"\\%,\\.,\\+,\\~,\\_"
|
||||
"]"), "_" );
|
||||
|
||||
QString reverse = useCache ? Cache::Instance()->GetPlacemarkFromCache(urlEnd) : "";
|
||||
|
||||
if(reverse.isNull()|reverse.isEmpty())
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Not in cache going internet";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QNetworkReply *reply;
|
||||
QNetworkRequest qheader;
|
||||
QNetworkAccessManager network;
|
||||
network.setProxy(Proxy);
|
||||
qheader.setUrl(QUrl(url));
|
||||
qheader.setRawHeader("User-Agent",UserAgent);
|
||||
reply=network.get(qheader);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:URL="<<url;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QTime time;
|
||||
time.start();
|
||||
while( (!(reply->isFinished()) || (time.elapsed()>(6*Timeout))) ){QCoreApplication::processEvents(QEventLoop::AllEvents);}
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"Finished?"<<reply->error()<<" abort?"<<(time.elapsed()>Timeout*6);
|
||||
#endif //DEBUG_URLFACTORY
|
||||
if( (reply->error()!=QNetworkReply::NoError) | (time.elapsed()>Timeout*6))
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl::Network error";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
return ret;
|
||||
}
|
||||
{
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<"GetLatLngFromGeocoderUrl:Reply ok";
|
||||
#endif //DEBUG_URLFACTORY
|
||||
QByteArray a=(reply->readAll());
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
reverse = codec->toUnicode(a);
|
||||
#ifdef DEBUG_URLFACTORY
|
||||
qDebug()<<reverse;
|
||||
#endif //DEBUG_URLFACTORY
|
||||
// cache geocoding
|
||||
if(useCache && reverse.startsWith("200"))
|
||||
{
|
||||
Cache::Instance()->CachePlacemark(urlEnd, reverse);
|
||||
}
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
// parse values
|
||||
// true : 200,4,56.1451640,22.0681787
|
||||
// false: 602,0,0,0
|
||||
if(reverse.startsWith("200"))
|
||||
{
|
||||
QString acc = reverse.left(reverse.indexOf('\"'));
|
||||
ret = Placemark(reverse.remove(reverse.indexOf('\"')));
|
||||
ret.SetAccuracy ((int) (( (QString) acc.split(',')[1]).toInt()) );
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
double UrlFactory::GetDistance(internals::PointLatLng p1, internals::PointLatLng p2)
|
||||
{
|
||||
double dLat1InRad = p1.Lat() * (M_PI / 180);
|
||||
double dLong1InRad = p1.Lng() * (M_PI / 180);
|
||||
double dLat2InRad = p2.Lat() * (M_PI / 180);
|
||||
double dLong2InRad = p2.Lng() * (M_PI / 180);
|
||||
double dLongitude = dLong2InRad - dLong1InRad;
|
||||
double dLatitude = dLat2InRad - dLat1InRad;
|
||||
double a = pow(sin(dLatitude / 2), 2) + cos(dLat1InRad) * cos(dLat2InRad) * pow(sin(dLongitude / 2), 2);
|
||||
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
|
||||
double dDistance = EarthRadiusKm * c;
|
||||
return dDistance;
|
||||
}
|
||||
}
|
||||
|
@ -1,680 +1,695 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file core.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "core.h"
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qlonglong internals::Core::debugcounter=0;
|
||||
#endif
|
||||
|
||||
using namespace projections;
|
||||
|
||||
namespace internals {
|
||||
Core::Core():MouseWheelZooming(false),currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0)
|
||||
,minOfTiles(0,0),maxOfTiles(0,0),zoom(0),isDragging(false),TooltipTextPadding(10,10),loaderLimit(5),maxzoom(21),started(false)
|
||||
{
|
||||
mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter;
|
||||
SetProjection(new MercatorProjection());
|
||||
this->setAutoDelete(false);
|
||||
ProcessLoadTaskCallback.setMaxThreadCount(10);
|
||||
renderOffset=Point(0,0);
|
||||
dragPoint=Point(0,0);
|
||||
CanDragMap=true;
|
||||
tilesToload=0;
|
||||
OPMaps::Instance();
|
||||
}
|
||||
Core::~Core()
|
||||
{
|
||||
ProcessLoadTaskCallback.waitForDone();
|
||||
}
|
||||
|
||||
void Core::run()
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qlonglong debug;
|
||||
Mdebug.lock();
|
||||
debug=++debugcounter;
|
||||
Mdebug.unlock();
|
||||
qDebug()<<"core:run"<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
bool last = false;
|
||||
|
||||
LoadTask task;
|
||||
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
if(tileLoadQueue.count() > 0)
|
||||
{
|
||||
task = tileLoadQueue.dequeue();
|
||||
{
|
||||
|
||||
last = (tileLoadQueue.count() == 0);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"TileLoadQueue: " << tileLoadQueue.count()<<" Point:"<<task.Pos.ToString()<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
}
|
||||
}
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
|
||||
if(task.HasValue())
|
||||
if(loaderLimit.tryAcquire(1,OPMaps::Instance()->Timeout))
|
||||
{
|
||||
MtileToload.lock();
|
||||
--tilesToload;
|
||||
MtileToload.unlock();
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"loadLimit semaphore aquired "<<loaderLimit.available()<<" ID="<<debug<<" TASK="<<task.Pos.ToString()<<" "<<task.Zoom;
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
{
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"task as value, begining get"<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
{
|
||||
Tile* m = Matrix.TileAt(task.Pos);
|
||||
|
||||
if(m==0 || m->Overlays.count() == 0)
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Fill empty TileMatrix: " + task.ToString()<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
Tile* t = new Tile(task.Zoom, task.Pos);
|
||||
QVector<MapType::Types> layers= OPMaps::Instance()->GetAllLayersOfType(GetMapType());
|
||||
|
||||
foreach(MapType::Types tl,layers)
|
||||
{
|
||||
int retry = 0;
|
||||
do
|
||||
{
|
||||
QByteArray img;
|
||||
|
||||
// tile number inversion(BottomLeft -> TopLeft) for pergo maps
|
||||
if(tl == MapType::PergoTurkeyMap)
|
||||
{
|
||||
img = OPMaps::Instance()->GetImageFrom(tl, Point(task.Pos.X(), maxOfTiles.Height() - task.Pos.Y()), task.Zoom);
|
||||
}
|
||||
else // ok
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"start getting image"<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
img = OPMaps::Instance()->GetImageFrom(tl, task.Pos, task.Zoom);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::run:gotimage size:"<<img.count()<<" ID="<<debug<<" time="<<t.elapsed();
|
||||
#endif //DEBUG_CORE
|
||||
}
|
||||
|
||||
if(img.length()!=0)
|
||||
{
|
||||
Moverlays.lock();
|
||||
{
|
||||
t->Overlays.append(img);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::run append img:"<<img.length()<<" to tile:"<<t->GetPos().ToString()<<" now has "<<t->Overlays.count()<<" overlays"<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
}
|
||||
Moverlays.unlock();
|
||||
|
||||
break;
|
||||
}
|
||||
else if(OPMaps::Instance()->RetryLoadTile > 0)
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"ProcessLoadTask: " << task.ToString()<< " -> empty tile, retry " << retry<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
{
|
||||
QWaitCondition wait;
|
||||
QMutex m;
|
||||
m.lock();
|
||||
wait.wait(&m,500);
|
||||
}
|
||||
}
|
||||
}
|
||||
while(++retry < OPMaps::Instance()->RetryLoadTile);
|
||||
}
|
||||
|
||||
if(t->Overlays.count() > 0)
|
||||
{
|
||||
Matrix.SetTileAt(task.Pos,t);
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::run add tile "<<t->GetPos().ToString()<<" to matrix index "<<task.Pos.ToString()<<" ID="<<debug;
|
||||
qDebug()<<"Core::run matrix index "<<task.Pos.ToString()<<" as tile with "<<Matrix.TileAt(task.Pos)->Overlays.count()<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
}
|
||||
else
|
||||
{
|
||||
// emit OnTilesStillToLoad(tilesToload);
|
||||
|
||||
delete t;
|
||||
t = 0;
|
||||
emit OnNeedInvalidation();
|
||||
}
|
||||
|
||||
// layers = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// last buddy cleans stuff ;}
|
||||
if(last)
|
||||
{
|
||||
OPMaps::Instance()->kiberCacheLock.lockForWrite();
|
||||
OPMaps::Instance()->TilesInMemory.RemoveMemoryOverload();
|
||||
OPMaps::Instance()->kiberCacheLock.unlock();
|
||||
|
||||
MtileDrawingList.lock();
|
||||
{
|
||||
Matrix.ClearPointsNotIn(tileDrawingList);
|
||||
}
|
||||
MtileDrawingList.unlock();
|
||||
|
||||
|
||||
emit OnTileLoadComplete();
|
||||
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"loaderLimit release:"+loaderLimit.available()<<" ID="<<debug;
|
||||
#endif
|
||||
emit OnTilesStillToLoad(tilesToload<0? 0:tilesToload);
|
||||
loaderLimit.release();
|
||||
}
|
||||
}
|
||||
void Core::SetZoom(const int &value)
|
||||
{
|
||||
if (!isDragging)
|
||||
{
|
||||
zoom=value;
|
||||
minOfTiles=Projection()->GetTileMatrixMinXY(value);
|
||||
maxOfTiles=Projection()->GetTileMatrixMaxXY(value);
|
||||
currentPositionPixel=Projection()->FromLatLngToPixel(currentPosition,value);
|
||||
if(started)
|
||||
{
|
||||
MtileLoadQueue.lock();
|
||||
tileLoadQueue.clear();
|
||||
MtileLoadQueue.unlock();
|
||||
MtileToload.lock();
|
||||
tilesToload=0;
|
||||
MtileToload.unlock();
|
||||
Matrix.Clear();
|
||||
GoToCurrentPositionOnZoom();
|
||||
UpdateBounds();
|
||||
emit OnMapDrag();
|
||||
emit OnMapZoomChanged();
|
||||
emit OnNeedInvalidation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::SetCurrentPosition(const PointLatLng &value)
|
||||
{
|
||||
if(!IsDragging())
|
||||
{
|
||||
currentPosition = value;
|
||||
SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom()));
|
||||
|
||||
if(started)
|
||||
{
|
||||
GoToCurrentPosition();
|
||||
emit OnCurrentPositionChanged(currentPosition);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPosition = value;
|
||||
SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom()));
|
||||
|
||||
if(started)
|
||||
{
|
||||
emit OnCurrentPositionChanged(currentPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Core::SetMapType(const MapType::Types &value)
|
||||
{
|
||||
|
||||
if(value != GetMapType())
|
||||
{
|
||||
mapType = value;
|
||||
|
||||
switch(value)
|
||||
{
|
||||
|
||||
|
||||
case MapType::ArcGIS_Map:
|
||||
case MapType::ArcGIS_Satellite:
|
||||
case MapType::ArcGIS_ShadedRelief:
|
||||
case MapType::ArcGIS_Terrain:
|
||||
{
|
||||
if(Projection()->Type()!="PlateCarreeProjection")
|
||||
{
|
||||
SetProjection(new PlateCarreeProjection());
|
||||
maxzoom=13;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::ArcGIS_MapsLT_Map_Hybrid:
|
||||
case MapType::ArcGIS_MapsLT_Map_Labels:
|
||||
case MapType::ArcGIS_MapsLT_Map:
|
||||
case MapType::ArcGIS_MapsLT_OrtoFoto:
|
||||
{
|
||||
if(Projection()->Type()!="LKS94Projection")
|
||||
{
|
||||
SetProjection(new LKS94Projection());
|
||||
maxzoom=11;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::PergoTurkeyMap:
|
||||
{
|
||||
if(Projection()->Type()!="PlateCarreeProjectionPergo")
|
||||
{
|
||||
SetProjection(new PlateCarreeProjectionPergo());
|
||||
maxzoom=17;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YandexMapRu:
|
||||
{
|
||||
if(Projection()->Type()!="MercatorProjectionYandex")
|
||||
{
|
||||
SetProjection(new MercatorProjectionYandex());
|
||||
maxzoom=13;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if(Projection()->Type()!="MercatorProjection")
|
||||
{
|
||||
SetProjection(new MercatorProjection());
|
||||
maxzoom=21;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
minOfTiles = Projection()->GetTileMatrixMinXY(Zoom());
|
||||
maxOfTiles = Projection()->GetTileMatrixMaxXY(Zoom());
|
||||
SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(CurrentPosition(), Zoom()));
|
||||
|
||||
if(started)
|
||||
{
|
||||
CancelAsyncTasks();
|
||||
OnMapSizeChanged(Width, Height);
|
||||
GoToCurrentPosition();
|
||||
ReloadMap();
|
||||
GoToCurrentPosition();
|
||||
emit OnMapTypeChanged(value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void Core::StartSystem()
|
||||
{
|
||||
if(!started)
|
||||
{
|
||||
started = true;
|
||||
|
||||
ReloadMap();
|
||||
GoToCurrentPosition();
|
||||
}
|
||||
}
|
||||
|
||||
void Core::UpdateCenterTileXYLocation()
|
||||
{
|
||||
PointLatLng center = FromLocalToLatLng(Width/2, Height/2);
|
||||
Point centerPixel = Projection()->FromLatLngToPixel(center, Zoom());
|
||||
centerTileXYLocation = Projection()->FromPixelToTileXY(centerPixel);
|
||||
}
|
||||
|
||||
void Core::OnMapSizeChanged(int const& width, int const& height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
||||
sizeOfMapArea.SetWidth(1 + (Width/Projection()->TileSize().Width())/2);
|
||||
sizeOfMapArea.SetHeight(1 + (Height/Projection()->TileSize().Height())/2);
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
|
||||
if(started)
|
||||
{
|
||||
UpdateBounds();
|
||||
|
||||
emit OnCurrentPositionChanged(currentPosition);
|
||||
}
|
||||
}
|
||||
void Core::OnMapClose()
|
||||
{
|
||||
// if(waitOnEmptyTasks != null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// waitOnEmptyTasks.Set();
|
||||
// waitOnEmptyTasks.Close();
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
CancelAsyncTasks();
|
||||
}
|
||||
GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys)
|
||||
{
|
||||
GeoCoderStatusCode::Types status = GeoCoderStatusCode::Unknow;
|
||||
PointLatLng pos = OPMaps::Instance()->GetLatLngFromGeodecoder(keys, status);
|
||||
if(!pos.IsEmpty() && (status == GeoCoderStatusCode::G_GEO_SUCCESS))
|
||||
{
|
||||
SetCurrentPosition(pos);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
RectLatLng Core::CurrentViewArea()
|
||||
{
|
||||
PointLatLng p = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y(), Zoom());
|
||||
double rlng = Projection()->FromPixelToLatLng(-renderOffset.X() + Width, -renderOffset.Y(), Zoom()).Lng();
|
||||
double blat = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y() + Height, Zoom()).Lat();
|
||||
return RectLatLng::FromLTRB(p.Lng(), p.Lat(), rlng, blat);
|
||||
|
||||
}
|
||||
PointLatLng Core::FromLocalToLatLng(int const& x, int const& y)
|
||||
{
|
||||
return Projection()->FromPixelToLatLng(Point(x - renderOffset.X(), y - renderOffset.Y()), Zoom());
|
||||
}
|
||||
|
||||
|
||||
Point Core::FromLatLngToLocal(PointLatLng const& latlng)
|
||||
{
|
||||
Point pLocal = Projection()->FromLatLngToPixel(latlng, Zoom());
|
||||
pLocal.Offset(renderOffset);
|
||||
return pLocal;
|
||||
}
|
||||
int Core::GetMaxZoomToFitRect(RectLatLng const& rect)
|
||||
{
|
||||
int zoom = 0;
|
||||
|
||||
for(int i = 1; i <= MaxZoom(); i++)
|
||||
{
|
||||
Point p1 = Projection()->FromLatLngToPixel(rect.LocationTopLeft(), i);
|
||||
Point p2 = Projection()->FromLatLngToPixel(rect.Bottom(), rect.Right(), i);
|
||||
|
||||
if(((p2.X() - p1.X()) <= Width+10) && (p2.Y() - p1.Y()) <= Height+10)
|
||||
{
|
||||
zoom = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return zoom;
|
||||
}
|
||||
void Core::BeginDrag(Point const& pt)
|
||||
{
|
||||
dragPoint.SetX(pt.X() - renderOffset.X());
|
||||
dragPoint.SetY(pt.Y() - renderOffset.Y());
|
||||
isDragging = true;
|
||||
}
|
||||
void Core::EndDrag()
|
||||
{
|
||||
isDragging = false;
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
}
|
||||
void Core::ReloadMap()
|
||||
{
|
||||
if(started)
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"------------------";
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
tileLoadQueue.clear();
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
MtileToload.lock();
|
||||
tilesToload=0;
|
||||
MtileToload.unlock();
|
||||
Matrix.Clear();
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
}
|
||||
}
|
||||
void Core::GoToCurrentPosition()
|
||||
{
|
||||
// reset stuff
|
||||
renderOffset = Point::Empty;
|
||||
centerTileXYLocationLast = Point::Empty;
|
||||
dragPoint = Point::Empty;
|
||||
|
||||
// goto location
|
||||
Drag(Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)));
|
||||
}
|
||||
void Core::GoToCurrentPositionOnZoom()
|
||||
{
|
||||
// reset stuff
|
||||
renderOffset = Point::Empty;
|
||||
centerTileXYLocationLast = Point::Empty;
|
||||
dragPoint = Point::Empty;
|
||||
|
||||
// goto location and centering
|
||||
if(MouseWheelZooming)
|
||||
{
|
||||
if(mousewheelzoomtype != MouseWheelZoomType::MousePositionWithoutCenter)
|
||||
{
|
||||
Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2));
|
||||
renderOffset.SetX(pt.X() - dragPoint.X());
|
||||
renderOffset.SetY(pt.Y() - dragPoint.Y());
|
||||
}
|
||||
else // without centering
|
||||
{
|
||||
renderOffset.SetX(-GetcurrentPositionGPixel().X() - dragPoint.X());
|
||||
renderOffset.SetY(-GetcurrentPositionGPixel().Y() - dragPoint.Y());
|
||||
renderOffset.Offset(mouseLastZoom);
|
||||
}
|
||||
}
|
||||
else // use current map center
|
||||
{
|
||||
mouseLastZoom = Point::Empty;
|
||||
|
||||
Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2));
|
||||
renderOffset.SetX(pt.X() - dragPoint.X());
|
||||
renderOffset.SetY(pt.Y() - dragPoint.Y());
|
||||
}
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
}
|
||||
void Core::DragOffset(Point const& offset)
|
||||
{
|
||||
renderOffset.Offset(offset);
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
|
||||
if(centerTileXYLocation != centerTileXYLocationLast)
|
||||
{
|
||||
centerTileXYLocationLast = centerTileXYLocation;
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
{
|
||||
LastLocationInBounds = CurrentPosition();
|
||||
SetCurrentPosition (FromLocalToLatLng((int) Width/2, (int) Height/2));
|
||||
}
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
emit OnMapDrag();
|
||||
}
|
||||
void Core::Drag(Point const& pt)
|
||||
{
|
||||
renderOffset.SetX(pt.X() - dragPoint.X());
|
||||
renderOffset.SetY(pt.Y() - dragPoint.Y());
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
|
||||
if(centerTileXYLocation != centerTileXYLocationLast)
|
||||
{
|
||||
centerTileXYLocationLast = centerTileXYLocation;
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
if(IsDragging())
|
||||
{
|
||||
LastLocationInBounds = CurrentPosition();
|
||||
SetCurrentPosition(FromLocalToLatLng((int) Width/2, (int) Height/2));
|
||||
}
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
|
||||
emit OnMapDrag();
|
||||
|
||||
}
|
||||
void Core::CancelAsyncTasks()
|
||||
{
|
||||
if(started)
|
||||
{
|
||||
ProcessLoadTaskCallback.waitForDone();
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
tileLoadQueue.clear();
|
||||
//tilesToload=0;
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
MtileToload.lock();
|
||||
tilesToload=0;
|
||||
MtileToload.unlock();
|
||||
// ProcessLoadTaskCallback.waitForDone();
|
||||
}
|
||||
}
|
||||
void Core::UpdateBounds()
|
||||
{
|
||||
MtileDrawingList.lock();
|
||||
{
|
||||
FindTilesAround(tileDrawingList);
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"OnTileLoadStart: " << tileDrawingList.count() << " tiles to load at zoom " << Zoom() << ", time: " << QDateTime::currentDateTime().date();
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
emit OnTileLoadStart();
|
||||
|
||||
|
||||
foreach(Point p,tileDrawingList)
|
||||
{
|
||||
LoadTask task = LoadTask(p, Zoom());
|
||||
{
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
if(!tileLoadQueue.contains(task))
|
||||
{
|
||||
MtileToload.lock();
|
||||
++tilesToload;
|
||||
MtileToload.unlock();
|
||||
tileLoadQueue.enqueue(task);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::UpdateBounds new Task"<<task.Pos.ToString();
|
||||
#endif //DEBUG_CORE
|
||||
ProcessLoadTaskCallback.start(this);
|
||||
}
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
MtileDrawingList.unlock();
|
||||
UpdateGroundResolution();
|
||||
}
|
||||
void Core::FindTilesAround(QList<Point> &list)
|
||||
{
|
||||
list.clear();;
|
||||
for(int i = -sizeOfMapArea.Width(); i <= sizeOfMapArea.Width(); i++)
|
||||
{
|
||||
for(int j = -sizeOfMapArea.Height(); j <= sizeOfMapArea.Height(); j++)
|
||||
{
|
||||
Point p = centerTileXYLocation;
|
||||
p.SetX(p.X() + i);
|
||||
p.SetY(p.Y() + j);
|
||||
|
||||
//if(p.X < minOfTiles.Width)
|
||||
//{
|
||||
// p.X += (maxOfTiles.Width + 1);
|
||||
//}
|
||||
|
||||
//if(p.X > maxOfTiles.Width)
|
||||
//{
|
||||
// p.X -= (maxOfTiles.Width + 1);
|
||||
//}
|
||||
|
||||
if(p.X() >= minOfTiles.Width() && p.Y() >= minOfTiles.Height() && p.X() <= maxOfTiles.Width() && p.Y() <= maxOfTiles.Height())
|
||||
{
|
||||
if(!list.contains(p))
|
||||
{
|
||||
list.append(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void Core::UpdateGroundResolution()
|
||||
{
|
||||
double rez = Projection()->GetGroundResolution(Zoom(), CurrentPosition().Lat());
|
||||
pxRes100m = (int) (100.0 / rez); // 100 meters
|
||||
pxRes1000m = (int) (1000.0 / rez); // 1km
|
||||
pxRes10km = (int) (10000.0 / rez); // 10km
|
||||
pxRes100km = (int) (100000.0 / rez); // 100km
|
||||
pxRes1000km = (int) (1000000.0 / rez); // 1000km
|
||||
pxRes5000km = (int) (5000000.0 / rez); // 5000km
|
||||
}
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file core.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "core.h"
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qlonglong internals::Core::debugcounter=0;
|
||||
#endif
|
||||
|
||||
using namespace projections;
|
||||
|
||||
namespace internals {
|
||||
Core::Core():MouseWheelZooming(false),currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds(-1,-1),sizeOfMapArea(0,0)
|
||||
,minOfTiles(0,0),maxOfTiles(0,0),zoom(0),isDragging(false),TooltipTextPadding(10,10),loaderLimit(5),maxzoom(21),started(false),runningThreads(0)
|
||||
{
|
||||
mousewheelzoomtype=MouseWheelZoomType::MousePositionAndCenter;
|
||||
SetProjection(new MercatorProjection());
|
||||
this->setAutoDelete(false);
|
||||
ProcessLoadTaskCallback.setMaxThreadCount(10);
|
||||
renderOffset=Point(0,0);
|
||||
dragPoint=Point(0,0);
|
||||
CanDragMap=true;
|
||||
tilesToload=0;
|
||||
OPMaps::Instance();
|
||||
}
|
||||
Core::~Core()
|
||||
{
|
||||
ProcessLoadTaskCallback.waitForDone();
|
||||
}
|
||||
|
||||
void Core::run()
|
||||
{
|
||||
MrunningThreads.lock();
|
||||
++runningThreads;
|
||||
MrunningThreads.unlock();
|
||||
#ifdef DEBUG_CORE
|
||||
qlonglong debug;
|
||||
Mdebug.lock();
|
||||
debug=++debugcounter;
|
||||
Mdebug.unlock();
|
||||
qDebug()<<"core:run"<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
bool last = false;
|
||||
|
||||
LoadTask task;
|
||||
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
if(tileLoadQueue.count() > 0)
|
||||
{
|
||||
task = tileLoadQueue.dequeue();
|
||||
{
|
||||
|
||||
last = (tileLoadQueue.count() == 0);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"TileLoadQueue: " << tileLoadQueue.count()<<" Point:"<<task.Pos.ToString()<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
}
|
||||
}
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
|
||||
if(task.HasValue())
|
||||
if(loaderLimit.tryAcquire(1,OPMaps::Instance()->Timeout))
|
||||
{
|
||||
MtileToload.lock();
|
||||
--tilesToload;
|
||||
MtileToload.unlock();
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"loadLimit semaphore aquired "<<loaderLimit.available()<<" ID="<<debug<<" TASK="<<task.Pos.ToString()<<" "<<task.Zoom;
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
{
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"task as value, begining get"<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
{
|
||||
Tile* m = Matrix.TileAt(task.Pos);
|
||||
|
||||
if(m==0 || m->Overlays.count() == 0)
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Fill empty TileMatrix: " + task.ToString()<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
Tile* t = new Tile(task.Zoom, task.Pos);
|
||||
QVector<MapType::Types> layers= OPMaps::Instance()->GetAllLayersOfType(GetMapType());
|
||||
|
||||
foreach(MapType::Types tl,layers)
|
||||
{
|
||||
int retry = 0;
|
||||
do
|
||||
{
|
||||
QByteArray img;
|
||||
|
||||
// tile number inversion(BottomLeft -> TopLeft) for pergo maps
|
||||
if(tl == MapType::PergoTurkeyMap)
|
||||
{
|
||||
img = OPMaps::Instance()->GetImageFrom(tl, Point(task.Pos.X(), maxOfTiles.Height() - task.Pos.Y()), task.Zoom);
|
||||
}
|
||||
else // ok
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"start getting image"<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
img = OPMaps::Instance()->GetImageFrom(tl, task.Pos, task.Zoom);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::run:gotimage size:"<<img.count()<<" ID="<<debug<<" time="<<t.elapsed();
|
||||
#endif //DEBUG_CORE
|
||||
}
|
||||
|
||||
if(img.length()!=0)
|
||||
{
|
||||
Moverlays.lock();
|
||||
{
|
||||
t->Overlays.append(img);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::run append img:"<<img.length()<<" to tile:"<<t->GetPos().ToString()<<" now has "<<t->Overlays.count()<<" overlays"<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
}
|
||||
Moverlays.unlock();
|
||||
|
||||
break;
|
||||
}
|
||||
else if(OPMaps::Instance()->RetryLoadTile > 0)
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"ProcessLoadTask: " << task.ToString()<< " -> empty tile, retry " << retry<<" ID="<<debug;;
|
||||
#endif //DEBUG_CORE
|
||||
{
|
||||
QWaitCondition wait;
|
||||
QMutex m;
|
||||
m.lock();
|
||||
wait.wait(&m,500);
|
||||
}
|
||||
}
|
||||
}
|
||||
while(++retry < OPMaps::Instance()->RetryLoadTile);
|
||||
}
|
||||
|
||||
if(t->Overlays.count() > 0)
|
||||
{
|
||||
Matrix.SetTileAt(task.Pos,t);
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::run add tile "<<t->GetPos().ToString()<<" to matrix index "<<task.Pos.ToString()<<" ID="<<debug;
|
||||
qDebug()<<"Core::run matrix index "<<task.Pos.ToString()<<" as tile with "<<Matrix.TileAt(task.Pos)->Overlays.count()<<" ID="<<debug;
|
||||
#endif //DEBUG_CORE
|
||||
}
|
||||
else
|
||||
{
|
||||
// emit OnTilesStillToLoad(tilesToload);
|
||||
|
||||
delete t;
|
||||
t = 0;
|
||||
emit OnNeedInvalidation();
|
||||
}
|
||||
|
||||
// layers = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// last buddy cleans stuff ;}
|
||||
if(last)
|
||||
{
|
||||
OPMaps::Instance()->kiberCacheLock.lockForWrite();
|
||||
OPMaps::Instance()->TilesInMemory.RemoveMemoryOverload();
|
||||
OPMaps::Instance()->kiberCacheLock.unlock();
|
||||
|
||||
MtileDrawingList.lock();
|
||||
{
|
||||
Matrix.ClearPointsNotIn(tileDrawingList);
|
||||
}
|
||||
MtileDrawingList.unlock();
|
||||
|
||||
|
||||
emit OnTileLoadComplete();
|
||||
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"loaderLimit release:"+loaderLimit.available()<<" ID="<<debug;
|
||||
#endif
|
||||
emit OnTilesStillToLoad(tilesToload<0? 0:tilesToload);
|
||||
loaderLimit.release();
|
||||
}
|
||||
MrunningThreads.lock();
|
||||
--runningThreads;
|
||||
MrunningThreads.unlock();
|
||||
}
|
||||
diagnostics Core::GetDiagnostics()
|
||||
{
|
||||
MrunningThreads.lock();
|
||||
diag=OPMaps::Instance()->GetDiagnostics();
|
||||
diag.runningThreads=runningThreads;
|
||||
MrunningThreads.unlock();
|
||||
return diag;
|
||||
}
|
||||
|
||||
void Core::SetZoom(const int &value)
|
||||
{
|
||||
if (!isDragging)
|
||||
{
|
||||
zoom=value;
|
||||
minOfTiles=Projection()->GetTileMatrixMinXY(value);
|
||||
maxOfTiles=Projection()->GetTileMatrixMaxXY(value);
|
||||
currentPositionPixel=Projection()->FromLatLngToPixel(currentPosition,value);
|
||||
if(started)
|
||||
{
|
||||
MtileLoadQueue.lock();
|
||||
tileLoadQueue.clear();
|
||||
MtileLoadQueue.unlock();
|
||||
MtileToload.lock();
|
||||
tilesToload=0;
|
||||
MtileToload.unlock();
|
||||
Matrix.Clear();
|
||||
GoToCurrentPositionOnZoom();
|
||||
UpdateBounds();
|
||||
emit OnMapDrag();
|
||||
emit OnMapZoomChanged();
|
||||
emit OnNeedInvalidation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::SetCurrentPosition(const PointLatLng &value)
|
||||
{
|
||||
if(!IsDragging())
|
||||
{
|
||||
currentPosition = value;
|
||||
SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom()));
|
||||
|
||||
if(started)
|
||||
{
|
||||
GoToCurrentPosition();
|
||||
emit OnCurrentPositionChanged(currentPosition);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPosition = value;
|
||||
SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(value, Zoom()));
|
||||
|
||||
if(started)
|
||||
{
|
||||
emit OnCurrentPositionChanged(currentPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Core::SetMapType(const MapType::Types &value)
|
||||
{
|
||||
|
||||
if(value != GetMapType())
|
||||
{
|
||||
mapType = value;
|
||||
|
||||
switch(value)
|
||||
{
|
||||
|
||||
|
||||
case MapType::ArcGIS_Map:
|
||||
case MapType::ArcGIS_Satellite:
|
||||
case MapType::ArcGIS_ShadedRelief:
|
||||
case MapType::ArcGIS_Terrain:
|
||||
{
|
||||
if(Projection()->Type()!="PlateCarreeProjection")
|
||||
{
|
||||
SetProjection(new PlateCarreeProjection());
|
||||
maxzoom=13;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::ArcGIS_MapsLT_Map_Hybrid:
|
||||
case MapType::ArcGIS_MapsLT_Map_Labels:
|
||||
case MapType::ArcGIS_MapsLT_Map:
|
||||
case MapType::ArcGIS_MapsLT_OrtoFoto:
|
||||
{
|
||||
if(Projection()->Type()!="LKS94Projection")
|
||||
{
|
||||
SetProjection(new LKS94Projection());
|
||||
maxzoom=11;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::PergoTurkeyMap:
|
||||
{
|
||||
if(Projection()->Type()!="PlateCarreeProjectionPergo")
|
||||
{
|
||||
SetProjection(new PlateCarreeProjectionPergo());
|
||||
maxzoom=17;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MapType::YandexMapRu:
|
||||
{
|
||||
if(Projection()->Type()!="MercatorProjectionYandex")
|
||||
{
|
||||
SetProjection(new MercatorProjectionYandex());
|
||||
maxzoom=13;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if(Projection()->Type()!="MercatorProjection")
|
||||
{
|
||||
SetProjection(new MercatorProjection());
|
||||
maxzoom=21;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
minOfTiles = Projection()->GetTileMatrixMinXY(Zoom());
|
||||
maxOfTiles = Projection()->GetTileMatrixMaxXY(Zoom());
|
||||
SetCurrentPositionGPixel(Projection()->FromLatLngToPixel(CurrentPosition(), Zoom()));
|
||||
|
||||
if(started)
|
||||
{
|
||||
CancelAsyncTasks();
|
||||
OnMapSizeChanged(Width, Height);
|
||||
GoToCurrentPosition();
|
||||
ReloadMap();
|
||||
GoToCurrentPosition();
|
||||
emit OnMapTypeChanged(value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void Core::StartSystem()
|
||||
{
|
||||
if(!started)
|
||||
{
|
||||
started = true;
|
||||
|
||||
ReloadMap();
|
||||
GoToCurrentPosition();
|
||||
}
|
||||
}
|
||||
|
||||
void Core::UpdateCenterTileXYLocation()
|
||||
{
|
||||
PointLatLng center = FromLocalToLatLng(Width/2, Height/2);
|
||||
Point centerPixel = Projection()->FromLatLngToPixel(center, Zoom());
|
||||
centerTileXYLocation = Projection()->FromPixelToTileXY(centerPixel);
|
||||
}
|
||||
|
||||
void Core::OnMapSizeChanged(int const& width, int const& height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
||||
sizeOfMapArea.SetWidth(1 + (Width/Projection()->TileSize().Width())/2);
|
||||
sizeOfMapArea.SetHeight(1 + (Height/Projection()->TileSize().Height())/2);
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
|
||||
if(started)
|
||||
{
|
||||
UpdateBounds();
|
||||
|
||||
emit OnCurrentPositionChanged(currentPosition);
|
||||
}
|
||||
}
|
||||
void Core::OnMapClose()
|
||||
{
|
||||
// if(waitOnEmptyTasks != null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// waitOnEmptyTasks.Set();
|
||||
// waitOnEmptyTasks.Close();
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
CancelAsyncTasks();
|
||||
}
|
||||
GeoCoderStatusCode::Types Core::SetCurrentPositionByKeywords(QString const& keys)
|
||||
{
|
||||
GeoCoderStatusCode::Types status = GeoCoderStatusCode::Unknow;
|
||||
PointLatLng pos = OPMaps::Instance()->GetLatLngFromGeodecoder(keys, status);
|
||||
if(!pos.IsEmpty() && (status == GeoCoderStatusCode::G_GEO_SUCCESS))
|
||||
{
|
||||
SetCurrentPosition(pos);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
RectLatLng Core::CurrentViewArea()
|
||||
{
|
||||
PointLatLng p = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y(), Zoom());
|
||||
double rlng = Projection()->FromPixelToLatLng(-renderOffset.X() + Width, -renderOffset.Y(), Zoom()).Lng();
|
||||
double blat = Projection()->FromPixelToLatLng(-renderOffset.X(), -renderOffset.Y() + Height, Zoom()).Lat();
|
||||
return RectLatLng::FromLTRB(p.Lng(), p.Lat(), rlng, blat);
|
||||
|
||||
}
|
||||
PointLatLng Core::FromLocalToLatLng(int const& x, int const& y)
|
||||
{
|
||||
return Projection()->FromPixelToLatLng(Point(x - renderOffset.X(), y - renderOffset.Y()), Zoom());
|
||||
}
|
||||
|
||||
|
||||
Point Core::FromLatLngToLocal(PointLatLng const& latlng)
|
||||
{
|
||||
Point pLocal = Projection()->FromLatLngToPixel(latlng, Zoom());
|
||||
pLocal.Offset(renderOffset);
|
||||
return pLocal;
|
||||
}
|
||||
int Core::GetMaxZoomToFitRect(RectLatLng const& rect)
|
||||
{
|
||||
int zoom = 0;
|
||||
|
||||
for(int i = 1; i <= MaxZoom(); i++)
|
||||
{
|
||||
Point p1 = Projection()->FromLatLngToPixel(rect.LocationTopLeft(), i);
|
||||
Point p2 = Projection()->FromLatLngToPixel(rect.Bottom(), rect.Right(), i);
|
||||
|
||||
if(((p2.X() - p1.X()) <= Width+10) && (p2.Y() - p1.Y()) <= Height+10)
|
||||
{
|
||||
zoom = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return zoom;
|
||||
}
|
||||
void Core::BeginDrag(Point const& pt)
|
||||
{
|
||||
dragPoint.SetX(pt.X() - renderOffset.X());
|
||||
dragPoint.SetY(pt.Y() - renderOffset.Y());
|
||||
isDragging = true;
|
||||
}
|
||||
void Core::EndDrag()
|
||||
{
|
||||
isDragging = false;
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
}
|
||||
void Core::ReloadMap()
|
||||
{
|
||||
if(started)
|
||||
{
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"------------------";
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
tileLoadQueue.clear();
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
MtileToload.lock();
|
||||
tilesToload=0;
|
||||
MtileToload.unlock();
|
||||
Matrix.Clear();
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
}
|
||||
}
|
||||
void Core::GoToCurrentPosition()
|
||||
{
|
||||
// reset stuff
|
||||
renderOffset = Point::Empty;
|
||||
centerTileXYLocationLast = Point::Empty;
|
||||
dragPoint = Point::Empty;
|
||||
|
||||
// goto location
|
||||
Drag(Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2)));
|
||||
}
|
||||
void Core::GoToCurrentPositionOnZoom()
|
||||
{
|
||||
// reset stuff
|
||||
renderOffset = Point::Empty;
|
||||
centerTileXYLocationLast = Point::Empty;
|
||||
dragPoint = Point::Empty;
|
||||
|
||||
// goto location and centering
|
||||
if(MouseWheelZooming)
|
||||
{
|
||||
if(mousewheelzoomtype != MouseWheelZoomType::MousePositionWithoutCenter)
|
||||
{
|
||||
Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2));
|
||||
renderOffset.SetX(pt.X() - dragPoint.X());
|
||||
renderOffset.SetY(pt.Y() - dragPoint.Y());
|
||||
}
|
||||
else // without centering
|
||||
{
|
||||
renderOffset.SetX(-GetcurrentPositionGPixel().X() - dragPoint.X());
|
||||
renderOffset.SetY(-GetcurrentPositionGPixel().Y() - dragPoint.Y());
|
||||
renderOffset.Offset(mouseLastZoom);
|
||||
}
|
||||
}
|
||||
else // use current map center
|
||||
{
|
||||
mouseLastZoom = Point::Empty;
|
||||
|
||||
Point pt = Point(-(GetcurrentPositionGPixel().X() - Width/2), -(GetcurrentPositionGPixel().Y() - Height/2));
|
||||
renderOffset.SetX(pt.X() - dragPoint.X());
|
||||
renderOffset.SetY(pt.Y() - dragPoint.Y());
|
||||
}
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
}
|
||||
void Core::DragOffset(Point const& offset)
|
||||
{
|
||||
renderOffset.Offset(offset);
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
|
||||
if(centerTileXYLocation != centerTileXYLocationLast)
|
||||
{
|
||||
centerTileXYLocationLast = centerTileXYLocation;
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
{
|
||||
LastLocationInBounds = CurrentPosition();
|
||||
SetCurrentPosition (FromLocalToLatLng((int) Width/2, (int) Height/2));
|
||||
}
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
emit OnMapDrag();
|
||||
}
|
||||
void Core::Drag(Point const& pt)
|
||||
{
|
||||
renderOffset.SetX(pt.X() - dragPoint.X());
|
||||
renderOffset.SetY(pt.Y() - dragPoint.Y());
|
||||
|
||||
UpdateCenterTileXYLocation();
|
||||
|
||||
if(centerTileXYLocation != centerTileXYLocationLast)
|
||||
{
|
||||
centerTileXYLocationLast = centerTileXYLocation;
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
if(IsDragging())
|
||||
{
|
||||
LastLocationInBounds = CurrentPosition();
|
||||
SetCurrentPosition(FromLocalToLatLng((int) Width/2, (int) Height/2));
|
||||
}
|
||||
|
||||
emit OnNeedInvalidation();
|
||||
|
||||
|
||||
emit OnMapDrag();
|
||||
|
||||
}
|
||||
void Core::CancelAsyncTasks()
|
||||
{
|
||||
if(started)
|
||||
{
|
||||
ProcessLoadTaskCallback.waitForDone();
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
tileLoadQueue.clear();
|
||||
//tilesToload=0;
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
MtileToload.lock();
|
||||
tilesToload=0;
|
||||
MtileToload.unlock();
|
||||
// ProcessLoadTaskCallback.waitForDone();
|
||||
}
|
||||
}
|
||||
void Core::UpdateBounds()
|
||||
{
|
||||
MtileDrawingList.lock();
|
||||
{
|
||||
FindTilesAround(tileDrawingList);
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"OnTileLoadStart: " << tileDrawingList.count() << " tiles to load at zoom " << Zoom() << ", time: " << QDateTime::currentDateTime().date();
|
||||
#endif //DEBUG_CORE
|
||||
|
||||
emit OnTileLoadStart();
|
||||
|
||||
|
||||
foreach(Point p,tileDrawingList)
|
||||
{
|
||||
LoadTask task = LoadTask(p, Zoom());
|
||||
{
|
||||
MtileLoadQueue.lock();
|
||||
{
|
||||
if(!tileLoadQueue.contains(task))
|
||||
{
|
||||
MtileToload.lock();
|
||||
++tilesToload;
|
||||
MtileToload.unlock();
|
||||
tileLoadQueue.enqueue(task);
|
||||
#ifdef DEBUG_CORE
|
||||
qDebug()<<"Core::UpdateBounds new Task"<<task.Pos.ToString();
|
||||
#endif //DEBUG_CORE
|
||||
ProcessLoadTaskCallback.start(this);
|
||||
}
|
||||
}
|
||||
MtileLoadQueue.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
MtileDrawingList.unlock();
|
||||
UpdateGroundResolution();
|
||||
}
|
||||
void Core::FindTilesAround(QList<Point> &list)
|
||||
{
|
||||
list.clear();;
|
||||
for(int i = -sizeOfMapArea.Width(); i <= sizeOfMapArea.Width(); i++)
|
||||
{
|
||||
for(int j = -sizeOfMapArea.Height(); j <= sizeOfMapArea.Height(); j++)
|
||||
{
|
||||
Point p = centerTileXYLocation;
|
||||
p.SetX(p.X() + i);
|
||||
p.SetY(p.Y() + j);
|
||||
|
||||
//if(p.X < minOfTiles.Width)
|
||||
//{
|
||||
// p.X += (maxOfTiles.Width + 1);
|
||||
//}
|
||||
|
||||
//if(p.X > maxOfTiles.Width)
|
||||
//{
|
||||
// p.X -= (maxOfTiles.Width + 1);
|
||||
//}
|
||||
|
||||
if(p.X() >= minOfTiles.Width() && p.Y() >= minOfTiles.Height() && p.X() <= maxOfTiles.Width() && p.Y() <= maxOfTiles.Height())
|
||||
{
|
||||
if(!list.contains(p))
|
||||
{
|
||||
list.append(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void Core::UpdateGroundResolution()
|
||||
{
|
||||
double rez = Projection()->GetGroundResolution(Zoom(), CurrentPosition().Lat());
|
||||
pxRes100m = (int) (100.0 / rez); // 100 meters
|
||||
pxRes1000m = (int) (1000.0 / rez); // 1km
|
||||
pxRes10km = (int) (10000.0 / rez); // 10km
|
||||
pxRes100km = (int) (100000.0 / rez); // 100km
|
||||
pxRes1000km = (int) (1000000.0 / rez); // 1000km
|
||||
pxRes5000km = (int) (5000000.0 / rez); // 5000km
|
||||
}
|
||||
}
|
||||
|
@ -1,278 +1,283 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file core.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef CORE_H
|
||||
#define CORE_H
|
||||
|
||||
#include "debugheader.h"
|
||||
|
||||
#include "../internals/pointlatlng.h"
|
||||
#include "mousewheelzoomtype.h"
|
||||
#include "../core/size.h"
|
||||
#include "../core/point.h"
|
||||
|
||||
#include "../core/maptype.h"
|
||||
#include "rectangle.h"
|
||||
#include "QThreadPool"
|
||||
#include "tilematrix.h"
|
||||
#include <QQueue>
|
||||
#include "loadtask.h"
|
||||
#include "copyrightstrings.h"
|
||||
#include "rectlatlng.h"
|
||||
#include "../internals/projections/lks94projection.h"
|
||||
#include "../internals/projections/mercatorprojection.h"
|
||||
#include "../internals/projections/mercatorprojectionyandex.h"
|
||||
#include "../internals/projections/platecarreeprojection.h"
|
||||
#include "../internals/projections/platecarreeprojectionpergo.h"
|
||||
#include "../core/geodecoderstatus.h"
|
||||
#include "../core/opmaps.h"
|
||||
#include <QSemaphore>
|
||||
#include <QThread>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace mapcontrol
|
||||
{
|
||||
class OPMapControl;
|
||||
class MapGraphicItem;
|
||||
}
|
||||
|
||||
namespace internals {
|
||||
|
||||
class Core:public QObject,public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class mapcontrol::OPMapControl;
|
||||
friend class mapcontrol::MapGraphicItem;
|
||||
public:
|
||||
Core();
|
||||
~Core();
|
||||
void run();
|
||||
PointLatLng CurrentPosition()const{return currentPosition;}
|
||||
|
||||
void SetCurrentPosition(const PointLatLng &value);
|
||||
|
||||
core::Point GetcurrentPositionGPixel(){return currentPositionPixel;}
|
||||
void SetcurrentPositionGPixel(const core::Point &value){currentPositionPixel=value;}
|
||||
|
||||
core::Point GetrenderOffset(){return renderOffset;}
|
||||
void SetrenderOffset(const core::Point &value){renderOffset=value;}
|
||||
|
||||
core::Point GetcenterTileXYLocation(){return centerTileXYLocation;}
|
||||
void SetcenterTileXYLocation(const core::Point &value){centerTileXYLocation=value;}
|
||||
|
||||
core::Point GetcenterTileXYLocationLast(){return centerTileXYLocationLast;}
|
||||
void SetcenterTileXYLocationLast(const core::Point &value){centerTileXYLocationLast=value;}
|
||||
|
||||
core::Point GetdragPoint(){return dragPoint;}
|
||||
void SetdragPoint(const core::Point &value){dragPoint=value;}
|
||||
|
||||
core::Point GetmouseDown(){return mouseDown;}
|
||||
void SetmouseDown(const core::Point &value){mouseDown=value;}
|
||||
|
||||
core::Point GetmouseCurrent(){return mouseCurrent;}
|
||||
void SetmouseCurrent(const core::Point &value){mouseCurrent=value;}
|
||||
|
||||
core::Point GetmouseLastZoom(){return mouseLastZoom;}
|
||||
void SetmouseLastZoom(const core::Point &value){mouseLastZoom=value;}
|
||||
|
||||
MouseWheelZoomType::Types GetMouseWheelZoomType(){return mousewheelzoomtype;}
|
||||
void SetMouseWheelZoomType(const MouseWheelZoomType::Types &value){mousewheelzoomtype=value;}
|
||||
|
||||
PointLatLng GetLastLocationInBounds(){return LastLocationInBounds;}
|
||||
void SetLastLocationInBounds(const PointLatLng &value){LastLocationInBounds=value;}
|
||||
|
||||
Size GetsizeOfMapArea(){return sizeOfMapArea;}
|
||||
void SetsizeOfMapArea(const Size &value){sizeOfMapArea=value;}
|
||||
|
||||
Size GetminOfTiles(){return minOfTiles;}
|
||||
void SetminOfTiles(const Size &value){minOfTiles=value;}
|
||||
|
||||
Size GetmaxOfTiles(){return maxOfTiles;}
|
||||
void SetmaxOfTiles(const Size &value){maxOfTiles=value;}
|
||||
|
||||
Rectangle GettileRect(){return tileRect;}
|
||||
void SettileRect(const Rectangle &value){tileRect=value;}
|
||||
|
||||
core::Point GettilePoint(){return tilePoint;}
|
||||
void SettilePoint(const core::Point &value){tilePoint=value;}
|
||||
|
||||
Rectangle GetCurrentRegion(){return CurrentRegion;}
|
||||
void SetCurrentRegion(const Rectangle &value){CurrentRegion=value;}
|
||||
|
||||
QList<core::Point> tileDrawingList;
|
||||
|
||||
PureProjection* Projection()
|
||||
{
|
||||
return projection;
|
||||
}
|
||||
void SetProjection(PureProjection* value)
|
||||
{
|
||||
projection=value;
|
||||
tileRect=Rectangle(core::Point(0,0),value->TileSize());
|
||||
}
|
||||
bool IsDragging()const{return isDragging;}
|
||||
|
||||
int Zoom()const{return zoom;}
|
||||
void SetZoom(int const& value);
|
||||
|
||||
int MaxZoom()const{return maxzoom;}
|
||||
|
||||
void UpdateBounds();
|
||||
|
||||
MapType::Types GetMapType(){return mapType;}
|
||||
void SetMapType(MapType::Types const& value);
|
||||
|
||||
void StartSystem();
|
||||
|
||||
void UpdateCenterTileXYLocation();
|
||||
|
||||
void OnMapSizeChanged(int const& width, int const& height);//TODO had as slot
|
||||
|
||||
void OnMapClose();//TODO had as slot
|
||||
|
||||
GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const& keys);
|
||||
|
||||
RectLatLng CurrentViewArea();
|
||||
|
||||
PointLatLng FromLocalToLatLng(int const& x, int const& y);
|
||||
|
||||
Point FromLatLngToLocal(PointLatLng const& latlng);
|
||||
|
||||
int GetMaxZoomToFitRect(RectLatLng const& rect);
|
||||
|
||||
void BeginDrag(core::Point const& pt);
|
||||
|
||||
void EndDrag();
|
||||
|
||||
void ReloadMap();
|
||||
|
||||
void GoToCurrentPosition();
|
||||
|
||||
bool MouseWheelZooming;
|
||||
|
||||
void DragOffset(core::Point const& offset);
|
||||
|
||||
void Drag(core::Point const& pt);
|
||||
|
||||
void CancelAsyncTasks();
|
||||
|
||||
void FindTilesAround(QList<core::Point> &list);
|
||||
|
||||
void UpdateGroundResolution();
|
||||
|
||||
TileMatrix Matrix;
|
||||
|
||||
bool isStarted(){return started;}
|
||||
|
||||
|
||||
signals:
|
||||
void OnCurrentPositionChanged(internals::PointLatLng point);
|
||||
void OnTileLoadComplete();
|
||||
void OnTilesStillToLoad(int number);
|
||||
void OnTileLoadStart();
|
||||
void OnMapDrag();
|
||||
void OnMapZoomChanged();
|
||||
void OnMapTypeChanged(MapType::Types type);
|
||||
void OnEmptyTileError(int zoom, core::Point pos);
|
||||
void OnNeedInvalidation();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
PointLatLng currentPosition;
|
||||
core::Point currentPositionPixel;
|
||||
core::Point renderOffset;
|
||||
core::Point centerTileXYLocation;
|
||||
core::Point centerTileXYLocationLast;
|
||||
core::Point dragPoint;
|
||||
Rectangle tileRect;
|
||||
core::Point mouseDown;
|
||||
bool CanDragMap;
|
||||
core::Point mouseCurrent;
|
||||
PointLatLng LastLocationInBounds;
|
||||
core::Point mouseLastZoom;
|
||||
|
||||
MouseWheelZoomType::Types mousewheelzoomtype;
|
||||
|
||||
|
||||
Size sizeOfMapArea;
|
||||
Size minOfTiles;
|
||||
Size maxOfTiles;
|
||||
|
||||
core::Point tilePoint;
|
||||
|
||||
Rectangle CurrentRegion;
|
||||
|
||||
QQueue<LoadTask> tileLoadQueue;
|
||||
|
||||
int zoom;
|
||||
|
||||
PureProjection* projection;
|
||||
|
||||
bool isDragging;
|
||||
|
||||
QMutex MtileLoadQueue;
|
||||
|
||||
QMutex Moverlays;
|
||||
|
||||
QMutex MtileDrawingList;
|
||||
#ifdef DEBUG_CORE
|
||||
QMutex Mdebug;
|
||||
static qlonglong debugcounter;
|
||||
#endif
|
||||
Size TooltipTextPadding;
|
||||
|
||||
MapType::Types mapType;
|
||||
|
||||
QSemaphore loaderLimit;
|
||||
|
||||
QThreadPool ProcessLoadTaskCallback;
|
||||
QMutex MtileToload;
|
||||
int tilesToload;
|
||||
|
||||
int maxzoom;
|
||||
|
||||
protected:
|
||||
bool started;
|
||||
|
||||
int Width;
|
||||
int Height;
|
||||
int pxRes100m; // 100 meters
|
||||
int pxRes1000m; // 1km
|
||||
int pxRes10km; // 10km
|
||||
int pxRes100km; // 100km
|
||||
int pxRes1000km; // 1000km
|
||||
int pxRes5000km; // 5000km
|
||||
void SetCurrentPositionGPixel(core::Point const& value){currentPositionPixel = value;}
|
||||
void GoToCurrentPositionOnZoom();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // CORE_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file core.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef CORE_H
|
||||
#define CORE_H
|
||||
|
||||
#include "debugheader.h"
|
||||
|
||||
#include "../internals/pointlatlng.h"
|
||||
#include "mousewheelzoomtype.h"
|
||||
#include "../core/size.h"
|
||||
#include "../core/point.h"
|
||||
|
||||
#include "../core/maptype.h"
|
||||
#include "rectangle.h"
|
||||
#include "QThreadPool"
|
||||
#include "tilematrix.h"
|
||||
#include <QQueue>
|
||||
#include "loadtask.h"
|
||||
#include "copyrightstrings.h"
|
||||
#include "rectlatlng.h"
|
||||
#include "../internals/projections/lks94projection.h"
|
||||
#include "../internals/projections/mercatorprojection.h"
|
||||
#include "../internals/projections/mercatorprojectionyandex.h"
|
||||
#include "../internals/projections/platecarreeprojection.h"
|
||||
#include "../internals/projections/platecarreeprojectionpergo.h"
|
||||
#include "../core/geodecoderstatus.h"
|
||||
#include "../core/opmaps.h"
|
||||
#include "../core/diagnostics.h"
|
||||
|
||||
#include <QSemaphore>
|
||||
#include <QThread>
|
||||
#include <QDateTime>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace mapcontrol
|
||||
{
|
||||
class OPMapControl;
|
||||
class MapGraphicItem;
|
||||
}
|
||||
|
||||
namespace internals {
|
||||
|
||||
class Core:public QObject,public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class mapcontrol::OPMapControl;
|
||||
friend class mapcontrol::MapGraphicItem;
|
||||
public:
|
||||
Core();
|
||||
~Core();
|
||||
void run();
|
||||
PointLatLng CurrentPosition()const{return currentPosition;}
|
||||
|
||||
void SetCurrentPosition(const PointLatLng &value);
|
||||
|
||||
core::Point GetcurrentPositionGPixel(){return currentPositionPixel;}
|
||||
void SetcurrentPositionGPixel(const core::Point &value){currentPositionPixel=value;}
|
||||
|
||||
core::Point GetrenderOffset(){return renderOffset;}
|
||||
void SetrenderOffset(const core::Point &value){renderOffset=value;}
|
||||
|
||||
core::Point GetcenterTileXYLocation(){return centerTileXYLocation;}
|
||||
void SetcenterTileXYLocation(const core::Point &value){centerTileXYLocation=value;}
|
||||
|
||||
core::Point GetcenterTileXYLocationLast(){return centerTileXYLocationLast;}
|
||||
void SetcenterTileXYLocationLast(const core::Point &value){centerTileXYLocationLast=value;}
|
||||
|
||||
core::Point GetdragPoint(){return dragPoint;}
|
||||
void SetdragPoint(const core::Point &value){dragPoint=value;}
|
||||
|
||||
core::Point GetmouseDown(){return mouseDown;}
|
||||
void SetmouseDown(const core::Point &value){mouseDown=value;}
|
||||
|
||||
core::Point GetmouseCurrent(){return mouseCurrent;}
|
||||
void SetmouseCurrent(const core::Point &value){mouseCurrent=value;}
|
||||
|
||||
core::Point GetmouseLastZoom(){return mouseLastZoom;}
|
||||
void SetmouseLastZoom(const core::Point &value){mouseLastZoom=value;}
|
||||
|
||||
MouseWheelZoomType::Types GetMouseWheelZoomType(){return mousewheelzoomtype;}
|
||||
void SetMouseWheelZoomType(const MouseWheelZoomType::Types &value){mousewheelzoomtype=value;}
|
||||
|
||||
PointLatLng GetLastLocationInBounds(){return LastLocationInBounds;}
|
||||
void SetLastLocationInBounds(const PointLatLng &value){LastLocationInBounds=value;}
|
||||
|
||||
Size GetsizeOfMapArea(){return sizeOfMapArea;}
|
||||
void SetsizeOfMapArea(const Size &value){sizeOfMapArea=value;}
|
||||
|
||||
Size GetminOfTiles(){return minOfTiles;}
|
||||
void SetminOfTiles(const Size &value){minOfTiles=value;}
|
||||
|
||||
Size GetmaxOfTiles(){return maxOfTiles;}
|
||||
void SetmaxOfTiles(const Size &value){maxOfTiles=value;}
|
||||
|
||||
Rectangle GettileRect(){return tileRect;}
|
||||
void SettileRect(const Rectangle &value){tileRect=value;}
|
||||
|
||||
core::Point GettilePoint(){return tilePoint;}
|
||||
void SettilePoint(const core::Point &value){tilePoint=value;}
|
||||
|
||||
Rectangle GetCurrentRegion(){return CurrentRegion;}
|
||||
void SetCurrentRegion(const Rectangle &value){CurrentRegion=value;}
|
||||
|
||||
QList<core::Point> tileDrawingList;
|
||||
|
||||
PureProjection* Projection()
|
||||
{
|
||||
return projection;
|
||||
}
|
||||
void SetProjection(PureProjection* value)
|
||||
{
|
||||
projection=value;
|
||||
tileRect=Rectangle(core::Point(0,0),value->TileSize());
|
||||
}
|
||||
bool IsDragging()const{return isDragging;}
|
||||
|
||||
int Zoom()const{return zoom;}
|
||||
void SetZoom(int const& value);
|
||||
|
||||
int MaxZoom()const{return maxzoom;}
|
||||
|
||||
void UpdateBounds();
|
||||
|
||||
MapType::Types GetMapType(){return mapType;}
|
||||
void SetMapType(MapType::Types const& value);
|
||||
|
||||
void StartSystem();
|
||||
|
||||
void UpdateCenterTileXYLocation();
|
||||
|
||||
void OnMapSizeChanged(int const& width, int const& height);//TODO had as slot
|
||||
|
||||
void OnMapClose();//TODO had as slot
|
||||
|
||||
GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const& keys);
|
||||
|
||||
RectLatLng CurrentViewArea();
|
||||
|
||||
PointLatLng FromLocalToLatLng(int const& x, int const& y);
|
||||
|
||||
Point FromLatLngToLocal(PointLatLng const& latlng);
|
||||
|
||||
int GetMaxZoomToFitRect(RectLatLng const& rect);
|
||||
|
||||
void BeginDrag(core::Point const& pt);
|
||||
|
||||
void EndDrag();
|
||||
|
||||
void ReloadMap();
|
||||
|
||||
void GoToCurrentPosition();
|
||||
|
||||
bool MouseWheelZooming;
|
||||
|
||||
void DragOffset(core::Point const& offset);
|
||||
|
||||
void Drag(core::Point const& pt);
|
||||
|
||||
void CancelAsyncTasks();
|
||||
|
||||
void FindTilesAround(QList<core::Point> &list);
|
||||
|
||||
void UpdateGroundResolution();
|
||||
|
||||
TileMatrix Matrix;
|
||||
|
||||
bool isStarted(){return started;}
|
||||
|
||||
diagnostics GetDiagnostics();
|
||||
signals:
|
||||
void OnCurrentPositionChanged(internals::PointLatLng point);
|
||||
void OnTileLoadComplete();
|
||||
void OnTilesStillToLoad(int number);
|
||||
void OnTileLoadStart();
|
||||
void OnMapDrag();
|
||||
void OnMapZoomChanged();
|
||||
void OnMapTypeChanged(MapType::Types type);
|
||||
void OnEmptyTileError(int zoom, core::Point pos);
|
||||
void OnNeedInvalidation();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
PointLatLng currentPosition;
|
||||
core::Point currentPositionPixel;
|
||||
core::Point renderOffset;
|
||||
core::Point centerTileXYLocation;
|
||||
core::Point centerTileXYLocationLast;
|
||||
core::Point dragPoint;
|
||||
Rectangle tileRect;
|
||||
core::Point mouseDown;
|
||||
bool CanDragMap;
|
||||
core::Point mouseCurrent;
|
||||
PointLatLng LastLocationInBounds;
|
||||
core::Point mouseLastZoom;
|
||||
|
||||
MouseWheelZoomType::Types mousewheelzoomtype;
|
||||
|
||||
|
||||
Size sizeOfMapArea;
|
||||
Size minOfTiles;
|
||||
Size maxOfTiles;
|
||||
|
||||
core::Point tilePoint;
|
||||
|
||||
Rectangle CurrentRegion;
|
||||
|
||||
QQueue<LoadTask> tileLoadQueue;
|
||||
|
||||
int zoom;
|
||||
|
||||
PureProjection* projection;
|
||||
|
||||
bool isDragging;
|
||||
|
||||
QMutex MtileLoadQueue;
|
||||
|
||||
QMutex Moverlays;
|
||||
|
||||
QMutex MtileDrawingList;
|
||||
#ifdef DEBUG_CORE
|
||||
QMutex Mdebug;
|
||||
static qlonglong debugcounter;
|
||||
#endif
|
||||
Size TooltipTextPadding;
|
||||
|
||||
MapType::Types mapType;
|
||||
|
||||
QSemaphore loaderLimit;
|
||||
|
||||
QThreadPool ProcessLoadTaskCallback;
|
||||
QMutex MtileToload;
|
||||
int tilesToload;
|
||||
|
||||
int maxzoom;
|
||||
QMutex MrunningThreads;
|
||||
int runningThreads;
|
||||
diagnostics diag;
|
||||
|
||||
protected:
|
||||
bool started;
|
||||
|
||||
int Width;
|
||||
int Height;
|
||||
int pxRes100m; // 100 meters
|
||||
int pxRes1000m; // 1km
|
||||
int pxRes10km; // 10km
|
||||
int pxRes100km; // 100km
|
||||
int pxRes1000km; // 1000km
|
||||
int pxRes5000km; // 5000km
|
||||
void SetCurrentPositionGPixel(core::Point const& value){currentPositionPixel = value;}
|
||||
void GoToCurrentPositionOnZoom();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // CORE_H
|
||||
|
@ -1,210 +1,210 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file mapgraphicitem.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief The main graphicsItem used on the widget, contains the map and map logic
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef MAPGRAPHICITEM_H
|
||||
#define MAPGRAPHICITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include "../internals/core.h"
|
||||
//#include "../internals/point.h"
|
||||
|
||||
#include "configuration.h"
|
||||
#include <QtGui>
|
||||
#include <QTransform>
|
||||
#include <QWidget>
|
||||
#include <QBrush>
|
||||
#include <QFont>
|
||||
#include <QObject>
|
||||
#include "waypointitem.h"
|
||||
//#include "uavitem.h"
|
||||
namespace mapcontrol
|
||||
{
|
||||
class OPMapWidget;
|
||||
/**
|
||||
* @brief The main graphicsItem used on the widget, contains the map and map logic
|
||||
*
|
||||
* @class MapGraphicItem mapgraphicitem.h "mapgraphicitem.h"
|
||||
*/
|
||||
class MapGraphicItem:public QObject,public QGraphicsItem
|
||||
{
|
||||
friend class mapcontrol::OPMapWidget;
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* @brief Contructer
|
||||
*
|
||||
* @param core
|
||||
* @param configuration the configuration to be used
|
||||
* @return
|
||||
*/
|
||||
MapGraphicItem(internals::Core *core,Configuration *configuration);
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
QSize sizeHint()const;
|
||||
/**
|
||||
* @brief Convertes LatLong coordinates to local item coordinates
|
||||
*
|
||||
* @param point LatLong point to be converted
|
||||
* @return core::Point Local item point
|
||||
*/
|
||||
core::Point FromLatLngToLocal(internals::PointLatLng const& point);
|
||||
/**
|
||||
* @brief Converts from local item coordinates to LatLong point
|
||||
*
|
||||
* @param x x local coordinate
|
||||
* @param y y local coordinate
|
||||
* @return internals::PointLatLng LatLng coordinate
|
||||
*/
|
||||
internals::PointLatLng FromLocalToLatLng(int x, int y);
|
||||
/**
|
||||
* @brief Returns true if map is being dragged
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
bool IsDragging()const{return core->IsDragging();}
|
||||
|
||||
QImage lastimage;
|
||||
// QPainter* imagePainter;
|
||||
core::Point lastimagepoint;
|
||||
void paintImage(QPainter* painter);
|
||||
void ConstructLastImage(int const& zoomdiff);
|
||||
internals::PureProjection* Projection()const{return core->Projection();}
|
||||
double Zoom();
|
||||
double ZoomDigi();
|
||||
double ZoomTotal();
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
|
||||
void mousePressEvent ( QGraphicsSceneMouseEvent * event );
|
||||
void wheelEvent ( QGraphicsSceneWheelEvent * event );
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
bool IsMouseOverMarker()const{return isMouseOverMarker;}
|
||||
|
||||
/**
|
||||
* @brief Returns current map zoom
|
||||
*
|
||||
* @return int Current map zoom
|
||||
*/
|
||||
int ZoomStep()const;
|
||||
/**
|
||||
* @brief Sets map zoom
|
||||
*
|
||||
* @param value zoom value
|
||||
*/
|
||||
void SetZoomStep(int const& value);
|
||||
|
||||
|
||||
private:
|
||||
bool SetZoomToFitRect(internals::RectLatLng const& rect);
|
||||
internals::Core *core;
|
||||
Configuration *config;
|
||||
bool showTileGridLines;
|
||||
qreal MapRenderTransform;
|
||||
void DrawMap2D(QPainter *painter);
|
||||
/**
|
||||
* @brief Maximum possible zoom
|
||||
*
|
||||
* @var maxZoom
|
||||
*/
|
||||
int maxZoom;
|
||||
/**
|
||||
* @brief Minimum possible zoom
|
||||
*
|
||||
* @var minZoom
|
||||
*/
|
||||
int minZoom;
|
||||
internals::RectLatLng selectedArea;
|
||||
internals::PointLatLng selectionStart;
|
||||
internals::PointLatLng selectionEnd;
|
||||
double zoomReal;
|
||||
double zoomDigi;
|
||||
QRectF maprect;
|
||||
bool isSelected;
|
||||
bool isMouseOverMarker;
|
||||
void SetIsMouseOverMarker(bool const& value){isMouseOverMarker = value;}
|
||||
|
||||
qreal rotation;
|
||||
/**
|
||||
* @brief Creates a rectangle that represents the "view" of the cuurent map, to compensate
|
||||
* rotation
|
||||
*
|
||||
* @param rect original rectangle
|
||||
* @param angle angle of rotation
|
||||
* @return QRectF
|
||||
*/
|
||||
QRectF boundingBox(QRectF const& rect, qreal const& angle);
|
||||
/**
|
||||
* @brief Returns the maximum allowed zoom
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int MaxZoom()const{return core->MaxZoom();}
|
||||
/**
|
||||
* @brief Returns the minimum allowed zoom
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int MinZoom()const{return minZoom;}
|
||||
internals::MouseWheelZoomType::Types GetMouseWheelZoomType(){return core->GetMouseWheelZoomType();}
|
||||
void SetSelectedArea(internals::RectLatLng const& value){selectedArea = value;this->update();}
|
||||
internals::RectLatLng SelectedArea()const{return selectedArea;}
|
||||
internals::RectLatLng BoundsOfMap;
|
||||
void Offset(int const& x, int const& y);
|
||||
bool CanDragMap()const{return core->CanDragMap;}
|
||||
void SetCanDragMap(bool const& value){core->CanDragMap = value;}
|
||||
|
||||
void SetZoom(double const& value);
|
||||
void mapRotate ( qreal angle );
|
||||
void start();
|
||||
void ReloadMap(){core->ReloadMap();}
|
||||
GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const& keys){return core->SetCurrentPositionByKeywords(keys);}
|
||||
MapType::Types GetMapType(){return core->GetMapType();}
|
||||
void SetMapType(MapType::Types const& value){core->SetMapType(value);}
|
||||
private slots:
|
||||
void Core_OnNeedInvalidation();
|
||||
void ChildPosRefresh();
|
||||
public slots:
|
||||
/**
|
||||
* @brief To be called when the scene size changes
|
||||
*
|
||||
* @param rect
|
||||
*/
|
||||
void resize ( QRectF const &rect=QRectF() );
|
||||
signals:
|
||||
/**
|
||||
* @brief Fired when the current zoom is changed
|
||||
*
|
||||
* @param zoom
|
||||
*/
|
||||
void zoomChanged(double zoomtotal,double zoomreal,double zoomdigi);
|
||||
};
|
||||
}
|
||||
#endif // MAPGRAPHICITEM_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file mapgraphicitem.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief The main graphicsItem used on the widget, contains the map and map logic
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef MAPGRAPHICITEM_H
|
||||
#define MAPGRAPHICITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include "../internals/core.h"
|
||||
//#include "../internals/point.h"
|
||||
#include "../core/diagnostics.h"
|
||||
#include "configuration.h"
|
||||
#include <QtGui>
|
||||
#include <QTransform>
|
||||
#include <QWidget>
|
||||
#include <QBrush>
|
||||
#include <QFont>
|
||||
#include <QObject>
|
||||
#include "waypointitem.h"
|
||||
//#include "uavitem.h"
|
||||
namespace mapcontrol
|
||||
{
|
||||
class OPMapWidget;
|
||||
/**
|
||||
* @brief The main graphicsItem used on the widget, contains the map and map logic
|
||||
*
|
||||
* @class MapGraphicItem mapgraphicitem.h "mapgraphicitem.h"
|
||||
*/
|
||||
class MapGraphicItem:public QObject,public QGraphicsItem
|
||||
{
|
||||
friend class mapcontrol::OPMapWidget;
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* @brief Contructer
|
||||
*
|
||||
* @param core
|
||||
* @param configuration the configuration to be used
|
||||
* @return
|
||||
*/
|
||||
MapGraphicItem(internals::Core *core,Configuration *configuration);
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
QSize sizeHint()const;
|
||||
/**
|
||||
* @brief Convertes LatLong coordinates to local item coordinates
|
||||
*
|
||||
* @param point LatLong point to be converted
|
||||
* @return core::Point Local item point
|
||||
*/
|
||||
core::Point FromLatLngToLocal(internals::PointLatLng const& point);
|
||||
/**
|
||||
* @brief Converts from local item coordinates to LatLong point
|
||||
*
|
||||
* @param x x local coordinate
|
||||
* @param y y local coordinate
|
||||
* @return internals::PointLatLng LatLng coordinate
|
||||
*/
|
||||
internals::PointLatLng FromLocalToLatLng(int x, int y);
|
||||
/**
|
||||
* @brief Returns true if map is being dragged
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
bool IsDragging()const{return core->IsDragging();}
|
||||
|
||||
QImage lastimage;
|
||||
// QPainter* imagePainter;
|
||||
core::Point lastimagepoint;
|
||||
void paintImage(QPainter* painter);
|
||||
void ConstructLastImage(int const& zoomdiff);
|
||||
internals::PureProjection* Projection()const{return core->Projection();}
|
||||
double Zoom();
|
||||
double ZoomDigi();
|
||||
double ZoomTotal();
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
|
||||
void mousePressEvent ( QGraphicsSceneMouseEvent * event );
|
||||
void wheelEvent ( QGraphicsSceneWheelEvent * event );
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
bool IsMouseOverMarker()const{return isMouseOverMarker;}
|
||||
|
||||
/**
|
||||
* @brief Returns current map zoom
|
||||
*
|
||||
* @return int Current map zoom
|
||||
*/
|
||||
int ZoomStep()const;
|
||||
/**
|
||||
* @brief Sets map zoom
|
||||
*
|
||||
* @param value zoom value
|
||||
*/
|
||||
void SetZoomStep(int const& value);
|
||||
|
||||
|
||||
private:
|
||||
bool SetZoomToFitRect(internals::RectLatLng const& rect);
|
||||
internals::Core *core;
|
||||
Configuration *config;
|
||||
bool showTileGridLines;
|
||||
qreal MapRenderTransform;
|
||||
void DrawMap2D(QPainter *painter);
|
||||
/**
|
||||
* @brief Maximum possible zoom
|
||||
*
|
||||
* @var maxZoom
|
||||
*/
|
||||
int maxZoom;
|
||||
/**
|
||||
* @brief Minimum possible zoom
|
||||
*
|
||||
* @var minZoom
|
||||
*/
|
||||
int minZoom;
|
||||
internals::RectLatLng selectedArea;
|
||||
internals::PointLatLng selectionStart;
|
||||
internals::PointLatLng selectionEnd;
|
||||
double zoomReal;
|
||||
double zoomDigi;
|
||||
QRectF maprect;
|
||||
bool isSelected;
|
||||
bool isMouseOverMarker;
|
||||
void SetIsMouseOverMarker(bool const& value){isMouseOverMarker = value;}
|
||||
|
||||
qreal rotation;
|
||||
/**
|
||||
* @brief Creates a rectangle that represents the "view" of the cuurent map, to compensate
|
||||
* rotation
|
||||
*
|
||||
* @param rect original rectangle
|
||||
* @param angle angle of rotation
|
||||
* @return QRectF
|
||||
*/
|
||||
QRectF boundingBox(QRectF const& rect, qreal const& angle);
|
||||
/**
|
||||
* @brief Returns the maximum allowed zoom
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int MaxZoom()const{return core->MaxZoom();}
|
||||
/**
|
||||
* @brief Returns the minimum allowed zoom
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int MinZoom()const{return minZoom;}
|
||||
internals::MouseWheelZoomType::Types GetMouseWheelZoomType(){return core->GetMouseWheelZoomType();}
|
||||
void SetSelectedArea(internals::RectLatLng const& value){selectedArea = value;this->update();}
|
||||
internals::RectLatLng SelectedArea()const{return selectedArea;}
|
||||
internals::RectLatLng BoundsOfMap;
|
||||
void Offset(int const& x, int const& y);
|
||||
bool CanDragMap()const{return core->CanDragMap;}
|
||||
void SetCanDragMap(bool const& value){core->CanDragMap = value;}
|
||||
|
||||
void SetZoom(double const& value);
|
||||
void mapRotate ( qreal angle );
|
||||
void start();
|
||||
void ReloadMap(){core->ReloadMap();}
|
||||
GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const& keys){return core->SetCurrentPositionByKeywords(keys);}
|
||||
MapType::Types GetMapType(){return core->GetMapType();}
|
||||
void SetMapType(MapType::Types const& value){core->SetMapType(value);}
|
||||
private slots:
|
||||
void Core_OnNeedInvalidation();
|
||||
void ChildPosRefresh();
|
||||
public slots:
|
||||
/**
|
||||
* @brief To be called when the scene size changes
|
||||
*
|
||||
* @param rect
|
||||
*/
|
||||
void resize ( QRectF const &rect=QRectF() );
|
||||
signals:
|
||||
/**
|
||||
* @brief Fired when the current zoom is changed
|
||||
*
|
||||
* @param zoom
|
||||
*/
|
||||
void zoomChanged(double zoomtotal,double zoomreal,double zoomdigi);
|
||||
};
|
||||
}
|
||||
#endif // MAPGRAPHICITEM_H
|
||||
|
@ -19,8 +19,8 @@ LIBS += -L../build \
|
||||
-linternals \
|
||||
-lcore
|
||||
|
||||
TARGETDEPS += ../build/libcore.a
|
||||
TARGETDEPS += ../build/libinternals.a
|
||||
POST_TARGETDEPS += ../build/libcore.a
|
||||
POST_TARGETDEPS += ../build/libinternals.a
|
||||
|
||||
HEADERS += mapgraphicitem.h \
|
||||
opmapwidget.h \
|
||||
|
@ -1,301 +1,347 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file opmapwidget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief The Map Widget, this is the part exposed to the user
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "opmapwidget.h"
|
||||
#include <QtGui>
|
||||
#include <QMetaObject>
|
||||
#include "waypointitem.h"
|
||||
|
||||
namespace mapcontrol
|
||||
{
|
||||
|
||||
OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),GPS(0),Home(0),followmouse(true),compass(0),showuav(false),showhome(false)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
core=new internals::Core;
|
||||
map=new MapGraphicItem(core,config);
|
||||
mscene.addItem(map);
|
||||
this->setScene(&mscene);
|
||||
this->adjustSize();
|
||||
connect(map,SIGNAL(zoomChanged(double,double,double)),this,SIGNAL(zoomChanged(double,double,double)));
|
||||
connect(map->core,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)),this,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)));
|
||||
connect(map->core,SIGNAL(OnEmptyTileError(int,core::Point)),this,SIGNAL(OnEmptyTileError(int,core::Point)));
|
||||
connect(map->core,SIGNAL(OnMapDrag()),this,SIGNAL(OnMapDrag()));
|
||||
connect(map->core,SIGNAL(OnMapTypeChanged(MapType::Types)),this,SIGNAL(OnMapTypeChanged(MapType::Types)));
|
||||
connect(map->core,SIGNAL(OnMapZoomChanged()),this,SIGNAL(OnMapZoomChanged()));
|
||||
connect(map->core,SIGNAL(OnTileLoadComplete()),this,SIGNAL(OnTileLoadComplete()));
|
||||
connect(map->core,SIGNAL(OnTileLoadStart()),this,SIGNAL(OnTileLoadStart()));
|
||||
connect(map->core,SIGNAL(OnTilesStillToLoad(int)),this,SIGNAL(OnTilesStillToLoad(int)));
|
||||
this->setMouseTracking(followmouse);
|
||||
SetShowCompass(true);
|
||||
|
||||
}
|
||||
|
||||
void OPMapWidget::SetShowUAV(const bool &value)
|
||||
{
|
||||
if(value && UAV==0)
|
||||
{
|
||||
UAV=new UAVItem(map,this);
|
||||
UAV->setParentItem(map);
|
||||
connect(this,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)),UAV,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)));
|
||||
connect(this,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)),UAV,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)));
|
||||
}
|
||||
else if(!value)
|
||||
{
|
||||
if(UAV!=0)
|
||||
{
|
||||
delete UAV;
|
||||
UAV=0;
|
||||
}
|
||||
|
||||
}
|
||||
if(value && GPS==0)
|
||||
{
|
||||
GPS=new GPSItem(map,this);
|
||||
GPS->setParentItem(map);
|
||||
}
|
||||
else if(!value)
|
||||
{
|
||||
if(GPS!=0)
|
||||
{
|
||||
delete GPS;
|
||||
GPS=0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void OPMapWidget::SetShowHome(const bool &value)
|
||||
{
|
||||
if(value && Home==0)
|
||||
{
|
||||
Home=new HomeItem(map,this);
|
||||
Home->setParentItem(map);
|
||||
}
|
||||
else if(!value)
|
||||
{
|
||||
if(Home!=0)
|
||||
{
|
||||
delete Home;
|
||||
Home=0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void OPMapWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (scene())
|
||||
scene()->setSceneRect(
|
||||
QRect(QPoint(0, 0), event->size()));
|
||||
QGraphicsView::resizeEvent(event);
|
||||
if(compass)
|
||||
compass->setScale(0.1+0.05*(qreal)(event->size().width())/1000*(qreal)(event->size().height())/600);
|
||||
|
||||
}
|
||||
QSize OPMapWidget::sizeHint() const
|
||||
{
|
||||
return map->sizeHint();
|
||||
}
|
||||
void OPMapWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
connect(&mscene,SIGNAL(sceneRectChanged(QRectF)),map,SLOT(resize(QRectF)));
|
||||
map->start();
|
||||
QGraphicsView::showEvent(event);
|
||||
}
|
||||
OPMapWidget::~OPMapWidget()
|
||||
{
|
||||
delete UAV;
|
||||
delete Home;
|
||||
delete map;
|
||||
delete core;
|
||||
delete configuration;
|
||||
foreach(QGraphicsItem* i,this->items())
|
||||
{
|
||||
delete i;
|
||||
}
|
||||
}
|
||||
void OPMapWidget::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
core->OnMapClose();
|
||||
event->accept();
|
||||
}
|
||||
void OPMapWidget::SetUseOpenGL(const bool &value)
|
||||
{
|
||||
useOpenGL=value;
|
||||
if (useOpenGL)
|
||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||
else
|
||||
setupViewport(new QWidget());
|
||||
update();
|
||||
}
|
||||
internals::PointLatLng OPMapWidget::currentMousePosition()
|
||||
{
|
||||
return currentmouseposition;
|
||||
}
|
||||
|
||||
void OPMapWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
QPointF p=event->posF();
|
||||
p=map->mapFromParent(p);
|
||||
currentmouseposition=map->FromLocalToLatLng(p.x(),p.y());
|
||||
}
|
||||
////////////////WAYPOINT////////////////////////
|
||||
WayPointItem* OPMapWidget::WPCreate()
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(this->CurrentPosition(),0,map);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
return item;
|
||||
}
|
||||
void OPMapWidget::WPCreate(WayPointItem* item)
|
||||
{
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,map);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
return item;
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude, QString const& description)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,description,map);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
return item;
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPInsert(const int &position)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(this->CurrentPosition(),0,map);
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
return item;
|
||||
}
|
||||
void OPMapWidget::WPInsert(WayPointItem* item,const int &position)
|
||||
{
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude,const int &position)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,map);
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
return item;
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude, QString const& description,const int &position)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,description,map);
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
return item;
|
||||
}
|
||||
void OPMapWidget::WPDelete(WayPointItem *item)
|
||||
{
|
||||
emit WPDeleted(item->Number());
|
||||
delete item;
|
||||
}
|
||||
void OPMapWidget::WPDeleteAll()
|
||||
{
|
||||
foreach(QGraphicsItem* i,map->childItems())
|
||||
{
|
||||
WayPointItem* w=qgraphicsitem_cast<WayPointItem*>(i);
|
||||
if(w)
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
QList<WayPointItem*> OPMapWidget::WPSelected()
|
||||
{
|
||||
QList<WayPointItem*> list;
|
||||
foreach(QGraphicsItem* i,mscene.selectedItems())
|
||||
{
|
||||
WayPointItem* w=qgraphicsitem_cast<WayPointItem*>(i);
|
||||
if(w)
|
||||
list.append(w);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
void OPMapWidget::WPRenumber(WayPointItem *item, const int &newnumber)
|
||||
{
|
||||
item->SetNumber(newnumber);
|
||||
}
|
||||
|
||||
void OPMapWidget::ConnectWP(WayPointItem *item)
|
||||
{
|
||||
connect(item,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)));
|
||||
connect(item,SIGNAL(WPValuesChanged(WayPointItem*)),this,SIGNAL(WPValuesChanged(WayPointItem*)));
|
||||
connect(this,SIGNAL(WPInserted(int,WayPointItem*)),item,SLOT(WPInserted(int,WayPointItem*)));
|
||||
connect(this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),item,SLOT(WPRenumbered(int,int,WayPointItem*)));
|
||||
connect(this,SIGNAL(WPDeleted(int)),item,SLOT(WPDeleted(int)));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
void OPMapWidget::SetShowCompass(const bool &value)
|
||||
{
|
||||
if(value && !compass)
|
||||
{
|
||||
compass=new QGraphicsSvgItem(QString::fromUtf8(":/markers/images/compas.svg"));
|
||||
compass->setScale(0.1+0.05*(qreal)(this->size().width())/1000*(qreal)(this->size().height())/600);
|
||||
// compass->setTransformOriginPoint(compass->boundingRect().width(),compass->boundingRect().height());
|
||||
compass->setFlag(QGraphicsItem::ItemIsMovable,true);
|
||||
mscene.addItem(compass);
|
||||
compass->setTransformOriginPoint(compass->boundingRect().width()/2,compass->boundingRect().height()/2);
|
||||
compass->setPos(55-compass->boundingRect().width()/2,55-compass->boundingRect().height()/2);
|
||||
compass->setZValue(3);
|
||||
compass->setOpacity(0.7);
|
||||
|
||||
}
|
||||
if(!value && compass)
|
||||
{
|
||||
delete compass;
|
||||
compass=0;
|
||||
}
|
||||
}
|
||||
void OPMapWidget::SetRotate(qreal const& value)
|
||||
{
|
||||
map->mapRotate(value);
|
||||
if(compass && (compass->rotation() != value)) {
|
||||
compass->setRotation(value);
|
||||
}
|
||||
}
|
||||
void OPMapWidget::RipMap()
|
||||
{
|
||||
new MapRipper(core,map->SelectedArea());
|
||||
}
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file opmapwidget.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief The Map Widget, this is the part exposed to the user
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup OPMapWidget
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "opmapwidget.h"
|
||||
#include <QtGui>
|
||||
#include <QMetaObject>
|
||||
#include "waypointitem.h"
|
||||
|
||||
namespace mapcontrol
|
||||
{
|
||||
|
||||
OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),GPS(0),Home(0),followmouse(true),compass(0),showuav(false),showhome(false),showDiag(false),diagGraphItem(0),diagTimer(0)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
core=new internals::Core;
|
||||
map=new MapGraphicItem(core,config);
|
||||
mscene.addItem(map);
|
||||
this->setScene(&mscene);
|
||||
this->adjustSize();
|
||||
connect(map,SIGNAL(zoomChanged(double,double,double)),this,SIGNAL(zoomChanged(double,double,double)));
|
||||
connect(map->core,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)),this,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)));
|
||||
connect(map->core,SIGNAL(OnEmptyTileError(int,core::Point)),this,SIGNAL(OnEmptyTileError(int,core::Point)));
|
||||
connect(map->core,SIGNAL(OnMapDrag()),this,SIGNAL(OnMapDrag()));
|
||||
connect(map->core,SIGNAL(OnMapTypeChanged(MapType::Types)),this,SIGNAL(OnMapTypeChanged(MapType::Types)));
|
||||
connect(map->core,SIGNAL(OnMapZoomChanged()),this,SIGNAL(OnMapZoomChanged()));
|
||||
connect(map->core,SIGNAL(OnTileLoadComplete()),this,SIGNAL(OnTileLoadComplete()));
|
||||
connect(map->core,SIGNAL(OnTileLoadStart()),this,SIGNAL(OnTileLoadStart()));
|
||||
connect(map->core,SIGNAL(OnTilesStillToLoad(int)),this,SIGNAL(OnTilesStillToLoad(int)));
|
||||
SetShowDiagnostics(showDiag);
|
||||
this->setMouseTracking(followmouse);
|
||||
SetShowCompass(true);
|
||||
|
||||
}
|
||||
void OPMapWidget::SetShowDiagnostics(bool const& value)
|
||||
{
|
||||
showDiag=value;
|
||||
if(!showDiag)
|
||||
{
|
||||
if(diagGraphItem!=0)
|
||||
{
|
||||
delete diagGraphItem;
|
||||
diagGraphItem=0;
|
||||
}
|
||||
if(diagTimer!=0)
|
||||
{
|
||||
delete diagTimer;
|
||||
diagTimer=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
diagTimer=new QTimer();
|
||||
connect(diagTimer,SIGNAL(timeout()),this,SLOT(diagRefresh()));
|
||||
diagTimer->start(500);
|
||||
}
|
||||
|
||||
}
|
||||
void OPMapWidget::SetShowUAV(const bool &value)
|
||||
{
|
||||
if(value && UAV==0)
|
||||
{
|
||||
UAV=new UAVItem(map,this);
|
||||
UAV->setParentItem(map);
|
||||
connect(this,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)),UAV,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)));
|
||||
connect(this,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)),UAV,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)));
|
||||
}
|
||||
else if(!value)
|
||||
{
|
||||
if(UAV!=0)
|
||||
{
|
||||
delete UAV;
|
||||
UAV=0;
|
||||
}
|
||||
|
||||
}
|
||||
if(value && GPS==0)
|
||||
{
|
||||
GPS=new GPSItem(map,this);
|
||||
GPS->setParentItem(map);
|
||||
}
|
||||
else if(!value)
|
||||
{
|
||||
if(GPS!=0)
|
||||
{
|
||||
delete GPS;
|
||||
GPS=0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void OPMapWidget::SetShowHome(const bool &value)
|
||||
{
|
||||
if(value && Home==0)
|
||||
{
|
||||
Home=new HomeItem(map,this);
|
||||
Home->setParentItem(map);
|
||||
}
|
||||
else if(!value)
|
||||
{
|
||||
if(Home!=0)
|
||||
{
|
||||
delete Home;
|
||||
Home=0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void OPMapWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (scene())
|
||||
scene()->setSceneRect(
|
||||
QRect(QPoint(0, 0), event->size()));
|
||||
QGraphicsView::resizeEvent(event);
|
||||
if(compass)
|
||||
compass->setScale(0.1+0.05*(qreal)(event->size().width())/1000*(qreal)(event->size().height())/600);
|
||||
|
||||
}
|
||||
QSize OPMapWidget::sizeHint() const
|
||||
{
|
||||
return map->sizeHint();
|
||||
}
|
||||
void OPMapWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
connect(&mscene,SIGNAL(sceneRectChanged(QRectF)),map,SLOT(resize(QRectF)));
|
||||
map->start();
|
||||
QGraphicsView::showEvent(event);
|
||||
}
|
||||
OPMapWidget::~OPMapWidget()
|
||||
{
|
||||
delete UAV;
|
||||
delete Home;
|
||||
delete map;
|
||||
delete core;
|
||||
delete configuration;
|
||||
foreach(QGraphicsItem* i,this->items())
|
||||
{
|
||||
delete i;
|
||||
}
|
||||
}
|
||||
void OPMapWidget::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
core->OnMapClose();
|
||||
event->accept();
|
||||
}
|
||||
void OPMapWidget::SetUseOpenGL(const bool &value)
|
||||
{
|
||||
useOpenGL=value;
|
||||
if (useOpenGL)
|
||||
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
||||
else
|
||||
setupViewport(new QWidget());
|
||||
update();
|
||||
}
|
||||
internals::PointLatLng OPMapWidget::currentMousePosition()
|
||||
{
|
||||
return currentmouseposition;
|
||||
}
|
||||
|
||||
void OPMapWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsView::mouseMoveEvent(event);
|
||||
QPointF p=event->posF();
|
||||
p=map->mapFromParent(p);
|
||||
currentmouseposition=map->FromLocalToLatLng(p.x(),p.y());
|
||||
}
|
||||
////////////////WAYPOINT////////////////////////
|
||||
WayPointItem* OPMapWidget::WPCreate()
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(this->CurrentPosition(),0,map);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
return item;
|
||||
}
|
||||
void OPMapWidget::WPCreate(WayPointItem* item)
|
||||
{
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,map);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
return item;
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude, QString const& description)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,description,map);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
return item;
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPInsert(const int &position)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(this->CurrentPosition(),0,map);
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
return item;
|
||||
}
|
||||
void OPMapWidget::WPInsert(WayPointItem* item,const int &position)
|
||||
{
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude,const int &position)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,map);
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
return item;
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude, QString const& description,const int &position)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(coord,altitude,description,map);
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
emit WPInserted(position,item);
|
||||
return item;
|
||||
}
|
||||
void OPMapWidget::WPDelete(WayPointItem *item)
|
||||
{
|
||||
emit WPDeleted(item->Number());
|
||||
delete item;
|
||||
}
|
||||
void OPMapWidget::WPDeleteAll()
|
||||
{
|
||||
foreach(QGraphicsItem* i,map->childItems())
|
||||
{
|
||||
WayPointItem* w=qgraphicsitem_cast<WayPointItem*>(i);
|
||||
if(w)
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
QList<WayPointItem*> OPMapWidget::WPSelected()
|
||||
{
|
||||
QList<WayPointItem*> list;
|
||||
foreach(QGraphicsItem* i,mscene.selectedItems())
|
||||
{
|
||||
WayPointItem* w=qgraphicsitem_cast<WayPointItem*>(i);
|
||||
if(w)
|
||||
list.append(w);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
void OPMapWidget::WPRenumber(WayPointItem *item, const int &newnumber)
|
||||
{
|
||||
item->SetNumber(newnumber);
|
||||
}
|
||||
|
||||
void OPMapWidget::ConnectWP(WayPointItem *item)
|
||||
{
|
||||
connect(item,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)));
|
||||
connect(item,SIGNAL(WPValuesChanged(WayPointItem*)),this,SIGNAL(WPValuesChanged(WayPointItem*)));
|
||||
connect(this,SIGNAL(WPInserted(int,WayPointItem*)),item,SLOT(WPInserted(int,WayPointItem*)));
|
||||
connect(this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),item,SLOT(WPRenumbered(int,int,WayPointItem*)));
|
||||
connect(this,SIGNAL(WPDeleted(int)),item,SLOT(WPDeleted(int)));
|
||||
}
|
||||
void OPMapWidget::diagRefresh()
|
||||
{
|
||||
if(showDiag)
|
||||
{
|
||||
if(diagGraphItem==0)
|
||||
{
|
||||
diagGraphItem=new QGraphicsTextItem();
|
||||
mscene.addItem(diagGraphItem);
|
||||
diagGraphItem->setPos(10,100);
|
||||
diagGraphItem->setZValue(3);
|
||||
diagGraphItem->setFlag(QGraphicsItem::ItemIsMovable,true);
|
||||
diagGraphItem->setDefaultTextColor(Qt::yellow);
|
||||
}
|
||||
diagGraphItem->setPlainText(core->GetDiagnostics().toString());
|
||||
}
|
||||
else
|
||||
if(diagGraphItem!=0)
|
||||
{
|
||||
delete diagGraphItem;
|
||||
diagGraphItem=0;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
void OPMapWidget::SetShowCompass(const bool &value)
|
||||
{
|
||||
if(value && !compass)
|
||||
{
|
||||
compass=new QGraphicsSvgItem(QString::fromUtf8(":/markers/images/compas.svg"));
|
||||
compass->setScale(0.1+0.05*(qreal)(this->size().width())/1000*(qreal)(this->size().height())/600);
|
||||
// compass->setTransformOriginPoint(compass->boundingRect().width(),compass->boundingRect().height());
|
||||
compass->setFlag(QGraphicsItem::ItemIsMovable,true);
|
||||
mscene.addItem(compass);
|
||||
compass->setTransformOriginPoint(compass->boundingRect().width()/2,compass->boundingRect().height()/2);
|
||||
compass->setPos(55-compass->boundingRect().width()/2,55-compass->boundingRect().height()/2);
|
||||
compass->setZValue(3);
|
||||
compass->setOpacity(0.7);
|
||||
|
||||
}
|
||||
if(!value && compass)
|
||||
{
|
||||
delete compass;
|
||||
compass=0;
|
||||
}
|
||||
}
|
||||
void OPMapWidget::SetRotate(qreal const& value)
|
||||
{
|
||||
map->mapRotate(value);
|
||||
if(compass && (compass->rotation() != value)) {
|
||||
compass->setRotation(value);
|
||||
}
|
||||
}
|
||||
void OPMapWidget::RipMap()
|
||||
{
|
||||
new MapRipper(core,map->SelectedArea());
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "../core/geodecoderstatus.h"
|
||||
#include "../core/maptype.h"
|
||||
#include "../core/languagetype.h"
|
||||
#include "../core/diagnostics.h"
|
||||
#include "configuration.h"
|
||||
#include <QObject>
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
@ -120,7 +121,7 @@ namespace mapcontrol
|
||||
*/
|
||||
static QStringList AccessModeTypes(){return core::AccessMode::TypesList();}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Converts from String to Type
|
||||
*/
|
||||
static UAVMapFollowType::Types UAVMapFollowFromString(QString const& value){return UAVMapFollowType::TypeByStr(value);}
|
||||
@ -135,31 +136,31 @@ namespace mapcontrol
|
||||
/**
|
||||
* @brief Converts from String to Type
|
||||
*/
|
||||
static UAVTrailType::Types UAVTrailTypeFromString(QString const& value){return UAVTrailType::TypeByStr(value);}
|
||||
/**
|
||||
static UAVTrailType::Types UAVTrailTypeFromString(QString const& value){return UAVTrailType::TypeByStr(value);}
|
||||
/**
|
||||
* @brief Converts from Type to String
|
||||
*/
|
||||
static QString StrFromUAVTrailType(UAVTrailType::Types const& value){return UAVTrailType::StrByType(value);}
|
||||
/**
|
||||
static QString StrFromUAVTrailType(UAVTrailType::Types const& value){return UAVTrailType::StrByType(value);}
|
||||
/**
|
||||
* @brief Returns QStringList with string representing all the enum values
|
||||
*/
|
||||
static QStringList UAVTrailTypes(){return UAVTrailType::TypesList();}
|
||||
static QStringList UAVTrailTypes(){return UAVTrailType::TypesList();}
|
||||
};
|
||||
|
||||
class OPMapWidget:public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
// Q_PROPERTY(int MaxZoom READ MaxZoom WRITE SetMaxZoom)
|
||||
// Q_PROPERTY(int MaxZoom READ MaxZoom WRITE SetMaxZoom)
|
||||
Q_PROPERTY(int MinZoom READ MinZoom WRITE SetMinZoom)
|
||||
Q_PROPERTY(bool ShowTileGridLines READ ShowTileGridLines WRITE SetShowTileGridLines)
|
||||
Q_PROPERTY(double Zoom READ ZoomTotal WRITE SetZoom)
|
||||
Q_PROPERTY(qreal Rotate READ Rotate WRITE SetRotate)
|
||||
Q_ENUMS(internals::MouseWheelZoomType::Types)
|
||||
Q_ENUMS(internals::GeoCoderStatusCode::Types)
|
||||
Q_PROPERTY(bool ShowTileGridLines READ ShowTileGridLines WRITE SetShowTileGridLines)
|
||||
Q_PROPERTY(double Zoom READ ZoomTotal WRITE SetZoom)
|
||||
Q_PROPERTY(qreal Rotate READ Rotate WRITE SetRotate)
|
||||
Q_ENUMS(internals::MouseWheelZoomType::Types)
|
||||
Q_ENUMS(internals::GeoCoderStatusCode::Types)
|
||||
|
||||
public:
|
||||
QSize sizeHint() const;
|
||||
QSize sizeHint() const;
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
@ -191,7 +192,7 @@ namespace mapcontrol
|
||||
*/
|
||||
int MaxZoom()const{return map->MaxZoom();}
|
||||
|
||||
// void SetMaxZoom(int const& value){map->maxZoom = value;}
|
||||
// void SetMaxZoom(int const& value){map->maxZoom = value;}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
@ -346,6 +347,7 @@ namespace mapcontrol
|
||||
bool ShowUAV()const{return showuav;}
|
||||
void SetShowHome(bool const& value);
|
||||
bool ShowHome()const{return showhome;}
|
||||
void SetShowDiagnostics(bool const& value);
|
||||
private:
|
||||
internals::Core *core;
|
||||
MapGraphicItem *map;
|
||||
@ -360,7 +362,12 @@ namespace mapcontrol
|
||||
QGraphicsSvgItem *compass;
|
||||
bool showuav;
|
||||
bool showhome;
|
||||
// WayPointItem* item;//apagar
|
||||
QTimer * diagTimer;
|
||||
QGraphicsTextItem * diagGraphItem;
|
||||
bool showDiag;
|
||||
private slots:
|
||||
void diagRefresh();
|
||||
// WayPointItem* item;//apagar
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void showEvent ( QShowEvent * event );
|
||||
@ -383,14 +390,14 @@ namespace mapcontrol
|
||||
* @param waypoint a pointer to the WayPoint
|
||||
*/
|
||||
void WPValuesChanged(WayPointItem* waypoint);
|
||||
/**
|
||||
/**
|
||||
* @brief Fires when a new WayPoint is inserted
|
||||
*
|
||||
* @param number new WayPoint number
|
||||
* @param waypoint WayPoint inserted
|
||||
*/
|
||||
void WPReached(WayPointItem* waypoint);
|
||||
/**
|
||||
/**
|
||||
* @brief Fires when a new WayPoint is inserted
|
||||
*
|
||||
* @param number new WayPoint number
|
||||
|
@ -463,6 +463,8 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||
|
||||
menu.addAction(showCompassAct);
|
||||
|
||||
menu.addAction(showDiagnostics);
|
||||
|
||||
menu.addSeparator()->setText(tr("Zoom"));
|
||||
|
||||
menu.addAction(zoomInAct);
|
||||
@ -1373,6 +1375,12 @@ void OPMapGadgetWidget::createActions()
|
||||
showCompassAct->setChecked(true);
|
||||
connect(showCompassAct, SIGNAL(toggled(bool)), this, SLOT(onShowCompassAct_toggled(bool)));
|
||||
|
||||
showDiagnostics = new QAction(tr("Show Diagnostics"), this);
|
||||
showDiagnostics->setStatusTip(tr("Show/Hide the diagnostics"));
|
||||
showDiagnostics->setCheckable(true);
|
||||
showDiagnostics->setChecked(false);
|
||||
connect(showDiagnostics, SIGNAL(toggled(bool)), this, SLOT(onShowDiagnostics_toggled(bool)));
|
||||
|
||||
showHomeAct = new QAction(tr("Show Home"), this);
|
||||
showHomeAct->setStatusTip(tr("Show/Hide the Home location"));
|
||||
showHomeAct->setCheckable(true);
|
||||
@ -1614,6 +1622,14 @@ void OPMapGadgetWidget::onShowCompassAct_toggled(bool show)
|
||||
m_map->SetShowCompass(show);
|
||||
}
|
||||
|
||||
void OPMapGadgetWidget::onShowDiagnostics_toggled(bool show)
|
||||
{
|
||||
if (!m_widget || !m_map)
|
||||
return;
|
||||
|
||||
m_map->SetShowDiagnostics(show);
|
||||
}
|
||||
|
||||
void OPMapGadgetWidget::onShowHomeAct_toggled(bool show)
|
||||
{
|
||||
if (!m_widget || !m_map)
|
||||
|
@ -185,6 +185,7 @@ private slots:
|
||||
void onCopyMouseLonToClipAct_triggered();
|
||||
// void onFindPlaceAct_triggered();
|
||||
void onShowCompassAct_toggled(bool show);
|
||||
void onShowDiagnostics_toggled(bool show);
|
||||
void onShowUAVAct_toggled(bool show);
|
||||
void onShowHomeAct_toggled(bool show);
|
||||
void onGoZoomInAct_triggered();
|
||||
@ -265,6 +266,7 @@ private:
|
||||
QAction *copyMouseLonToClipAct;
|
||||
QAction *findPlaceAct;
|
||||
QAction *showCompassAct;
|
||||
QAction *showDiagnostics;
|
||||
QAction *showHomeAct;
|
||||
QAction *showUAVAct;
|
||||
QAction *zoomInAct;
|
||||
|
Loading…
x
Reference in New Issue
Block a user