1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

OP-37 GCS/MapPlugin

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@690 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-05-30 17:16:35 +00:00 committed by zedamota
parent 3ea3bf4018
commit 76802e0d38
10 changed files with 132 additions and 27 deletions

View File

@ -31,14 +31,20 @@ Cache::Cache()
}
QString Cache::GetGeocoderFromCache(const QString &urlEnd)
{
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"Entered GetGeocoderFromCache";
#endif
QString ret=QString::null;
QString filename=geoCache+QString(urlEnd)+".geo";
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"GetGeocoderFromCache: Does file exist?:"<<filename;
#endif
QFileInfo File(filename);
if (File .exists())
{
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"GetGeocoderFromCache:File exists!!";
#endif
QFile file(filename);
if (file.open(QIODevice::ReadOnly))
{
@ -47,7 +53,9 @@ QString Cache::GetGeocoderFromCache(const QString &urlEnd)
stream>>ret;
}
}
#ifdef DEBUG_GetGeocoderFromCache
qDebug()<<"GetGeocoderFromCache:Returning:"<<ret;
#endif
return ret;
}
void Cache::CacheGeocoder(const QString &urlEnd, const QString &content)

View File

@ -8,6 +8,7 @@ Core::Core():currentPosition(0,0),currentPositionPixel(0,0),LastLocationInBounds
this->setAutoDelete(false);
renderOffset=Point(0,0);
dragPoint=Point(0,0);
CanDragMap=true;
}
void Core::run()
{
@ -509,6 +510,7 @@ void Core::UpdateBounds()
if(!tileLoadQueue.contains(task))
{
tileLoadQueue.enqueue(task);
qDebug()<<"Core::UpdateBounds new Task"<<task.Pos.ToString();
ProcessLoadTaskCallback.start(this);
}
}
@ -551,10 +553,7 @@ void Core::FindTilesAround(QList<Point> &list)
}
}
// if(GMaps::Instance()->ShuffleTilesOnLoad)
// {
// Stuff.Shuffle<Point>(list);
// }
}
void Core::UpdateGroundResolution()
{

View File

@ -93,7 +93,7 @@ public:
projection=value;
tileRect=Rectangle(Point(0,0),value->TileSize());
}
bool IsDragging(){return isDragging;}
bool IsDragging()const{return isDragging;}
int Zoom(){return zoom;}
@ -147,6 +147,9 @@ public:
TileMatrix Matrix;
Rectangle tileRect;
Point mouseDown;
bool CanDragMap;
Point mouseCurrent;
signals:
void OnCurrentPositionChanged(PointLatLng point);
void OnTileLoadComplete();
@ -156,6 +159,7 @@ signals:
void OnMapTypeChanged(MapType::Types type);
void OnEmptyTileError(int zoom, Point pos);
void OnNeedInvalidation();
private:
PointLatLng currentPosition;
@ -164,8 +168,8 @@ private:
Point centerTileXYLocation;
Point centerTileXYLocationLast;
Point dragPoint;
Point mouseDown;
Point mouseCurrent;
Point mouseLastZoom;
MouseWheelZoomType::Types mousewheelzoomtype;

View File

@ -1,7 +1,7 @@
#include "pointlatlng.h"
PointLatLng PointLatLng::Empty=PointLatLng();
PointLatLng::PointLatLng():lat(0),lng(0)
PointLatLng::PointLatLng():lat(0),lng(0),empty(true)
{
}

View File

@ -17,7 +17,7 @@ struct PointLatLng
private:
double lat;
double lng;
bool empty;
public:
PointLatLng();
@ -28,11 +28,12 @@ struct PointLatLng
{
this->lat = lat;
this->lng = lng;
empty=false;
}
bool IsEmpty()
{
return ((this->lng == 0) && (this->lat == 0));
return empty;
}
double Lat()const
@ -43,6 +44,7 @@ struct PointLatLng
void SetLat(const double &value)
{
this->lat = value;
empty=false;
}
@ -53,6 +55,7 @@ struct PointLatLng
void SetLng(const double &value)
{
this->lng = value;
empty=false;
}

View File

@ -1,8 +1,6 @@
#include "rectlatlng.h"
RectLatLng::RectLatLng():lng(0),lat(0),widthLng(0),heightLat(0)
{
}
RectLatLng RectLatLng::Empty=RectLatLng();
uint qHash(RectLatLng const& rect)
{

View File

@ -9,7 +9,6 @@
struct RectLatLng
{
public:
RectLatLng();
static RectLatLng Empty;
friend uint qHash(RectLatLng const& rect);
friend bool operator==(RectLatLng const& left,RectLatLng const& right);
@ -20,6 +19,7 @@ public:
this->lat = lat;
this->widthLng = widthLng;
this->heightLat = heightLat;
isempty=false;
}
RectLatLng(PointLatLng const& location, SizeLatLng const& size)
{
@ -27,7 +27,17 @@ public:
this->lat = location.Lat();
this->widthLng = size.WidthLng();
this->heightLat = size.HeightLat();
isempty=false;
}
RectLatLng()
{
this->lng = 0;
this->lat = 0;
this->widthLng = 0;
this->heightLat = 0;
isempty=true;
}
static RectLatLng FromLTRB(double const& lng, double const& lat, double const& rightLng, double const& bottomLat)
{
return RectLatLng(lat, lng, rightLng - lng, lat - bottomLat);
@ -40,6 +50,7 @@ public:
{
this->lng = value.Lng();
this->lat = value.Lat();
isempty=false;
}
PointLatLng LocationRightBottom()
{
@ -56,6 +67,7 @@ public:
{
this->widthLng = value.WidthLng();
this->heightLat = value.HeightLat();
isempty=false;
}
double Lng()const
{
@ -64,6 +76,7 @@ public:
void SetLng(double const& value)
{
this->lng = value;
isempty=false;
}
@ -74,6 +87,7 @@ public:
void SetLat(double const& value)
{
this->lat = value;
isempty=false;
}
double WidthLng()const
@ -83,6 +97,7 @@ public:
void SetWidthLng(double const& value)
{
this->widthLng = value;
isempty=false;
}
double HeightLat()const
{
@ -91,6 +106,7 @@ public:
void SetHeightLat(double const& value)
{
this->heightLat = value;
isempty=false;
}
double Left()const
{
@ -113,11 +129,7 @@ public:
}
bool IsEmpty()const
{
if(this->WidthLng() > 0)
{
return (this->HeightLat() <= 0);
}
return true;
return isempty;
}
bool Contains(double const& lat, double const& lng)
{
@ -209,6 +221,7 @@ private:
double lat;
double widthLng;
double heightLat;
bool isempty;
};
#endif // RECTLATLNG_H

View File

@ -44,6 +44,7 @@ void TileMatrix::ClearPointsNotIn(QList<Point>list)
}
Tile* TileMatrix::TileAt(const Point &p)
{
qDebug()<<"TileMatrix:TileAt:"<<p.ToString();
Tile* ret;
mutex.lock();

View File

@ -1,15 +1,20 @@
#include "opmapcontrol.h"
OPMapControl::OPMapControl(QWidget *parent):QWidget(parent),MapRenderTransform(1), maxZoom(2),minZoom(2)
OPMapControl::OPMapControl(QWidget *parent):QWidget(parent),MapRenderTransform(1), maxZoom(2),minZoom(2),zoomReal(0),isSelected(false)
{
EmptytileBrush = Qt::blue;
EmptytileBrush = Qt::cyan;
MissingDataFont =QFont ("Times",10,QFont::Bold);
EmptyTileText = "We are sorry, but we don't\nhave imagery at this zoom\nlevel for this region.";
EmptyTileBorders = QPen(Qt::white);
ShowTileGridLines=true;
ScalePen = QPen(Qt::blue);
SelectionPen = QPen(Qt::blue);
MapScaleInfoEnabled = true;
showTileGridLines=true;
DragButton = Qt::RightButton;
isMouseOverMarker=false;
core.SetCurrentRegion(Rectangle(-50, -50, this->width()+100, this->height()+100));
core.SetMapType(MapType::GoogleSatellite);
core.SetZoom(2);
core.SetZoom(3);
connect(&core,SIGNAL(OnNeedInvalidation()),this,SLOT(Core_OnNeedInvalidation()));
@ -93,7 +98,7 @@ void OPMapControl::DrawMap2D(QPainter &painter)
}
}
if(ShowTileGridLines)
if(showTileGridLines)
{
painter.setPen(EmptyTileBorders);
painter.drawRect(core.tileRect.X(), core.tileRect.Y(), core.tileRect.Width(), core.tileRect.Height());
@ -130,9 +135,40 @@ void OPMapControl::DrawMap2D(QPainter &painter)
void OPMapControl::mousePressEvent ( QMouseEvent* evnt )
{
if(!IsMouseOverMarker())
{
if(evnt->button() == DragButton && CanDragMap())
{
core.mouseDown.SetX(evnt->x());
core.mouseDown.SetY(evnt->y());
this->setCursor(Qt::SizeAllCursor);
core.BeginDrag(core.mouseDown);
this->repaint();
}
else if(!isSelected)
{
isSelected = true;
SetSelectedArea (RectLatLng::Empty);
selectionEnd = PointLatLng::Empty;
selectionStart = FromLocalToLatLng(evnt->x(), evnt->y());
}
}
QWidget::mousePressEvent(evnt);
}
PointLatLng OPMapControl::FromLocalToLatLng(int x, int y)
{
if(MapRenderTransform!=-1)
{
x = (int) (x * MapRenderTransform);
y = (int) (y * MapRenderTransform);
}
return core.FromLocalToLatLng(x, y);
}
void OPMapControl::mouseReleaseEvent ( QMouseEvent* evnt )
{
@ -140,7 +176,16 @@ void OPMapControl::mouseReleaseEvent ( QMouseEvent* evnt )
void OPMapControl::mouseMoveEvent ( QMouseEvent* evnt )
{
if(core.IsDragging())
{
core.mouseCurrent.SetX(evnt->x());
core.mouseCurrent.SetY(evnt->y());
{
core.Drag(core.mouseCurrent);
}
}
}
void OPMapControl::resizeEvent ( QResizeEvent * event )
{
@ -157,3 +202,12 @@ void OPMapControl::resize()
core.GoToCurrentPosition();
}
}
void OPMapControl::Offset(int const& x, int const& y)
{
core.DragOffset(Point(x, y));
}
void OPMapControl::closeEvent(QCloseEvent *event)
{
core.OnMapClose();
event->accept();
}

View File

@ -15,13 +15,16 @@ class OPMapControl:public QWidget
Q_PROPERTY(int MinZoom READ MinZoom WRITE SetMinZoom)
Q_PROPERTY(MouseWheelZoomType::Types MouseWheelZoom READ GetMouseWheelZoomType WRITE SetMouseWheelZoomType)
Q_PROPERTY(QString MouseWheelZoomStr READ GetMouseWheelZoomTypeStr WRITE SetMouseWheelZoomTypeByStr)
Q_PROPERTY(bool ShowTileGridLines READ ShowTileGridLines WRITE SetShowTileGridLines)
public:
OPMapControl(QWidget *parent=0);
QBrush EmptytileBrush;
QString EmptyTileText;
QPen EmptyTileBorders;
bool ShowTileGridLines;
QPen ScalePen;
QPen SelectionPen;
bool ShowTileGridLines()const {return showTileGridLines;}
void SetShowTileGridLines(bool const& value){showTileGridLines=value;this->repaint();}
int MaxZoom()const{return maxZoom;}
void SetMaxZoom(int const& value){maxZoom = value;}
int MinZoom()const{return minZoom;}
@ -30,6 +33,15 @@ public:
void SetMouseWheelZoomType(MouseWheelZoomType::Types const& value){core.SetMouseWheelZoomType(value);}
void SetMouseWheelZoomTypeByStr(const QString &value){core.SetMouseWheelZoomType(MouseWheelZoomType::TypeByStr(value));}
QString GetMouseWheelZoomTypeStr(){return MouseWheelZoomType::TypesStrList().at((int)core.GetMouseWheelZoomType());}
bool MapScaleInfoEnabled;
Qt::MouseButton DragButton;
RectLatLng SelectedArea()const{return selectedArea;}
void SetSelectedArea(RectLatLng const& value){selectedArea = value;this->repaint();}
RectLatLng BoundsOfMap;
void Offset(int const& x, int const& y);
bool CanDragMap()const{return core.CanDragMap;}
void SetCanDragMap(bool const& value){core.CanDragMap = value;}
protected:
void paintEvent ( QPaintEvent* evnt );
void mousePressEvent ( QMouseEvent* evnt );
@ -37,7 +49,12 @@ protected:
void mouseMoveEvent ( QMouseEvent* evnt );
void resizeEvent ( QResizeEvent * event );
void showEvent ( QShowEvent * event );
void closeEvent ( QCloseEvent * event );
bool IsDragging()const{return core.IsDragging();}
bool IsMouseOverMarker()const{return isMouseOverMarker;}
private:
bool showTileGridLines;
Core core;
qreal MapRenderTransform;
void DrawMap2D(QPainter &painter);
@ -45,6 +62,14 @@ private:
void resize();
int maxZoom;
int minZoom;
RectLatLng selectedArea;
PointLatLng selectionStart;
PointLatLng selectionEnd;
double zoomReal;
bool isSelected;
bool isMouseOverMarker;
void SetIsMouseOverMarker(bool const& value){isMouseOverMarker = value;}
PointLatLng FromLocalToLatLng(int x, int y);
private slots:
void Core_OnNeedInvalidation();
};