Format QMapControl code & update acknowledgements

This commit is contained in:
Alex Spataru 2021-12-06 14:36:46 -06:00
parent cde136e0ce
commit 6e9de8e956
83 changed files with 7996 additions and 7733 deletions

View File

@ -52,6 +52,26 @@ License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
## QMapControl
Copyright (C) 2007 - 2008 Kai Winter
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
Contact e-mail: kaiwinter@gmx.de
Program URL : http://qmapcontrol.sourceforge.net/
## qtcsv
Copyright © 2015 Antony Cherepanov (antony.cherepanov@gmail.com)
@ -623,8 +643,8 @@ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICE
“Contribution” means:
* **a)** in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
* **b)** in the case of each subsequent Contributor:
* **i)** changes to the Program, and
* **ii)** additions to the Program;
**i)** changes to the Program, and
**ii)** additions to the Program;
where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: **(i)** are separate modules of software distributed in conjunction with the Program under their own license agreement, and **(ii)** are not derivative works of the Program.
“Contributor” means any person or entity that distributes the Program.
@ -650,10 +670,10 @@ where such changes and/or additions to the Program originate from and are distri
A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
* **a)** it complies with the terms and conditions of this Agreement; and
* **b)** its license agreement:
* **i)** effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
* **ii)** effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
* **iii)** states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
* **iv)** states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
**i)** effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
**ii)** effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
**iii)** states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
**iv)** states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
When the Program is made available in source code form:
* **a)** it must be made available under this Agreement; and

View File

@ -22,17 +22,17 @@
#include <QLabel>
#include <QTimer>
Citymap::Citymap(QWidget*)
Citymap::Citymap(QWidget *)
{
// create MapControl
mc = new MapControl(QSize(380,540));
mc = new MapControl(QSize(380, 540));
mc->showScale(true);
// display the MapControl in the application
QVBoxLayout* layout = new QVBoxLayout;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mc);
layout->setContentsMargins(0,0,0,0);
layout->setContentsMargins(0, 0, 0, 0);
QWidget* w = new QWidget();
QWidget *w = new QWidget();
w->setLayout(layout);
setCentralWidget(w);
@ -58,13 +58,14 @@ Citymap::Citymap(QWidget*)
createActions();
createMenus();
connect(mc, SIGNAL(viewChanged(QPointF,int)), this, SLOT(mapControlZoomChanged(QPointF,int)), Qt::QueuedConnection);
connect(mc, SIGNAL(viewChanged(QPointF, int)), this,
SLOT(mapControlZoomChanged(QPointF, int)), Qt::QueuedConnection);
mc->addLayer(notes);
connect(notes, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(editNote(Geometry*, QPoint)));
connect(notes, SIGNAL(geometryClicked(Geometry *, QPoint)), this,
SLOT(editNote(Geometry *, QPoint)));
mc->setView(QPointF(8.26,50));
mc->setView(QPointF(8.26, 50));
mc->setZoom(13);
ignoreClicks = false;
@ -72,19 +73,20 @@ Citymap::Citymap(QWidget*)
noteID = 0;
notetextedit = new QTextEdit(mc);
notetextedit->setGeometry(0,0,200,100);
notetextedit->setGeometry(0, 0, 200, 100);
notepoint = new Point(0, 0, notetextedit, ".", Point::TopLeft);
notepoint->setVisible(false);
notes->addGeometry(notepoint);
statusBar = new QStatusBar( this );
statusBar = new QStatusBar(this);
setStatusBar(statusBar);
loadingProgress = new QLabel("");
statusBar->addWidget( loadingProgress );
statusBar->addWidget(loadingProgress);
loadingProgressTimer = new QTimer(this);
connect(loadingProgressTimer, SIGNAL(timeout()), this, SLOT(updateProgress()), Qt::QueuedConnection );
loadingProgressTimer->start( 500 ); //update every 500ms
connect(loadingProgressTimer, SIGNAL(timeout()), this, SLOT(updateProgress()),
Qt::QueuedConnection);
loadingProgressTimer->start(500); // update every 500ms
cacheTiles(true);
}
@ -93,7 +95,7 @@ void Citymap::updateProgress()
{
QString progressText = QString(" %1 tiles remaining").arg(mc->loadingQueueSize());
loadingProgress->setText( progressText );
loadingProgress->setText(progressText);
}
void Citymap::cacheTiles(bool qEnabled)
@ -110,10 +112,10 @@ void Citymap::cacheTiles(bool qEnabled)
void Citymap::createTours()
{
QPen* pen = new QPen(QColor(0,0,255,100));
QPen *pen = new QPen(QColor(0, 0, 255, 100));
pen->setWidth(5);
QList<Point*> points;
QList<Point *> points;
points << new Point(8.2606, 50.0051);
points << new Point(8.2602, 50.0050);
points << new Point(8.2598, 50.0044);
@ -158,87 +160,143 @@ void Citymap::addSights()
{
sights = new GeometryLayer("Sehenswürdigkeiten", mapadapter);
mc->addLayer(sights);
Point* dom = new ImagePoint(8.274167, 49.998889, QCoreApplication::applicationDirPath() + "/images/180-dom.jpg", "Mainzer Dom");
Point *dom = new ImagePoint(
8.274167, 49.998889,
QCoreApplication::applicationDirPath() + "/images/180-dom.jpg", "Mainzer Dom");
dom->setBaselevel(17);
sights->addGeometry(dom);
Point* stephan = new ImagePoint(8.268611, 49.995556, QCoreApplication::applicationDirPath() + "/images/180-stephan.jpg","St. Stephan");
Point *stephan = new ImagePoint(8.268611, 49.995556,
QCoreApplication::applicationDirPath()
+ "/images/180-stephan.jpg",
"St. Stephan");
stephan->setBaselevel(17);
sights->addGeometry(stephan);
Point* quitin = new ImagePoint(8.272222, 50.000833, QCoreApplication::applicationDirPath() + "/images/180-quintin.jpg","St. Quintin");
Point *quitin = new ImagePoint(8.272222, 50.000833,
QCoreApplication::applicationDirPath()
+ "/images/180-quintin.jpg",
"St. Quintin");
quitin->setBaselevel(17);
sights->addGeometry(quitin);
connect(sights, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClicked(Geometry*, QPoint)));
connect(sights, SIGNAL(geometryClicked(Geometry *, QPoint)), this,
SLOT(geometryClicked(Geometry *, QPoint)));
}
void Citymap::addPubs()
{
pubs = new GeometryLayer("Kneipe", mapadapter);
mc->addLayer(pubs);
Point* bagatelle = new Point(8.2606, 50.0052, QPixmap(QCoreApplication::applicationDirPath() + "/images/pub.png"), "Bagatelle");
Point *bagatelle = new Point(
8.2606, 50.0052,
QPixmap(QCoreApplication::applicationDirPath() + "/images/pub.png"), "Bagatelle");
pubs->addGeometry(bagatelle);
Point* nirgendwo = new Point(8.2595, 50.0048, QPixmap(QCoreApplication::applicationDirPath() + "/images/pub.png"), "Nirgendwo");
Point *nirgendwo = new Point(
8.2595, 50.0048,
QPixmap(QCoreApplication::applicationDirPath() + "/images/pub.png"), "Nirgendwo");
pubs->addGeometry(nirgendwo);
Point* krokodil = new Point(8.2594,50.0106, QPixmap(QCoreApplication::applicationDirPath() + "/images/pub.png"), "Krokodil");
Point *krokodil = new Point(
8.2594, 50.0106,
QPixmap(QCoreApplication::applicationDirPath() + "/images/pub.png"), "Krokodil");
pubs->addGeometry(krokodil);
connect(pubs, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClickEventKneipe(Geometry*, QPoint)));
connect(pubs, SIGNAL(geometryClicked(Geometry *, QPoint)), this,
SLOT(geometryClickEventKneipe(Geometry *, QPoint)));
}
void Citymap::addMuseums()
{
museum = new GeometryLayer("Museen", mapadapter);
mc->addLayer(museum);
Point* rgzm = new ImagePoint(8.269722, 50.006111, QCoreApplication::applicationDirPath() + "/images/180-rgzm.jpg", "rgzm");
Point *rgzm = new ImagePoint(
8.269722, 50.006111,
QCoreApplication::applicationDirPath() + "/images/180-rgzm.jpg", "rgzm");
rgzm->setBaselevel(17);
museum->addGeometry(rgzm);
Point* lm= new ImagePoint(8.26778, 50.00385, QCoreApplication::applicationDirPath() + "/images/180-lm.jpg", "lm");
lm ->setBaselevel(17);
Point *lm = new ImagePoint(
8.26778, 50.00385, QCoreApplication::applicationDirPath() + "/images/180-lm.jpg",
"lm");
lm->setBaselevel(17);
museum->addGeometry(lm);
connect(museum, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClicked(Geometry*, QPoint)));
connect(museum, SIGNAL(geometryClicked(Geometry *, QPoint)), this,
SLOT(geometryClicked(Geometry *, QPoint)));
}
void Citymap::geometryClicked(Geometry* geometry, QPoint)
void Citymap::geometryClicked(Geometry *geometry, QPoint)
{
if (ignoreClicks || addingNote)
return;
InfoDialog* infodialog = new InfoDialog(this);
InfoDialog *infodialog = new InfoDialog(this);
infodialog->setWindowTitle(geometry->name());
if (geometry->name() == "Mainzer Dom")
{
infodialog->setInfotext("<h1>Mainzer Dom</h1><p><img src=\"images/180-dom.jpg\" align=\"left\"/>Der Hohe Dom zu Mainz ist die Bischofskirche der Diözese Mainz und steht unter dem Patrozinium des heiligen Martin von Tours. Der Ostchor ist dem Hl. Stephan geweiht. Der zu den Kaiserdomen zählende Bau ist in seiner heutigen Form eine dreischiffige romanische Säulenbasilika, die in ihren Anbauten sowohl gotische als auch barocke Elemente aufweist.</p>");
} else if (geometry->name() == "St. Stephan")
infodialog->setInfotext(
"<h1>Mainzer Dom</h1><p><img src=\"images/180-dom.jpg\" align=\"left\"/>Der "
"Hohe Dom zu Mainz ist die Bischofskirche der Diözese Mainz und steht unter "
"dem Patrozinium des heiligen Martin von Tours. Der Ostchor ist dem Hl. "
"Stephan geweiht. Der zu den Kaiserdomen zählende Bau ist in seiner heutigen "
"Form eine dreischiffige romanische Säulenbasilika, die in ihren Anbauten "
"sowohl gotische als auch barocke Elemente aufweist.</p>");
}
else if (geometry->name() == "St. Stephan")
{
infodialog->setInfotext("<h1>St. Stephan</h1><p><img src=\"images/180-stephan.jpg\" align=\"left\"/>Die katholische Pfarrkirche Sankt Stephan in Mainz wurde 990 von Erzbischof Willigis auf der höchsten Erhebung der Stadt gegründet. Auftraggeberin war höchstwahrscheinlich die Kaiserwitwe Theophanu. Willigis wollte mit ihr die Gebetsstätte des Reiches schaffen. In der Kirche war ursprünglich ein Stift untergebracht. Der Propst des Stiftes verwaltete eines der Archidiakonate (mittelalterliche Organisationseinheit, ähnlich den heutigen Dekanaten) des Erzbistums.</p>");
} else if (geometry->name() == "St. Quintin")
infodialog->setInfotext(
"<h1>St. Stephan</h1><p><img src=\"images/180-stephan.jpg\" "
"align=\"left\"/>Die katholische Pfarrkirche Sankt Stephan in Mainz wurde "
"990 von Erzbischof Willigis auf der höchsten Erhebung der Stadt gegründet. "
"Auftraggeberin war höchstwahrscheinlich die Kaiserwitwe Theophanu. Willigis "
"wollte mit ihr die Gebetsstätte des Reiches schaffen. In der Kirche war "
"ursprünglich ein Stift untergebracht. Der Propst des Stiftes verwaltete "
"eines der Archidiakonate (mittelalterliche Organisationseinheit, ähnlich "
"den heutigen Dekanaten) des Erzbistums.</p>");
}
else if (geometry->name() == "St. Quintin")
{
infodialog->setInfotext("<h1>St. Quintin</h1><p><img src=\"images/180-quintin.jpg\" align=\"left\"/>Die Kirche St. Quintin in Mainz ist die Pfarrkirche der ältesten nachgewiesenen Pfarrei der Stadt.");
} else if (geometry->name() == "rgzm")
infodialog->setInfotext(
"<h1>St. Quintin</h1><p><img src=\"images/180-quintin.jpg\" "
"align=\"left\"/>Die Kirche St. Quintin in Mainz ist die Pfarrkirche der "
"ältesten nachgewiesenen Pfarrei der Stadt.");
}
else if (geometry->name() == "rgzm")
{
infodialog->setInfotext("<h1>Römisch-Germanisches Zentralmuseum</h1><p><img src=\"images/180-rgzm.jpg\" align=\"left\"/>Das Römisch-Germanische Zentralmuseum (RGZM) in Mainz ist ein Forschungsinstitut für Vor- und Frühgeschichte, das von Bund und Ländern getragen wird und zur Leibniz-Gemeinschaft deutscher Forschungseinrichtungen gehört. Gegliedert in mehrere Abteilungen, arbeitet das Institut im Bereich der Alten Welt sowie seiner Kontaktzonen von der Altsteinzeit bis ins Mittelalter.");
} else if (geometry->name() == "lm")
infodialog->setInfotext(
"<h1>Römisch-Germanisches Zentralmuseum</h1><p><img "
"src=\"images/180-rgzm.jpg\" align=\"left\"/>Das Römisch-Germanische "
"Zentralmuseum (RGZM) in Mainz ist ein Forschungsinstitut für Vor- und "
"Frühgeschichte, das von Bund und Ländern getragen wird und zur "
"Leibniz-Gemeinschaft deutscher Forschungseinrichtungen gehört. Gegliedert "
"in mehrere Abteilungen, arbeitet das Institut im Bereich der Alten Welt "
"sowie seiner Kontaktzonen von der Altsteinzeit bis ins Mittelalter.");
}
else if (geometry->name() == "lm")
{
infodialog->setInfotext("<h1>Landesmuseum Mainz</h1><p><img src=\"images/180-lm.jpg\" align=\"left\"/>Das Landesmuseum Mainz ist eines der ältesten Museen in Deutschland. Eine seiner Vorgängerinstitutionen, die Städtische Gemäldesammlung, wurde bereits 1803 von Jean-Antoine Chaptal auf Veranlassung Napoléon Bonapartes durch eine Schenkung von 36 Gemälden gegründet. Das Museum, welches sich heute im ehemaligen kurfürstlichen Marstall befindet, gehört zusammen mit dem Römisch-Germanischen Zentralmuseum und dem Gutenbergmuseum zu den bedeutenden Museen in Mainz. Seine kunst- und kulturgeschichtliche Sammlung erstreckt sich von der Vorgeschichte über die römische Zeit, dem Mittelalter und Barock bis hin zur Jugendstilzeit und der Kunst des 20. Jahrhunderts.");
infodialog->setInfotext(
"<h1>Landesmuseum Mainz</h1><p><img src=\"images/180-lm.jpg\" "
"align=\"left\"/>Das Landesmuseum Mainz ist eines der ältesten Museen in "
"Deutschland. Eine seiner Vorgängerinstitutionen, die Städtische "
"Gemäldesammlung, wurde bereits 1803 von Jean-Antoine Chaptal auf "
"Veranlassung Napoléon Bonapartes durch eine Schenkung von 36 Gemälden "
"gegründet. Das Museum, welches sich heute im ehemaligen kurfürstlichen "
"Marstall befindet, gehört zusammen mit dem Römisch-Germanischen "
"Zentralmuseum und dem Gutenbergmuseum zu den bedeutenden Museen in Mainz. "
"Seine kunst- und kulturgeschichtliche Sammlung erstreckt sich von der "
"Vorgeschichte über die römische Zeit, dem Mittelalter und Barock bis hin "
"zur Jugendstilzeit und der Kunst des 20. Jahrhunderts.");
}
if (geometry->name() != "")
infodialog->showMaximized();
}
void Citymap::geometryClickEventKneipe(Geometry* geometry, QPoint)
void Citymap::geometryClickEventKneipe(Geometry *geometry, QPoint)
{
if (ignoreClicks || addingNote)
return;
InfoDialog* infodialog = new InfoDialog(this);
InfoDialog *infodialog = new InfoDialog(this);
infodialog->setWindowTitle(geometry->name());
infodialog->setInfotext("<h1>" + geometry->name() + "</h1>");
infodialog->showNormal();
@ -247,18 +305,16 @@ void Citymap::geometryClickEventKneipe(Geometry* geometry, QPoint)
void Citymap::addZoomButtons()
{
// create buttons as controls for zoom
QPushButton* zoomin = new QPushButton("+");
QPushButton* zoomout = new QPushButton("-");
QPushButton *zoomin = new QPushButton("+");
QPushButton *zoomout = new QPushButton("-");
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
connect(zoomin, SIGNAL(clicked(bool)), mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)), mc, SLOT(zoomOut()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
QVBoxLayout *innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
@ -269,55 +325,47 @@ void Citymap::createActions()
toggleSights = new QAction(tr("Show Sights"), this);
toggleSights->setCheckable(true);
toggleSights->setChecked(true);
connect(toggleSights, SIGNAL(triggered(bool)),
sights, SLOT(setVisible(bool)));
connect(toggleSights, SIGNAL(triggered(bool)), sights, SLOT(setVisible(bool)));
togglePub = new QAction(tr("Show Pubs"), this);
togglePub->setCheckable(true);
togglePub->setChecked(true);
connect(togglePub, SIGNAL(triggered(bool)),
pubs, SLOT(setVisible(bool)));
connect(togglePub, SIGNAL(triggered(bool)), pubs, SLOT(setVisible(bool)));
toggleMuseum = new QAction(tr("Show Museums"), this);
toggleMuseum->setCheckable(true);
toggleMuseum->setChecked(true);
connect(toggleMuseum, SIGNAL(triggered(bool)),
museum, SLOT(setVisible(bool)));
connect(toggleMuseum, SIGNAL(triggered(bool)), museum, SLOT(setVisible(bool)));
toggleSightTour = new QAction(tr("Show Sight Tour"), this);
toggleSightTour->setCheckable(true);
toggleSightTour->setChecked(true);
connect(toggleSightTour, SIGNAL(triggered(bool)),
sights_tour, SLOT(setVisible(bool)));
connect(toggleSightTour, SIGNAL(triggered(bool)), sights_tour,
SLOT(setVisible(bool)));
togglePubTour = new QAction(tr("Show Pub Tour"), this);
togglePubTour->setCheckable(true);
togglePubTour->setChecked(true);
connect(togglePubTour, SIGNAL(triggered(bool)),
pub_tour, SLOT(setVisible(bool)));
connect(togglePubTour, SIGNAL(triggered(bool)), pub_tour, SLOT(setVisible(bool)));
toggleMuseumTour = new QAction(tr("Show Museum Tour"), this);
toggleMuseumTour->setCheckable(true);
toggleMuseumTour->setChecked(true);
connect(toggleMuseumTour, SIGNAL(triggered(bool)),
museum_tour, SLOT(setVisible(bool)));
connect(toggleMuseumTour, SIGNAL(triggered(bool)), museum_tour,
SLOT(setVisible(bool)));
addNoteAction = new QAction(tr("Add Note"), this);
connect(addNoteAction, SIGNAL(triggered(bool)),
this, SLOT(addNote()));
connect(addNoteAction, SIGNAL(triggered(bool)), this, SLOT(addNote()));
toolsDistance = new QAction(tr("Calculate Distance"), this);
connect(toolsDistance, SIGNAL(triggered(bool)),
this, SLOT(calcDistance()));
connect(toolsDistance, SIGNAL(triggered(bool)), this, SLOT(calcDistance()));
toolsLocalDiskCache = new QAction(tr("Cache Tiles Locally"), this);
toolsLocalDiskCache->setCheckable(true);
toolsLocalDiskCache->setChecked(true);
connect(toolsLocalDiskCache, SIGNAL(triggered(bool)),
this, SLOT(cacheTiles(bool)));
connect(toolsLocalDiskCache, SIGNAL(triggered(bool)), this, SLOT(cacheTiles(bool)));
QActionGroup* mapproviderGroup = new QActionGroup(this);
QActionGroup *mapproviderGroup = new QActionGroup(this);
osmAction = new QAction(tr("OpenStreetMap"), mapproviderGroup);
googleActionMap = new QAction(tr("Google: Roadmap (default)"), mapproviderGroup);
googleActionSatellite = new QAction(tr("Google: Satellite"), mapproviderGroup);
@ -332,20 +380,20 @@ void Citymap::createActions()
googleActionTerrain->setCheckable(true);
googleActionHybrid->setCheckable(true);
osmAction->setChecked(true);
connect(mapproviderGroup, SIGNAL(triggered(QAction*)),
this, SLOT(mapproviderSelected(QAction*)));
connect(mapproviderGroup, SIGNAL(triggered(QAction *)), this,
SLOT(mapproviderSelected(QAction *)));
QActionGroup* mapZoomGroup = new QActionGroup(this);
QActionGroup *mapZoomGroup = new QActionGroup(this);
for( int i=0; i <= 17; ++i )
for (int i = 0; i <= 17; ++i)
{
QString title = QString("Zoom %1").arg(i);
QAction* action = new QAction(title, mapZoomGroup);
QAction *action = new QAction(title, mapZoomGroup);
action->setCheckable(true);
zoomActions << action;
}
connect(mapZoomGroup, SIGNAL(triggered(QAction*)),
this, SLOT(mapZoomSelected(QAction*)));
connect(mapZoomGroup, SIGNAL(triggered(QAction *)), this,
SLOT(mapZoomSelected(QAction *)));
}
void Citymap::createMenus()
@ -373,23 +421,23 @@ void Citymap::createMenus()
mapMenu->addAction(googleActionHybrid);
zoomMenu = menuBar()->addMenu(tr("&Zoom Level"));
foreach( QAction* action, zoomActions )
foreach (QAction *action, zoomActions)
{
zoomMenu->addAction(action);
}
}
void Citymap::addNote()
{
addingNote = true;
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(writeNote(const QMouseEvent*, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(writeNote(const QMouseEvent *, const QPointF)));
}
void Citymap::writeNote(const QMouseEvent*, const QPointF coord)
void Citymap::writeNote(const QMouseEvent *, const QPointF coord)
{
Point* p = new Point(coord.x(), coord.y(), *notepixmap, QString::number(++noteID), Point::BottomLeft);
Point *p = new Point(coord.x(), coord.y(), *notepixmap, QString::number(++noteID),
Point::BottomLeft);
currentnoteID = noteID;
p->setBaselevel(16);
p->setMinsize(QSize(12, 10));
@ -403,14 +451,14 @@ void Citymap::writeNote(const QMouseEvent*, const QPointF coord)
mc->updateRequestNew();
disconnect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(writeNote(const QMouseEvent*, const QPointF)));
disconnect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(writeNote(const QMouseEvent *, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(hideNote(const QMouseEvent*, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(hideNote(const QMouseEvent *, const QPointF)));
}
void Citymap::hideNote(const QMouseEvent* evnt, const QPointF)
void Citymap::hideNote(const QMouseEvent *evnt, const QPointF)
{
if (addingNote && evnt->type() == QEvent::MouseButtonDblClick)
{
@ -422,12 +470,12 @@ void Citymap::hideNote(const QMouseEvent* evnt, const QPointF)
// save text
notestext[currentnoteID] = notetextedit->toPlainText();
disconnect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(hideNote(const QMouseEvent*, const QPointF)));
disconnect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)),
this, SLOT(hideNote(const QMouseEvent *, const QPointF)));
}
}
void Citymap::editNote(Geometry* geom, QPoint)
void Citymap::editNote(Geometry *geom, QPoint)
{
addingNote = true;
currentnoteID = QVariant(geom->name()).toInt();
@ -436,13 +484,13 @@ void Citymap::editNote(Geometry* geom, QPoint)
notepoint->setVisible(true);
mc->updateRequestNew();
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(hideNote(const QMouseEvent*, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(hideNote(const QMouseEvent *, const QPointF)));
}
void Citymap::resizeEvent(QResizeEvent *qEvent)
{
Q_UNUSED( qEvent );
Q_UNUSED(qEvent);
if (mc)
{
mc->resize(size());
@ -452,32 +500,41 @@ void Citymap::resizeEvent(QResizeEvent *qEvent)
void Citymap::calcDistance()
{
ignoreClicks = true;
connect(mc, SIGNAL(mouseEventCoordinate( const QMouseEvent*, const QPointF )),
this, SLOT(calcDistanceClick(const QMouseEvent*, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(calcDistanceClick(const QMouseEvent *, const QPointF)));
}
void Citymap::calcDistanceClick(const QMouseEvent* evnt, const QPointF coord)
void Citymap::calcDistanceClick(const QMouseEvent *evnt, const QPointF coord)
{
if (coord1 == QPointF() && evnt->type() == QEvent::MouseButtonPress)
{
coord1 = coord;
l->addGeometry(new ImagePoint(coord1.x(), coord1.y(), QCoreApplication::applicationDirPath() + "/images/flag.png", "", Point::BottomRight));
l->addGeometry(
new ImagePoint(coord1.x(), coord1.y(),
QCoreApplication::applicationDirPath() + "/images/flag.png",
"", Point::BottomRight));
mc->updateRequestNew();
}
else if (coord2 == QPointF() && evnt->type() == QEvent::MouseButtonPress)
{
coord2 = coord;
double PI = acos(-1.0);
double a1 = coord1.x()* (PI/180.0);;
double b1 = coord1.y()* (PI/180.0);;
double a2 = coord2.x()* (PI/180.0);;
double b2 = coord2.y()* (PI/180.0);;
double a1 = coord1.x() * (PI / 180.0);
;
double b1 = coord1.y() * (PI / 180.0);
;
double a2 = coord2.x() * (PI / 180.0);
;
double b2 = coord2.y() * (PI / 180.0);
;
double r = 6378;
double km = acos(cos(a1)*cos(b1)*cos(a2)*cos(b2) + cos(a1)*sin(b1)*cos(a2)*sin(b2) + sin(a1)*sin(a2)) * r;
double km = acos(cos(a1) * cos(b1) * cos(a2) * cos(b2)
+ cos(a1) * sin(b1) * cos(a2) * sin(b2) + sin(a1) * sin(a2))
* r;
QList<Point*> points;
QList<Point *> points;
points.append(new Point(coord1.x(), coord1.y()));
QPixmap* pixm = new QPixmap(100,20);
QPixmap *pixm = new QPixmap(100, 20);
pixm->fill(Qt::transparent);
QPainter pain(pixm);
pain.setFont(QFont("Helvetiva", 6));
@ -489,27 +546,26 @@ void Citymap::calcDistanceClick(const QMouseEvent* evnt, const QPointF coord)
coord1 = QPointF();
coord2 = QPointF();
ignoreClicks = false;
disconnect(mc, SIGNAL(mouseEventCoordinate( const QMouseEvent*, const QPointF)),
this, SLOT(calcDistanceClick(const QMouseEvent*, const QPointF)));
disconnect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)),
this, SLOT(calcDistanceClick(const QMouseEvent *, const QPointF)));
}
}
void Citymap::mapControlZoomChanged(const QPointF &coordinate, int zoom) const
{
Q_UNUSED(coordinate);
if ( zoomActions.at(zoom) )
if (zoomActions.at(zoom))
{
zoomActions.at(zoom)->setChecked( true );
zoomActions.at(zoom)->setChecked(true);
}
}
void Citymap::mapZoomSelected(QAction* action)
void Citymap::mapZoomSelected(QAction *action)
{
mc->setZoom( zoomActions.indexOf(action) );
mc->setZoom(zoomActions.indexOf(action));
}
void Citymap::mapproviderSelected(QAction* action)
void Citymap::mapproviderSelected(QAction *action)
{
if (action == osmAction)
{
@ -589,4 +645,3 @@ Citymap::~Citymap()
delete pubs;
delete museum;
}

View File

@ -14,24 +14,24 @@
class QLabel;
using namespace qmapcontrol;
class Citymap: public QMainWindow
class Citymap : public QMainWindow
{
Q_OBJECT
public:
Citymap(QWidget* parent = 0);
public:
Citymap(QWidget *parent = 0);
~Citymap();
private:
MapControl* mc;
MapAdapter* mapadapter;
private:
MapControl *mc;
MapAdapter *mapadapter;
QPixmap* notepixmap;
QPixmap *notepixmap;
Layer* sights;
Layer* museum;
Layer* pubs;
Layer* notes;
Layer *sights;
Layer *museum;
Layer *pubs;
Layer *notes;
void addZoomButtons();
@ -39,33 +39,33 @@ class Citymap: public QMainWindow
void createActions();
void createMenus();
QMenu* layerMenu;
QMenu* tourMenu;
QMenu* toolsMenu;
QMenu* mapMenu;
QMenu* zoomMenu;
QMenu *layerMenu;
QMenu *tourMenu;
QMenu *toolsMenu;
QMenu *mapMenu;
QMenu *zoomMenu;
QAction* toggleSights;
QAction* togglePub;
QAction* toggleMuseum;
QAction *toggleSights;
QAction *togglePub;
QAction *toggleMuseum;
QAction* togglePubTour;
QAction* toggleMuseumTour;
QAction* toggleSightTour;
QAction *togglePubTour;
QAction *toggleMuseumTour;
QAction *toggleSightTour;
QAction* addNoteAction;
QAction* toolsDistance;
QAction* toolsLocalDiskCache;
QAction *addNoteAction;
QAction *toolsDistance;
QAction *toolsLocalDiskCache;
QAction* osmAction;
QAction* googleActionMap;
QAction* googleActionSatellite;
QAction* googleActionTerrain;
QAction* googleActionHybrid;
QAction *osmAction;
QAction *googleActionMap;
QAction *googleActionSatellite;
QAction *googleActionTerrain;
QAction *googleActionHybrid;
QList<QAction*> zoomActions;
QList<QAction *> zoomActions;
QStatusBar* statusBar;
QStatusBar *statusBar;
bool ignoreClicks;
bool addingNote;
@ -77,33 +77,33 @@ class Citymap: public QMainWindow
QPointF coord1;
QPointF coord2;
Layer* l;
Layer *l;
LineString* pub_tour;
LineString* museum_tour;
LineString* sights_tour;
LineString *pub_tour;
LineString *museum_tour;
LineString *sights_tour;
QTextEdit* notetextedit;
Point* notepoint;
QTextEdit *notetextedit;
Point *notepoint;
int noteID;
int currentnoteID;
QHash<int, QString> notestext;
QLabel* loadingProgress;
QTimer* loadingProgressTimer;
QLabel *loadingProgress;
QTimer *loadingProgressTimer;
public slots:
void hideNote(const QMouseEvent* evnt, const QPointF coordinate);
void geometryClicked(Geometry* geometry, QPoint point);
void geometryClickEventKneipe(Geometry* geometry, QPoint point);
public slots:
void hideNote(const QMouseEvent *evnt, const QPointF coordinate);
void geometryClicked(Geometry *geometry, QPoint point);
void geometryClickEventKneipe(Geometry *geometry, QPoint point);
void addNote();
void writeNote(const QMouseEvent*, const QPointF);
void writeNote(const QMouseEvent *, const QPointF);
void calcDistance();
void calcDistanceClick(const QMouseEvent*, const QPointF);
void mapControlZoomChanged(const QPointF &coordinate, int zoom ) const;
void calcDistanceClick(const QMouseEvent *, const QPointF);
void mapControlZoomChanged(const QPointF &coordinate, int zoom) const;
void mapproviderSelected(QAction*);
void mapZoomSelected(QAction*);
void editNote(Geometry* geom, QPoint point);
void mapproviderSelected(QAction *);
void mapZoomSelected(QAction *);
void editNote(Geometry *geom, QPoint point);
void resizeEvent(QResizeEvent *qEvent);
void updateProgress();
void cacheTiles(bool qEnabled);

View File

@ -1,14 +1,14 @@
#include "dialogs.h"
#include <QHBoxLayout>
InfoDialog::InfoDialog(QWidget* parent)
InfoDialog::InfoDialog(QWidget *parent)
: QDialog(parent)
{
setWindowFlags(Qt::Dialog | Qt::WindowStaysOnTopHint);
infotext = new QTextEdit();
infotext->setReadOnly(true);
QHBoxLayout* layout = new QHBoxLayout();
QHBoxLayout *layout = new QHBoxLayout();
setLayout(layout);
layout->addWidget(infotext);

View File

@ -10,12 +10,12 @@
class InfoDialog : public QDialog
{
Q_OBJECT
public:
InfoDialog(QWidget* parent=0);
public:
InfoDialog(QWidget *parent = 0);
void setInfotext(QString text);
private:
QTextEdit* infotext;
private:
QTextEdit *infotext;
};
#endif

View File

@ -4,11 +4,10 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Citymap * mw = new Citymap();
Citymap *mw = new Citymap();
mw->resize(400,590);
mw->resize(400, 590);
mw->setWindowTitle("City Map Mainz");
mw->show();
return app.exec();
}

View File

@ -2,8 +2,9 @@
/*!
* \example gps.cpp
* This sample application uses GPS data from the gllin service, which you have to start manually before using this application.
* The file /tmp/nmeaNP is read in for the posiitons.
* This sample application uses GPS data from the gllin service, which you have to start
* manually before using this application. The file /tmp/nmeaNP is read in for the
* posiitons.
*
* The application receives positions from the GPS_Neo class and writes it into a label.
* You can toggle a button to set the view to the received coordinate.
@ -20,30 +21,31 @@
GPS::GPS()
{
// create MapControl
mc = new MapControl(QSize(480,640));
// ImageManager::instance()->setProxy("www-cache", 8080);
mc = new MapControl(QSize(480, 640));
// ImageManager::instance()->setProxy("www-cache", 8080);
// create MapAdapter to get maps from
TileMapAdapter* mapadapter = new TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17);
TileMapAdapter *mapadapter
= new TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17);
// create a layer with the mapadapter and type MapLayer
Layer* l = new Layer("Custom Layer", mapadapter, Layer::MapLayer);
Layer *l = new Layer("Custom Layer", mapadapter, Layer::MapLayer);
//current GPS Location
gpsDot = new CirclePoint(0,0, "GPS", CirclePoint::Middle, new QPen( Qt::darkBlue ));
l->addGeometry( gpsDot );
// current GPS Location
gpsDot = new CirclePoint(0, 0, "GPS", CirclePoint::Middle, new QPen(Qt::darkBlue));
l->addGeometry(gpsDot);
// add Layer to the MapControl
mc->addLayer(l);
// display the MapControl in the application
QHBoxLayout* layout = new QHBoxLayout;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(mc);
setLayout(layout);
// create buttons as controls for zoom
QPushButton* zoomin = new QPushButton("+");
QPushButton* zoomout = new QPushButton("-");
QPushButton *zoomin = new QPushButton("+");
QPushButton *zoomout = new QPushButton("-");
followgps = new QPushButton("Follow");
followgps->setCheckable(true);
@ -56,16 +58,13 @@ GPS::GPS()
simulategps->setMaximumWidth(50);
gpsposition->setFont(QFont("Arial", 10));
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
connect(zoomin, SIGNAL(clicked(bool)), mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)), mc, SLOT(zoomOut()));
connect(simulategps, SIGNAL(clicked(bool)),
this, SLOT(simulategps_checked()));
connect(simulategps, SIGNAL(clicked(bool)), this, SLOT(simulategps_checked()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
QVBoxLayout *innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
innerlayout->addWidget(followgps);
@ -73,38 +72,37 @@ GPS::GPS()
innerlayout->addWidget(gpsposition);
mc->setLayout(innerlayout);
GPS_Neo* gm = new GPS_Neo();
connect(gm, SIGNAL(new_position(float, QPointF)),
this, SLOT(updatePosition(float, QPointF)));
GPS_Neo *gm = new GPS_Neo();
connect(gm, SIGNAL(new_position(float, QPointF)), this,
SLOT(updatePosition(float, QPointF)));
gpsSim = new GPS_Simulation(this);
connect(gpsSim, SIGNAL(newPosition(float,QPointF)),
this, SLOT(updatePosition(float, QPointF)));
connect(gpsSim, SIGNAL(newPosition(float, QPointF)), this,
SLOT(updatePosition(float, QPointF)));
mc->setView(QPointF(0, 0));
gm->start();
}
GPS::~GPS()
{
}
GPS::~GPS() { }
void GPS::updatePosition(float time, QPointF coordinate)
{
gpsposition->setText(QString::number(time) + " / " + QString::number(coordinate.x()) + " / " + QString::number(coordinate.y()));
gpsposition->setText(QString::number(time) + " / " + QString::number(coordinate.x())
+ " / " + QString::number(coordinate.y()));
if (followgps->isChecked())
{
mc->setView(coordinate);
}
//update the gps dot location on map
// update the gps dot location on map
gpsDot->setCoordinate(coordinate);
}
void GPS::resizeEvent(QResizeEvent *qEvent)
{
Q_UNUSED( qEvent );
Q_UNUSED(qEvent);
if (mc)
{
mc->resize(size());
@ -113,7 +111,7 @@ void GPS::resizeEvent(QResizeEvent *qEvent)
void GPS::simulategps_checked()
{
if ( simulategps->isChecked() )
if (simulategps->isChecked())
{
gpsSim->start();
}
@ -122,4 +120,3 @@ void GPS::simulategps_checked()
gpsSim->stop();
}
}

View File

@ -9,22 +9,22 @@
#include "circlepoint.h"
using namespace qmapcontrol;
class GPS: public QWidget
class GPS : public QWidget
{
Q_OBJECT
public:
public:
GPS();
~GPS();
private:
QPushButton* followgps;
QPushButton* simulategps;
QLabel* gpsposition;
MapControl* mc;
GPS_Simulation* gpsSim;
CirclePoint* gpsDot;
private:
QPushButton *followgps;
QPushButton *simulategps;
QLabel *gpsposition;
MapControl *mc;
GPS_Simulation *gpsSim;
CirclePoint *gpsDot;
public slots:
public slots:
void updatePosition(float time, QPointF coordinate);
void resizeEvent(QResizeEvent *qEvent);
void simulategps_checked();

View File

@ -6,10 +6,7 @@ GPS_Neo::GPS_Neo(QObject *parent)
running = false;
}
GPS_Neo::~GPS_Neo()
{
}
GPS_Neo::~GPS_Neo() { }
void GPS_Neo::start()
{
@ -29,7 +26,7 @@ void GPS_Neo::tick()
QFile file("/tmp/nmeaNP");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// qDebug() << file.error();
// qDebug() << file.error();
return;
}
@ -61,9 +58,9 @@ GPS_Position GPS_Neo::process_line(QByteArray line)
QList<QByteArray> elems = line.split(',');
float time = QString(elems.at(1)).toFloat();
float latitude = elems.at(3).toFloat()/100;
float latitude = elems.at(3).toFloat() / 100;
QString latitude_dir = elems.at(4);
float longitude = elems.at(5).toFloat()/100;
float longitude = elems.at(5).toFloat() / 100;
QString longitude_dir = elems.at(6);
return GPS_Position(time, longitude, longitude_dir, latitude, latitude_dir);

View File

@ -6,30 +6,31 @@
#include <gps_position.h>
//! A parser for the NMEA data format
/*!
* This class parses gps data from the Neo´s gllin service, which you have to start manually
* It reads the device file every seconds and emits a signal which contains a GPS_Position.
* This class parses gps data from the Neo´s gllin service, which you have to start
*manually It reads the device file every seconds and emits a signal which contains a
*GPS_Position.
* @see http://3rdparty.downloads.openmoko.org
* @author Kai Winter <kaiwinter@gmx.de>
*/
*/
using namespace qmapcontrol;
class GPS_Neo: public QObject
class GPS_Neo : public QObject
{
Q_OBJECT
public:
public:
GPS_Neo(QObject *parent = 0);
~GPS_Neo();
void start();
void stop();
private:
private:
QList<GPS_Position> positions;
GPS_Position process_line(QByteArray line);
bool running;
signals:
signals:
void new_position(float, QPointF);
public slots:
public slots:
void tick();
};

View File

@ -3,23 +3,23 @@
#include <QtGlobal>
#include <QPointF>
GPS_Simulation::GPS_Simulation(QObject *parent) :
QObject(parent),
timer(new QTimer(this)),
mLat(40.748817f), //new york lat
mLong(-73.985428f) //new york lat
GPS_Simulation::GPS_Simulation(QObject *parent)
: QObject(parent)
, timer(new QTimer(this))
, mLat(40.748817f)
, // new york lat
mLong(-73.985428f) // new york lat
{
bool connected = connect( timer, SIGNAL(timeout()), this, SLOT(tick()), Qt::QueuedConnection );
Q_ASSERT( connected );
bool connected
= connect(timer, SIGNAL(timeout()), this, SLOT(tick()), Qt::QueuedConnection);
Q_ASSERT(connected);
}
GPS_Simulation::~GPS_Simulation()
{
}
GPS_Simulation::~GPS_Simulation() { }
void GPS_Simulation::start()
{
timer->start(1000); //1 sec updates
timer->start(1000); // 1 sec updates
}
void GPS_Simulation::stop()
@ -31,11 +31,11 @@ void GPS_Simulation::tick()
{
static float faketime = qrand() % 5000;
float lTempLat = qrand() % 2 - 1; //gives a number between -1 and 1
float lTempLong = qrand() % 2 - 1; //gives a number between -1 and 1
float lTempLat = qrand() % 2 - 1; // gives a number between -1 and 1
float lTempLong = qrand() % 2 - 1; // gives a number between -1 and 1
mLat = qBound(float(-90), (mLat + (lTempLat/10)), float(90));
mLong = qBound(float(-180), (mLat + (lTempLong/10)), float(180));
mLat = qBound(float(-90), (mLat + (lTempLat / 10)), float(90));
mLong = qBound(float(-180), (mLat + (lTempLong / 10)), float(180));
emit newPosition( ++faketime, QPointF(mLong, mLat) );
emit newPosition(++faketime, QPointF(mLong, mLat));
}

View File

@ -22,7 +22,7 @@ public slots:
void tick();
private:
QTimer* timer;
QTimer *timer;
float mLat;
float mLong;
};

View File

@ -1,7 +1,8 @@
#include "linesandpoints.h"
/*!
* \example linesandpoints.cpp
* This application demonstrates how to use Geometry objects and how to add them to a layer.
* This application demonstrates how to use Geometry objects and how to add them to a
* layer.
*
* Here are used three different point types:
* - One which displays a image
@ -25,52 +26,65 @@ LinesAndPoints::LinesAndPoints(QWidget *parent)
: QWidget(parent)
{
// the size which the QMapControl should fill
QSize size = QSize(480,640);
QSize size = QSize(480, 640);
mc = new MapControl(size);
// create layout
QHBoxLayout* layout = new QHBoxLayout;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(mc);
setLayout(layout);
// create layer
MapAdapter* mapadapter = new OSMMapAdapter();
Layer* l = new MapLayer("Custom Layer", mapadapter);
MapAdapter *mapadapter = new OSMMapAdapter();
Layer *l = new MapLayer("Custom Layer", mapadapter);
mc->addLayer(l);
// create a LineString
QList<Point*> points;
QList<Point *> points;
// Points with image
points.append(new ImagePoint(8.259959, 50.001781, "images/bus_stop.png", "Mainz, Hauptbahnhof", Point::BottomLeft));
points.append(new ImagePoint(8.263758, 49.998917, "images/bus_stop.png", "Mainz, Münsterplatz", Point::BottomLeft));
points.append(new ImagePoint(8.265812, 50.001952, "images/bus_stop.png","Mainz, Neubrunnenplatz", Point::BottomLeft));
points.append(new ImagePoint(8.259959, 50.001781, "images/bus_stop.png",
"Mainz, Hauptbahnhof", Point::BottomLeft));
points.append(new ImagePoint(8.263758, 49.998917, "images/bus_stop.png",
"Mainz, Münsterplatz", Point::BottomLeft));
points.append(new ImagePoint(8.265812, 50.001952, "images/bus_stop.png",
"Mainz, Neubrunnenplatz", Point::BottomLeft));
// Points with a circle
points.append(new CirclePoint(8.2688, 50.004015, "Mainz, Bauhofstraße LRP", Point::Middle));
points.append(
new CirclePoint(8.2688, 50.004015, "Mainz, Bauhofstraße LRP", Point::Middle));
points.append(new CirclePoint(8.272845, 50.00495, "Mainz, Landtag", Point::Middle));
points.append(new CirclePoint(8.280349, 50.008173, "Mainz, Brückenkopf", Point::Middle));
points.append(
new CirclePoint(8.280349, 50.008173, "Mainz, Brückenkopf", Point::Middle));
// A QPen can be used to customize the
QPen* pointpen = new QPen(QColor(0,255,0));
QPen *pointpen = new QPen(QColor(0, 255, 0));
pointpen->setWidth(3);
points.append(new CirclePoint(8.273573, 50.016315, 15, "Wiesbaden-Mainz-Kastel, Eleonorenstraße", Point::Middle, pointpen));
points.append(new CirclePoint(8.275145, 50.016992, 15, "Wiesbaden-Mainz-Kastel, Johannes-Goßner-Straße", Point::Middle, pointpen));
points.append(new CirclePoint(8.270476, 50.021426, 15, "Wiesbaden-Mainz-Kastel, Ruthof", Point::Middle, pointpen));
points.append(new CirclePoint(8.273573, 50.016315, 15,
"Wiesbaden-Mainz-Kastel, Eleonorenstraße",
Point::Middle, pointpen));
points.append(new CirclePoint(8.275145, 50.016992, 15,
"Wiesbaden-Mainz-Kastel, Johannes-Goßner-Straße",
Point::Middle, pointpen));
points.append(new CirclePoint(8.270476, 50.021426, 15,
"Wiesbaden-Mainz-Kastel, Ruthof", Point::Middle,
pointpen));
// "Blind" Points
points.append(new Point(8.266445, 50.025913, "Wiesbaden-Mainz-Kastel, Mudra Kaserne"));
points.append(new Point(8.260378, 50.030345, "Wiesbaden-Mainz-Amoneburg, Dyckerhoffstraße"));
points.append(
new Point(8.266445, 50.025913, "Wiesbaden-Mainz-Kastel, Mudra Kaserne"));
points.append(
new Point(8.260378, 50.030345, "Wiesbaden-Mainz-Amoneburg, Dyckerhoffstraße"));
// A QPen also can use transparency
QPen* linepen = new QPen(QColor(0, 0, 255, 100));
QPen *linepen = new QPen(QColor(0, 0, 255, 100));
linepen->setWidth(5);
// Add the Points and the QPen to a LineString
LineString* ls = new LineString(points, "Busline 54", linepen);
LineString *ls = new LineString(points, "Busline 54", linepen);
// Add the LineString to the layer
l->addGeometry(ls);
// Connect click events of the layer to this object
connect(l, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClicked(Geometry*, QPoint)));
connect(l, SIGNAL(geometryClicked(Geometry *, QPoint)), this,
SLOT(geometryClicked(Geometry *, QPoint)));
// Sets the view to the interesting area
mc->setView(QPointF(8.259959, 50.001781));
@ -82,32 +96,30 @@ LinesAndPoints::LinesAndPoints(QWidget *parent)
void LinesAndPoints::addZoomButtons()
{
// create buttons as controls for zoom
QPushButton* zoomin = new QPushButton("+");
QPushButton* zoomout = new QPushButton("-");
QPushButton *zoomin = new QPushButton("+");
QPushButton *zoomout = new QPushButton("-");
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
connect(zoomin, SIGNAL(clicked(bool)), mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)), mc, SLOT(zoomOut()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
QVBoxLayout *innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
}
void LinesAndPoints::geometryClicked(Geometry* geom, QPoint)
void LinesAndPoints::geometryClicked(Geometry *geom, QPoint)
{
qDebug() << "parent: " << geom->parentGeometry();
qDebug() << "Element clicked: " << geom->name();
if (geom->hasClickedPoints())
{
QList<Geometry*> pp = geom->clickedPoints();
QList<Geometry *> pp = geom->clickedPoints();
qDebug() << "number of child elements: " << pp.size();
for (int i=0; i<pp.size(); ++i)
for (int i = 0; i < pp.size(); ++i)
{
QMessageBox::information(this, geom->name(), pp.at(i)->name());
}
@ -118,20 +130,18 @@ void LinesAndPoints::geometryClicked(Geometry* geom, QPoint)
}
}
LinesAndPoints::~LinesAndPoints()
{
}
LinesAndPoints::~LinesAndPoints() { }
void LinesAndPoints::resizeEvent(QResizeEvent *qEvent)
{
Q_UNUSED( qEvent );
Q_UNUSED(qEvent);
if (mc)
{
mc->resize(size());
}
}
void LinesAndPoints::keyPressEvent(QKeyEvent* evnt)
void LinesAndPoints::keyPressEvent(QKeyEvent *evnt)
{
if (evnt->key() == 49 || evnt->key() == 17825792) // tastatur '1'
{
@ -147,7 +157,7 @@ void LinesAndPoints::keyPressEvent(QKeyEvent* evnt)
}
else if (evnt->key() == 54) // 6
{
mc->setView(QPointF(8,50));
mc->setView(QPointF(8, 50));
}
else if (evnt->key() == 16777234) // left
{
@ -157,7 +167,7 @@ void LinesAndPoints::keyPressEvent(QKeyEvent* evnt)
{
mc->scrollRight();
}
else if (evnt->key() == 16777235 ) // up
else if (evnt->key() == 16777235) // up
{
mc->scrollUp();
}

View File

@ -11,20 +11,20 @@ using namespace qmapcontrol;
class LinesAndPoints : public QWidget
{
Q_OBJECT
public:
public:
LinesAndPoints(QWidget *parent = 0);
~LinesAndPoints();
private:
MapControl* mc;
private:
MapControl *mc;
void addZoomButtons();
public slots:
void geometryClicked(Geometry* geom, QPoint coord_px);
public slots:
void geometryClicked(Geometry *geom, QPoint coord_px);
void resizeEvent(QResizeEvent *qEvent);
protected:
void keyPressEvent(QKeyEvent* evnt);
protected:
void keyPressEvent(QKeyEvent *evnt);
};
#endif

View File

@ -5,7 +5,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
LinesAndPoints ta;
ta.resize(480,640);
ta.resize(480, 640);
ta.setWindowTitle("QMapControl Demo");
ta.show();
return app.exec();

View File

@ -20,51 +20,46 @@ Mapviewer::Mapviewer(QWidget *parent)
// show mapcontrol in mainwindow
setCentralWidget(mc);
FixedImageOverlay* fip = new FixedImageOverlay(-36, 66, 37, 23, QCoreApplication::applicationDirPath() + "/sample.png");
FixedImageOverlay *fip = new FixedImageOverlay(
-36, 66, 37, 23, QCoreApplication::applicationDirPath() + "/sample.png");
mc->setView(QPointF(10,50));
mc->setView(QPointF(10, 50));
mc->zoomIn();
mainlayer->addGeometry(fip);
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(coordinateClicked(const QMouseEvent*, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(coordinateClicked(const QMouseEvent *, const QPointF)));
}
void Mapviewer::addZoomButtons()
{
// create buttons as controls for zoom
QPushButton* zoomin = new QPushButton("+");
QPushButton* zoomout = new QPushButton("-");
QPushButton *zoomin = new QPushButton("+");
QPushButton *zoomout = new QPushButton("-");
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
connect(zoomin, SIGNAL(clicked(bool)), mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)), mc, SLOT(zoomOut()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
QVBoxLayout *innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
}
Mapviewer::~Mapviewer()
{
}
Mapviewer::~Mapviewer() { }
// resize the widget
void Mapviewer::resizeEvent ( QResizeEvent * event )
void Mapviewer::resizeEvent(QResizeEvent *event)
{
mc->resize(event->size());
}
void Mapviewer::coordinateClicked(const QMouseEvent * evnt, const QPointF coordinate)
void Mapviewer::coordinateClicked(const QMouseEvent *evnt, const QPointF coordinate)
{
if (evnt->type()==QEvent::MouseButtonPress)
if (evnt->type() == QEvent::MouseButtonPress)
{
qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y();
}

View File

@ -14,17 +14,17 @@ public:
~Mapviewer();
private:
MapControl* mc;
MapAdapter* mapadapter;
Layer* mainlayer;
MapControl *mc;
MapAdapter *mapadapter;
Layer *mainlayer;
void addZoomButtons();
public slots:
void coordinateClicked(const QMouseEvent* evnt, const QPointF coordinate);
void coordinateClicked(const QMouseEvent *evnt, const QPointF coordinate);
protected:
virtual void resizeEvent ( QResizeEvent * event );
virtual void resizeEvent(QResizeEvent *event);
};
#endif

View File

@ -31,7 +31,7 @@ Mapviewer::Mapviewer(QWidget *parent)
addZoomButtons();
mc->setView(QPointF(0,0));
mc->setView(QPointF(0, 0));
mc->setZoom(2);
// show mapcontrol in mainwindow
setCentralWidget(mc);
@ -40,29 +40,25 @@ Mapviewer::Mapviewer(QWidget *parent)
void Mapviewer::addZoomButtons()
{
// create buttons as controls for zoom
QPushButton* zoomin = new QPushButton("+");
QPushButton* zoomout = new QPushButton("-");
QPushButton *zoomin = new QPushButton("+");
QPushButton *zoomout = new QPushButton("-");
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
connect(zoomin, SIGNAL(clicked(bool)), mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)), mc, SLOT(zoomOut()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
QVBoxLayout *innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
}
Mapviewer::~Mapviewer()
{
}
Mapviewer::~Mapviewer() { }
// resize the widget
void Mapviewer::resizeEvent ( QResizeEvent * event )
void Mapviewer::resizeEvent(QResizeEvent *event)
{
mc->resize(event->size());
}

View File

@ -16,14 +16,14 @@ public:
~Mapviewer();
private:
MapControl* mc;
MapAdapter* mapadapter;
Layer* mainlayer;
MapControl *mc;
MapAdapter *mapadapter;
Layer *mainlayer;
void addZoomButtons();
protected:
virtual void resizeEvent ( QResizeEvent * event );
virtual void resizeEvent(QResizeEvent *event);
};
#endif

View File

@ -5,16 +5,13 @@ double y = 1.0;
GPS_Modul::GPS_Modul(QObject *parent)
: QObject(parent)
{
// qDebug() << "GPS_Modul()";
// qDebug() << "GPS_Modul()";
loadFile();
running = false;
}
GPS_Modul::~GPS_Modul()
{
}
GPS_Modul::~GPS_Modul() { }
void GPS_Modul::start()
{
@ -22,7 +19,7 @@ void GPS_Modul::start()
if (!running)
{
running = true;
QTimer::singleShot(1000/25, this, SLOT(tick()));
QTimer::singleShot(1000 / 25, this, SLOT(tick()));
}
}
void GPS_Modul::stop()
@ -32,27 +29,27 @@ void GPS_Modul::stop()
void GPS_Modul::tick()
{
// qDebug() << "GPS_Modul::tick()";
// qDebug() << "GPS_Modul::tick()";
// GPS_Position pos = positions.takeFirst();
// x = pos.longitude;
// y = pos.latitude;
// GPS_Position pos = positions.takeFirst();
// x = pos.longitude;
// y = pos.latitude;
// qDebug() << pos.latitude << ", " << pos.longitude;
// qDebug() << pos.latitude << ", " << pos.longitude;
x += .1;
y += .1;
emit(new_position(QPointF(x,y)));
// emit(changed());
emit(new_position(QPointF(x, y)));
// emit(changed());
// if (running && !positions.isEmpty())
// if (running && !positions.isEmpty())
if (running)
QTimer::singleShot(1000/25, this, SLOT(tick()));
QTimer::singleShot(1000 / 25, this, SLOT(tick()));
}
void GPS_Modul::loadFile()
{
QFile file("/home/kai/kwint001/trunk/code/MapAPI/src/mainz_gps.nme");
// qDebug() << file.exists();
// qDebug() << file.exists();
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << file.error();
@ -71,19 +68,19 @@ void GPS_Modul::process_line(QByteArray line)
return;
line.chop(1);
// qDebug() << line;
// qDebug() << line;
// get time
QList<QByteArray> elems = line.split(',');
float time = QString(elems.at(1)).toFloat();
float latitude = elems.at(3).toFloat()/100;
float latitude = elems.at(3).toFloat() / 100;
QString latitude_dir = elems.at(4);
float longitude = elems.at(5).toFloat()/100;
float longitude = elems.at(5).toFloat() / 100;
QString longitude_dir = elems.at(6);
positions.append(GPS_Position(time, longitude, longitude_dir, latitude, latitude_dir));
positions.append(
GPS_Position(time, longitude, longitude_dir, latitude, latitude_dir));
// qDebug() << elems.at(6) << " | " << latitude;
// qDebug() << elems.at(6) << " | " << latitude;
}

View File

@ -12,25 +12,24 @@ using namespace qmapcontrol;
class GPS_Modul : public QObject
{
Q_OBJECT
public:
public:
GPS_Modul(QObject *parent = 0);
~GPS_Modul();
void start();
void stop();
private:
private:
QList<GPS_Position> positions;
void loadFile();
void process_line(QByteArray line);
bool running;
signals:
signals:
void new_position(QPointF);
void changed();
public slots:
public slots:
void tick();
};
#endif

View File

@ -5,7 +5,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
Multidemo ta;
ta.resize(480,640);
ta.resize(480, 640);
ta.setWindowTitle("QMapControl Demo");
ta.show();
return app.exec();

View File

@ -11,10 +11,12 @@
* - Add Point: adds a Point to the coordinate you click (this point will be clickable)
* - Drag Rect: lets to drag a rectangular into which will be zoomed in
* - Move To Click: moves the view middle to the clicked coordinate
* - GPS: starts a "pseudo" GPS receiver which emits new positions, these are connected to the ImagePoint
* - GPS: starts a "pseudo" GPS receiver which emits new positions, these are connected
* to the ImagePoint
* - Follow Geom: Follows the ImagePoint, when it moves because of new GPS positions
*
* A overview map lefts you see where you are. You can even click on it to change your position.
* A overview map lefts you see where you are. You can even click on it to change your
* position.
*
* You can find this example here: MapAPI/Samples/Multimap
* \image html sample_multidemo.png "screenshot"
@ -26,82 +28,103 @@ Multidemo::Multidemo(QWidget *parent)
createLayout();
gm = new GPS_Modul();
connect(gm, SIGNAL(new_position(QPointF)),
ip, SLOT(setCoordinate(QPointF)));
connect(gm, SIGNAL(new_position(QPointF)), ip, SLOT(setCoordinate(QPointF)));
}
void Multidemo::setupMaps()
{
QSize size = QSize(480,640);
QSize size = QSize(480, 640);
// main map control
mc = new MapControl(size);
MapAdapter* mapadapter = new WMSMapAdapter("www2.demis.nl", "/wms/wms.asp?wms=WorldMap&LAYERS=Countries,Borders,Cities,Rivers,Settlements,Hillshading,Waterbodies,Railroads,Highways,Roads&FORMAT=image/png&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&TRANSPARENT=FALSE", 256);
MapAdapter *mapadapter = new WMSMapAdapter(
"www2.demis.nl",
"/wms/"
"wms.asp?wms=WorldMap&LAYERS=Countries,Borders,Cities,Rivers,Settlements,"
"Hillshading,Waterbodies,Railroads,Highways,Roads&FORMAT=image/"
"png&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/"
"vnd.ogc.se_inimage&SRS=EPSG:4326&TRANSPARENT=FALSE",
256);
// maplayer
Layer* l = new MapLayer("Custom Layer", mapadapter);
Layer *l = new MapLayer("Custom Layer", mapadapter);
mc->addLayer(l);
// Geometry layer
Layer* l2 = new GeometryLayer("Geom Layer", mapadapter);
Layer *l2 = new GeometryLayer("Geom Layer", mapadapter);
mc->addLayer(l2);
// "minimap" control
mc2 = new MapControl(QSize(150,150), MapControl::None);
MapAdapter* mapadapter_mini = new OSMMapAdapter();
Layer* layer_mini = new MapLayer("Custom Layer", mapadapter_mini);
mc2 = new MapControl(QSize(150, 150), MapControl::None);
MapAdapter *mapadapter_mini = new OSMMapAdapter();
Layer *layer_mini = new MapLayer("Custom Layer", mapadapter_mini);
mc2->addLayer(layer_mini);
// create points
QPen* pen = new QPen(QColor(255, 0, 0, 100));
QPen *pen = new QPen(QColor(255, 0, 0, 100));
pen->setWidth(5);
QList<Point*> points;
points.append(new CirclePoint(8.259959, 50.001781, "Mainz, Hauptbahnhof", Point::Middle, pen));
points.append(new CirclePoint(8.263758, 49.998917, "Mainz, Münsterplatz", Point::Middle, pen));
points.append(new CirclePoint(8.265812, 50.001952, "Mainz, Neubrunnenplatz", Point::Middle, pen));
points.append(new CirclePoint(8.2688, 50.004015, "Mainz, Bauhofstraße LRP", Point::Middle, pen));
points.append(new CirclePoint(8.272845, 50.00495, "Mainz, Landtag", Point::Middle, pen));
points.append(new CirclePoint(8.272845, 50.00495, "Mainz, Brückenplatz", Point::Middle, pen));
points.append(new CirclePoint(8.280349, 50.008173, "Mainz, Brückenkopf", Point::Middle, pen));
points.append(new CirclePoint(8.273573, 50.016315, "Wiesbaden-Mainz-Kastel, Eleonorenstraße", Point::Middle, pen));
points.append(new CirclePoint(8.275145, 50.016992, "Wiesbaden-Mainz-Kastel, Johannes-Goßner-Straße", Point::Middle, pen));
points.append(new CirclePoint(8.270476, 50.021426, "Wiesbaden-Mainz-Kastel, Ruthof", Point::Middle, pen));
points.append(new CirclePoint(8.266445, 50.025913, "Wiesbaden-Mainz-Kastel, Mudra Kaserne", Point::Middle, pen));
points.append(new CirclePoint(8.260378, 50.030345, "Wiesbaden-Mainz-Amoneburg, Dyckerhoffstraße", Point::Middle, pen));
QList<Point *> points;
points.append(
new CirclePoint(8.259959, 50.001781, "Mainz, Hauptbahnhof", Point::Middle, pen));
points.append(
new CirclePoint(8.263758, 49.998917, "Mainz, Münsterplatz", Point::Middle, pen));
points.append(new CirclePoint(8.265812, 50.001952, "Mainz, Neubrunnenplatz",
Point::Middle, pen));
points.append(new CirclePoint(8.2688, 50.004015, "Mainz, Bauhofstraße LRP",
Point::Middle, pen));
points.append(
new CirclePoint(8.272845, 50.00495, "Mainz, Landtag", Point::Middle, pen));
points.append(
new CirclePoint(8.272845, 50.00495, "Mainz, Brückenplatz", Point::Middle, pen));
points.append(
new CirclePoint(8.280349, 50.008173, "Mainz, Brückenkopf", Point::Middle, pen));
points.append(new CirclePoint(8.273573, 50.016315,
"Wiesbaden-Mainz-Kastel, Eleonorenstraße",
Point::Middle, pen));
points.append(new CirclePoint(8.275145, 50.016992,
"Wiesbaden-Mainz-Kastel, Johannes-Goßner-Straße",
Point::Middle, pen));
points.append(new CirclePoint(8.270476, 50.021426, "Wiesbaden-Mainz-Kastel, Ruthof",
Point::Middle, pen));
points.append(new CirclePoint(8.266445, 50.025913,
"Wiesbaden-Mainz-Kastel, Mudra Kaserne", Point::Middle,
pen));
points.append(new CirclePoint(8.260378, 50.030345,
"Wiesbaden-Mainz-Amoneburg, Dyckerhoffstraße",
Point::Middle, pen));
// add points to linestring
pen = new QPen(QColor(0, 0, 255, 100));
pen->setWidth(5);
LineString* ls = new LineString(points, "Busline 54", pen);
LineString *ls = new LineString(points, "Busline 54", pen);
// the linestring is added to the MapLayer l, since it doenst change its points
l->addGeometry(ls);
// this point receives position changes from the "gps modul"
ip = new ImagePoint(0,0, QCoreApplication::applicationDirPath() + "/images/marker1.png", "image point", Point::TopRight);
ip = new ImagePoint(0, 0,
QCoreApplication::applicationDirPath() + "/images/marker1.png",
"image point", Point::TopRight);
// so if have to be added to the GeometryLayer l2
l2->addGeometry(ip);
QPushButton* pb = new QPushButton("test button", mc);
QPushButton *pb = new QPushButton("test button", mc);
// widget example
Point* wpoint = new Point(-20,-20, pb, ".", Point::TopLeft);
Point *wpoint = new Point(-20, -20, pb, ".", Point::TopLeft);
wpoint->setBaselevel(3);
l->addGeometry(wpoint);
pb->setGeometry(0,0,100,50);
pb->setGeometry(0, 0, 100, 50);
connect(l, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClickEvent(Geometry*, QPoint)));
connect(l2, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClickEvent(Geometry*, QPoint)));
connect(mc, SIGNAL(boxDragged(const QRectF)),
this, SLOT(draggedRect(QRectF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(mouseEventCoordinate(const QMouseEvent*, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(coordinateClicked(const QMouseEvent*, const QPointF)));
connect(mc2, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(coordinateClicked_mc2(const QMouseEvent*, const QPointF)));
connect(l, SIGNAL(geometryClicked(Geometry *, QPoint)), this,
SLOT(geometryClickEvent(Geometry *, QPoint)));
connect(l2, SIGNAL(geometryClicked(Geometry *, QPoint)), this,
SLOT(geometryClickEvent(Geometry *, QPoint)));
connect(mc, SIGNAL(boxDragged(const QRectF)), this, SLOT(draggedRect(QRectF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(mouseEventCoordinate(const QMouseEvent *, const QPointF)));
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(coordinateClicked(const QMouseEvent *, const QPointF)));
connect(mc2, SIGNAL(mouseEventCoordinate(const QMouseEvent *, const QPointF)), this,
SLOT(coordinateClicked_mc2(const QMouseEvent *, const QPointF)));
}
void Multidemo::createLayout()
@ -141,8 +164,8 @@ void Multidemo::createLayout()
btn4->setFocusPolicy(Qt::NoFocus);
btn5->setFocusPolicy(Qt::NoFocus);
QHBoxLayout* layout = new QHBoxLayout;
QVBoxLayout* layoutinner = new QVBoxLayout;
QHBoxLayout *layout = new QHBoxLayout;
QVBoxLayout *layoutinner = new QVBoxLayout;
layoutinner->addWidget(mc2);
layoutinner->addWidget(btn1);
@ -153,54 +176,54 @@ void Multidemo::createLayout()
layoutinner->addSpacing(70);
layout->addLayout(layoutinner);
QHBoxLayout* mclayout = new QHBoxLayout;
QHBoxLayout *mclayout = new QHBoxLayout;
mclayout->addWidget(mc);
mclayout->setMargin(0);
setLayout(mclayout);
mc->setLayout(layoutinner);
connect(btn2, SIGNAL(toggled( bool )),
this, SLOT(buttonToggled(bool)));
connect(btn2, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool)));
connect(btn4, SIGNAL(toggled( bool )),
this, SLOT(toggleFollow(bool)));
connect(btn4, SIGNAL(toggled(bool)), this, SLOT(toggleFollow(bool)));
connect(btn5, SIGNAL(toggled( bool )),
this, SLOT(toggleGPS(bool)));
connect(btn5, SIGNAL(toggled(bool)), this, SLOT(toggleGPS(bool)));
}
void Multidemo::coordinateClicked(const QMouseEvent* evnt, const QPointF coord)
void Multidemo::coordinateClicked(const QMouseEvent *evnt, const QPointF coord)
{
if (btn1->isChecked() && evnt->type()==QEvent::MouseButtonPress)
if (btn1->isChecked() && evnt->type() == QEvent::MouseButtonPress)
{
mc->layer("Geom Layer")->addGeometry(new CirclePoint(coord.x(), coord.y(), 10, "added point"));
mc->layer("Geom Layer")
->addGeometry(new CirclePoint(coord.x(), coord.y(), 10, "added point"));
mc->updateRequestNew();
}
}
void Multidemo::geometryClickEvent(Geometry* geom, QPoint)
void Multidemo::geometryClickEvent(Geometry *geom, QPoint)
{
if (geom->hasClickedPoints())
{
QList<Geometry*> pp = geom->clickedPoints();
for (int i=0; i<pp.size(); ++i)
QList<Geometry *> pp = geom->clickedPoints();
for (int i = 0; i < pp.size(); ++i)
{
QMessageBox::information(this, geom->name(), pp.at(i)->name());
}
}
else if (geom->GeometryType == "Point")
{
QMessageBox::information(this, geom->name(), QString("Position: ").append(QString().setNum(((Point*)geom)->longitude())).append(QString("/")).append(QString().setNum(((Point*)geom)->latitude())));
QMessageBox::information(
this, geom->name(),
QString("Position: ")
.append(QString().setNum(((Point *)geom)->longitude()))
.append(QString("/"))
.append(QString().setNum(((Point *)geom)->latitude())));
}
}
Multidemo::~Multidemo()
{
}
Multidemo::~Multidemo() { }
void Multidemo::keyPressEvent(QKeyEvent* evnt)
void Multidemo::keyPressEvent(QKeyEvent *evnt)
{
if (evnt->key() == 49 || evnt->key() == 17825792) // keyboard '1'
{
@ -214,7 +237,7 @@ void Multidemo::keyPressEvent(QKeyEvent* evnt)
{
mc->zoomOut();
}
else if (evnt->key() == 52) //4
else if (evnt->key() == 52) // 4
{
mc->updateRequestNew();
}
@ -226,7 +249,7 @@ void Multidemo::keyPressEvent(QKeyEvent* evnt)
{
mc->scrollRight();
}
else if (evnt->key() == 16777235 ) // up
else if (evnt->key() == 16777235) // up
{
mc->scrollUp();
}
@ -265,7 +288,6 @@ void Multidemo::toggleGPS(bool gps)
gm->start();
else
gm->stop();
}
void Multidemo::draggedRect(QRectF rect)
@ -276,19 +298,19 @@ void Multidemo::draggedRect(QRectF rect)
mc->setViewAndZoomIn(coords);
}
void Multidemo::mouseEventCoordinate(const QMouseEvent* evnt, const QPointF coordinate)
void Multidemo::mouseEventCoordinate(const QMouseEvent *evnt, const QPointF coordinate)
{
if (evnt->type() == QEvent::MouseButtonPress && btn3->isChecked())
{
mc->moveTo(coordinate);
}
//update mini-window
else if(evnt->type() == QEvent::MouseButtonRelease)
// update mini-window
else if (evnt->type() == QEvent::MouseButtonRelease)
{
mc2->setView(mc->currentCoordinate());
}
}
void Multidemo::coordinateClicked_mc2(const QMouseEvent* evnt, const QPointF coordinate)
void Multidemo::coordinateClicked_mc2(const QMouseEvent *evnt, const QPointF coordinate)
{
if (evnt->type() == QEvent::MouseButtonPress)
{

View File

@ -14,47 +14,46 @@ using namespace qmapcontrol;
class Multidemo : public QWidget
{
Q_OBJECT
public:
public:
Multidemo(QWidget *parent = 0);
~Multidemo();
private:
MapControl* mc;
MapControl* mc2;
QPushButton* btn1;
QPushButton* btn2;
QPushButton* btn3;
QPushButton* btn4;
QPushButton* btn5;
ImagePoint* ip;
GPS_Modul* gm;
private:
MapControl *mc;
MapControl *mc2;
QPushButton *btn1;
QPushButton *btn2;
QPushButton *btn3;
QPushButton *btn4;
QPushButton *btn5;
ImagePoint *ip;
GPS_Modul *gm;
void setupMaps();
void createLayout();
Layer* l;
Layer *l;
public slots:
void geometryClickEvent(Geometry* geom, QPoint coord_px);
void coordinateClicked(const QMouseEvent*, const QPointF);
void coordinateClicked_mc2(const QMouseEvent*, const QPointF);
public slots:
void geometryClickEvent(Geometry *geom, QPoint coord_px);
void coordinateClicked(const QMouseEvent *, const QPointF);
void coordinateClicked_mc2(const QMouseEvent *, const QPointF);
void buttonToggled(bool);
void toggleFollow(bool);
void toggleGPS(bool);
void draggedRect(QRectF);
void mouseEventCoordinate(const QMouseEvent*, const QPointF);
void mouseEventCoordinate(const QMouseEvent *, const QPointF);
protected:
void keyPressEvent(QKeyEvent* evnt);
virtual void resizeEvent ( QResizeEvent * event );
protected:
void keyPressEvent(QKeyEvent *evnt);
virtual void resizeEvent(QResizeEvent *event);
signals:
signals:
void setX(int);
void setY(int);
void zoomIn();
void zoomOut();
};
#endif

View File

@ -12,4 +12,3 @@ int main(int argc, char *argv[])
pb.show();
return app.exec();
}

View File

@ -1,53 +1,50 @@
#include "phonebook.h"
Phonebook::Phonebook(QWidget* parent)
Phonebook::Phonebook(QWidget *parent)
{
mc = new MapControl(QSize(480, 540));
MapAdapter* mapadapter = new OSMMapAdapter();
Layer* map = new MapLayer("Karte", mapadapter);
MapAdapter *mapadapter = new OSMMapAdapter();
Layer *map = new MapLayer("Karte", mapadapter);
friends = new GeometryLayer("Friends", mapadapter);
friendpoint = new CirclePoint(0.,0., 10);
friendpoint = new CirclePoint(0., 0., 10);
friends->addGeometry(friendpoint);
mc->addLayer(map);
mc->addLayer(friends);
QListWidget* list = new QListWidget();
QListWidget *list = new QListWidget();
QStringList strlist;
strlist << "Kai" << "2";
strlist << "Kai"
<< "2";
list->addItems(strlist);
connect(list, SIGNAL(itemClicked( QListWidgetItem* )),
this, SLOT(selectedName(QListWidgetItem*)));
connect(list, SIGNAL(itemClicked(QListWidgetItem *)), this,
SLOT(selectedName(QListWidgetItem *)));
QSlider* slider = new QSlider(Qt::Horizontal);
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setMinimum(0);
slider->setMaximum(17);
connect(slider, SIGNAL(valueChanged(int)),
mc, SLOT(setZoom(int)));
connect(slider, SIGNAL(valueChanged(int)), mc, SLOT(setZoom(int)));
mc->setMinimumWidth(480);
QVBoxLayout* maplayout = new QVBoxLayout;
QVBoxLayout *maplayout = new QVBoxLayout;
maplayout->addWidget(mc);
maplayout->addWidget(slider);
QHBoxLayout* layout = new QHBoxLayout;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(list);
layout->addLayout(maplayout);
QWidget* w = new QWidget;
QWidget *w = new QWidget;
w->setLayout(layout);
setCentralWidget(w);
createActions();
createMenus();
}
void Phonebook::selectedName(QListWidgetItem* item)
void Phonebook::selectedName(QListWidgetItem *item)
{
if (item->text() == "Kai")
{
@ -62,70 +59,64 @@ void Phonebook::selectedName(QListWidgetItem* item)
}
}
void Phonebook::createActions()
{
// newAct = new QAction(QIcon(":/filenew.xpm"), tr("&New"), this);
// newAct->setShortcut(tr("Ctrl+N"));
// newAct->setStatusTip(tr("Create a new file"));
// connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
//
// openAct = new QAction(QIcon(":/fileopen.xpm"), tr("&Open..."), this);
// openAct->setShortcut(tr("Ctrl+O"));
// openAct->setStatusTip(tr("Open an existing file"));
// connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
//
// saveAct = new QAction(QIcon(":/filesave.xpm"), tr("&Save"), this);
// saveAct->setShortcut(tr("Ctrl+S"));
// saveAct->setStatusTip(tr("Save the document to disk"));
// connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
//
// saveAsAct = new QAction(tr("Save &As..."), this);
// saveAsAct->setStatusTip(tr("Save the document under a new name"));
// connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
//
// exitAct = new QAction(tr("E&xit"), this);
// exitAct->setShortcut(tr("Ctrl+Q"));
// exitAct->setStatusTip(tr("Exit the application"));
// connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
//
// aboutAct = new QAction(tr("&About"), this);
// aboutAct->setStatusTip(tr("Show the application's About box"));
// connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
//
// aboutQtAct = new QAction(tr("About &Qt"), this);
// aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
// connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
//
// cutAct->setEnabled(false);
// copyAct->setEnabled(false);
// newAct = new QAction(QIcon(":/filenew.xpm"), tr("&New"), this);
// newAct->setShortcut(tr("Ctrl+N"));
// newAct->setStatusTip(tr("Create a new file"));
// connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
//
// openAct = new QAction(QIcon(":/fileopen.xpm"), tr("&Open..."), this);
// openAct->setShortcut(tr("Ctrl+O"));
// openAct->setStatusTip(tr("Open an existing file"));
// connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
//
// saveAct = new QAction(QIcon(":/filesave.xpm"), tr("&Save"), this);
// saveAct->setShortcut(tr("Ctrl+S"));
// saveAct->setStatusTip(tr("Save the document to disk"));
// connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
//
// saveAsAct = new QAction(tr("Save &As..."), this);
// saveAsAct->setStatusTip(tr("Save the document under a new name"));
// connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
//
// exitAct = new QAction(tr("E&xit"), this);
// exitAct->setShortcut(tr("Ctrl+Q"));
// exitAct->setStatusTip(tr("Exit the application"));
// connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
//
// aboutAct = new QAction(tr("&About"), this);
// aboutAct->setStatusTip(tr("Show the application's About box"));
// connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
//
// aboutQtAct = new QAction(tr("About &Qt"), this);
// aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
// connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
//
// cutAct->setEnabled(false);
// copyAct->setEnabled(false);
}
void Phonebook::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
// fileMenu->addAction(newAct);
// fileMenu->addAction(openAct);
// fileMenu->addAction(saveAct);
// fileMenu->addAction(saveAsAct);
// fileMenu->addSeparator();
// fileMenu->addAction(exitAct);
// fileMenu->addAction(newAct);
// fileMenu->addAction(openAct);
// fileMenu->addAction(saveAct);
// fileMenu->addAction(saveAsAct);
// fileMenu->addSeparator();
// fileMenu->addAction(exitAct);
editMenu = menuBar()->addMenu(tr("&Edit"));
// editMenu->addAction(cutAct);
// editMenu->addAction(copyAct);
// editMenu->addAction(pasteAct);
// editMenu->addAction(cutAct);
// editMenu->addAction(copyAct);
// editMenu->addAction(pasteAct);
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("&Help"));
// helpMenu->addAction(aboutAct);
// helpMenu->addAction(aboutQtAct);
}
Phonebook::~Phonebook()
{
// helpMenu->addAction(aboutAct);
// helpMenu->addAction(aboutQtAct);
}
Phonebook::~Phonebook() { }

View File

@ -4,17 +4,17 @@
#include <QtGui>
#include "../../../qmapcontrol.h"
using namespace qmapcontrol;
class Phonebook: public QMainWindow
class Phonebook : public QMainWindow
{
Q_OBJECT
public:
Phonebook(QWidget* parent = 0);
public:
Phonebook(QWidget *parent = 0);
~Phonebook();
private:
MapControl* mc;
Layer* friends;
Point* friendpoint;
MapControl *mc;
Layer *friends;
Point *friendpoint;
void createActions();
void createMenus();
@ -34,8 +34,8 @@ private:
QAction *aboutAct;
QAction *aboutQtAct;
public slots:
void selectedName(QListWidgetItem* item);
public slots:
void selectedName(QListWidgetItem *item);
};
#endif

View File

@ -1,73 +1,73 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2010 Jeffery MacEachern
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2010 Jeffery MacEachern
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "arrowpoint.h"
namespace qmapcontrol
{
ArrowPoint::ArrowPoint(qreal x, qreal y, int sideLength, qreal heading, QString name, qmapcontrol::Point::Alignment alignment, QPen* pen)
ArrowPoint::ArrowPoint(qreal x, qreal y, int sideLength, qreal heading, QString name,
qmapcontrol::Point::Alignment alignment, QPen *pen)
: Point(x, y, name, alignment)
{
{
size = QSize(sideLength, sideLength);
h = heading;
mypen = pen;
mypixmap = QPixmap(sideLength, sideLength);
drawArrow();
}
}
ArrowPoint::~ArrowPoint()
{
}
ArrowPoint::~ArrowPoint() { }
void ArrowPoint::setHeading(qreal heading)
{
void ArrowPoint::setHeading(qreal heading)
{
h = heading;
drawArrow();
}
}
qreal ArrowPoint::getHeading() const
{
qreal ArrowPoint::getHeading() const
{
return h;
}
}
void ArrowPoint::setPen(QPen* pen)
{
void ArrowPoint::setPen(QPen *pen)
{
mypen = pen;
drawArrow();
}
}
void ArrowPoint::drawArrow()
{
void ArrowPoint::drawArrow()
{
mypixmap = QPixmap(size);
mypixmap.fill(Qt::transparent);
QPainter painter(&mypixmap);
//#if !defined Q_WS_MAEMO_5 //FIXME Maemo has a bug - it will antialias our point out of existence
//#if !defined Q_WS_MAEMO_5 //FIXME Maemo has a bug - it will antialias our point out
//of existence
painter.setRenderHints(QPainter::Antialiasing | QPainter::Qt4CompatiblePainting);
//#endif
//#endif
if(mypen)
if (mypen)
{
painter.setPen(*mypen);
painter.setBrush(QBrush(mypen->color()));
@ -77,7 +77,8 @@ namespace qmapcontrol
painter.setBrush(QBrush(painter.pen().color()));
}
painter.setWindow(-(size.width() / 2), -(size.height() / 2), size.width(), size.height());
painter.setWindow(-(size.width() / 2), -(size.height() / 2), size.width(),
size.height());
QTransform transform;
transform.rotate(-h);
transform.scale(0.4, 0.75);
@ -90,6 +91,6 @@ namespace qmapcontrol
arrow << QPoint(+(size.width() / 2), +(size.height() / 2));
painter.drawPolygon(arrow);
}
}
}

View File

@ -1,28 +1,28 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2010 Jeffery MacEachern
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2010 Jeffery MacEachern
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef ARROWPOINT_H
#define ARROWPOINT_H
@ -35,28 +35,30 @@
namespace qmapcontrol
{
//! Draws a directed arrow (showing orientation) into the map
/*! This is a convenience class for Point.
//! Draws a directed arrow (showing orientation) into the map
/*! This is a convenience class for Point.
* It configures the pixmap of a Point to draw an arrow in a specific direction.
* A QPen could be used to change the color or line-width of the arrow
*
* @author Jeffery MacEachern <j.maceachern@gmail.com>
*/
class QMAPCONTROL_EXPORT ArrowPoint : public Point
{
public:
class QMAPCONTROL_EXPORT ArrowPoint : public Point
{
public:
//!
/*!
*
* @param x longitude
* @param y latitude
* @param sideLength side length of the arrow's bounding box (square)
* @param heading compass heading determining direction that arrow faces, measured in degrees clockwise from North
* @param heading compass heading determining direction that arrow faces, measured in
* degrees clockwise from North
* @param name name of the arrow point
* @param alignment alignment (Middle or TopLeft)
* @param pen QPen for drawing
*/
ArrowPoint(qreal x, qreal y, int sideLength, qreal heading, QString name = QString(), Alignment alignment = Middle, QPen* pen=0);
ArrowPoint(qreal x, qreal y, int sideLength, qreal heading, QString name = QString(),
Alignment alignment = Middle, QPen *pen = 0);
virtual ~ArrowPoint();
//! sets the QPen which is used for drawing the arrow
@ -65,7 +67,7 @@ namespace qmapcontrol
* @param pen the QPen which should be used for drawing
* @see http://doc.trolltech.com/4.3/qpen.html
*/
virtual void setPen(QPen* pen);
virtual void setPen(QPen *pen);
//! sets the heading of the arrow and redraws it in the new orientation
/*!
@ -75,7 +77,8 @@ namespace qmapcontrol
//! gets the current heading of the arrow
qreal getHeading() const;
private:
private:
void drawArrow();
// Heading
@ -83,6 +86,6 @@ namespace qmapcontrol
// Brush to fill the arrow with - solid colour, same as pen
QBrush mybrush;
};
};
}
#endif

View File

@ -1,35 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Google Static Maps API V2 by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Google Static Maps API V2 by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
#include "bingapimapadapter.h"
@ -38,65 +38,71 @@
namespace qmapcontrol
{
bingApiMapadapter::bingApiMapadapter(QString mapType, QString apiKey)
: TileMapAdapter("dev.virtualearth.net", "/REST/v1/Imagery/Map/", 256, 0, 21),
myKey(apiKey),
myMapType(mapType)
{
bingApiMapadapter::bingApiMapadapter(QString mapType, QString apiKey)
: TileMapAdapter("dev.virtualearth.net", "/REST/v1/Imagery/Map/", 256, 0, 21)
, myKey(apiKey)
, myMapType(mapType)
{
mNumberOfTiles = pow(2., mCurrent_zoom + 0.0);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
if (! myKey.isEmpty())
if (!myKey.isEmpty())
myKey.prepend("&key=");
if (myMapType.isEmpty())
myMapType.append("Road");
}
}
bingApiMapadapter::~bingApiMapadapter()
{
}
bingApiMapadapter::~bingApiMapadapter() { }
QPoint bingApiMapadapter::coordinateToDisplay(const QPointF& coordinate) const
{
qreal x = (coordinate.x() + 180.) * (mNumberOfTiles * mTileSize) / 360.; // coord to pixel!
qreal y = (1. - log(tan(coordinate.y() * M_PI / 180.) + 1. / cos(coordinate.y() * M_PI / 180.)) / M_PI) / 2. * (mNumberOfTiles*mTileSize);
QPoint bingApiMapadapter::coordinateToDisplay(const QPointF &coordinate) const
{
qreal x = (coordinate.x() + 180.) * (mNumberOfTiles * mTileSize)
/ 360.; // coord to pixel!
qreal y = (1.
- log(tan(coordinate.y() * M_PI / 180.)
+ 1. / cos(coordinate.y() * M_PI / 180.))
/ M_PI)
/ 2. * (mNumberOfTiles * mTileSize);
x += mTileSize / 2;
y += mTileSize / 2;
return QPoint(int(x), int(y));
}
}
QPointF bingApiMapadapter::displayToCoordinate(const QPoint& point) const
{
QPointF bingApiMapadapter::displayToCoordinate(const QPoint &point) const
{
qreal lon = (point.x() - mTileSize / 2) / (mNumberOfTiles * mTileSize) * 360. - 180.;
qreal lat = M_PI - 2. * M_PI * (point.y() - mTileSize / 2) / (mNumberOfTiles * mTileSize);
qreal lat
= M_PI - 2. * M_PI * (point.y() - mTileSize / 2) / (mNumberOfTiles * mTileSize);
lat = 180. / M_PI * atan(0.5 * (exp(lat) - exp(-lat)));
return QPointF(lon, lat);
}
}
qreal bingApiMapadapter::getMercatorLatitude(qreal YCoord) const
{
if (YCoord > M_PI) return 9999.;
if (YCoord < -M_PI) return -9999.;
qreal bingApiMapadapter::getMercatorLatitude(qreal YCoord) const
{
if (YCoord > M_PI)
return 9999.;
if (YCoord < -M_PI)
return -9999.;
qreal t = atan(exp(YCoord));
qreal res = (2. * t) - (M_PI / 2.);
return res;
}
}
qreal bingApiMapadapter::getMercatorYCoord(qreal lati) const
{
qreal bingApiMapadapter::getMercatorYCoord(qreal lati) const
{
qreal phi = M_PI * lati / 180.;
qreal res = 0.5 * log((1. + sin(phi)) / (1. - sin(phi)));
return res;
}
}
void bingApiMapadapter::zoom_in()
{
void bingApiMapadapter::zoom_in()
{
if (mCurrent_zoom >= maxZoom())
return;
@ -104,10 +110,10 @@ namespace qmapcontrol
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
}
}
void bingApiMapadapter::zoom_out()
{
void bingApiMapadapter::zoom_out()
{
if (mCurrent_zoom <= minZoom())
return;
@ -115,43 +121,46 @@ namespace qmapcontrol
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
}
}
QString bingApiMapadapter::getQ(qreal longitude, qreal latitude, int zoom) const
{
QString bingApiMapadapter::getQ(qreal longitude, qreal latitude, int zoom) const
{
QString location = "/REST/v1/Imagery/Map/";
if (! myMapType.isEmpty())
if (!myMapType.isEmpty())
location.append(myMapType + "/");
else
location.append("Road/");
location.append(QVariant(latitude).toString() + ",");
location.append(QVariant(longitude).toString() + "/");
location.append(QString::number(zoom) + "?");
location.append("&mapSize=" + QString::number(mTileSize) + "," + QString::number(mTileSize));
location.append("&mapSize=" + QString::number(mTileSize) + ","
+ QString::number(mTileSize));
if (! myKey.isEmpty())
if (!myKey.isEmpty())
location.append(myKey);
else
fprintf(stderr, "You are useing Bing Maps API without a (valid) key. This is not possible...\r\n");
fprintf(stderr,
"You are useing Bing Maps API without a (valid) key. This is not "
"possible...\r\n");
return location;
}
}
void bingApiMapadapter::setKey(QString apiKey)
{
void bingApiMapadapter::setKey(QString apiKey)
{
if (apiKey.isEmpty())
return;
myKey.clear();
myKey.append("&key=" + apiKey);
}
}
void bingApiMapadapter::setMapType(QString mapType) /* Aerial, AerialWithLabels, Road */
{
void bingApiMapadapter::setMapType(QString mapType) /* Aerial, AerialWithLabels, Road */
{
if (mapType.isEmpty())
return;
myMapType.clear();
myMapType.append(mapType);
}
}
}

View File

@ -1,36 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Bing Maps by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Bing Maps by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
#ifndef BINGAPIMAPADAPTER_H
#define BINGAPIMAPADAPTER_H
@ -40,24 +39,24 @@
namespace qmapcontrol
{
class QMAPCONTROL_EXPORT bingApiMapadapter : public TileMapAdapter
{
class QMAPCONTROL_EXPORT bingApiMapadapter : public TileMapAdapter
{
Q_OBJECT
public:
public:
bingApiMapadapter(QString mapType = "Road", QString apiKey = "");
virtual ~bingApiMapadapter();
virtual QPoint coordinateToDisplay(const QPointF&) const;
virtual QPointF displayToCoordinate(const QPoint&) const;
virtual QPoint coordinateToDisplay(const QPointF &) const;
virtual QPointF displayToCoordinate(const QPoint &) const;
void setKey(QString apiKey);
void setMapType(QString mapType); /* Aerial, AerialWithLabels, Road */
protected:
protected:
virtual void zoom_in();
virtual void zoom_out();
private:
private:
virtual QString getQ(qreal longitude, qreal latitude, int zoom) const;
qreal getMercatorLatitude(qreal YCoord) const;
qreal getMercatorYCoord(qreal lati) const;
@ -67,7 +66,7 @@ namespace qmapcontrol
int srvNum;
QString myKey;
QString myMapType;
};
};
}
#endif // BINGAPIMAPADAPTER_H

View File

@ -1,71 +1,71 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "circlepoint.h"
namespace qmapcontrol
{
CirclePoint::CirclePoint(qreal x, qreal y, int radius, QString name, Alignment alignment, QPen* pen)
CirclePoint::CirclePoint(qreal x, qreal y, int radius, QString name, Alignment alignment,
QPen *pen)
: Point(x, y, name, alignment)
{
{
size = QSize(radius, radius);
mypen = pen;
mypixmap = QPixmap(radius+1, radius+1);
mypixmap = QPixmap(radius + 1, radius + 1);
drawCircle();
}
}
CirclePoint::CirclePoint(qreal x, qreal y, QString name, Alignment alignment, QPen* pen)
CirclePoint::CirclePoint(qreal x, qreal y, QString name, Alignment alignment, QPen *pen)
: Point(x, y, name, alignment)
{
{
int radius = 10;
size = QSize(radius, radius);
mypen = pen;
mypixmap = QPixmap(radius+1, radius+1);
mypixmap = QPixmap(radius + 1, radius + 1);
drawCircle();
}
}
CirclePoint::~CirclePoint()
{
}
CirclePoint::~CirclePoint() { }
void CirclePoint::setPen(QPen* pen)
{
void CirclePoint::setPen(QPen *pen)
{
mypen = pen;
drawCircle();
}
}
void CirclePoint::drawCircle()
{
void CirclePoint::drawCircle()
{
mypixmap.fill(Qt::transparent);
QPainter painter(&mypixmap);
//#if !defined Q_WS_MAEMO_5 //FIXME Maemo has a bug - it will antialias our point out of existence
//#if !defined Q_WS_MAEMO_5 //FIXME Maemo has a bug - it will antialias our point out
//of existence
painter.setRenderHints(QPainter::Antialiasing | QPainter::Qt4CompatiblePainting);
//#endif
//#endif
if (mypen != 0)
{
painter.setPen(*mypen);
}
painter.drawEllipse(0,0, size.width(), size.height());
}
painter.drawEllipse(0, 0, size.width(), size.height());
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef CIRCLEPOINT_H
#define CIRCLEPOINT_H
@ -31,16 +31,16 @@
namespace qmapcontrol
{
//! Draws a circle into the map
/*! This is a conveniece class for Point.
//! Draws a circle into the map
/*! This is a conveniece class for Point.
* It configures the pixmap of a Point to draw a circle.
* A QPen could be used to change the color or line-width of the circle
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT CirclePoint : public Point
{
public:
class QMAPCONTROL_EXPORT CirclePoint : public Point
{
public:
//!
/*!
*
@ -50,7 +50,8 @@ namespace qmapcontrol
* @param alignment alignment (Middle or TopLeft)
* @param pen QPen for drawing
*/
CirclePoint(qreal x, qreal y, QString name = QString(), Alignment alignment = Middle, QPen* pen=0);
CirclePoint(qreal x, qreal y, QString name = QString(), Alignment alignment = Middle,
QPen *pen = 0);
//!
/*!
@ -62,7 +63,8 @@ namespace qmapcontrol
* @param alignment alignment (Middle or TopLeft)
* @param pen QPen for drawing
*/
CirclePoint(qreal x, qreal y, int radius = 10, QString name = QString(), Alignment alignment = Middle, QPen* pen=0);
CirclePoint(qreal x, qreal y, int radius = 10, QString name = QString(),
Alignment alignment = Middle, QPen *pen = 0);
virtual ~CirclePoint();
//! sets the QPen which is used for drawing the circle
@ -71,10 +73,10 @@ namespace qmapcontrol
* @param pen the QPen which should be used for drawing
* @see http://doc.trolltech.com/4.3/qpen.html
*/
virtual void setPen(QPen* pen);
virtual void setPen(QPen *pen);
private:
private:
void drawCircle();
};
};
}
#endif

View File

@ -1,40 +1,37 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "curve.h"
namespace qmapcontrol
{
Curve::Curve(QString name)
Curve::Curve(QString name)
: Geometry(name)
{
}
{
}
Curve::~Curve()
{
}
Curve::~Curve() { }
}
// Geometry Curve::Clone(){}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef CURVE_H
#define CURVE_H
@ -32,21 +32,22 @@
namespace qmapcontrol
{
//! A Curve Geometry, implemented to fullfil OGC Spec
/*!
//! A Curve Geometry, implemented to fullfil OGC Spec
/*!
* The Curve class is used by LineString as parent class.
* This class could not be used directly.
*
* From the OGC Candidate Implementation Specification:
* "A Curve is a 1-dimensional geometric object usually stored as a sequence of Points, with the subtype of Curve
* specifying the form of the interpolation between Points. This specification defines only one subclass of Curve,
* LineString, which uses a linear interpolation between Points."
* "A Curve is a 1-dimensional geometric object usually stored as a sequence of Points,
*with the subtype of Curve specifying the form of the interpolation between Points. This
*specification defines only one subclass of Curve, LineString, which uses a linear
*interpolation between Points."
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Curve : public Geometry
{
class QMAPCONTROL_EXPORT Curve : public Geometry
{
Q_OBJECT
public:
public:
virtual ~Curve();
double Length;
@ -58,9 +59,11 @@ namespace qmapcontrol
// virtual Point StartPoint() = 0;
// virtual Point Value() = 0;
protected:
protected:
Curve(QString name = QString());
virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset) = 0;
};
virtual void draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &screensize, const QPoint offset)
= 0;
};
}
#endif

View File

@ -1,125 +1,124 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "emptymapadapter.h"
namespace qmapcontrol
{
EmptyMapAdapter::EmptyMapAdapter(int tileSize, int minZoom, int maxZoom)
:MapAdapter("", "", 256, minZoom, maxZoom)
{
EmptyMapAdapter::EmptyMapAdapter(int tileSize, int minZoom, int maxZoom)
: MapAdapter("", "", 256, minZoom, maxZoom)
{
Q_UNUSED(tileSize)
PI = acos(-1.0);
mNumberOfTiles = tilesonzoomlevel(minZoom);
}
}
EmptyMapAdapter::~EmptyMapAdapter()
{
}
EmptyMapAdapter::~EmptyMapAdapter() { }
void EmptyMapAdapter::zoom_in()
{
void EmptyMapAdapter::zoom_in()
{
if (mCurrent_zoom < mMax_zoom)
{
mCurrent_zoom = mCurrent_zoom + 1;
}
mNumberOfTiles = tilesonzoomlevel(mCurrent_zoom);
}
}
void EmptyMapAdapter::zoom_out()
{
void EmptyMapAdapter::zoom_out()
{
if (mCurrent_zoom > mMin_zoom)
{
mCurrent_zoom = mCurrent_zoom - 1;
}
mNumberOfTiles = tilesonzoomlevel(mCurrent_zoom);
}
}
qreal EmptyMapAdapter::deg_rad(qreal x) const
{
return x * (PI/180.0);
}
qreal EmptyMapAdapter::deg_rad(qreal x) const
{
return x * (PI / 180.0);
}
qreal EmptyMapAdapter::rad_deg(qreal x) const
{
return x * (180/PI);
}
qreal EmptyMapAdapter::rad_deg(qreal x) const
{
return x * (180 / PI);
}
QString EmptyMapAdapter::query(int x, int y, int z) const
{
QString EmptyMapAdapter::query(int x, int y, int z) const
{
Q_UNUSED(x)
Q_UNUSED(y)
Q_UNUSED(z)
return QString();
}
}
QPoint EmptyMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
{
qreal x = (coordinate.x()+180) * (mNumberOfTiles*mTileSize)/360.; // coord to pixel!
qreal y = (1-(log(tan(PI/4+deg_rad(coordinate.y())/2)) /PI)) /2 * (mNumberOfTiles*mTileSize);
QPoint EmptyMapAdapter::coordinateToDisplay(const QPointF &coordinate) const
{
qreal x
= (coordinate.x() + 180) * (mNumberOfTiles * mTileSize) / 360.; // coord to pixel!
qreal y = (1 - (log(tan(PI / 4 + deg_rad(coordinate.y()) / 2)) / PI)) / 2
* (mNumberOfTiles * mTileSize);
return QPoint(int(x), int(y));
}
}
QPointF EmptyMapAdapter::displayToCoordinate(const QPoint& point) const
{
qreal longitude = (point.x()*(360/(mNumberOfTiles*mTileSize)))-180;
qreal latitude = rad_deg(atan(sinh((1-point.y()*(2/(mNumberOfTiles*mTileSize)))*PI)));
QPointF EmptyMapAdapter::displayToCoordinate(const QPoint &point) const
{
qreal longitude = (point.x() * (360 / (mNumberOfTiles * mTileSize))) - 180;
qreal latitude
= rad_deg(atan(sinh((1 - point.y() * (2 / (mNumberOfTiles * mTileSize))) * PI)));
return QPointF(longitude, latitude);
}
}
bool EmptyMapAdapter::isTileValid(int x, int y, int z) const
{
bool EmptyMapAdapter::isTileValid(int x, int y, int z) const
{
if (mMax_zoom < mMin_zoom)
{
z= mMin_zoom - z;
z = mMin_zoom - z;
}
bool result = true;
if (x<0 || x>pow(2.0,z)-1 ||
y<0 || y>pow(2.0,z)-1)
if (x < 0 || x > pow(2.0, z) - 1 || y < 0 || y > pow(2.0, z) - 1)
{
result = false;
}
return result;
}
int EmptyMapAdapter::tilesonzoomlevel(int zoomlevel) const
{
return int(pow(2.0, zoomlevel));
}
int EmptyMapAdapter::xoffset(int x) const
{
return x;
}
int EmptyMapAdapter::yoffset(int y) const
{
return y;
}
}
int EmptyMapAdapter::tilesonzoomlevel(int zoomlevel) const
{
return int(pow(2.0, zoomlevel));
}
int EmptyMapAdapter::xoffset(int x) const
{
return x;
}
int EmptyMapAdapter::yoffset(int y) const
{
return y;
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef EMPTYMAPADAPTER_H
#define EMPTYMAPADAPTER_H
@ -31,21 +31,22 @@
namespace qmapcontrol
{
//! MapAdapter which do not load map tiles.
/*!
* The EmptyMapAdapter can be used if QMapControl should not load any map tiles. This is useful if you
* only want to display an image through a FixedImageOverlay e.g.
//! MapAdapter which do not load map tiles.
/*!
* The EmptyMapAdapter can be used if QMapControl should not load any map tiles. This is
*useful if you only want to display an image through a FixedImageOverlay e.g.
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT EmptyMapAdapter : public MapAdapter
{
class QMAPCONTROL_EXPORT EmptyMapAdapter : public MapAdapter
{
Q_OBJECT
public:
public:
//! Constructor.
/*!
* @param tileSize This parameter seems unnecessary for this type of MapAdaper on first sight. But since
* this parameter defines the size of the offscreen image it could be used for a little performance
* tuning (larger offscreen-images have to be redrawed less times).
* @param tileSize This parameter seems unnecessary for this type of MapAdaper on
* first sight. But since this parameter defines the size of the offscreen image it
* could be used for a little performance tuning (larger offscreen-images have to be
* redrawed less times).
* @param minZoom the minimum zoom level
* @param maxZoom the maximum zoom level
*/
@ -53,12 +54,12 @@ namespace qmapcontrol
virtual ~EmptyMapAdapter();
virtual QPoint coordinateToDisplay(const QPointF&) const;
virtual QPointF displayToCoordinate(const QPoint&) const;
virtual QPoint coordinateToDisplay(const QPointF &) const;
virtual QPointF displayToCoordinate(const QPoint &) const;
qreal PI;
protected:
protected:
qreal rad_deg(qreal) const;
qreal deg_rad(qreal) const;
@ -69,6 +70,6 @@ namespace qmapcontrol
virtual int tilesonzoomlevel(int zoomlevel) const;
virtual int xoffset(int x) const;
virtual int yoffset(int y) const;
};
};
}
#endif

View File

@ -1,51 +1,58 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "fixedimageoverlay.h"
namespace qmapcontrol
{
FixedImageOverlay::FixedImageOverlay(qreal x_upperleft, qreal y_upperleft, qreal x_lowerright, qreal y_lowerright, QString filename, QString name)
: ImagePoint(x_upperleft, y_upperleft, filename, name, TopLeft),
x_lowerright(x_lowerright), y_lowerright(y_lowerright)
{
//qDebug() << "loading image: " << filename;
FixedImageOverlay::FixedImageOverlay(qreal x_upperleft, qreal y_upperleft,
qreal x_lowerright, qreal y_lowerright,
QString filename, QString name)
: ImagePoint(x_upperleft, y_upperleft, filename, name, TopLeft)
, x_lowerright(x_lowerright)
, y_lowerright(y_lowerright)
{
// qDebug() << "loading image: " << filename;
mypixmap = QPixmap(filename);
size = mypixmap.size();
//qDebug() << "image size: " << size;
}
// qDebug() << "image size: " << size;
}
FixedImageOverlay::FixedImageOverlay(qreal x_upperleft, qreal y_upperleft, qreal x_lowerright, qreal y_lowerright, QPixmap pixmap, QString name)
: ImagePoint(x_upperleft, y_upperleft, pixmap, name, TopLeft),
x_lowerright(x_lowerright), y_lowerright(y_lowerright)
{
FixedImageOverlay::FixedImageOverlay(qreal x_upperleft, qreal y_upperleft,
qreal x_lowerright, qreal y_lowerright,
QPixmap pixmap, QString name)
: ImagePoint(x_upperleft, y_upperleft, pixmap, name, TopLeft)
, x_lowerright(x_lowerright)
, y_lowerright(y_lowerright)
{
mypixmap = pixmap;
size = mypixmap.size();
}
}
void FixedImageOverlay::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &, const QPoint)
{
void FixedImageOverlay::draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &, const QPoint)
{
if (!visible)
return;
@ -55,12 +62,9 @@ namespace qmapcontrol
const QPointF c2 = QPointF(x_lowerright, y_lowerright);
QPoint lowerright = mapadapter->coordinateToDisplay(c2);
painter->drawPixmap(topleft.x(), topleft.y(), lowerright.x()-topleft.x(), lowerright.y()-topleft.y(), mypixmap);
}
FixedImageOverlay::~FixedImageOverlay()
{
}
painter->drawPixmap(topleft.x(), topleft.y(), lowerright.x() - topleft.x(),
lowerright.y() - topleft.y(), mypixmap);
}
FixedImageOverlay::~FixedImageOverlay() { }
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef FIXEDIMAGEOVERLAY_H
#define FIXEDIMAGEOVERLAY_H
@ -32,50 +32,61 @@
namespace qmapcontrol
{
//! Draws a fixed image into the map.
/*!
//! Draws a fixed image into the map.
/*!
* This class draws a image overlay onto a map, whose upper left and lower
* right corners lay always on the given coordinates. The methods
* setBaselevel, setMaxsize and setMinsize have no effect for this class.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT FixedImageOverlay : public ImagePoint
{
public:
class QMAPCONTROL_EXPORT FixedImageOverlay : public ImagePoint
{
public:
//! Creates an image overlay which loads and displays the given image file
/*!
* Use this contructor to load the given image file and let the point
* display it.
* When you want multiple points to display the same image, use the
* other contructor and pass a pointer to that image.
* @param x_upperleft the coordinate of the upper left corner where the image should be aligned
* @param y_upperleft the coordinate of the upper left corner where the image should be aligned
* @param x_lowerright the coordinate of the lower right corner where the image should be aligned
* @param y_lowerright the coordinate of the lower right corner where the image should be aligned
* @param x_upperleft the coordinate of the upper left corner where the image should
* be aligned
* @param y_upperleft the coordinate of the upper left corner where the image should
* be aligned
* @param x_lowerright the coordinate of the lower right corner where the image should
* be aligned
* @param y_lowerright the coordinate of the lower right corner where the image should
* be aligned
* @param filename the file which should be loaded and displayed
* @param name the name of the image point
*/
FixedImageOverlay(qreal x_upperleft, qreal y_upperleft, qreal x_lowerright, qreal y_lowerright, QString filename, QString name = QString());
FixedImageOverlay(qreal x_upperleft, qreal y_upperleft, qreal x_lowerright,
qreal y_lowerright, QString filename, QString name = QString());
//! Creates an image overlay which displays the given image
/*!
* Use this contructor to display the given image.
* @param x_upperleft the coordinate of the upper left corner where the image should be aligned
* @param y_upperleft the coordinate of the upper left corner where the image should be aligned
* @param x_lowerright the coordinate of the lower right corner where the image should be aligned
* @param y_lowerright the coordinate of the lower right corner where the image should be aligned
* @param x_upperleft the coordinate of the upper left corner where the image should
* be aligned
* @param y_upperleft the coordinate of the upper left corner where the image should
* be aligned
* @param x_lowerright the coordinate of the lower right corner where the image should
* be aligned
* @param y_lowerright the coordinate of the lower right corner where the image should
* be aligned
* @param pixmap pointer to the image pixmap
* @param name the name of the image point
*/
FixedImageOverlay(qreal x_upperleft, qreal y_upperleft, qreal x_lowerright, qreal y_lowerright, QPixmap pixmap, QString name = QString());
FixedImageOverlay(qreal x_upperleft, qreal y_upperleft, qreal x_lowerright,
qreal y_lowerright, QPixmap pixmap, QString name = QString());
virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset);
virtual void draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &viewport, const QPoint offset);
virtual ~FixedImageOverlay();
private:
private:
qreal x_lowerright;
qreal y_lowerright;
};
};
}
#endif

View File

@ -1,87 +1,89 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "geometry.h"
namespace qmapcontrol
{
Geometry::Geometry(QString name)
: GeometryType("Geometry"), myparentGeometry(0), mypen(0), visible(true), myname(name)
{
}
Geometry::Geometry(QString name)
: GeometryType("Geometry")
, myparentGeometry(0)
, mypen(0)
, visible(true)
, myname(name)
{
}
Geometry::~Geometry()
{
}
Geometry::~Geometry() { }
QString Geometry::name() const
{
QString Geometry::name() const
{
return myname;
}
Geometry* Geometry::parentGeometry() const
{
}
Geometry *Geometry::parentGeometry() const
{
return myparentGeometry;
}
void Geometry::setParentGeometry(Geometry* geom)
{
}
void Geometry::setParentGeometry(Geometry *geom)
{
myparentGeometry = geom;
}
bool Geometry::hasPoints() const
{
}
bool Geometry::hasPoints() const
{
return false;
}
bool Geometry::hasClickedPoints() const
{
}
bool Geometry::hasClickedPoints() const
{
return false;
}
}
QList<Geometry*>& Geometry::clickedPoints()
{
QList<Geometry *> &Geometry::clickedPoints()
{
return touchedPoints;
}
}
bool Geometry::isVisible() const
{
bool Geometry::isVisible() const
{
return visible;
}
void Geometry::setVisible(bool visible)
{
}
void Geometry::setVisible(bool visible)
{
this->visible = visible;
emit(updateRequest(boundingBox()));
}
void Geometry::setName(QString name)
{
myname = name;
}
void Geometry::setPen(QPen* pen)
{
mypen = pen;
}
QPen* Geometry::pen() const
{
return mypen;
}
}
void Geometry::setName(QString name)
{
myname = name;
}
void Geometry::setPen(QPen *pen)
{
mypen = pen;
}
QPen *Geometry::pen() const
{
return mypen;
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef GEOMETRY_H
#define GEOMETRY_H
@ -34,10 +34,11 @@
namespace qmapcontrol
{
class Point;
//! Main class for objects that should be painted in maps
/*!
* Geometry is the root class of the hierarchy. Geometry is an abstract (non-instantiable) class.
class Point;
//! Main class for objects that should be painted in maps
/*!
* Geometry is the root class of the hierarchy. Geometry is an abstract (non-instantiable)
*class.
*
* This class and the derived classes Point, Curve and LineString are leant on the Simple
* Feature Specification of the Open Geospatial Consortium.
@ -45,11 +46,11 @@ namespace qmapcontrol
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Geometry : public QObject
{
class QMAPCONTROL_EXPORT Geometry : public QObject
{
friend class LineString;
Q_OBJECT
public:
public:
explicit Geometry(QString name = QString());
virtual ~Geometry();
@ -61,7 +62,7 @@ namespace qmapcontrol
* @param geom The Geometry to be tested
* @return true if the given Geometry is equal to this
*/
bool Equals(Geometry* geom);
bool Equals(Geometry *geom);
//! returns a String representation of this Geometry
/*!
@ -78,10 +79,11 @@ namespace qmapcontrol
//! returns the parent Geometry of this Geometry
/*!
* A LineString is a composition of many Points. This methods returns the parent (the LineString) of a Point
* A LineString is a composition of many Points. This methods returns the parent (the
* LineString) of a Point
* @return the parent Geometry of this Geometry
*/
Geometry* parentGeometry() const;
Geometry *parentGeometry() const;
//! returns true if this Geometry is visible
/*!
@ -97,39 +99,42 @@ namespace qmapcontrol
//! returns the QPen which is used on drawing
/*!
* The pen is set depending on the Geometry. A CirclePoint for example takes one with the constructor.
* The pen is set depending on the Geometry. A CirclePoint for example takes one with
* the constructor.
* @return the QPen which is used for drawing
*/
QPen* pen() const;
QPen *pen() const;
//! returns the BoundingBox
/*!
* The bounding box in world coordinates
* @return the BoundingBox
*/
virtual QRectF boundingBox()=0;
virtual bool Touches(Point* geom, const MapAdapter* mapadapter)=0;
virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset)=0;
virtual QRectF boundingBox() = 0;
virtual bool Touches(Point *geom, const MapAdapter *mapadapter) = 0;
virtual void draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &viewport, const QPoint offset)
= 0;
virtual bool hasPoints() const;
virtual bool hasClickedPoints() const;
virtual void setPen(QPen* pen);
virtual QList<Geometry*>& clickedPoints();
virtual QList<Point*> points()=0;
virtual void setPen(QPen *pen);
virtual QList<Geometry *> &clickedPoints();
virtual QList<Point *> points() = 0;
private:
Q_DISABLE_COPY( Geometry )
private:
Q_DISABLE_COPY(Geometry)
Geometry* myparentGeometry;
QList<Geometry*> touchedPoints;
Geometry *myparentGeometry;
QList<Geometry *> touchedPoints;
protected:
QPen* mypen;
protected:
QPen *mypen;
bool visible;
QString myname;
void setParentGeometry(Geometry* geom);
void setParentGeometry(Geometry *geom);
signals:
void updateRequest(Geometry* geom);
signals:
void updateRequest(Geometry *geom);
void updateRequest(QRectF rect);
//! This signal is emitted when a Geometry is clicked
/*!
@ -138,20 +143,20 @@ namespace qmapcontrol
* @param geometry The clicked Geometry
* @param point -unused-
*/
void geometryClicked(Geometry* geometry, QPoint point);
void geometryClicked(Geometry *geometry, QPoint point);
//! A Geometry emits this signal, when its position gets changed
/*!
* @param geom the Geometry
*/
void positionChanged(Geometry* geom);
void positionChanged(Geometry *geom);
public slots:
public slots:
//! if visible is true, the layer is made visible
/*!
* @param visible if the layer should be visible
*/
virtual void setVisible(bool visible);
};
};
}
#endif

View File

@ -1,38 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "geometrylayer.h"
namespace qmapcontrol
{
GeometryLayer::GeometryLayer(QString layername, MapAdapter* mapadapter, bool takeevents)
GeometryLayer::GeometryLayer(QString layername, MapAdapter *mapadapter, bool takeevents)
: Layer(layername, mapadapter, Layer::GeometryLayer, takeevents)
{
}
GeometryLayer::~GeometryLayer()
{
}
{
}
GeometryLayer::~GeometryLayer() { }
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef GEOMETRYLAYER_H
#define GEOMETRYLAYER_H
@ -31,36 +31,39 @@
namespace qmapcontrol
{
//! GeometryLayer class
/*!
//! GeometryLayer class
/*!
* There are two different layer types:
* - MapLayer: Displays Maps, but also Geometries. The configuration for displaying maps have to be done in the MapAdapter
* - MapLayer: Displays Maps, but also Geometries. The configuration for displaying maps
*have to be done in the MapAdapter
* - GeometryLayer: Only displays Geometry objects.
*
* MapLayers also can display Geometry objects. The difference to the GeometryLayer is the repainting. Objects that are
* added to a MapLayer are "baken" on the map. This means, when you change it´s position for example the changes are
* not visible until a new offscreen image has been drawn. If you have "static" Geometries which won´t change their
* position this is fine. But if you want to change the objects position or pen you should use a GeometryLayer. Those
* are repainted immediately on changes.
* MapLayers also can display Geometry objects. The difference to the GeometryLayer is the
*repainting. Objects that are added to a MapLayer are "baken" on the map. This means,
*when you change it´s position for example the changes are not visible until a new
*offscreen image has been drawn. If you have "static" Geometries which won´t change their
* position this is fine. But if you want to change the objects position or pen you should
*use a GeometryLayer. Those are repainted immediately on changes.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT GeometryLayer : public Layer
{
class QMAPCONTROL_EXPORT GeometryLayer : public Layer
{
Q_OBJECT
public:
public:
//! GeometryLayer constructor
/*!
* This is used to construct a map layer.
*
* @param layername The name of the Layer
* @param mapadapter The MapAdapter which does coordinate translation and Query-String-Forming
* @param takeevents Should the Layer receive MouseEvents? This is set to true by default. Setting it to false could
* be something like a "speed up hint"
* @param mapadapter The MapAdapter which does coordinate translation and
* Query-String-Forming
* @param takeevents Should the Layer receive MouseEvents? This is set to true by
* default. Setting it to false could be something like a "speed up hint"
*/
GeometryLayer(QString layername, MapAdapter* mapadapter, bool takeevents=true);
GeometryLayer(QString layername, MapAdapter *mapadapter, bool takeevents = true);
virtual ~GeometryLayer();
};
};
}
#endif

View File

@ -1,35 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Google Static Maps API V2 by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Google Static Maps API V2 by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
#include "googleapimapadapter.h"
#include <QCryptographicHash>
@ -39,12 +39,14 @@
namespace qmapcontrol
{
googleApiMapadapter::googleApiMapadapter(layerType qMapType, apiType qApiType, QString qApiKey, QString qApiClientID, QString qServerAddress)
: TileMapAdapter(qServerAddress, "/maps/api/staticmap?", 256, 1, 22),
mApiKey(qApiKey),
mApiClientID(qApiClientID),
mApiType( qApiType )
{
googleApiMapadapter::googleApiMapadapter(layerType qMapType, apiType qApiType,
QString qApiKey, QString qApiClientID,
QString qServerAddress)
: TileMapAdapter(qServerAddress, "/maps/api/staticmap?", 256, 1, 22)
, mApiKey(qApiKey)
, mApiClientID(qApiClientID)
, mApiType(qApiType)
{
mMapLayerType = typeToString(qMapType);
mNumberOfTiles = pow(2., mCurrent_zoom + 0.0);
mCoord_per_x_tile = 360. / mNumberOfTiles;
@ -52,71 +54,76 @@ namespace qmapcontrol
bool usingBusinessAPI = (mApiType == GoogleMapsForBusinessesAPI);
if ( !mApiKey.isEmpty() && !usingBusinessAPI )
if (!mApiKey.isEmpty() && !usingBusinessAPI)
{
mApiKey.prepend("&key=");
}
if ( !mApiClientID.isEmpty() && usingBusinessAPI )
if (!mApiClientID.isEmpty() && usingBusinessAPI)
{
mApiClientID.prepend("&client=");
}
if ( !mMapLayerType.isEmpty() )
if (!mMapLayerType.isEmpty())
{
mMapLayerType.prepend("&maptype=");
}
}
}
googleApiMapadapter::~googleApiMapadapter()
{
}
googleApiMapadapter::~googleApiMapadapter() { }
QString googleApiMapadapter::getHost() const
{
QString googleApiMapadapter::getHost() const
{
return QString("maps.googleapis.com");
}
}
QPoint googleApiMapadapter::coordinateToDisplay(const QPointF& coordinate) const
{
qreal x = (coordinate.x() + 180.) * (mNumberOfTiles * mTileSize) / 360.; // coord to pixel!
qreal y = (1. - log(tan(coordinate.y() * PI / 180.) + 1. / cos(coordinate.y() * PI / 180.)) / PI) / 2. * (mNumberOfTiles*mTileSize);
QPoint googleApiMapadapter::coordinateToDisplay(const QPointF &coordinate) const
{
qreal x = (coordinate.x() + 180.) * (mNumberOfTiles * mTileSize)
/ 360.; // coord to pixel!
qreal y
= (1.
- log(tan(coordinate.y() * PI / 180.) + 1. / cos(coordinate.y() * PI / 180.))
/ PI)
/ 2. * (mNumberOfTiles * mTileSize);
x += mTileSize / 2;
y += mTileSize / 2;
return QPoint(int(x), int(y));
}
}
QPointF googleApiMapadapter::displayToCoordinate(const QPoint& point) const
{
QPointF googleApiMapadapter::displayToCoordinate(const QPoint &point) const
{
qreal lon = (point.x() - mTileSize / 2) / (mNumberOfTiles * mTileSize) * 360. - 180.;
qreal lat = PI - 2. * PI * (point.y() - mTileSize / 2) / (mNumberOfTiles * mTileSize);
lat = 180. / PI * atan(0.5 * (exp(lat) - exp(-lat)));
return QPointF(lon, lat);
}
}
qreal googleApiMapadapter::getMercatorLatitude(qreal YCoord) const
{
if (YCoord > PI) return 9999.;
if (YCoord < -PI) return -9999.;
qreal googleApiMapadapter::getMercatorLatitude(qreal YCoord) const
{
if (YCoord > PI)
return 9999.;
if (YCoord < -PI)
return -9999.;
qreal t = atan(exp(YCoord));
qreal res = (2. * t) - (PI / 2.);
return res;
}
}
qreal googleApiMapadapter::getMercatorYCoord(qreal lati) const
{
qreal googleApiMapadapter::getMercatorYCoord(qreal lati) const
{
qreal phi = PI * lati / 180.;
qreal res = 0.5 * log((1. + sin(phi)) / (1. - sin(phi)));
return res;
}
}
void googleApiMapadapter::zoom_in()
{
void googleApiMapadapter::zoom_in()
{
if (mCurrent_zoom >= maxZoom())
return;
@ -124,10 +131,10 @@ namespace qmapcontrol
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
mCoord_per_x_tile = 360. / mNumberOfTiles;
mCoord_per_y_tile = 180. / mNumberOfTiles;
}
}
void googleApiMapadapter::zoom_out()
{
void googleApiMapadapter::zoom_out()
{
if (mCurrent_zoom <= minZoom())
return;
@ -135,92 +142,105 @@ namespace qmapcontrol
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
mCoord_per_x_tile = 360. / mNumberOfTiles;
mCoord_per_y_tile = 180. / mNumberOfTiles;
}
}
bool googleApiMapadapter::isValid(int x, int y, int z) const
{
bool googleApiMapadapter::isValid(int x, int y, int z) const
{
if ((x >= 0 && x < mNumberOfTiles) && (y >= 0 && y < mNumberOfTiles) && z >= 0)
return true;
return false;
}
}
QString googleApiMapadapter::typeToString(layerType qLayerType)
{
QString googleApiMapadapter::typeToString(layerType qLayerType)
{
switch (qLayerType)
{
case layerType_SATELLITE: return "satellite";
case layerType_HYBRID: return "hybrid";
case layerType_TERRAIN: return "terrain";
case layerType_SATELLITE:
return "satellite";
case layerType_HYBRID:
return "hybrid";
case layerType_TERRAIN:
return "terrain";
case layerType_ROADMAP:
default:
return "roadmap";
}
}
}
QString googleApiMapadapter::query(int i, int j, int z) const
{
qreal longi = ((i * mTileSize) - (mTileSize * pow(2.0, z - 1))) / ((mTileSize * pow(2.0, z)) / 360.);
QString googleApiMapadapter::query(int i, int j, int z) const
{
qreal longi = ((i * mTileSize) - (mTileSize * pow(2.0, z - 1)))
/ ((mTileSize * pow(2.0, z)) / 360.);
qreal latit = PI - 2. * PI * j / pow(2., z);
latit = 180. / PI * atan(0.5 * (exp(latit) - exp(-latit)));
return getQ(longi, latit, z);
}
}
QString googleApiMapadapter::getQ(qreal longitude, qreal latitude, int zoom) const
{
QString googleApiMapadapter::getQ(qreal longitude, qreal latitude, int zoom) const
{
QString location = "/maps/api/staticmap?&sensor=false&center=";
location.append(QVariant(latitude).toString());
location.append(",");
location.append(QVariant(longitude).toString());
location.append("&zoom=");
location.append(QString::number(zoom));
location.append("&size=" + QString::number(mTileSize) + "x" + QString::number(mTileSize) + "&scale=1");
location.append("&size=" + QString::number(mTileSize) + "x"
+ QString::number(mTileSize) + "&scale=1");
if (! mMapLayerType.isEmpty())
if (!mMapLayerType.isEmpty())
{
location.append(mMapLayerType);
}
if ( mApiType == GoogleMapsAPI )
if (mApiType == GoogleMapsAPI)
{
if (mApiClientID.isEmpty())
{
fprintf(stderr, "You are using Google Maps API without a (valid) key. This is against \"Terms of use\" of Google Maps\r\n");
fprintf(stderr,
"You are using Google Maps API without a (valid) key. This is "
"against \"Terms of use\" of Google Maps\r\n");
}
else
{
location.append(mApiClientID);
}
}
else if ( mApiType == GoogleMapsForBusinessesAPI )
else if (mApiType == GoogleMapsForBusinessesAPI)
{
if (mApiClientID.isEmpty())
{
fprintf(stderr, "You are using Google Maps API without a (valid) key. This is against \"Terms of use\" of Google Maps\r\n");
fprintf(stderr,
"You are using Google Maps API without a (valid) key. This is "
"against \"Terms of use\" of Google Maps\r\n");
}
else
{
// Google maps for business requires we sign every URL request against our apiKey
// Google maps for business requires we sign every URL request against our
// apiKey
//Example as taken from https://developers.google.com/maps/documentation/business/webservices/auth#digital_signatures
// Example as taken from
// https://developers.google.com/maps/documentation/business/webservices/auth#digital_signatures
//
// URL: https://maps.googleapis.com/maps/api/geocode/json?address=New+York&client=clientID
// URL:
// https://maps.googleapis.com/maps/api/geocode/json?address=New+York&client=clientID
// Private Key: vNIXE0xscrmjlyV-12Nj_BvUPaw=
// URL Portion to Sign: /maps/api/geocode/json?address=New+York&client=clientID
// Signature: chaRF2hTJKOScPr-RQCEhZbSzIE=
// URL Portion to Sign:
// /maps/api/geocode/json?address=New+York&client=clientID Signature:
// chaRF2hTJKOScPr-RQCEhZbSzIE=
QString urlSignature = "&signature=";
QString computedHash = signURL( location, mApiKey );
urlSignature.append( computedHash );
location.append( urlSignature );
QString computedHash = signURL(location, mApiKey);
urlSignature.append(computedHash);
location.append(urlSignature);
}
}
return location;
}
}
QString googleApiMapadapter::signURL(const QString &qURL, const QString &qCryptoKey) const
{
QString googleApiMapadapter::signURL(const QString &qURL, const QString &qCryptoKey) const
{
// Convert the key from 'web safe' base 64 to binary
QString usablePrivateKey = qCryptoKey;
usablePrivateKey.replace("-", "+");
@ -245,22 +265,22 @@ namespace qmapcontrol
result.replace("/", "_");
return result;
}
}
void googleApiMapadapter::setKey(QString qApiKey)
{
void googleApiMapadapter::setKey(QString qApiKey)
{
if (qApiKey.isEmpty())
return;
mApiKey.clear();
mApiKey.append("&key=");
mApiKey.append(qApiKey);
}
}
void googleApiMapadapter::setMapLayerType(layerType qMapType)
{
void googleApiMapadapter::setMapLayerType(layerType qMapType)
{
mMapLayerType.clear();
mMapLayerType.append("&maptype=");
mMapLayerType.append(typeToString(qMapType));
}
}
}

View File

@ -1,36 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Google Static Maps API V2 by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
* Copyright (C) 2014 Mattes Jaehne
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* original software by Kai Winter
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
* modified to use Google Static Maps API V2 by
* Mattes Jaehne <mattes@dev.uavp.ch>
* for
* NGOS - The Next Generation multicopter OS
* http://ng.uavp.ch
*
*/
#ifndef GOOGLEAPIMAPADAPTER_H
#define GOOGLEAPIMAPADAPTER_H
@ -40,17 +39,17 @@
namespace qmapcontrol
{
class QMAPCONTROL_EXPORT googleApiMapadapter : public TileMapAdapter
{
class QMAPCONTROL_EXPORT googleApiMapadapter : public TileMapAdapter
{
Q_OBJECT
public:
public:
enum layerType
{
layerType_ROADMAP = 0, //displays the default road map view. This is the default map type.
layerType_SATELLITE , //displays Google Earth satellite images
layerType_HYBRID , //displays a mixture of normal and satellite views
layerType_TERRAIN //displays a physical map based on terrain information
layerType_ROADMAP
= 0, // displays the default road map view. This is the default map type.
layerType_SATELLITE, // displays Google Earth satellite images
layerType_HYBRID, // displays a mixture of normal and satellite views
layerType_TERRAIN // displays a physical map based on terrain information
};
enum apiType
@ -59,26 +58,29 @@ namespace qmapcontrol
GoogleMapsForBusinessesAPI
};
googleApiMapadapter(layerType qMapType = layerType_ROADMAP, apiType qApiType = GoogleMapsAPI, QString qApiKey = "", QString qApiClientID = "", QString qServerAddress = "maps.googleapis.com");
googleApiMapadapter(layerType qMapType = layerType_ROADMAP,
apiType qApiType = GoogleMapsAPI, QString qApiKey = "",
QString qApiClientID = "",
QString qServerAddress = "maps.googleapis.com");
virtual ~googleApiMapadapter();
virtual QPoint coordinateToDisplay(const QPointF&) const;
virtual QPointF displayToCoordinate(const QPoint&) const;
virtual QPoint coordinateToDisplay(const QPointF &) const;
virtual QPointF displayToCoordinate(const QPoint &) const;
QString getHost() const;
void setKey(QString apiKey);
void setMapLayerType(layerType qMapType = layerType_ROADMAP);
protected:
protected:
virtual void zoom_in();
virtual void zoom_out();
virtual QString query(int x, int y, int z) const;
virtual bool isValid(int x, int y, int z) const;
virtual QString signURL( const QString& qURL, const QString& qCryptoKey ) const;
virtual QString signURL(const QString &qURL, const QString &qCryptoKey) const;
private:
QString typeToString( layerType qLayerType );
private:
QString typeToString(layerType qLayerType);
virtual QString getQ(qreal longitude, qreal latitude, int zoom) const;
qreal getMercatorLatitude(qreal YCoord) const;
qreal getMercatorYCoord(qreal lati) const;
@ -90,7 +92,7 @@ namespace qmapcontrol
QString mApiClientID;
apiType mApiType;
QString mMapLayerType;
};
};
}
#endif // GOOGLEAPIMAPADAPTER_H

View File

@ -1,52 +1,56 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "googlemapadapter.h"
namespace qmapcontrol
{
GoogleMapAdapter::GoogleMapAdapter( googleLayerType qLayerType )
: TileMapAdapter("mt1.google.com", "/vt/v=ap.106&hl=en&x=%2&y=%3&zoom=%1&lyrs=" + typeToString(qLayerType), 256, 17, 0)
//: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17)
{
QString layerType = typeToString( qLayerType );
}
GoogleMapAdapter::GoogleMapAdapter(googleLayerType qLayerType)
: TileMapAdapter("mt1.google.com",
"/vt/v=ap.106&hl=en&x=%2&y=%3&zoom=%1&lyrs="
+ typeToString(qLayerType),
256, 17, 0)
//: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17)
{
QString layerType = typeToString(qLayerType);
}
GoogleMapAdapter::~GoogleMapAdapter()
{
}
GoogleMapAdapter::~GoogleMapAdapter() { }
QString GoogleMapAdapter::typeToString( googleLayerType qLayerType )
{
QString GoogleMapAdapter::typeToString(googleLayerType qLayerType)
{
switch (qLayerType)
{
case satellite: return "s";
case terrain: return "t";
case hybrid: return "h";
case satellite:
return "s";
case terrain:
return "t";
case hybrid:
return "h";
case roadmap:
default:
return "m";
}
}
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef GOOGLEMAPADAPTER_H
#define GOOGLEMAPADAPTER_H
@ -31,16 +31,16 @@
namespace qmapcontrol
{
//! MapAdapter for Google
/*!
//! MapAdapter for Google
/*!
* This is a conveniece class, which extends and configures a TileMapAdapter
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT GoogleMapAdapter : public TileMapAdapter
{
class QMAPCONTROL_EXPORT GoogleMapAdapter : public TileMapAdapter
{
Q_OBJECT
public:
public:
enum googleLayerType
{
roadmap = 0,
@ -52,10 +52,11 @@ namespace qmapcontrol
/*!
* This construct a Google Adapter
*/
GoogleMapAdapter( googleLayerType qLayerType = roadmap );
GoogleMapAdapter(googleLayerType qLayerType = roadmap);
virtual ~GoogleMapAdapter();
private:
QString typeToString( googleLayerType qLayerType );
};
private:
QString typeToString(googleLayerType qLayerType);
};
}
#endif

View File

@ -1,33 +1,38 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "gps_position.h"
namespace qmapcontrol
{
GPS_Position::GPS_Position(float time, float longitude, QString longitude_dir, float latitude, QString latitude_dir)
:time(time), longitude(longitude), latitude(latitude), longitude_dir(longitude_dir), latitude_dir(latitude_dir)
{
}
GPS_Position::GPS_Position(float time, float longitude, QString longitude_dir,
float latitude, QString latitude_dir)
: time(time)
, longitude(longitude)
, latitude(latitude)
, longitude_dir(longitude_dir)
, latitude_dir(latitude_dir)
{
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef GPS_POSITION_H
#define GPS_POSITION_H
@ -31,23 +31,25 @@
namespace qmapcontrol
{
//! Represents a coordinate from a GPS receiver
/*!
//! Represents a coordinate from a GPS receiver
/*!
* This class is used to represent a coordinate which has been parsed from a NMEA string.
* This is not fully integrated in the API. An example which uses this data type can be found under Samples.
* This is not fully integrated in the API. An example which uses this data type can be
* found under Samples.
* @author Kai Winter
*/
class QMAPCONTROL_EXPORT GPS_Position
{
public:
GPS_Position(float time, float longitude, QString longitude_dir, float latitude, QString latitude_dir);
class QMAPCONTROL_EXPORT GPS_Position
{
public:
GPS_Position(float time, float longitude, QString longitude_dir, float latitude,
QString latitude_dir);
float time; /*!< time of the string*/
float longitude; /*!< longitude coordinate*/
float latitude; /*!< latitude coordinate*/
private:
private:
QString longitude_dir;
QString latitude_dir;
};
};
}
#endif

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "imagemanager.h"
#include "mapnetwork.h"
@ -34,88 +34,90 @@ static const int kDefaultPixmapCacheSizeKB = 20000;
namespace qmapcontrol
{
ImageManager::ImageManager(QObject* parent)
: QObject(parent),
emptyPixmap(QPixmap(1,1)),
loadingPixmap(QPixmap(256,256)),
net(new MapNetwork(this)),
diskCache( new QNetworkDiskCache(this))
{
ImageManager::ImageManager(QObject *parent)
: QObject(parent)
, emptyPixmap(QPixmap(1, 1))
, loadingPixmap(QPixmap(256, 256))
, net(new MapNetwork(this))
, diskCache(new QNetworkDiskCache(this))
{
emptyPixmap.fill(Qt::transparent);
//initialize loading image
loadingPixmap.fill( Qt::transparent );
// initialize loading image
loadingPixmap.fill(Qt::transparent);
QPainter paint(&loadingPixmap);
QBrush brush( Qt::lightGray, Qt::Dense5Pattern );
paint.fillRect(loadingPixmap.rect(), brush );
QBrush brush(Qt::lightGray, Qt::Dense5Pattern);
paint.fillRect(loadingPixmap.rect(), brush);
paint.end();
if (QPixmapCache::cacheLimit() <= kDefaultPixmapCacheSizeKB)
{
QPixmapCache::setCacheLimit(kDefaultPixmapCacheSizeKB);
}
}
}
ImageManager::~ImageManager()
{
ImageManager::~ImageManager()
{
delete net;
net = 0;
}
}
QPixmap ImageManager::getImage(const QString& host, const QString& url)
{
//qDebug() << "ImageManager::getImage";
QPixmap ImageManager::getImage(const QString &host, const QString &url)
{
// qDebug() << "ImageManager::getImage";
QPixmap pm;
if ( net->imageIsLoading(url) )
if (net->imageIsLoading(url))
{
//currently loading an image
// currently loading an image
return loadingPixmap;
}
else if ( QPixmapCache::find(url, &pm) )
else if (QPixmapCache::find(url, &pm))
{
//image found in cache, use this version
// image found in cache, use this version
return pm;
}
//is image cached (memory)
else if ( QPixmapCache::find(url, &pm) &&
!pm.isNull() )
// is image cached (memory)
else if (QPixmapCache::find(url, &pm) && !pm.isNull())
{
//we had a valid copy cached in memory (not disk) so return this
// we had a valid copy cached in memory (not disk) so return this
return pm;
}
else if ( failedFetches.contains(url) &&
failedFetches[url].secsTo(QDateTime::currentDateTime()) < kDefaultTimeoutDelaySecs )
else if (failedFetches.contains(url)
&& failedFetches[url].secsTo(QDateTime::currentDateTime())
< kDefaultTimeoutDelaySecs)
{
//prevents spamming public servers when requests fail to return an image or server returns error code (busy/ivalid useragent etc)
qDebug() << "Ignored: " << url << " - last request failed less than 30 seconds ago";
// prevents spamming public servers when requests fail to return an image or
// server returns error code (busy/ivalid useragent etc)
qDebug() << "Ignored: " << url
<< " - last request failed less than 30 seconds ago";
}
else
{
//load from net, add empty image
// load from net, add empty image
net->loadImage(host, url);
}
return emptyPixmap;
}
}
QPixmap ImageManager::prefetchImage(const QString& host, const QString& url)
{
// TODO See if this actually helps on the N900 & Symbian Phones
#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
// on mobile devices we don´t want the display refreshing when tiles are received which are
// prefetched... This is a performance issue, because mobile devices are very slow in
// repainting the screen
QPixmap ImageManager::prefetchImage(const QString &host, const QString &url)
{
// TODO See if this actually helps on the N900 & Symbian Phones
#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
// on mobile devices we don´t want the display refreshing when tiles are received
// which are prefetched... This is a performance issue, because mobile devices are
// very slow in repainting the screen
prefetch.append(url);
#endif
#endif
return getImage(host, url);
}
}
void ImageManager::receivedImage(const QPixmap pixmap, const QString& url)
{
//qDebug() << "ImageManager::receivedImage";
void ImageManager::receivedImage(const QPixmap pixmap, const QString &url)
{
// qDebug() << "ImageManager::receivedImage";
QPixmapCache::insert(url, pixmap);
//remove from failed list (if exists) as it has now come good
// remove from failed list (if exists) as it has now come good
if (failedFetches.contains(url))
{
failedFetches.remove(url);
@ -127,57 +129,58 @@ namespace qmapcontrol
}
else
{
#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
prefetch.remove(prefetch.indexOf(url));
#endif
}
#endif
}
}
void ImageManager::loadingQueueEmpty()
{
void ImageManager::loadingQueueEmpty()
{
emit loadingFinished();
}
}
void ImageManager::abortLoading()
{
void ImageManager::abortLoading()
{
net->abortLoading();
}
}
void ImageManager::setProxy(QString host, int port, const QString username, const QString password)
{
void ImageManager::setProxy(QString host, int port, const QString username,
const QString password)
{
net->setProxy(host, port, username, password);
}
}
void ImageManager::setCacheDir(const QDir& path, const int qDiskSizeMB)
{
if ( !path.absolutePath().isEmpty() )
void ImageManager::setCacheDir(const QDir &path, const int qDiskSizeMB)
{
if (!path.absolutePath().isEmpty())
{
QDir cacheDir = path;
if (!cacheDir.exists())
{
cacheDir.mkpath( cacheDir.absolutePath() );
cacheDir.mkpath(cacheDir.absolutePath());
}
diskCache->setCacheDirectory( cacheDir.absolutePath() );
diskCache->setMaximumCacheSize( qDiskSizeMB *1024*1024 ); //Megabytes to bytes
diskCache->setCacheDirectory(cacheDir.absolutePath());
diskCache->setMaximumCacheSize(qDiskSizeMB * 1024 * 1024); // Megabytes to bytes
net->setDiskCache(diskCache);
}
else
{
net->setDiskCache(0);
}
}
}
int ImageManager::loadQueueSize() const
{
int ImageManager::loadQueueSize() const
{
return net->loadQueueSize();
}
}
void qmapcontrol::ImageManager::fetchFailed(const QString &url)
{
void qmapcontrol::ImageManager::fetchFailed(const QString &url)
{
qDebug() << "ImageManager::fetchFailed" << url;
//store current time for this failed image to prevent loading it again until
// store current time for this failed image to prevent loading it again until
failedFetches.insert(url, QDateTime::currentDateTime());
}
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef IMAGEMANAGER_H
#define IMAGEMANAGER_H
@ -39,16 +39,16 @@
namespace qmapcontrol
{
class MapNetwork;
/**
@author Kai Winter <kaiwinter@gmx.de>
class MapNetwork;
/**
@author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT ImageManager : public QObject
{
class QMAPCONTROL_EXPORT ImageManager : public QObject
{
Q_OBJECT
public:
ImageManager(QObject* parent = 0);
public:
ImageManager(QObject *parent = 0);
virtual ~ImageManager();
//! returns a QPixmap of the asked image
@ -58,24 +58,25 @@ namespace qmapcontrol
* @param path the path to the image
* @return the pixmap of the asked image
*/
QPixmap getImage(const QString& host, const QString& path);
QPixmap getImage(const QString &host, const QString &path);
QPixmap prefetchImage(const QString& host, const QString& path);
QPixmap prefetchImage(const QString &host, const QString &path);
void receivedImage(const QPixmap pixmap, const QString& url);
void receivedImage(const QPixmap pixmap, const QString &url);
void fetchFailed(const QString &url);
/*!
* This method is called by MapNetwork, after all images in its queue were loaded.
* The ImageManager emits a signal, which is used in MapControl to remove the zoom image.
* The zoom image should be removed on Tile Images with transparency.
* Else the zoom image stay visible behind the newly loaded tiles.
* The ImageManager emits a signal, which is used in MapControl to remove the zoom
* image. The zoom image should be removed on Tile Images with transparency. Else the
* zoom image stay visible behind the newly loaded tiles.
*/
void loadingQueueEmpty();
/*!
* Aborts all current loading threads.
* This is useful when changing the zoom-factor, though newly needed images loads faster
* This is useful when changing the zoom-factor, though newly needed images loads
* faster
*/
void abortLoading();
@ -88,7 +89,8 @@ namespace qmapcontrol
* @param username the proxy<EFBFBD>s username
* @param password the proxy<EFBFBD>s password
*/
void setProxy(QString host, int port, const QString username = QString(), const QString password = QString());
void setProxy(QString host, int port, const QString username = QString(),
const QString password = QString());
//! sets the cache directory for persistently saving map tiles
/*!
@ -96,28 +98,28 @@ namespace qmapcontrol
* @param path the path where map tiles should be stored
* @param qDiskSizeMB the about of disk space to use for caching. Default is 250MB
*/
void setCacheDir(const QDir& path, const int qDiskSizeMB = 250);
void setCacheDir(const QDir &path, const int qDiskSizeMB = 250);
/*!
* @return Number of images pending in the load queue
*/
int loadQueueSize() const;
private:
Q_DISABLE_COPY( ImageManager )
private:
Q_DISABLE_COPY(ImageManager)
QPixmap emptyPixmap;
QPixmap loadingPixmap;
MapNetwork* net;
QNetworkDiskCache* diskCache;
MapNetwork *net;
QNetworkDiskCache *diskCache;
QVector<QString> prefetch;
QHash<QString,QDateTime> failedFetches;
QHash<QString, QDateTime> failedFetches;
signals:
signals:
void imageReceived();
void loadingFinished();
};
};
}
#endif

View File

@ -1,49 +1,48 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "imagepoint.h"
namespace qmapcontrol
{
ImagePoint::ImagePoint(qreal x, qreal y, QString filename, QString name, Alignment alignment)
ImagePoint::ImagePoint(qreal x, qreal y, QString filename, QString name,
Alignment alignment)
: Point(x, y, name, alignment)
{
//qDebug() << "loading image: " << filename;
{
// qDebug() << "loading image: " << filename;
mypixmap = QPixmap(filename);
size = mypixmap.size();
//qDebug() << "image size: " << size;
}
// qDebug() << "image size: " << size;
}
ImagePoint::ImagePoint(qreal x, qreal y, QPixmap pixmap, QString name, Alignment alignment)
ImagePoint::ImagePoint(qreal x, qreal y, QPixmap pixmap, QString name,
Alignment alignment)
: Point(x, y, name, alignment)
{
{
mypixmap = pixmap;
size = mypixmap.size();
}
ImagePoint::~ImagePoint()
{
}
}
ImagePoint::~ImagePoint() { }
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef IMAGEPOINT_H
#define IMAGEPOINT_H
@ -32,27 +32,29 @@
namespace qmapcontrol
{
//! Draws an image into the map
/*! This is a convenience class for Point.
//! Draws an image into the map
/*! This is a convenience class for Point.
* It configures the pixmap of a Point to draw the given image.
* The image will be loaded from the given path and written in the points pixmap.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT ImagePoint : public Point
{
public:
class QMAPCONTROL_EXPORT ImagePoint : public Point
{
public:
//! Creates a point which loads and displays the given image file
/*!
* Use this contructor to load the given image file and let the point display it.
* When you want multiple points to display the same image, use the other contructor and pass a pointer to that image.
* When you want multiple points to display the same image, use the other contructor
* and pass a pointer to that image.
* @param x longitude
* @param y latitude
* @param filename the file which should be loaded and displayed
* @param name the name of the image point
* @param alignment alignment (Middle or TopLeft)
*/
ImagePoint(qreal x, qreal y, QString filename, QString name = QString(), Alignment alignment = Middle);
ImagePoint(qreal x, qreal y, QString filename, QString name = QString(),
Alignment alignment = Middle);
//! Creates a point which displays the given image
/*!
@ -64,8 +66,9 @@ namespace qmapcontrol
* @param name the name of the image point
* @param alignment alignment (Middle or TopLeft)
*/
ImagePoint(qreal x, qreal y, QPixmap pixmap, QString name = QString(), Alignment alignment = Middle);
ImagePoint(qreal x, qreal y, QPixmap pixmap, QString name = QString(),
Alignment alignment = Middle);
virtual ~ImagePoint();
};
};
}
#endif

View File

@ -1,52 +1,50 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2014 Frederic Bourgeois
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2014 Frederic Bourgeois
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "invisiblepoint.h"
namespace qmapcontrol
{
InvisiblePoint::InvisiblePoint(qreal x, qreal y, int sideLength, QString name)
InvisiblePoint::InvisiblePoint(qreal x, qreal y, int sideLength, QString name)
: Point(x, y, name, Point::Middle)
{
{
size = QSize(sideLength, sideLength);
}
}
InvisiblePoint::InvisiblePoint(qreal x, qreal y, int width, int height, QString name)
InvisiblePoint::InvisiblePoint(qreal x, qreal y, int width, int height, QString name)
: Point(x, y, name, Point::Middle)
{
{
size = QSize(width, height);
}
}
InvisiblePoint::InvisiblePoint(qreal x, qreal y, QString name)
InvisiblePoint::InvisiblePoint(qreal x, qreal y, QString name)
: Point(x, y, name, Point::Middle)
{
{
int sideLength = 10;
size = QSize(sideLength, sideLength);
}
InvisiblePoint::~InvisiblePoint()
{
}
}
InvisiblePoint::~InvisiblePoint() { }
}

View File

@ -1,28 +1,28 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2014 Frederic Bourgeois
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2014 Frederic Bourgeois
* Based on CirclePoint code by Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef INVISIBLEPOINT_H
#define INVISIBLEPOINT_H
@ -32,16 +32,16 @@
namespace qmapcontrol
{
//! Draws an invisible point into the map
/*! This is a convenience class for point.
//! Draws an invisible point into the map
/*! This is a convenience class for point.
* It configures the pixmap of a point to draw nothing,
* still being a clickable point.
*
* @author Frederic Bourgeois <bourgeoislab@gmail.com>
*/
class QMAPCONTROL_EXPORT InvisiblePoint : public Point
{
public:
class QMAPCONTROL_EXPORT InvisiblePoint : public Point
{
public:
//!
/*!
*
@ -60,7 +60,8 @@ namespace qmapcontrol
* @param height height
* @param name name of the invisible point
*/
InvisiblePoint(qreal x, qreal y, int width = 10, int height = 10, QString name = QString());
InvisiblePoint(qreal x, qreal y, int width = 10, int height = 10,
QString name = QString());
//!
/*!
@ -72,6 +73,6 @@ namespace qmapcontrol
*/
InvisiblePoint(qreal x, qreal y, int sideLength = 10, QString name = QString());
virtual ~InvisiblePoint();
};
};
}
#endif

View File

@ -1,144 +1,144 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "layer.h"
namespace qmapcontrol
{
Layer::Layer()
: visible(true),
mylayertype(MapLayer),
mapAdapter(0),
takeevents(true),
myoffscreenViewport(QRect(0,0,0,0)),
m_ImageManager(0)
{
}
Layer::Layer(QString layername, MapAdapter* mapadapter, enum LayerType layertype, bool takeevents)
: visible(true),
mylayername(layername),
mylayertype(layertype),
mapAdapter(mapadapter),
takeevents(takeevents),
myoffscreenViewport(QRect(0,0,0,0)),
m_ImageManager(0)
{
}
Layer::Layer()
: visible(true)
, mylayertype(MapLayer)
, mapAdapter(0)
, takeevents(true)
, myoffscreenViewport(QRect(0, 0, 0, 0))
, m_ImageManager(0)
{
}
Layer::Layer(QString layername, MapAdapter *mapadapter, enum LayerType layertype,
bool takeevents)
: visible(true)
, mylayername(layername)
, mylayertype(layertype)
, mapAdapter(mapadapter)
, takeevents(takeevents)
, myoffscreenViewport(QRect(0, 0, 0, 0))
, m_ImageManager(0)
{
}
Layer::~Layer()
{
if( mapAdapter )
Layer::~Layer()
{
if (mapAdapter)
{
mapAdapter->deleteLater();
mapAdapter = 0;
}
}
}
void Layer::setSize(QSize size)
{
void Layer::setSize(QSize size)
{
this->size = size;
screenmiddle = QPoint(size.width()/2, size.height()/2);
screenmiddle = QPoint(size.width() / 2, size.height() / 2);
emit(updateRequest());
}
}
QString Layer::layername() const
{
QString Layer::layername() const
{
return mylayername;
}
}
MapAdapter* Layer::mapadapter()
{
MapAdapter *Layer::mapadapter()
{
return mapAdapter;
}
}
void Layer::setVisible(bool visible)
{
void Layer::setVisible(bool visible)
{
this->visible = visible;
emit(updateRequest());
}
}
QList<Geometry*>& Layer::getGeometries()
{
QList<Geometry *> &Layer::getGeometries()
{
return geometries;
}
}
bool Layer::containsGeometry( Geometry* geometry )
{
return geometry && geometries.contains( geometry );
}
bool Layer::containsGeometry(Geometry *geometry)
{
return geometry && geometries.contains(geometry);
}
void Layer::sendGeometryToFront(Geometry *geometry)
{
if ( !geometry || !geometries.contains( geometry ) )
void Layer::sendGeometryToFront(Geometry *geometry)
{
if (!geometry || !geometries.contains(geometry))
{
return;
}
geometries.removeAll(geometry);
geometries.prepend(geometry);
emit(updateRequest());
}
}
void Layer::sendGeometryToBack(Geometry *geometry)
{
if ( !geometry || !geometries.contains( geometry ) )
void Layer::sendGeometryToBack(Geometry *geometry)
{
if (!geometry || !geometries.contains(geometry))
{
return;
}
geometries.removeAll(geometry);
geometries.append(geometry);
emit(updateRequest());
}
}
void Layer::addGeometry(Geometry* geom)
{
if ( !geom || containsGeometry( geom ) )
void Layer::addGeometry(Geometry *geom)
{
if (!geom || containsGeometry(geom))
{
return;
}
geometries.append(geom);
emit(updateRequest(geom->boundingBox()));
//a geometry can request a redraw, e.g. when its position has been changed
connect(geom, SIGNAL(updateRequest(QRectF)),
this, SIGNAL(updateRequest(QRectF)));
}
// a geometry can request a redraw, e.g. when its position has been changed
connect(geom, SIGNAL(updateRequest(QRectF)), this, SIGNAL(updateRequest(QRectF)));
}
void Layer::removeGeometry(Geometry* geometry, bool qDeleteObject)
{
if ( !geometry )
void Layer::removeGeometry(Geometry *geometry, bool qDeleteObject)
{
if (!geometry)
{
return;
}
QRectF boundingBox = geometry->boundingBox();
foreach( Geometry* geo, geometries )
foreach (Geometry *geo, geometries)
{
if ( geo && geo == geometry )
if (geo && geo == geometry)
{
disconnect(geometry);
geometries.removeAll( geometry );
geometries.removeAll(geometry);
if (qDeleteObject)
{
delete geo;
@ -147,48 +147,49 @@ namespace qmapcontrol
}
}
emit(updateRequest(boundingBox));
}
}
void Layer::clearGeometries( bool qDeleteObject )
{
foreach(Geometry *geometry, geometries)
void Layer::clearGeometries(bool qDeleteObject)
{
foreach (Geometry *geometry, geometries)
{
disconnect(geometry);
if ( qDeleteObject )
if (qDeleteObject)
{
delete geometry;
geometry = 0;
}
}
geometries.clear();
}
}
bool Layer::isVisible() const
{
bool Layer::isVisible() const
{
return visible;
}
void Layer::zoomIn() const
{
}
void Layer::zoomIn() const
{
mapAdapter->zoom_in();
}
void Layer::zoomOut() const
{
}
void Layer::zoomOut() const
{
mapAdapter->zoom_out();
}
}
void Layer::mouseEvent(const QMouseEvent* evnt, const QPoint mapmiddle_px)
{
void Layer::mouseEvent(const QMouseEvent *evnt, const QPoint mapmiddle_px)
{
if (takesMouseEvents())
{
if ( geometries.size() > 0 &&
evnt->button() == Qt::LeftButton &&
evnt->type() == QEvent::MouseButtonPress)
if (geometries.size() > 0 && evnt->button() == Qt::LeftButton
&& evnt->type() == QEvent::MouseButtonPress)
{
// check for collision
QPointF c = mapAdapter->displayToCoordinate(QPoint(evnt->x()-screenmiddle.x()+mapmiddle_px.x(),
evnt->y()-screenmiddle.y()+mapmiddle_px.y()));
Point* tmppoint = new Point(c.x(), c.y());
for(QList<Geometry*>::const_iterator iter = geometries.begin(); iter != geometries.end(); ++iter)
QPointF c = mapAdapter->displayToCoordinate(
QPoint(evnt->x() - screenmiddle.x() + mapmiddle_px.x(),
evnt->y() - screenmiddle.y() + mapmiddle_px.y()));
Point *tmppoint = new Point(c.x(), c.y());
for (QList<Geometry *>::const_iterator iter = geometries.begin();
iter != geometries.end(); ++iter)
{
Geometry *geo = *iter;
if (geo && geo->isVisible() && geo->Touches(tmppoint, mapAdapter))
@ -199,24 +200,28 @@ namespace qmapcontrol
delete tmppoint;
}
}
}
}
bool Layer::takesMouseEvents() const
{
bool Layer::takesMouseEvents() const
{
return takeevents;
}
}
void Layer::drawYourImage(QPainter* painter, const QPoint mapmiddle_px) const
{
void Layer::drawYourImage(QPainter *painter, const QPoint mapmiddle_px) const
{
if (mylayertype == MapLayer)
{
_draw(painter, mapmiddle_px);
}
drawYourGeometries(painter, QPoint(mapmiddle_px.x()-screenmiddle.x(), mapmiddle_px.y()-screenmiddle.y()), myoffscreenViewport);
}
void Layer::drawYourGeometries(QPainter* painter, const QPoint mapmiddle_px, QRect viewport) const
{
drawYourGeometries(
painter,
QPoint(mapmiddle_px.x() - screenmiddle.x(), mapmiddle_px.y() - screenmiddle.y()),
myoffscreenViewport);
}
void Layer::drawYourGeometries(QPainter *painter, const QPoint mapmiddle_px,
QRect viewport) const
{
QPoint offset;
if (mylayertype == MapLayer)
{
@ -224,59 +229,61 @@ namespace qmapcontrol
}
else
{
offset = mapmiddle_px-screenmiddle;
offset = mapmiddle_px - screenmiddle;
}
painter->translate(-mapmiddle_px+screenmiddle);
painter->translate(-mapmiddle_px + screenmiddle);
for(QList<Geometry*>::const_iterator iter = geometries.begin(); iter != geometries.end(); ++iter)
for (QList<Geometry *>::const_iterator iter = geometries.begin();
iter != geometries.end(); ++iter)
{
Geometry *geo = *iter;
geo->draw(painter, mapAdapter, viewport, offset);
}
painter->translate(mapmiddle_px-screenmiddle);
painter->translate(mapmiddle_px - screenmiddle);
}
}
void Layer::_draw(QPainter* painter, const QPoint mapmiddle_px) const
{
if ( m_ImageManager == 0 )
void Layer::_draw(QPainter *painter, const QPoint mapmiddle_px) const
{
if (m_ImageManager == 0)
{
return;
}
// screen middle...
int tilesize = mapAdapter->tilesize();
int cross_x = int(mapmiddle_px.x())%tilesize; // position on middle tile
int cross_y = int(mapmiddle_px.y())%tilesize;
int cross_x = int(mapmiddle_px.x()) % tilesize; // position on middle tile
int cross_y = int(mapmiddle_px.y()) % tilesize;
// calculate how many surrounding tiles have to be drawn to fill the display
int space_left = screenmiddle.x() - cross_x;
int tiles_left = space_left/tilesize;
if (space_left>0)
tiles_left+=1;
int tiles_left = space_left / tilesize;
if (space_left > 0)
tiles_left += 1;
int space_above = screenmiddle.y() - cross_y;
int tiles_above = space_above/tilesize;
if (space_above>0)
tiles_above+=1;
int tiles_above = space_above / tilesize;
if (space_above > 0)
tiles_above += 1;
int space_right = screenmiddle.x() - (tilesize-cross_x);
int tiles_right = space_right/tilesize;
if (space_right>0)
tiles_right+=1;
int space_right = screenmiddle.x() - (tilesize - cross_x);
int tiles_right = space_right / tilesize;
if (space_right > 0)
tiles_right += 1;
int space_bottom = screenmiddle.y() - (tilesize-cross_y);
int tiles_bottom = space_bottom/tilesize;
if (space_bottom>0)
tiles_bottom+=1;
int space_bottom = screenmiddle.y() - (tilesize - cross_y);
int tiles_bottom = space_bottom / tilesize;
if (space_bottom > 0)
tiles_bottom += 1;
//int tiles_displayed = 0;
int mapmiddle_tile_x = mapmiddle_px.x()/tilesize;
int mapmiddle_tile_y = mapmiddle_px.y()/tilesize;
// int tiles_displayed = 0;
int mapmiddle_tile_x = mapmiddle_px.x() / tilesize;
int mapmiddle_tile_y = mapmiddle_px.y() / tilesize;
const QPoint from = QPoint((-tiles_left+mapmiddle_tile_x)*tilesize, (-tiles_above+mapmiddle_tile_y)*tilesize);
const QPoint to = QPoint((tiles_right+mapmiddle_tile_x+1)*tilesize, (tiles_bottom+mapmiddle_tile_y+1)*tilesize);
const QPoint from = QPoint((-tiles_left + mapmiddle_tile_x) * tilesize,
(-tiles_above + mapmiddle_tile_y) * tilesize);
const QPoint to = QPoint((tiles_right + mapmiddle_tile_x + 1) * tilesize,
(tiles_bottom + mapmiddle_tile_y + 1) * tilesize);
myoffscreenViewport = QRect(from, to);
@ -286,101 +293,120 @@ namespace qmapcontrol
return;
}
//grab the middle tile (under the pointer) first
if (mapAdapter->isTileValid(mapmiddle_tile_x, mapmiddle_tile_y, mapAdapter->currentZoom()))
// grab the middle tile (under the pointer) first
if (mapAdapter->isTileValid(mapmiddle_tile_x, mapmiddle_tile_y,
mapAdapter->currentZoom()))
{
painter->drawPixmap(-cross_x+size.width(),
-cross_y+size.height(),
m_ImageManager->getImage(mapAdapter->host(), mapAdapter->query(mapmiddle_tile_x, mapmiddle_tile_y, mapAdapter->currentZoom())) );
painter->drawPixmap(
-cross_x + size.width(), -cross_y + size.height(),
m_ImageManager->getImage(mapAdapter->host(),
mapAdapter->query(mapmiddle_tile_x, mapmiddle_tile_y,
mapAdapter->currentZoom())));
}
for (int i=-tiles_left+mapmiddle_tile_x; i<=tiles_right+mapmiddle_tile_x; ++i)
for (int i = -tiles_left + mapmiddle_tile_x; i <= tiles_right + mapmiddle_tile_x; ++i)
{
for (int j=-tiles_above+mapmiddle_tile_y; j<=tiles_bottom+mapmiddle_tile_y; ++j)
for (int j = -tiles_above + mapmiddle_tile_y;
j <= tiles_bottom + mapmiddle_tile_y; ++j)
{
// check if image is valid
if (!(i==mapmiddle_tile_x && j==mapmiddle_tile_y))
if (!(i == mapmiddle_tile_x && j == mapmiddle_tile_y))
{
if (mapAdapter->isTileValid(i, j, mapAdapter->currentZoom()))
{
painter->drawPixmap(((i-mapmiddle_tile_x)*tilesize)-cross_x+size.width(),
((j-mapmiddle_tile_y)*tilesize)-cross_y+size.height(),
m_ImageManager->getImage(mapAdapter->host(), mapAdapter->query(i, j, mapAdapter->currentZoom())));
painter->drawPixmap(
((i - mapmiddle_tile_x) * tilesize) - cross_x + size.width(),
((j - mapmiddle_tile_y) * tilesize) - cross_y + size.height(),
m_ImageManager->getImage(
mapAdapter->host(),
mapAdapter->query(i, j, mapAdapter->currentZoom())));
}
}
}
}
bool enabledPrefetch = false;
if ( enabledPrefetch )
if (enabledPrefetch)
{
// Prefetch the next set of rows/column tiles (ready for when the user starts panning).
// Prefetch the next set of rows/column tiles (ready for when the user starts
// panning).
const int prefetch_tile_left = tiles_left - 1;
const int prefetch_tile_top = tiles_above - 1;
const int prefetch_tile_right = tiles_right + 1;
const int prefetch_tile_bottom = tiles_bottom + 1;
// Fetch the top/bottom rows
for (int i=prefetch_tile_left; i<=prefetch_tile_right; ++i)
for (int i = prefetch_tile_left; i <= prefetch_tile_right; ++i)
{
if (mapAdapter->isTileValid(i, prefetch_tile_top, mapAdapter->currentZoom()))
{
m_ImageManager->prefetchImage(mapAdapter->host(), mapAdapter->query(i, prefetch_tile_top, mapAdapter->currentZoom()));
m_ImageManager->prefetchImage(
mapAdapter->host(),
mapAdapter->query(i, prefetch_tile_top, mapAdapter->currentZoom()));
}
if (mapAdapter->isTileValid(i, prefetch_tile_bottom, mapAdapter->currentZoom()))
if (mapAdapter->isTileValid(i, prefetch_tile_bottom,
mapAdapter->currentZoom()))
{
m_ImageManager->prefetchImage(mapAdapter->host(), mapAdapter->query(i, prefetch_tile_bottom, mapAdapter->currentZoom()));
m_ImageManager->prefetchImage(
mapAdapter->host(),
mapAdapter->query(i, prefetch_tile_bottom,
mapAdapter->currentZoom()));
}
}
for (int i=prefetch_tile_top; i<=prefetch_tile_bottom; ++i)
for (int i = prefetch_tile_top; i <= prefetch_tile_bottom; ++i)
{
if (mapAdapter->isTileValid(prefetch_tile_left, i, mapAdapter->currentZoom()))
{
m_ImageManager->prefetchImage(mapAdapter->host(), mapAdapter->query(prefetch_tile_left, i, mapAdapter->currentZoom()));
m_ImageManager->prefetchImage(
mapAdapter->host(),
mapAdapter->query(prefetch_tile_left, i, mapAdapter->currentZoom()));
}
if (mapAdapter->isTileValid(prefetch_tile_right, i, mapAdapter->currentZoom()))
if (mapAdapter->isTileValid(prefetch_tile_right, i,
mapAdapter->currentZoom()))
{
m_ImageManager->prefetchImage(mapAdapter->host(), mapAdapter->query(prefetch_tile_right, i, mapAdapter->currentZoom()));
}
m_ImageManager->prefetchImage(
mapAdapter->host(),
mapAdapter->query(prefetch_tile_right, i, mapAdapter->currentZoom()));
}
}
}
}
QRect Layer::offscreenViewport() const
{
QRect Layer::offscreenViewport() const
{
return myoffscreenViewport;
}
}
void Layer::moveWidgets(const QPoint mapmiddle_px) const
{
foreach( Geometry* geometry, geometries )
void Layer::moveWidgets(const QPoint mapmiddle_px) const
{
foreach (Geometry *geometry, geometries)
{
if (geometry->GeometryType == "Point")
{
Point* point = dynamic_cast<Point*>(geometry);
if (point !=0)
Point *point = dynamic_cast<Point *>(geometry);
if (point != 0)
{
QPoint topleft_relative = QPoint(mapmiddle_px-screenmiddle);
QPoint topleft_relative = QPoint(mapmiddle_px - screenmiddle);
point->drawWidget(mapAdapter, topleft_relative);
}
}
}
}
}
Layer::LayerType Layer::layertype() const
{
Layer::LayerType Layer::layertype() const
{
return mylayertype;
}
}
void Layer::setMapAdapter(MapAdapter* mapadapter)
{
void Layer::setMapAdapter(MapAdapter *mapadapter)
{
mapAdapter = mapadapter;
emit(updateRequest());
}
void Layer::setImageManager(ImageManager *qImageManager)
{
m_ImageManager = qImageManager;
}
}
void Layer::setImageManager(ImageManager *qImageManager)
{
m_ImageManager = qImageManager;
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef LAYER_H
#define LAYER_H
@ -43,26 +43,29 @@
namespace qmapcontrol
{
//! Layer class
/*!
//! Layer class
/*!
* There are two different layer types:
* - MapLayer: Displays Maps, but also Geometries. The configuration for displaying maps have to be done in the MapAdapter
* - MapLayer: Displays Maps, but also Geometries. The configuration for displaying maps
*have to be done in the MapAdapter
* - GeometryLayer: Only displays Geometry objects.
*
* MapLayers also can display Geometry objects. The difference to the GeometryLayer is the repainting. Objects that are
* added to a MapLayer are "baken" on the map. This means, when you change it´s position for example the changes are
* not visible until a new offscreen image has been drawn. If you have "static" Geometries which won´t change their
* position this is fine. But if you want to change the objects position or pen you should use a GeometryLayer. Those
* are repainted immediately on changes.
* You can either use this class and give a layertype on creation or you can use the classes MapLayer and GeometryLayer.
* MapLayers also can display Geometry objects. The difference to the GeometryLayer is the
*repainting. Objects that are added to a MapLayer are "baken" on the map. This means,
*when you change it´s position for example the changes are not visible until a new
*offscreen image has been drawn. If you have "static" Geometries which won´t change their
* position this is fine. But if you want to change the objects position or pen you should
*use a GeometryLayer. Those are repainted immediately on changes. You can either use this
*class and give a layertype on creation or you can use the classes MapLayer and
*GeometryLayer.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Layer : public QObject
{
class QMAPCONTROL_EXPORT Layer : public QObject
{
Q_OBJECT
public:
public:
friend class LayerManager;
//! sets the type of a layer, see Layer class doc for further information
@ -83,13 +86,15 @@ namespace qmapcontrol
* This is used to construct a layer.
*
* @param layername The name of the Layer
* @param mapadapter The MapAdapter which does coordinate translation and Query-String-Forming
* @param mapadapter The MapAdapter which does coordinate translation and
* Query-String-Forming
* @param layertype The above explained LayerType
* @param takeevents Should the Layer receive MouseEvents? This is set to true by default. Setting it to false could
* be something like a "speed up hint"
* @param takeevents Should the Layer receive MouseEvents? This is set to true by
* default. Setting it to false could be something like a "speed up hint"
*/
Layer(QString layername, MapAdapter* mapadapter, enum LayerType layertype, bool takeevents=true);
Layer(QString layername, MapAdapter *mapadapter, enum LayerType layertype,
bool takeevents = true);
virtual ~Layer();
//! returns the layer's name
@ -104,14 +109,15 @@ namespace qmapcontrol
* to do coordinate transformations.
* @return the MapAdapter which us used by this Layer
*/
MapAdapter* mapadapter();
MapAdapter *mapadapter();
//! adds a Geometry object to this Layer
/*!
* Please notice the different LayerTypes (MapLayer and GeometryLayer) and the differences
* Please notice the different LayerTypes (MapLayer and GeometryLayer) and the
* differences
* @param geometry the new Geometry
*/
void addGeometry(Geometry* geometry);
void addGeometry(Geometry *geometry);
//! removes the Geometry object from this Layer
/*!
@ -119,7 +125,7 @@ namespace qmapcontrol
* NOTE: this method does not delete the object unless qDeleteObject is set
* @param qDeleteObject cleans up memory of object after removal
*/
void removeGeometry(Geometry* geometry, bool qDeleteObject = false);
void removeGeometry(Geometry *geometry, bool qDeleteObject = false);
//! removes all Geometry objects from this Layer
/*!
@ -127,34 +133,34 @@ namespace qmapcontrol
* NOTE: this method does not delete the object unless qDeleteObject is set
* @param qDeleteObject cleans up memory of object after removal
*/
void clearGeometries( bool qDeleteObject = false);
void clearGeometries(bool qDeleteObject = false);
//! returns all Geometry objects from this Layer
/*!
* This method removes all Geometry objects from this Layer.
* @return a list of geometries that are on this Layer
*/
QList<Geometry*>& getGeometries();
QList<Geometry *> &getGeometries();
//! returns true if Layer contains geometry
/*!
* This method returns if a Geometry objects is on this Layer.
*/
bool containsGeometry( Geometry* geometry );
bool containsGeometry(Geometry *geometry);
//! allow moving a geometry to the top of the list (drawing last)
/*!
* This method re-order the Geometry objects so the desired
* geometry is drawn last and visible above all geometries
*/
void sendGeometryToFront( Geometry* geometry );
void sendGeometryToFront(Geometry *geometry);
//! allow moving a geometry to the top of the list (drawing last)
/*!
* This method re-order the Geometry objects so the desired
* geometry is drawn first and under all other geometries
*/
void sendGeometryToBack( Geometry* geometry );
void sendGeometryToBack(Geometry *geometry);
//! return true if the layer is visible
/*!
@ -169,20 +175,21 @@ namespace qmapcontrol
*/
Layer::LayerType layertype() const;
void setMapAdapter(MapAdapter* mapadapter);
void setImageManager(ImageManager* qImageManager);
void setMapAdapter(MapAdapter *mapadapter);
void setImageManager(ImageManager *qImageManager);
private:
private:
void moveWidgets(const QPoint mapmiddle_px) const;
void drawYourImage(QPainter* painter, const QPoint mapmiddle_px) const;
void drawYourGeometries(QPainter* painter, const QPoint mapmiddle_px, QRect viewport) const;
void drawYourImage(QPainter *painter, const QPoint mapmiddle_px) const;
void drawYourGeometries(QPainter *painter, const QPoint mapmiddle_px,
QRect viewport) const;
void setSize(QSize size);
QRect offscreenViewport() const;
bool takesMouseEvents() const;
void mouseEvent(const QMouseEvent*, const QPoint mapmiddle_px);
void mouseEvent(const QMouseEvent *, const QPoint mapmiddle_px);
void zoomIn() const;
void zoomOut() const;
void _draw(QPainter* painter, const QPoint mapmiddle_px) const;
void _draw(QPainter *painter, const QPoint mapmiddle_px) const;
bool visible;
QString mylayername;
@ -190,14 +197,14 @@ namespace qmapcontrol
QSize size;
QPoint screenmiddle;
QList<Geometry*> geometries;
MapAdapter* mapAdapter;
QList<Geometry *> geometries;
MapAdapter *mapAdapter;
bool takeevents;
mutable QRect myoffscreenViewport;
ImageManager* m_ImageManager;
ImageManager *m_ImageManager;
signals:
signals:
//! This signal is emitted when a Geometry is clicked
/*!
* A Geometry is clickable, if the containing layer is clickable.
@ -205,17 +212,17 @@ namespace qmapcontrol
* @param geometry The clicked Geometry
* @param point The coordinate (in widget coordinates) of the click
*/
void geometryClicked(Geometry* geometry, QPoint point);
void geometryClicked(Geometry *geometry, QPoint point);
void updateRequest(QRectF rect);
void updateRequest();
public slots:
public slots:
//! if visible is true, the layer is made visible
/*!
* @param visible if the layer should be visible
*/
void setVisible(bool visible);
};
};
}
#endif

View File

@ -1,98 +1,99 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "layermanager.h"
namespace qmapcontrol
{
LayerManager::LayerManager(MapControl* mapcontrol, QSize size)
:mapcontrol(mapcontrol), scroll(QPoint(0,0)), size(size), whilenewscroll(QPoint(0,0))
{
LayerManager::LayerManager(MapControl *mapcontrol, QSize size)
: mapcontrol(mapcontrol)
, scroll(QPoint(0, 0))
, size(size)
, whilenewscroll(QPoint(0, 0))
{
// genauer berechnen?
offSize = size *2;
offSize = size * 2;
composedOffscreenImage = QPixmap(offSize);
zoomImage = QPixmap(size);
zoomImage.fill(Qt::white);
screenmiddle = QPoint(size.width()/2, size.height()/2);
screenmiddle = QPoint(size.width() / 2, size.height() / 2);
useBoundingBox = false;
}
}
LayerManager::~LayerManager()
{
LayerManager::~LayerManager()
{
mylayers.clear();
}
}
QPointF LayerManager::currentCoordinate() const
{
QPointF LayerManager::currentCoordinate() const
{
return mapmiddle;
}
}
QPixmap LayerManager::getImage() const
{
QPixmap LayerManager::getImage() const
{
return composedOffscreenImage;
}
}
Layer* LayerManager::layer() const
{
if ( mylayers.isEmpty() )
Layer *LayerManager::layer() const
{
if (mylayers.isEmpty())
{
qDebug() << "LayerManager::getLayer() - No layers were added";
return 0;
}
return mylayers.at(0) ? mylayers.at(0) : 0;
}
}
Layer* LayerManager::layer(const QString& layername) const
{
QListIterator<Layer*> layerit(mylayers);
Layer *LayerManager::layer(const QString &layername) const
{
QListIterator<Layer *> layerit(mylayers);
while (layerit.hasNext())
{
Layer* l = layerit.next();
Layer *l = layerit.next();
if (l->layername() == layername)
return l;
}
return 0;
}
}
QList<QString> LayerManager::layers() const
{
QList<QString> LayerManager::layers() const
{
QList<QString> keys;
QListIterator<Layer*> layerit(mylayers);
QListIterator<Layer *> layerit(mylayers);
while (layerit.hasNext())
{
keys.append(layerit.next()->layername());
}
return keys;
}
}
void LayerManager::scrollView(const QPoint& point)
{
void LayerManager::scrollView(const QPoint &point)
{
QPointF tempMiddle = layer()->mapadapter()->displayToCoordinate(mapmiddle_px + point);
if((useBoundingBox && boundingBox.contains(tempMiddle)) || !useBoundingBox)
if ((useBoundingBox && boundingBox.contains(tempMiddle)) || !useBoundingBox)
{
scroll += point;
zoomImageScroll += point;
@ -109,28 +110,30 @@ namespace qmapcontrol
moveWidgets();
}
}
}
}
void LayerManager::moveWidgets()
{
QListIterator<Layer*> it(mylayers);
void LayerManager::moveWidgets()
{
QListIterator<Layer *> it(mylayers);
while (it.hasNext())
{
it.next()->moveWidgets(mapmiddle_px);
}
}
}
void LayerManager::setView(const QPointF& coordinate)
void LayerManager::setView(const QPointF &coordinate)
{
if (!layer())
{
if ( !layer() )
{
qDebug() << "LayerManager::setView() - cannot set view settings with no layers configured";
qDebug() << "LayerManager::setView() - cannot set view settings with no layers "
"configured";
return;
}
if ( !layer()->mapadapter() )
if (!layer()->mapadapter())
{
qDebug() << "LayerManager::setView() - cannot set view settings with no map adapter configured";
qDebug() << "LayerManager::setView() - cannot set view settings with no map "
"adapter configured";
return;
}
@ -138,30 +141,29 @@ namespace qmapcontrol
mapmiddle = coordinate;
newOffscreenImage(true, false);
}
}
void LayerManager::setView(QList<QPointF> coordinates)
{
void LayerManager::setView(QList<QPointF> coordinates)
{
setMiddle(coordinates);
mapcontrol->update();
}
}
void LayerManager::setViewAndZoomIn(const QList<QPointF> coordinates)
{
if ( !layer() )
void LayerManager::setViewAndZoomIn(const QList<QPointF> coordinates)
{
if (!layer())
{
qDebug() << "LayerManager::setViewAndZoomIn() - no layers configured";
return;
}
while (!containsAll(coordinates))
{
setMiddle(coordinates);
zoomOut();
// bugfix Tl
// if points are too close -> Loop of death...
if ( layer()->mapadapter()->currentZoom() == 0 )
if (layer()->mapadapter()->currentZoom() == 0)
{
qDebug() << "LayerManager::setViewAndZoomIn() - reached minium zoom level";
break;
@ -174,7 +176,7 @@ namespace qmapcontrol
zoomIn();
// bugfix Tl
// if points are too close -> Loop of death...
if ( layer()->mapadapter()->currentZoom() == 17 )
if (layer()->mapadapter()->currentZoom() == 17)
{
qDebug() << "LayerManager::setViewAndZoomIn() - reached maximum zoom level";
break;
@ -187,11 +189,11 @@ namespace qmapcontrol
}
mapcontrol->update();
}
}
void LayerManager::setMiddle(QList<QPointF> coordinates)
{
if ( !layer() )
void LayerManager::setMiddle(QList<QPointF> coordinates)
{
if (!layer())
{
qDebug() << "LayerManager::setMiddle() - no layers configured";
return;
@ -199,92 +201,95 @@ namespace qmapcontrol
int sum_x = 0;
int sum_y = 0;
for (int i=0; i<coordinates.size(); ++i)
for (int i = 0; i < coordinates.size(); ++i)
{
// mitte muss in px umgerechnet werden, da aufgrund der projektion die mittebestimmung aus koordinaten ungenau ist
// mitte muss in px umgerechnet werden, da aufgrund der projektion die
// mittebestimmung aus koordinaten ungenau ist
QPoint p = layer()->mapadapter()->coordinateToDisplay(coordinates.at(i));
sum_x += p.x();
sum_y += p.y();
}
QPointF middle = layer()->mapadapter()->displayToCoordinate(QPoint(sum_x/coordinates.size(), sum_y/coordinates.size()));
QPointF middle = layer()->mapadapter()->displayToCoordinate(
QPoint(sum_x / coordinates.size(), sum_y / coordinates.size()));
// middle in px rechnen!
setView(middle);
}
}
bool LayerManager::containsAll(QList<QPointF> coordinates) const
{
bool LayerManager::containsAll(QList<QPointF> coordinates) const
{
QRectF bb = getViewport();
bool containsall = true;
for (int i=0; i<coordinates.size(); ++i)
for (int i = 0; i < coordinates.size(); ++i)
{
if (!bb.contains(coordinates.at(i)))
return false;
}
return containsall;
}
}
QPoint LayerManager::getMapmiddle_px() const
{
QPoint LayerManager::getMapmiddle_px() const
{
return mapmiddle_px;
}
}
QRectF LayerManager::getViewport() const
{
if ( !layer() )
QRectF LayerManager::getViewport() const
{
if (!layer())
{
qDebug() << "LayerManager::getViewport() - no layers configured";
return QRectF();
}
QPoint upperLeft = QPoint(mapmiddle_px.x()-screenmiddle.x(), mapmiddle_px.y()+screenmiddle.y());
QPoint lowerRight = QPoint(mapmiddle_px.x()+screenmiddle.x(), mapmiddle_px.y()-screenmiddle.y());
QPoint upperLeft = QPoint(mapmiddle_px.x() - screenmiddle.x(),
mapmiddle_px.y() + screenmiddle.y());
QPoint lowerRight = QPoint(mapmiddle_px.x() + screenmiddle.x(),
mapmiddle_px.y() - screenmiddle.y());
QPointF ulCoord = layer()->mapadapter()->displayToCoordinate(upperLeft);
QPointF lrCoord = layer()->mapadapter()->displayToCoordinate(lowerRight);
QRectF coordinateBB = QRectF(ulCoord, QSizeF( (lrCoord-ulCoord).x(), (lrCoord-ulCoord).y()));
QRectF coordinateBB
= QRectF(ulCoord, QSizeF((lrCoord - ulCoord).x(), (lrCoord - ulCoord).y()));
return coordinateBB;
}
}
void LayerManager::addLayer(Layer* layer)
{
void LayerManager::addLayer(Layer *layer)
{
mylayers.append(layer);
layer->setSize(size);
//sanity check first
disconnect( layer, 0, this, 0 );
// sanity check first
disconnect(layer, 0, this, 0);
connect(layer, SIGNAL(updateRequest(QRectF)),
this, SLOT(updateRequest(QRectF)));
connect(layer, SIGNAL(updateRequest()),
this, SLOT(updateRequest()));
connect(layer, SIGNAL(updateRequest(QRectF)), this, SLOT(updateRequest(QRectF)));
connect(layer, SIGNAL(updateRequest()), this, SLOT(updateRequest()));
if (mylayers.size() > 0)
{
//setView(QPointF(0,0));
// setView(QPointF(0,0));
}
mapcontrol->update();
}
}
void LayerManager::removeLayer(Layer* layer)
void LayerManager::removeLayer(Layer *layer)
{
if (layer)
{
if ( layer )
{
disconnect( layer, 0, this, 0 );
disconnect(layer, 0, this, 0);
mylayers.removeAll(layer);
}
if (mylayers.size() > 0)
{
//setView(QPointF(0,0));
// setView(QPointF(0,0));
}
mapcontrol->update();
}
}
void LayerManager::newOffscreenImage(bool clearImage, bool showZoomImage)
{
void LayerManager::newOffscreenImage(bool clearImage, bool showZoomImage)
{
// qDebug() << "LayerManager::newOffscreenImage()";
whilenewscroll = mapmiddle_px;
@ -294,13 +299,14 @@ namespace qmapcontrol
}
QPainter painter(&composedOffscreenImage);
if (showZoomImage|| mapcontrol->getImageManager()->loadQueueSize() != 0)
if (showZoomImage || mapcontrol->getImageManager()->loadQueueSize() != 0)
{
painter.drawPixmap(screenmiddle.x()-zoomImageScroll.x(), screenmiddle.y()-zoomImageScroll.y(),zoomImage);
painter.drawPixmap(screenmiddle.x() - zoomImageScroll.x(),
screenmiddle.y() - zoomImageScroll.y(), zoomImage);
}
//only draw basemaps
foreach(const Layer* l, mylayers)
// only draw basemaps
foreach (const Layer *l, mylayers)
{
if (l->isVisible() && l->layertype() == Layer::MapLayer)
{
@ -308,45 +314,47 @@ namespace qmapcontrol
}
}
//stop the painter now that we've finished drawing
// stop the painter now that we've finished drawing
painter.end();
//composedOffscreenImage = composedOffscreenImage2;
scroll = mapmiddle_px-whilenewscroll;
// composedOffscreenImage = composedOffscreenImage2;
scroll = mapmiddle_px - whilenewscroll;
mapcontrol->update();
}
}
void LayerManager::zoomIn()
{
if ( !layer() )
void LayerManager::zoomIn()
{
if (!layer())
{
qDebug() << "LayerManager::zoomIn() - no layers configured";
return;
}
mapcontrol->getImageManager()->abortLoading();
//QCoreApplication::processEvents();
// QCoreApplication::processEvents();
// layer rendern abbrechen?
zoomImageScroll = QPoint(0,0);
zoomImageScroll = QPoint(0, 0);
zoomImage.fill(Qt::white);
QPixmap tmpImg = composedOffscreenImage.copy(screenmiddle.x()+scroll.x(),screenmiddle.y()+scroll.y(), size.width(), size.height());
QPixmap tmpImg = composedOffscreenImage.copy(screenmiddle.x() + scroll.x(),
screenmiddle.y() + scroll.y(),
size.width(), size.height());
QPainter painter(&zoomImage);
painter.translate(screenmiddle);
painter.scale(2, 2);
painter.translate(-screenmiddle);
painter.drawPixmap(0,0,tmpImg);
painter.drawPixmap(0, 0, tmpImg);
QListIterator<Layer*> it(mylayers);
//TODO: remove hack, that mapadapters wont get set zoom multiple times
QList<const MapAdapter*> doneadapters;
QListIterator<Layer *> it(mylayers);
// TODO: remove hack, that mapadapters wont get set zoom multiple times
QList<const MapAdapter *> doneadapters;
while (it.hasNext())
{
Layer* l = it.next();
Layer *l = it.next();
if (!doneadapters.contains(l->mapadapter()))
{
l->zoomIn();
@ -356,12 +364,12 @@ namespace qmapcontrol
mapmiddle_px = layer()->mapadapter()->coordinateToDisplay(mapmiddle);
whilenewscroll = mapmiddle_px;
newOffscreenImage(true, true); //show zoomed image while map loads
}
newOffscreenImage(true, true); // show zoomed image while map loads
}
bool LayerManager::checkOffscreen() const
{
if ( !layer() )
bool LayerManager::checkOffscreen() const
{
if (!layer())
{
qDebug() << "LayerManager::checkOffscreen() - no layers configured";
return true;
@ -380,36 +388,38 @@ namespace qmapcontrol
}
return true;
}
void LayerManager::zoomOut()
{
if ( !layer() )
}
void LayerManager::zoomOut()
{
if (!layer())
{
qDebug() << "LayerManager::zoomOut() - no layers configured";
return;
}
//QCoreApplication::processEvents();
// QCoreApplication::processEvents();
mapcontrol->getImageManager()->abortLoading();
zoomImageScroll = QPoint(0,0);
zoomImageScroll = QPoint(0, 0);
zoomImage.fill(Qt::white);
QPixmap tmpImg = composedOffscreenImage.copy(screenmiddle.x()+scroll.x(),screenmiddle.y()+scroll.y(), size.width(), size.height());
QPixmap tmpImg = composedOffscreenImage.copy(screenmiddle.x() + scroll.x(),
screenmiddle.y() + scroll.y(),
size.width(), size.height());
QPainter painter(&zoomImage);
painter.translate(screenmiddle);
painter.scale(0.500001,0.500001);
painter.scale(0.500001, 0.500001);
painter.translate(-screenmiddle);
painter.drawPixmap(0,0,tmpImg);
painter.drawPixmap(0, 0, tmpImg);
painter.translate(screenmiddle);
painter.scale(2,2);
painter.scale(2, 2);
painter.translate(-screenmiddle);
QListIterator<Layer*> it(mylayers);
//TODO: remove hack, that mapadapters wont get set zoom multiple times
QList<const MapAdapter*> doneadapters;
QListIterator<Layer *> it(mylayers);
// TODO: remove hack, that mapadapters wont get set zoom multiple times
QList<const MapAdapter *> doneadapters;
while (it.hasNext())
{
Layer* l = it.next();
Layer *l = it.next();
if (!doneadapters.contains(l->mapadapter()))
{
l->zoomOut();
@ -419,12 +429,12 @@ namespace qmapcontrol
mapmiddle_px = layer()->mapadapter()->coordinateToDisplay(mapmiddle);
whilenewscroll = mapmiddle_px;
newOffscreenImage(true, true); //show zoomed image while map loads
}
newOffscreenImage(true, true); // show zoomed image while map loads
}
void LayerManager::setZoom(int zoomlevel)
{
if ( !layer() )
void LayerManager::setZoom(int zoomlevel)
{
if (!layer())
{
qDebug() << "LayerManager::setZoom() - no layers configured";
return;
@ -437,166 +447,167 @@ namespace qmapcontrol
}
else
{
current_zoom = layer()->mapadapter()->minZoom() - layer()->mapadapter()->currentZoom();
current_zoom
= layer()->mapadapter()->minZoom() - layer()->mapadapter()->currentZoom();
}
if (zoomlevel < current_zoom)
{
for (int i=current_zoom; i>zoomlevel; --i)
for (int i = current_zoom; i > zoomlevel; --i)
{
zoomOut();
}
}
else
{
for (int i=current_zoom; i<zoomlevel; ++i)
for (int i = current_zoom; i < zoomlevel; ++i)
{
zoomIn();
}
}
}
}
void LayerManager::mouseEvent(const QMouseEvent* evnt)
{
if ( mapcontrol && !mapcontrol->mouseWheelEventsEnabled() )
void LayerManager::mouseEvent(const QMouseEvent *evnt)
{
if (mapcontrol && !mapcontrol->mouseWheelEventsEnabled())
{
return;
}
foreach( Layer* l, mylayers )
foreach (Layer *l, mylayers)
{
if (l && l->isVisible() )
if (l && l->isVisible())
{
l->mouseEvent(evnt, mapmiddle_px);
}
}
}
}
void LayerManager::updateRequest(QRectF rect)
{
if (getViewport().contains(rect.topLeft()) || getViewport().contains(rect.bottomRight()))
void LayerManager::updateRequest(QRectF rect)
{
if (getViewport().contains(rect.topLeft())
|| getViewport().contains(rect.bottomRight()))
{
// QPoint point = getLayer()->getMapAdapter()->coordinateToDisplay(c);
// const QPoint topleft = mapmiddle_px - screenmiddle;
// QPoint finalpoint = point-topleft;
// QRect rect_px = QRect(int(finalpoint.x()-(rect.width()-1)/2), int(finalpoint.y()-(rect.height()-1)/2),
// QRect rect_px = QRect(int(finalpoint.x()-(rect.width()-1)/2),
// int(finalpoint.y()-(rect.height()-1)/2),
// int(rect.width()+1), int(rect.height()+1));
//
// mapcontrol->updateRequest(rect_px);
newOffscreenImage(false, false);
}
}
void LayerManager::updateRequest()
{
}
void LayerManager::updateRequest()
{
newOffscreenImage(true, false);
}
void LayerManager::forceRedraw()
{
}
void LayerManager::forceRedraw()
{
newOffscreenImage(true, false);
}
void LayerManager::removeZoomImage()
{
}
void LayerManager::removeZoomImage()
{
zoomImage.fill(Qt::white);
forceRedraw();
}
}
void LayerManager::drawGeoms(QPainter* painter)
{
if ( !layer() )
void LayerManager::drawGeoms(QPainter *painter)
{
if (!layer())
{
qDebug() << "LayerManager::drawGeoms() - no layers configured";
return;
}
QListIterator<Layer*> it(mylayers);
QListIterator<Layer *> it(mylayers);
while (it.hasNext())
{
Layer* l = it.next();
Layer *l = it.next();
if (l->layertype() == Layer::GeometryLayer && l->isVisible())
{
l->drawYourGeometries(painter, mapmiddle_px, layer()->offscreenViewport());
}
}
}
void LayerManager::drawImage(QPainter* painter)
{
painter->drawPixmap(-scroll.x()-screenmiddle.x(),
-scroll.y()-screenmiddle.y(),
}
void LayerManager::drawImage(QPainter *painter)
{
painter->drawPixmap(-scroll.x() - screenmiddle.x(), -scroll.y() - screenmiddle.y(),
composedOffscreenImage);
}
}
int LayerManager::currentZoom() const
{
if ( !layer() )
int LayerManager::currentZoom() const
{
if (!layer())
{
qDebug() << "LayerManager::currentZoom() - no layers configured";
return 0;
}
return layer()->mapadapter()->currentZoom();
}
}
int LayerManager::minZoom()
{
if ( !layer() )
int LayerManager::minZoom()
{
if (!layer())
{
qDebug() << "LayerManager::minZoom() - no layers configured";
return 0;
}
return layer()->mapadapter()->minZoom();
}
}
int LayerManager::maxZoom()
{
if ( !layer() )
int LayerManager::maxZoom()
{
if (!layer())
{
qDebug() << "LayerManager::maxZoom() - no layers configured";
return 0;
}
return layer()->mapadapter()->maxZoom();
}
}
void LayerManager::resize(QSize newSize)
{
void LayerManager::resize(QSize newSize)
{
size = newSize;
offSize = newSize *2;
offSize = newSize * 2;
composedOffscreenImage = QPixmap(offSize);
zoomImage = QPixmap(newSize);
screenmiddle = QPoint(newSize.width()/2, newSize.height()/2);
screenmiddle = QPoint(newSize.width() / 2, newSize.height() / 2);
QListIterator<Layer*> it(mylayers);
QListIterator<Layer *> it(mylayers);
while (it.hasNext())
{
Layer* l = it.next();
Layer *l = it.next();
l->setSize(newSize);
}
forceRedraw();
}
}
void LayerManager::setUseBoundingBox( bool usebounds )
{
void LayerManager::setUseBoundingBox(bool usebounds)
{
useBoundingBox = usebounds;
}
}
bool LayerManager::isBoundingBoxEnabled()
{
bool LayerManager::isBoundingBoxEnabled()
{
return useBoundingBox;
}
}
void LayerManager::setBoundingBox( QRectF &rect )
{
if( rect.right() < rect.left() )
void LayerManager::setBoundingBox(QRectF &rect)
{
if (rect.right() < rect.left())
qDebug() << "LayerManager::setBoundingBox() - min longitude is bigger than max";
if( rect.top() < rect.bottom() )
if (rect.top() < rect.bottom())
qDebug() << "LayerManager::setBoundingBox() - min latitude is bigger than max";
boundingBox = rect;
}
QRectF LayerManager::getBoundingBox()
{
return boundingBox;
}
}
QRectF LayerManager::getBoundingBox()
{
return boundingBox;
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef LAYERMANAGER_H
#define LAYERMANAGER_H
@ -37,25 +37,26 @@
namespace qmapcontrol
{
class Layer;
class MapAdapter;
class MapControl;
class Layer;
class MapAdapter;
class MapControl;
class LayerManager;
class LayerManager;
//! Handles Layers and viewport related settings
/*!
//! Handles Layers and viewport related settings
/*!
* This class handles internally all layers which were added to the MapControl.
* It also stores values for scrolling.
* It initiates the creation of a new offscreen image and on zooming the zoom images gets here created.
* It initiates the creation of a new offscreen image and on zooming the zoom images gets
*here created.
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT LayerManager : public QObject
{
class QMAPCONTROL_EXPORT LayerManager : public QObject
{
Q_OBJECT
public:
LayerManager(MapControl*, QSize);
public:
LayerManager(MapControl *, QSize);
~LayerManager();
//! returns the coordinate of the center of the map
@ -75,7 +76,7 @@ namespace qmapcontrol
* @param layername name of the wanted layer
* @return the layer with the given name
*/
Layer* layer(const QString&) const;
Layer *layer(const QString &) const;
//! returns the base layer
/*!
@ -83,7 +84,7 @@ namespace qmapcontrol
* The base layer is the one which is used to do internal coordinate calculations.
* @return the base layer
*/
Layer* layer() const;
Layer *layer() const;
//! returns the names of all layers
/*!
@ -95,7 +96,7 @@ namespace qmapcontrol
/*!
* @param coordinate the coordinate which the view´s middle should be set to
*/
void setView(const QPointF& coordinate);
void setView(const QPointF &coordinate);
//! sets the view, so all coordinates are visible
/*!
@ -105,11 +106,11 @@ namespace qmapcontrol
//! sets the view and zooms in, so all coordinates are visible
/*!
* The code of setting the view to multiple coordinates is "brute force" and pretty slow.
* Have to be reworked.
* The code of setting the view to multiple coordinates is "brute force" and pretty
* slow. Have to be reworked.
* @param coordinates the Coorinates which should be visible
*/
void setViewAndZoomIn (const QList<QPointF> coordinates);
void setViewAndZoomIn(const QList<QPointF> coordinates);
//! zooms in one step
void zoomIn();
@ -141,7 +142,7 @@ namespace qmapcontrol
* Scrolls the view by the given value in pixels and in display coordinates
* @param offset the distance which the view should be scrolled
*/
void scrollView(const QPoint& offset);
void scrollView(const QPoint &offset);
//! forwards mouseevents to the layers
/*!
@ -149,7 +150,7 @@ namespace qmapcontrol
* These events are forwarded to the layers, so they can check for clicked geometries.
* @param evnt the mouse event
*/
void mouseEvent(const QMouseEvent* evnt);
void mouseEvent(const QMouseEvent *evnt);
//! returns the middle of the map in projection coordinates
/*!
@ -166,14 +167,14 @@ namespace qmapcontrol
* If multiple layers are added, they are painted in the added order.
* @param layer the layer which should be added
*/
void addLayer(Layer* layer);
void addLayer(Layer *layer);
//! removes a layer
/*!
* Removes a layer and redraws existing layers
* @param layer the layer which should be removed
*/
void removeLayer( Layer* layer );
void removeLayer(Layer *layer);
//! returns the current zoom level
/*!
@ -181,16 +182,15 @@ namespace qmapcontrol
*/
int currentZoom() const;
void drawGeoms(QPainter* painter);
void drawImage(QPainter* painter);
void drawGeoms(QPainter *painter);
void drawImage(QPainter *painter);
//! Set whether to enable a view bounding box
/*!
*
* @param usebounds enable/disable use of bounding box
*/
void setUseBoundingBox( bool usebounds );
void setUseBoundingBox(bool usebounds);
//! Check if bounding box is being used
/*!
@ -204,7 +204,7 @@ namespace qmapcontrol
*
* @param rect specified bounds for view to stay within
*/
void setBoundingBox( QRectF &rect );
void setBoundingBox(QRectF &rect);
//! Get current bounding box
/*!
@ -213,21 +213,21 @@ namespace qmapcontrol
*/
QRectF getBoundingBox();
private:
LayerManager& operator=(const LayerManager& rhs);
LayerManager(const LayerManager& old);
private:
LayerManager &operator=(const LayerManager &rhs);
LayerManager(const LayerManager &old);
//! This method have to be invoked to draw a new offscreen image
/*!
* @param clearImage if the current offscreeen image should be cleared
* @param showZoomImage if a zoom image should be painted
*/
void newOffscreenImage(bool clearImage=true, bool showZoomImage=true);
void newOffscreenImage(bool clearImage = true, bool showZoomImage = true);
inline bool checkOffscreen() const;
inline bool containsAll(QList<QPointF> coordinates) const;
inline void moveWidgets();
inline void setMiddle(QList<QPointF> coordinates);
MapControl* mapcontrol;
MapControl *mapcontrol;
QPoint screenmiddle; // middle of the screen
QPoint scroll; // scrollvalue of the offscreen image
QPoint zoomImageScroll; // scrollvalue of the zoom image
@ -238,7 +238,7 @@ namespace qmapcontrol
QPixmap composedOffscreenImage;
QPixmap zoomImage;
QList<Layer*> mylayers;
QList<Layer *> mylayers;
QPoint mapmiddle_px; // projection-display coordinates
QPointF mapmiddle; // world coordinate
@ -248,10 +248,10 @@ namespace qmapcontrol
QRectF boundingBox; // limit viewing area if desired
bool useBoundingBox;
public slots:
public slots:
void updateRequest(QRectF rect);
void updateRequest();
void resize(QSize newSize);
};
};
}
#endif

View File

@ -1,54 +1,54 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "linestring.h"
namespace qmapcontrol
{
LineString::LineString()
LineString::LineString()
: Curve()
{
{
GeometryType = "LineString";
}
}
LineString::LineString(QList<Point*> const points, QString name, QPen* pen)
:Curve(name)
{
LineString::LineString(QList<Point *> const points, QString name, QPen *pen)
: Curve(name)
{
mypen = pen;
LineString();
setPoints(points);
}
}
LineString::~LineString()
{
LineString::~LineString()
{
removePoints();
}
}
void LineString::removePoints()
{
QListIterator<Point*> iter(childPoints);
while(iter.hasNext())
void LineString::removePoints()
{
QListIterator<Point *> iter(childPoints);
while (iter.hasNext())
{
Point *pt = iter.next();
if (pt && pt->parentGeometry() == this)
@ -58,39 +58,40 @@ namespace qmapcontrol
}
}
childPoints.clear();
}
}
void LineString::addPoint(Point* point)
{
void LineString::addPoint(Point *point)
{
point->setParentGeometry(this);
childPoints.append(point);
}
}
QList<Point*> LineString::points()
{
QList<Point *> LineString::points()
{
return childPoints;
}
}
void LineString::setPoints(QList<Point*> points)
{
void LineString::setPoints(QList<Point *> points)
{
removePoints();
for (int i=0; i<points.size(); i++)
for (int i = 0; i < points.size(); i++)
{
points.at(i)->setParentGeometry(this);
}
childPoints = points;
}
}
void LineString::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset)
{
void LineString::draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &screensize, const QPoint offset)
{
if (!visible)
return;
QPolygon p = QPolygon();
QPointF c;
for (int i=0; i<childPoints.size(); i++)
for (int i = 0; i < childPoints.size(); i++)
{
c = childPoints[i]->coordinate();
p.append(mapadapter->coordinateToDisplay(c));
@ -105,24 +106,25 @@ namespace qmapcontrol
{
painter->restore();
}
for (int i=0; i<childPoints.size(); i++)
for (int i = 0; i < childPoints.size(); i++)
{
childPoints[i]->draw(painter, mapadapter, screensize, offset);
}
}
}
int LineString::numberOfPoints() const
{
int LineString::numberOfPoints() const
{
return childPoints.count();
}
}
bool LineString::Touches(Point* geom, const MapAdapter* mapadapter)
{
bool LineString::Touches(Point *geom, const MapAdapter *mapadapter)
{
touchedPoints.clear();
if (points().size() < 2)
{
// really shouldn't end up here since we always add atleast points to create a line
// really shouldn't end up here since we always add atleast points to create a
// line
return false;
}
@ -133,7 +135,7 @@ namespace qmapcontrol
qreal halfwidth = 2; // use 2 pixels by default
if (mypen && mypen->width() > 0)
{
halfwidth = static_cast<qreal> (mypen->width())/ static_cast<qreal> (2);
halfwidth = static_cast<qreal>(mypen->width()) / static_cast<qreal>(2);
}
QPointF pt1 = mapadapter->coordinateToDisplay(points().at(0)->coordinate());
@ -155,8 +157,7 @@ namespace qmapcontrol
qreal lowerRightX = qMax(pt1x1, qMax(pt1x2, qMax(pt2x1, pt2x2)));
qreal lowerRightY = qMax(pt1y1, qMax(pt1y2, qMax(pt2y1, pt2y2)));
QRectF bounds(QPointF(upperLeftX, upperLeftY),
QPointF(lowerRightX,lowerRightY));
QRectF bounds(QPointF(upperLeftX, upperLeftY), QPointF(lowerRightX, lowerRightY));
if (bounds.contains(clickPt))
{
@ -172,47 +173,51 @@ namespace qmapcontrol
if (touches)
{
emit(geometryClicked(this, QPoint(0,0)));
emit(geometryClicked(this, QPoint(0, 0)));
}
return touches;
}
}
bool LineString::Touches(Geometry* /*geom*/, const MapAdapter* /*mapadapter*/)
{
bool LineString::Touches(Geometry * /*geom*/, const MapAdapter * /*mapadapter*/)
{
touchedPoints.clear();
return false;
}
}
QList<Geometry*>& LineString::clickedPoints()
{
QList<Geometry *> &LineString::clickedPoints()
{
return Geometry::clickedPoints();
}
}
bool LineString::hasPoints() const
{
bool LineString::hasPoints() const
{
return childPoints.size() > 0 ? true : false;
}
}
bool LineString::hasClickedPoints() const
{
bool LineString::hasClickedPoints() const
{
return touchedPoints.size() > 0 ? true : false;
}
}
QRectF LineString::boundingBox()
QRectF LineString::boundingBox()
{
qreal minlon = 180;
qreal maxlon = -180;
qreal minlat = 90;
qreal maxlat = -90;
for (int i = 0; i < childPoints.size(); ++i)
{
qreal minlon=180;
qreal maxlon=-180;
qreal minlat=90;
qreal maxlat=-90;
for (int i=0; i<childPoints.size(); ++i)
{
Point* tmp = childPoints.at(i);
if (tmp->longitude() < minlon) minlon = tmp->longitude();
if (tmp->longitude() > maxlon) maxlon = tmp->longitude();
if (tmp->latitude() < minlat) minlat = tmp->latitude();
if (tmp->latitude() > maxlat) maxlat = tmp->latitude();
Point *tmp = childPoints.at(i);
if (tmp->longitude() < minlon)
minlon = tmp->longitude();
if (tmp->longitude() > maxlon)
maxlon = tmp->longitude();
if (tmp->latitude() < minlat)
minlat = tmp->latitude();
if (tmp->latitude() > maxlat)
maxlat = tmp->latitude();
}
QPointF min = QPointF(minlon, minlat);
QPointF max = QPointF(maxlon, maxlat);
@ -220,5 +225,5 @@ namespace qmapcontrol
QSizeF si = QSizeF(dist.x(), dist.y());
return QRectF(min, si);
}
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef LINESTRING_H
#define LINESTRING_H
@ -31,16 +31,17 @@
namespace qmapcontrol
{
//! A collection of Point objects to describe a line
/*!
* A LineString is a Curve with linear interpolation between Points. Each consecutive pair of Points defines a Line segment.
//! A collection of Point objects to describe a line
/*!
* A LineString is a Curve with linear interpolation between Points. Each consecutive pair
*of Points defines a Line segment.
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT LineString : public Curve
{
class QMAPCONTROL_EXPORT LineString : public Curve
{
Q_OBJECT
public:
public:
LineString();
//! constructor
/*!
@ -50,27 +51,27 @@ namespace qmapcontrol
* @param pen a QPen can be used to modify the look of the line.
* @see http://doc.trolltech.com/4.3/qpen.html
*/
LineString ( QList<Point*> const points, QString name = QString(), QPen* pen = 0 );
LineString(QList<Point *> const points, QString name = QString(), QPen *pen = 0);
virtual ~LineString();
//! returns the points of the LineString
/*!
* @return a list with the points of the LineString
*/
QList<Point*> points();
QList<Point *> points();
//! adds a point at the end of the LineString
/*!
* @param point the point which should be added to the LineString
*/
void addPoint ( Point* point );
void addPoint(Point *point);
//! sets the given list as points of the LineString
//! NOTE: these points will get reparented and cleaned up automatically
/*!
* @param points the points which should be set for the LineString
*/
void setPoints ( QList<Point*> points);
void setPoints(QList<Point *> points);
//! returns the number of Points the LineString consists of
/*!
@ -101,27 +102,29 @@ namespace qmapcontrol
//! returns the clicked Points
/*!
* If a LineString was clicked it could be neccessary to figure out which of its points where clicked.
* Do do so the methods hasPoints() and clickedPoints() can be used.
* When a point is added to a LineString the Point becomes its child.
* It is possible (depending on the zoomfactor) to click more than one Point of a LineString, so this method returns a list.
* If a LineString was clicked it could be neccessary to figure out which of its
* points where clicked. Do do so the methods hasPoints() and clickedPoints() can be
* used. When a point is added to a LineString the Point becomes its child. It is
* possible (depending on the zoomfactor) to click more than one Point of a
* LineString, so this method returns a list.
* @return the clicked Points of the LineString
*/
virtual QList<Geometry*> & clickedPoints();
virtual QList<Geometry *> &clickedPoints();
protected:
virtual bool Touches ( Geometry* geom, const MapAdapter* mapadapter );
virtual bool Touches ( Point* geom, const MapAdapter* mapadapter );
virtual void draw ( QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset );
protected:
virtual bool Touches(Geometry *geom, const MapAdapter *mapadapter);
virtual bool Touches(Point *geom, const MapAdapter *mapadapter);
virtual void draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &screensize, const QPoint offset);
private:
private:
//! removes cleans up memory of child points that were reparented with setPoints()
/*!
* @see setPoints()
*/
void removePoints();
QList<Point*> childPoints;
};
QList<Point *> childPoints;
};
}
#endif

View File

@ -1,90 +1,91 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "mapadapter.h"
namespace qmapcontrol
{
MapAdapter::MapAdapter(const QString& qHost, const QString& qServerPath, int qTilesize, int qMinZoom, int qMaxZoom)
:mTileSize(qTilesize), mMin_zoom(qMinZoom), mMax_zoom(qMaxZoom)
{
MapAdapter::MapAdapter(const QString &qHost, const QString &qServerPath, int qTilesize,
int qMinZoom, int qMaxZoom)
: mTileSize(qTilesize)
, mMin_zoom(qMinZoom)
, mMax_zoom(qMaxZoom)
{
mCurrent_zoom = qMinZoom;
changeHostAddress( qHost, qServerPath );
}
changeHostAddress(qHost, qServerPath);
}
MapAdapter::~MapAdapter()
{
}
MapAdapter::~MapAdapter() { }
void MapAdapter::changeHostAddress( const QString qHost, const QString qServerPath )
{
void MapAdapter::changeHostAddress(const QString qHost, const QString qServerPath)
{
mServerHost = qHost;
mServerPath = qServerPath;
}
QString MapAdapter::host() const
{
return mServerHost;
}
QString MapAdapter::serverPath() const
{
return mServerPath;
}
int MapAdapter::tilesize() const
{
return mTileSize;
}
int MapAdapter::minZoom() const
{
return mMin_zoom;
}
int MapAdapter::maxZoom() const
{
return mMax_zoom;
}
int MapAdapter::currentZoom() const
{
return mCurrent_zoom;
}
int MapAdapter::adaptedZoom() const
{
return mMax_zoom < mMin_zoom ? mMin_zoom - mCurrent_zoom : mCurrent_zoom;
}
void MapAdapter::setBoundingBox(qreal qMinX, qreal qMinY, qreal qMaxX, qreal qMaxY )
{
mBoundingBox = QRectF( QPointF( qMinX, qMinY ), QPointF(qMaxX, qMaxY ) );
}
int MapAdapter::tileSize()
{
return mTileSize;
}
}
QString MapAdapter::host() const
{
return mServerHost;
}
QString MapAdapter::serverPath() const
{
return mServerPath;
}
int MapAdapter::tilesize() const
{
return mTileSize;
}
int MapAdapter::minZoom() const
{
return mMin_zoom;
}
int MapAdapter::maxZoom() const
{
return mMax_zoom;
}
int MapAdapter::currentZoom() const
{
return mCurrent_zoom;
}
int MapAdapter::adaptedZoom() const
{
return mMax_zoom < mMin_zoom ? mMin_zoom - mCurrent_zoom : mCurrent_zoom;
}
void MapAdapter::setBoundingBox(qreal qMinX, qreal qMinY, qreal qMaxX, qreal qMaxY)
{
mBoundingBox = QRectF(QPointF(qMinX, qMinY), QPointF(qMaxX, qMaxY));
}
int MapAdapter::tileSize()
{
return mTileSize;
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef MAPADAPTER_H
#define MAPADAPTER_H
@ -38,28 +38,31 @@
namespace qmapcontrol
{
//! Used to fit map servers into QMapControl
/*!
//! Used to fit map servers into QMapControl
/*!
* MapAdapters are needed to convert between world- and display coordinates.
* This calculations depend on the used map projection.
* There are two ready-made MapAdapters:
* - TileMapAdapter, which is ready to use for OpenStreetMap or Google (Mercator projection)
* - WMSMapAdapter, which could be used for the most WMS-Server (some servers show errors, because of image ratio)
* - TileMapAdapter, which is ready to use for OpenStreetMap or Google (Mercator
* projection)
* - WMSMapAdapter, which could be used for the most WMS-Server (some servers show
* errors, because of image ratio)
*
* MapAdapters are also needed to form the HTTP-Queries to load the map tiles.
* The maps from WMS Servers are also divided into tiles, because those can be better cached.
* The maps from WMS Servers are also divided into tiles, because those can be better
* cached.
*
* @see TileMapAdapter, @see WMSMapAdapter
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapAdapter : public QObject
{
class QMAPCONTROL_EXPORT MapAdapter : public QObject
{
friend class Layer;
Q_OBJECT
public:
public:
virtual ~MapAdapter();
//! returns the host of this MapAdapter
@ -79,7 +82,8 @@ namespace qmapcontrol
* @param host the host address
* @param serverPath the server path
*/
virtual void changeHostAddress( const QString qHost, const QString qServerPath = QString() );
virtual void changeHostAddress(const QString qHost,
const QString qServerPath = QString());
//! returns the size of the tiles
/*!
@ -105,28 +109,30 @@ namespace qmapcontrol
*/
int currentZoom() const;
virtual int adaptedZoom()const;
virtual int adaptedZoom() const;
//! translates a world coordinate to display coordinate
/*!
* The calculations also needs the current zoom. The current zoom is managed by the MapAdapter, so this is no problem.
* To divide model from view the current zoom should be moved to the layers.
* The calculations also needs the current zoom. The current zoom is managed by the
* MapAdapter, so this is no problem. To divide model from view the current zoom
* should be moved to the layers.
* @param coordinate the world coordinate
* @return the display coordinate (in widget coordinates)
*/
virtual QPoint coordinateToDisplay(const QPointF& coordinate) const = 0;
virtual QPoint coordinateToDisplay(const QPointF &coordinate) const = 0;
//! translates display coordinate to world coordinate
/*!
* The calculations also needs the current zoom. The current zoom is managed by the MapAdapter, so this is no problem.
* To divide model from view the current zoom should be moved to the layers.
* The calculations also needs the current zoom. The current zoom is managed by the
* MapAdapter, so this is no problem. To divide model from view the current zoom
* should be moved to the layers.
* @param point the display coordinate
* @return the world coordinate
*/
virtual QPointF displayToCoordinate(const QPoint& point) const = 0;
virtual QPointF displayToCoordinate(const QPoint &point) const = 0;
QRectF getBoundingbox() const { return mBoundingBox; }
void setBoundingBox(qreal qMinX, qreal qMinY, qreal qMaxX, qreal qMaxY );
void setBoundingBox(qreal qMinX, qreal qMinY, qreal qMaxX, qreal qMaxY);
//! returns the tilesize for the mapadapter
/*!
@ -135,8 +141,9 @@ namespace qmapcontrol
*/
int tileSize();
protected:
MapAdapter(const QString& qHost, const QString& qServerPath, int qTilesize, int qMinZoom = 0, int qMaxZoom = 0);
protected:
MapAdapter(const QString &qHost, const QString &qServerPath, int qTilesize,
int qMinZoom = 0, int qMaxZoom = 0);
virtual void zoom_in() = 0;
virtual void zoom_out() = 0;
virtual bool isTileValid(int x, int y, int z) const = 0;
@ -173,6 +180,6 @@ namespace qmapcontrol
qreal mNumberOfTiles;
QLocale loc;
QRectF mBoundingBox;
};
};
}
#endif

View File

@ -1,165 +1,166 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "mapcontrol.h"
#include <QTimer>
namespace qmapcontrol
{
MapControl::MapControl (QWidget * parent, Qt::WindowFlags windowFlags)
: QFrame( parent, windowFlags ),
m_layermanager(0),
m_imagemanager(0),
size(100,100),
mouse_wheel_events(true),
mousepressed(false),
mymousemode(Panning),
scaleVisible(false),
crosshairsVisible(true),
m_loadingFlag(false),
steps(0),
m_doubleBuffer(0)
{
MapControl::MapControl(QWidget *parent, Qt::WindowFlags windowFlags)
: QFrame(parent, windowFlags)
, m_layermanager(0)
, m_imagemanager(0)
, size(100, 100)
, mouse_wheel_events(true)
, mousepressed(false)
, mymousemode(Panning)
, scaleVisible(false)
, crosshairsVisible(true)
, m_loadingFlag(false)
, steps(0)
, m_doubleBuffer(0)
{
__init();
}
}
MapControl::MapControl(QSize size, MouseMode mousemode, bool showScale, bool showCrosshairs, QWidget * parent, Qt::WindowFlags windowFlags)
: QFrame( parent, windowFlags ),
m_layermanager(0),
m_imagemanager(0),
size(size),
mouse_wheel_events(true),
mousepressed(false),
mymousemode(mousemode),
scaleVisible(showScale),
crosshairsVisible(showCrosshairs),
m_loadingFlag(false),
steps(0),
m_doubleBuffer(0)
{
MapControl::MapControl(QSize size, MouseMode mousemode, bool showScale,
bool showCrosshairs, QWidget *parent, Qt::WindowFlags windowFlags)
: QFrame(parent, windowFlags)
, m_layermanager(0)
, m_imagemanager(0)
, size(size)
, mouse_wheel_events(true)
, mousepressed(false)
, mymousemode(mousemode)
, scaleVisible(showScale)
, crosshairsVisible(showCrosshairs)
, m_loadingFlag(false)
, steps(0)
, m_doubleBuffer(0)
{
__init();
}
}
MapControl::~MapControl()
{
if ( m_layermanager )
MapControl::~MapControl()
{
if (m_layermanager)
{
m_layermanager->deleteLater();
m_layermanager = 0;
}
if ( m_imagemanager )
if (m_imagemanager)
{
m_imagemanager->deleteLater();
m_imagemanager = 0;
}
}
}
void MapControl::__init()
{
void MapControl::__init()
{
m_layermanager = new LayerManager(this, size);
m_imagemanager = new ImageManager(this);
screen_middle = QPoint(size.width()/2, size.height()/2);
screen_middle = QPoint(size.width() / 2, size.height() / 2);
mousepressed = false;
connect(m_imagemanager, SIGNAL(imageReceived()),
this, SLOT(updateRequestNew()));
connect(m_imagemanager, SIGNAL(imageReceived()), this, SLOT(updateRequestNew()));
connect(m_imagemanager, SIGNAL(loadingFinished()),
this, SLOT(loadingFinished()));
connect(m_imagemanager, SIGNAL(loadingFinished()), this, SLOT(loadingFinished()));
this->setMaximumSize(size.width()+1, size.height()+1);
this->setMaximumSize(size.width() + 1, size.height() + 1);
mouse_wheel_events = true;
}
}
void MapControl::enableMouseWheelEvents( bool enabled )
{
void MapControl::enableMouseWheelEvents(bool enabled)
{
mouse_wheel_events = enabled;
}
}
bool MapControl::mouseWheelEventsEnabled()
{
bool MapControl::mouseWheelEventsEnabled()
{
return mouse_wheel_events;
}
}
QPointF MapControl::currentCoordinate() const
{
QPointF MapControl::currentCoordinate() const
{
return m_layermanager->currentCoordinate();
}
}
Layer* MapControl::layer(const QString& layername) const
{
Layer *MapControl::layer(const QString &layername) const
{
return m_layermanager->layer(layername);
}
}
QList<QString> MapControl::layers() const
{
QList<QString> MapControl::layers() const
{
return m_layermanager->layers();
}
}
int MapControl::numberOfLayers() const
{
int MapControl::numberOfLayers() const
{
return m_layermanager->layers().size();
}
}
void MapControl::followGeometry(const Geometry* geom) const
{
if ( geom == 0 )
void MapControl::followGeometry(const Geometry *geom) const
{
if (geom == 0)
{
return;
}
//ensures only one signal is ever connected
// ensures only one signal is ever connected
stopFollowing(geom);
connect(geom, SIGNAL(positionChanged(Geometry*)),
this, SLOT(positionChanged(Geometry*)));
}
connect(geom, SIGNAL(positionChanged(Geometry *)), this,
SLOT(positionChanged(Geometry *)));
}
void MapControl::positionChanged(Geometry* geom)
{
if ( !m_layermanager->layer() || !m_layermanager->layer()->mapadapter() )
void MapControl::positionChanged(Geometry *geom)
{
if (!m_layermanager->layer() || !m_layermanager->layer()->mapadapter())
{
qDebug() << "MapControl::positionChanged() - no layers configured";
return;
}
Point* point = dynamic_cast<Point*>(geom);
if (point!=0)
Point *point = dynamic_cast<Point *>(geom);
if (point != 0)
{
QPoint start = m_layermanager->layer()->mapadapter()->coordinateToDisplay(currentCoordinate());
QPoint dest = m_layermanager->layer()->mapadapter()->coordinateToDisplay(point->coordinate());
QPoint step = (dest-start);
QPoint start = m_layermanager->layer()->mapadapter()->coordinateToDisplay(
currentCoordinate());
QPoint dest = m_layermanager->layer()->mapadapter()->coordinateToDisplay(
point->coordinate());
QPoint step = (dest - start);
m_layermanager->scrollView(step);
updateRequestNew();
}
}
}
void MapControl::moveTo(QPointF coordinate)
{
void MapControl::moveTo(QPointF coordinate)
{
target = coordinate;
steps = 25;
if (moveMutex.tryLock())
@ -171,25 +172,26 @@ namespace qmapcontrol
// stopMove(coordinate);
moveMutex.unlock();
}
}
void MapControl::tick()
{
if ( !m_layermanager->layer() || !m_layermanager->layer()->mapadapter() )
}
void MapControl::tick()
{
if (!m_layermanager->layer() || !m_layermanager->layer()->mapadapter())
{
qDebug() << "MapControl::tick() - no layers configured";
return;
}
QPoint start = m_layermanager->layer()->mapadapter()->coordinateToDisplay(currentCoordinate());
QPoint start
= m_layermanager->layer()->mapadapter()->coordinateToDisplay(currentCoordinate());
QPoint dest = m_layermanager->layer()->mapadapter()->coordinateToDisplay(target);
QPoint step = (dest-start)/steps;
QPoint step = (dest - start) / steps;
m_layermanager->scrollView(step);
update();
m_layermanager->updateRequest();
steps--;
if (steps>0)
if (steps > 0)
{
QTimer::singleShot(50, this, SLOT(tick()));
}
@ -197,18 +199,18 @@ namespace qmapcontrol
{
moveMutex.unlock();
}
}
}
void MapControl::paintEvent(QPaintEvent* evnt)
{
void MapControl::paintEvent(QPaintEvent *evnt)
{
Q_UNUSED(evnt);
if ( m_doubleBuffer == 0 )
if (m_doubleBuffer == 0)
{
m_doubleBuffer = new QPixmap(width(), height());
}
//check for resize change
else if ( m_doubleBuffer->width() != width() || m_doubleBuffer->height() != height() )
// check for resize change
else if (m_doubleBuffer->width() != width() || m_doubleBuffer->height() != height())
{
delete m_doubleBuffer;
m_doubleBuffer = new QPixmap(width(), height());
@ -226,34 +228,40 @@ namespace qmapcontrol
static QList<double> distanceList;
if (distanceList.isEmpty())
{
distanceList<<5000000<<2000000<<1000000<<1000000<<1000000<<100000<<100000<<50000<<50000<<10000<<10000<<10000<<1000<<1000<<500<<200<<100<<50<<25;
distanceList << 5000000 << 2000000 << 1000000 << 1000000 << 1000000 << 100000
<< 100000 << 50000 << 50000 << 10000 << 10000 << 10000 << 1000
<< 1000 << 500 << 200 << 100 << 50 << 25;
}
if (currentZoom() >= m_layermanager->minZoom() && distanceList.size() > currentZoom())
if (currentZoom() >= m_layermanager->minZoom()
&& distanceList.size() > currentZoom())
{
double line;
line = distanceList.at( currentZoom() ) / pow(2.0, 18-currentZoom() ) / 0.597164;
line = distanceList.at(currentZoom()) / pow(2.0, 18 - currentZoom())
/ 0.597164;
// draw the scale
dbPainter.setPen(Qt::black);
QPoint p1(10,size.height()-20);
QPoint p2((int)line,size.height()-20);
dbPainter.drawLine(p1,p2);
QPoint p1(10, size.height() - 20);
QPoint p2((int)line, size.height() - 20);
dbPainter.drawLine(p1, p2);
dbPainter.drawLine(10,size.height()-15, 10,size.height()-25);
dbPainter.drawLine((int)line,size.height()-15, (int)line,size.height()-25);
dbPainter.drawLine(10, size.height() - 15, 10, size.height() - 25);
dbPainter.drawLine((int)line, size.height() - 15, (int)line,
size.height() - 25);
QString distance;
if (distanceList.at(currentZoom()) >= 1000)
{
distance = QVariant( distanceList.at(currentZoom())/1000 ) .toString()+ " km";
distance
= QVariant(distanceList.at(currentZoom()) / 1000).toString() + " km";
}
else
{
distance = QVariant( distanceList.at(currentZoom()) ).toString() + " m";
distance = QVariant(distanceList.at(currentZoom())).toString() + " m";
}
dbPainter.drawText(QPoint((int)line+10,size.height()-15), distance);
dbPainter.drawText(QPoint((int)line + 10, size.height() - 15), distance);
}
}
@ -261,15 +269,15 @@ namespace qmapcontrol
{
auto oldPen = dbPainter.pen();
dbPainter.setPen(QPen(QBrush(QColor(255, 0, 0)), 1));
dbPainter.drawLine(screen_middle.x(), screen_middle.y()-15,
screen_middle.x(), screen_middle.y()+15); // |
dbPainter.drawLine(screen_middle.x()-15, screen_middle.y(),
screen_middle.x()+15, screen_middle.y()); // -
dbPainter.drawLine(screen_middle.x(), screen_middle.y() - 15, screen_middle.x(),
screen_middle.y() + 15); // |
dbPainter.drawLine(screen_middle.x() - 15, screen_middle.y(),
screen_middle.x() + 15, screen_middle.y()); // -
dbPainter.drawEllipse(screen_middle.x() - 10, screen_middle.y() - 10, 20, 20);
dbPainter.setPen(oldPen);
}
dbPainter.drawRect(0,0, size.width(), size.height());
dbPainter.drawRect(0, 0, size.width(), size.height());
if (mousepressed && mymousemode == Dragging)
{
@ -278,32 +286,30 @@ namespace qmapcontrol
}
dbPainter.end();
QPainter painter;
painter.begin( this );
painter.drawPixmap( rect(), *m_doubleBuffer, m_doubleBuffer->rect() );
painter.begin(this);
painter.drawPixmap(rect(), *m_doubleBuffer, m_doubleBuffer->rect());
painter.end();
}
}
// mouse events
void MapControl::mousePressEvent(QMouseEvent* evnt)
{
// mouse events
void MapControl::mousePressEvent(QMouseEvent *evnt)
{
m_layermanager->mouseEvent(evnt);
if (m_layermanager->layers().size()>0)
if (m_layermanager->layers().size() > 0)
{
if (evnt->button() == 1)
{
mousepressed = true;
pre_click_px = QPoint(evnt->x(), evnt->y());
}
else if ( evnt->button() == 2 &&
mouseWheelEventsEnabled() &&
mymousemode != None) // zoom in
else if (evnt->button() == 2 && mouseWheelEventsEnabled()
&& mymousemode != None) // zoom in
{
zoomIn();
}
else if ( evnt->button() == 4 &&
mouseWheelEventsEnabled() &&
mymousemode != None) // zoom out
else if (evnt->button() == 4 && mouseWheelEventsEnabled()
&& mymousemode != None) // zoom out
{
zoomOut();
}
@ -311,26 +317,27 @@ namespace qmapcontrol
// emit(mouseEvent(evnt));
emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos())));
}
}
void MapControl::mouseReleaseEvent(QMouseEvent* evnt)
{
void MapControl::mouseReleaseEvent(QMouseEvent *evnt)
{
mousepressed = false;
if (mymousemode == Dragging)
{
QPointF ulCoord = clickToWorldCoordinate(pre_click_px);
QPointF lrCoord = clickToWorldCoordinate(current_mouse_pos);
QRectF coordinateBB = QRectF(ulCoord, QSizeF( (lrCoord-ulCoord).x(), (lrCoord-ulCoord).y()));
QRectF coordinateBB
= QRectF(ulCoord, QSizeF((lrCoord - ulCoord).x(), (lrCoord - ulCoord).y()));
emit(boxDragged(coordinateBB));
}
emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos())));
}
}
void MapControl::mouseMoveEvent(QMouseEvent* evnt)
{
void MapControl::mouseMoveEvent(QMouseEvent *evnt)
{
if (mousepressed && mymousemode == Panning)
{
QPoint offset = pre_click_px - QPoint(evnt->x(), evnt->y());
@ -343,10 +350,10 @@ namespace qmapcontrol
}
update();
}
}
void MapControl::wheelEvent(QWheelEvent *evnt)
{
void MapControl::wheelEvent(QWheelEvent *evnt)
{
/*if(mouse_wheel_events && evnt->angleDelta() )
{
if(evnt->delta() > 0)
@ -373,239 +380,242 @@ namespace qmapcontrol
{
evnt->ignore();
}*/
}
}
ImageManager* MapControl::getImageManager()
{
ImageManager *MapControl::getImageManager()
{
return m_imagemanager;
}
}
QPointF MapControl::clickToWorldCoordinate(QPoint click)
{
if ( !m_layermanager->layer() || !m_layermanager->layer()->mapadapter() )
QPointF MapControl::clickToWorldCoordinate(QPoint click)
{
if (!m_layermanager->layer() || !m_layermanager->layer()->mapadapter())
{
qDebug() << "MapControl::clickToWorldCoordinate() - no layers configured";
return QPointF();
}
// click coordinate to image coordinate
QPoint displayToImage= QPoint(click.x()-screen_middle.x()+m_layermanager->getMapmiddle_px().x(),
click.y()-screen_middle.y()+m_layermanager->getMapmiddle_px().y());
QPoint displayToImage
= QPoint(click.x() - screen_middle.x() + m_layermanager->getMapmiddle_px().x(),
click.y() - screen_middle.y() + m_layermanager->getMapmiddle_px().y());
// image coordinate to world coordinate
return m_layermanager->layer()->mapadapter()->displayToCoordinate(displayToImage);
}
}
void MapControl::updateRequest(QRect rect)
{
void MapControl::updateRequest(QRect rect)
{
update(rect);
}
}
void MapControl::updateRequestNew()
{
void MapControl::updateRequestNew()
{
m_layermanager->forceRedraw();
}
}
// slots
void MapControl::zoomIn()
{
// slots
void MapControl::zoomIn()
{
m_layermanager->zoomIn();
updateView();
emit viewChanged(currentCoordinate(), currentZoom());
}
}
void MapControl::zoomOut()
{
void MapControl::zoomOut()
{
m_layermanager->zoomOut();
updateView();
emit viewChanged(currentCoordinate(), currentZoom());
}
}
void MapControl::setZoom(int zoomlevel)
{
void MapControl::setZoom(int zoomlevel)
{
m_layermanager->setZoom(zoomlevel);
updateView();
emit viewChanged(currentCoordinate(), currentZoom());
}
}
int MapControl::currentZoom() const
{
int MapControl::currentZoom() const
{
return m_layermanager->currentZoom();
}
}
void MapControl::scrollLeft(int pixel)
{
m_layermanager->scrollView(QPoint(-pixel,0));
void MapControl::scrollLeft(int pixel)
{
m_layermanager->scrollView(QPoint(-pixel, 0));
updateView();
}
}
void MapControl::scrollRight(int pixel)
{
m_layermanager->scrollView(QPoint(pixel,0));
void MapControl::scrollRight(int pixel)
{
m_layermanager->scrollView(QPoint(pixel, 0));
updateView();
}
}
void MapControl::scrollUp(int pixel)
{
m_layermanager->scrollView(QPoint(0,-pixel));
void MapControl::scrollUp(int pixel)
{
m_layermanager->scrollView(QPoint(0, -pixel));
updateView();
}
}
void MapControl::scrollDown(int pixel)
{
m_layermanager->scrollView(QPoint(0,pixel));
void MapControl::scrollDown(int pixel)
{
m_layermanager->scrollView(QPoint(0, pixel));
updateView();
}
}
void MapControl::scroll(const QPoint scroll)
{
void MapControl::scroll(const QPoint scroll)
{
m_layermanager->scrollView(scroll);
updateView();
}
}
void MapControl::updateView() const
{
m_layermanager->setView( currentCoordinate() );
void MapControl::updateView() const
{
m_layermanager->setView(currentCoordinate());
emit viewChanged(currentCoordinate(), currentZoom());
}
}
void MapControl::setView(const QPointF& coordinate) const
{
void MapControl::setView(const QPointF &coordinate) const
{
m_layermanager->setView(coordinate);
emit viewChanged(currentCoordinate(), currentZoom());
}
}
void MapControl::setView(const QList<QPointF> coordinates) const
{
void MapControl::setView(const QList<QPointF> coordinates) const
{
m_layermanager->setView(coordinates);
emit viewChanged(currentCoordinate(), currentZoom());
}
}
void MapControl::setViewAndZoomIn(const QList<QPointF> coordinates) const
{
void MapControl::setViewAndZoomIn(const QList<QPointF> coordinates) const
{
m_layermanager->setViewAndZoomIn(coordinates);
emit viewChanged(currentCoordinate(), currentZoom());
}
}
void MapControl::setView(const Point* point) const
{
void MapControl::setView(const Point *point) const
{
m_layermanager->setView(point->coordinate());
}
}
void MapControl::loadingFinished()
{
void MapControl::loadingFinished()
{
m_layermanager->removeZoomImage();
}
}
void MapControl::addLayer(Layer* layer)
{
void MapControl::addLayer(Layer *layer)
{
layer->setImageManager(m_imagemanager);
m_layermanager->addLayer(layer);
update();
}
}
void MapControl::removeLayer( Layer* layer )
{
void MapControl::removeLayer(Layer *layer)
{
disconnect(layer, 0, 0, 0);
m_layermanager->removeLayer( layer );
m_layermanager->removeLayer(layer);
update();
}
}
void MapControl::setMouseMode(MouseMode mousemode)
{
void MapControl::setMouseMode(MouseMode mousemode)
{
mymousemode = mousemode;
}
}
MapControl::MouseMode MapControl::mouseMode()
{
MapControl::MouseMode MapControl::mouseMode()
{
return mymousemode;
}
}
void MapControl::stopFollowing(const Geometry* geom) const
{
disconnect(geom,SIGNAL(positionChanged(Geometry*)), this, SLOT(positionChanged(Geometry*)));
}
void MapControl::stopFollowing(const Geometry *geom) const
{
disconnect(geom, SIGNAL(positionChanged(Geometry *)), this,
SLOT(positionChanged(Geometry *)));
}
void MapControl::enablePersistentCache( const QDir& path, const int qDiskSizeMB )
{
m_imagemanager->setCacheDir( path, qDiskSizeMB );
}
void MapControl::enablePersistentCache(const QDir &path, const int qDiskSizeMB)
{
m_imagemanager->setCacheDir(path, qDiskSizeMB);
}
void MapControl::setProxy(QString host, int port, const QString username, const QString password)
{
void MapControl::setProxy(QString host, int port, const QString username,
const QString password)
{
m_imagemanager->setProxy(host, port, username, password);
}
}
void MapControl::showScale(bool visible)
{
void MapControl::showScale(bool visible)
{
scaleVisible = visible;
}
}
void MapControl::showCrosshairs(bool visible)
{
void MapControl::showCrosshairs(bool visible)
{
crosshairsVisible = visible;
}
}
void MapControl::resize(const QSize newSize)
{
void MapControl::resize(const QSize newSize)
{
this->size = newSize;
screen_middle = QPoint(newSize.width()/2, newSize.height()/2);
screen_middle = QPoint(newSize.width() / 2, newSize.height() / 2);
this->setMaximumSize(newSize.width()+1, newSize.height()+1);
this->setMaximumSize(newSize.width() + 1, newSize.height() + 1);
m_layermanager->resize(newSize);
QFrame::resize(newSize);
emit viewChanged(currentCoordinate(), currentZoom());
}
}
void MapControl::setUseBoundingBox( bool usebounds )
{
if( m_layermanager )
m_layermanager->setUseBoundingBox( usebounds );
}
void MapControl::setUseBoundingBox(bool usebounds)
{
if (m_layermanager)
m_layermanager->setUseBoundingBox(usebounds);
}
bool MapControl::isBoundingBoxEnabled()
{
if( m_layermanager )
bool MapControl::isBoundingBoxEnabled()
{
if (m_layermanager)
return m_layermanager->isBoundingBoxEnabled();
return false;
}
}
void MapControl::setBoundingBox( QRectF &rect )
{
if( m_layermanager )
m_layermanager->setBoundingBox( rect );
}
void MapControl::setBoundingBox(QRectF &rect)
{
if (m_layermanager)
m_layermanager->setBoundingBox(rect);
}
QRectF MapControl::getBoundingBox()
{
if( m_layermanager )
QRectF MapControl::getBoundingBox()
{
if (m_layermanager)
return m_layermanager->getBoundingBox();
// Return an empty QRectF if there is no m_layermanager
return QRectF();
}
}
QRectF MapControl::getViewport()
{
if( m_layermanager )
QRectF MapControl::getViewport()
{
if (m_layermanager)
return m_layermanager->getViewport();
// Return an empty QRectF if there is no m_layermanager
return QRectF();
}
}
bool MapControl::isGeometryVisible( Geometry * geometry)
{
if ( !geometry || getViewport() == QRectF() )
bool MapControl::isGeometryVisible(Geometry *geometry)
{
if (!geometry || getViewport() == QRectF())
return false;
return getViewport().contains( geometry->boundingBox() );
}
return getViewport().contains(geometry->boundingBox());
}
int MapControl::loadingQueueSize()
{
int MapControl::loadingQueueSize()
{
return m_imagemanager->loadQueueSize();
}
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef MAPCONTROL_H
#define MAPCONTROL_H
@ -40,24 +40,25 @@
//! QMapControl namespace
namespace qmapcontrol
{
class LayerManager;
class MapAdapter;
class Layer;
class LayerManager;
class MapAdapter;
class Layer;
//! The control element of the widget and also the widget itself
/*!
//! The control element of the widget and also the widget itself
/*!
* This is the main widget.
* To this control layers can be added.
* A MapControl has to be instantiated with a QSize which sets the size the widget takes in a layout.
* The given size is also the size which is assured to be filled with map images.
* A MapControl has to be instantiated with a QSize which sets the size the widget takes
* in a layout. The given size is also the size which is assured to be filled with map
* images.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapControl : public QFrame
{
class QMAPCONTROL_EXPORT MapControl : public QFrame
{
Q_OBJECT
public:
public:
//! Declares what actions mouse movements have on the map
enum MouseMode
{
@ -71,16 +72,17 @@ namespace qmapcontrol
* @param qParent QWidget parent
* @param windowFlags QWidget Window flags
*/
MapControl (QWidget * parent = 0, Qt::WindowFlags windowFlags = Qt::WindowFlags());
MapControl(QWidget *parent = 0, Qt::WindowFlags windowFlags = Qt::WindowFlags());
//! The constructor of MapControl
/*!
* The MapControl is the widget which displays the maps.
* The size describes the area which gets filled with map data
* When you give no MouseMode, the mouse moves the map.
* You can change the MouseMode at runtime, e.g. to Dragging, which lets the user drag a rectangular box.
* After the dragging a signal with the size of the box is emitted.
* The MouseMode ´None´ can be used, to completely define the control of the map yourself.
* You can change the MouseMode at runtime, e.g. to Dragging, which lets the user drag
* a rectangular box. After the dragging a signal with the size of the box is emitted.
* The MouseMode ´None´ can be used, to completely define the control of the map
* yourself.
* @param size the size which the widget should fill with map data
* @param mousemode the way mouse events are handled
* @param showScale true if the scale should be displayed
@ -88,7 +90,9 @@ namespace qmapcontrol
* @param parent QWidget parent
* @param windowFlags QWidget Window flags
*/
MapControl ( QSize size, MouseMode mousemode = Panning, bool showScale = false, bool showCrosshairs = true, QWidget * parent = 0, Qt::WindowFlags windowFlags = Qt::WindowFlags());
MapControl(QSize size, MouseMode mousemode = Panning, bool showScale = false,
bool showCrosshairs = true, QWidget *parent = 0,
Qt::WindowFlags windowFlags = Qt::WindowFlags());
~MapControl();
@ -97,21 +101,21 @@ namespace qmapcontrol
* If multiple layers are added, they are painted in the added order.
* @param layer the layer which should be added
*/
void addLayer ( Layer* layer );
void addLayer(Layer *layer);
//! removes a layer
/*!
* Removes a layer and redraws existing layers
* @param layer the layer which should be removed
*/
void removeLayer ( Layer* layer );
void removeLayer(Layer *layer);
//! returns the layer with the given name
/*!
* @param layername name of the wanted layer
* @return the layer with the given name
*/
Layer* layer ( const QString& layername ) const;
Layer *layer(const QString &layername) const;
//! returns the names of all layers
/*!
@ -144,7 +148,7 @@ namespace qmapcontrol
/*!
* @parm enable mouse event
*/
void enableMouseWheelEvents( bool enabled = true );
void enableMouseWheelEvents(bool enabled = true);
//! returns mouse wheel allowed
/*!
@ -156,37 +160,37 @@ namespace qmapcontrol
/*!
* @param coordinate the coordinate which the view´s middle should be set to
*/
void setView ( const QPointF& coordinate ) const;
void setView(const QPointF &coordinate) const;
//! sets the view, so all coordinates are visible
/*!
* @param coordinates the Coorinates which should be visible
*/
void setView ( const QList<QPointF> coordinates ) const;
void setView(const QList<QPointF> coordinates) const;
//! sets the view and zooms in, so all coordinates are visible
/*!
* The code of setting the view to multiple coordinates is "brute force" and pretty slow.
* Have to be reworked.
* The code of setting the view to multiple coordinates is "brute force" and pretty
* slow. Have to be reworked.
* @param coordinates the Coorinates which should be visible
*/
void setViewAndZoomIn ( const QList<QPointF> coordinates ) const;
void setViewAndZoomIn(const QList<QPointF> coordinates) const;
//! sets the view to the given Point
/*!
*
* @param point the geometric point the view should be set to
*/
void setView ( const Point* point ) const;
void setView(const Point *point) const;
//! Keeps the center of the map on the Geometry, even when it moves
/*!
* To stop the following the method stopFollowing() have to be called
* @param geometry the Geometry which should stay centered.
*/
void followGeometry ( const Geometry* geometry ) const;
void followGeometry(const Geometry *geometry) const;
//TODO:
// TODO:
// void followGeometry(const QList<Geometry*>) const;
//! Stops the following of a Geometry
@ -195,24 +199,24 @@ namespace qmapcontrol
* See followGeometry().
* @param geometry the Geometry which should not followed anymore
*/
void stopFollowing ( const Geometry* geometry ) const;
void stopFollowing(const Geometry *geometry) const;
//! Smoothly moves the center of the view to the given Coordinate
/*!
* @param coordinate the Coordinate which the center of the view should moved to
*/
void moveTo ( QPointF coordinate );
void moveTo(QPointF coordinate);
//! sets the Mouse Mode of the MapControl
/*!
* There are three MouseModes declard by an enum.
* The MouesMode Dragging draws an rectangular in the map while the MouseButton is pressed.
* When the Button is released a boxDragged() signal is emitted.
* The MouesMode Dragging draws an rectangular in the map while the MouseButton is
* pressed. When the Button is released a boxDragged() signal is emitted.
*
* The second MouseMode (the default) is Panning, which allows to drag the map around.
* @param mousemode the MouseMode
*/
void setMouseMode ( MouseMode mousemode );
void setMouseMode(MouseMode mousemode);
//! returns the current MouseMode
/*!
@ -228,9 +232,11 @@ namespace qmapcontrol
* Tiles are stored in the subdirectory "QMapControl.cache" within the
* user's home directory. This can be changed by giving a path.
* @param path the path to the cache directory
* @param tileExpiry how long to keep in cache before requesting a new image. 0 or -1 to disable and keep forever
* @param tileExpiry how long to keep in cache before requesting a new image. 0 or -1
* to disable and keep forever
*/
void enablePersistentCache ( const QDir& path= QDir::homePath() + "/QMapControl.cache", const int qDiskSizeMB = 250 );
void enablePersistentCache(const QDir &path = QDir::homePath() + "/QMapControl.cache",
const int qDiskSizeMB = 250);
//! Sets the proxy for HTTP connections
/*!
@ -241,23 +247,24 @@ namespace qmapcontrol
* @param username the proxy´s username
* @param password the proxy´s password
*/
void setProxy(QString host, int port, const QString username = QString(), const QString password = QString());
void setProxy(QString host, int port, const QString username = QString(),
const QString password = QString());
//! Displays the scale within the widget
/*!
*
* @param show true if the scale should be displayed
*/
void showScale ( bool visible );
void showScale(bool visible);
void showCrosshairs ( bool visible );
void showCrosshairs(bool visible);
//! Set whether to enable a view bounding box
/*!
*
* @param usebounds enable/disable use of bounding box
*/
void setUseBoundingBox( bool usebounds );
void setUseBoundingBox(bool usebounds);
//! Check if bounding box is being used
/*!
@ -271,7 +278,7 @@ namespace qmapcontrol
*
* @param rect specified bounds for view to stay within
*/
void setBoundingBox( QRectF &rect );
void setBoundingBox(QRectF &rect);
//! Get current bounding box
/*!
@ -293,7 +300,7 @@ namespace qmapcontrol
* @param geometry the Geometry object to check
* @return true if geometry is visible
*/
bool isGeometryVisible( Geometry * geometry);
bool isGeometryVisible(Geometry *geometry);
//! returns loading images queue size
/*!
@ -307,17 +314,18 @@ namespace qmapcontrol
*
* @return imagemanager pointer
*/
ImageManager* getImageManager();
ImageManager *getImageManager();
private:
private:
void __init();
LayerManager* m_layermanager;
ImageManager* m_imagemanager;
LayerManager *m_layermanager;
ImageManager *m_imagemanager;
QPoint screen_middle; // middle of the widget (half size)
QPoint pre_click_px; // used for scrolling (MouseMode Panning)
QPoint current_mouse_pos; // used for scrolling and dragging (MouseMode Panning/Dragging)
QPoint
current_mouse_pos; // used for scrolling and dragging (MouseMode Panning/Dragging)
QSize size; // size of the widget
@ -335,53 +343,53 @@ namespace qmapcontrol
QPixmap *m_doubleBuffer;
QPointF clickToWorldCoordinate ( QPoint click );
QPointF clickToWorldCoordinate(QPoint click);
Q_DISABLE_COPY( MapControl )
Q_DISABLE_COPY(MapControl)
protected:
void paintEvent ( QPaintEvent* evnt );
void mousePressEvent ( QMouseEvent* evnt );
void mouseReleaseEvent ( QMouseEvent* evnt );
void mouseMoveEvent ( QMouseEvent* evnt );
void wheelEvent( QWheelEvent* evnt );
protected:
void paintEvent(QPaintEvent *evnt);
void mousePressEvent(QMouseEvent *evnt);
void mouseReleaseEvent(QMouseEvent *evnt);
void mouseMoveEvent(QMouseEvent *evnt);
void wheelEvent(QWheelEvent *evnt);
signals:
signals:
// void mouseEvent(const QMouseEvent* evnt);
//! Emitted AFTER a MouseEvent occured
/*!
* This signals allows to receive click events within the MapWidget together with the world coordinate.
* It is emitted on MousePressEvents and MouseReleaseEvents.
* The kind of the event can be obtained by checking the events type.
* This signals allows to receive click events within the MapWidget together with the
* world coordinate. It is emitted on MousePressEvents and MouseReleaseEvents. The
* kind of the event can be obtained by checking the events type.
* @param evnt the QMouseEvent that occured
* @param coordinate the corresponding world coordinate
*/
void mouseEventCoordinate ( const QMouseEvent* evnt, const QPointF coordinate );
void mouseEventCoordinate(const QMouseEvent *evnt, const QPointF coordinate);
//! Emitted, after a Rectangular is dragged.
/*!
* It is possible to select a rectangular area in the map, if the MouseMode is set to Dragging.
* The coordinates are in world coordinates
* It is possible to select a rectangular area in the map, if the MouseMode is set to
* Dragging. The coordinates are in world coordinates
* @param QRectF the dragged Rect
*/
void boxDragged ( const QRectF );
void boxDragged(const QRectF);
//! This signal is emitted, when a Geometry is clicked
/*!
* @param geometry The clicked Geometry object
* @param coord_px The coordinate in pixel coordinates
*/
void geometryClicked ( Geometry* geometry, QPoint coord_px );
void geometryClicked(Geometry *geometry, QPoint coord_px);
//! This signal is emitted, after the view have changed
/*!
* @param coordinate The current coordinate
* @param zoom The current zoom
*/
void viewChanged ( const QPointF &coordinate, int zoom ) const;
void viewChanged(const QPointF &coordinate, int zoom) const;
public slots:
public slots:
//! zooms in one step
void zoomIn();
@ -392,28 +400,28 @@ namespace qmapcontrol
/*!
* @param zoomlevel the zoomlevel
*/
void setZoom ( int zoomlevel );
void setZoom(int zoomlevel);
//! scrolls the view to the left
void scrollLeft ( int pixel=10 );
void scrollLeft(int pixel = 10);
//! scrolls the view to the right
void scrollRight ( int pixel=10 );
void scrollRight(int pixel = 10);
//! scrolls the view up
void scrollUp ( int pixel=10 );
void scrollUp(int pixel = 10);
//! scrolls the view down
void scrollDown ( int pixel=10 );
void scrollDown(int pixel = 10);
//! scrolls the view by the given point
void scroll ( const QPoint scroll );
void scroll(const QPoint scroll);
//! updates the map for the given rect
/*!
* @param rect the area which should be repainted
*/
void updateRequest ( QRect rect );
void updateRequest(QRect rect);
//! updates the hole map by creating a new offscreen image
/*!
@ -427,11 +435,10 @@ namespace qmapcontrol
*/
void resize(const QSize newSize);
private slots:
private slots:
void tick();
void loadingFinished();
void positionChanged ( Geometry* geom );
};
void positionChanged(Geometry *geom);
};
}
#endif

View File

@ -1,38 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "maplayer.h"
namespace qmapcontrol
{
MapLayer::MapLayer(QString layername, MapAdapter* mapadapter, bool takeevents)
MapLayer::MapLayer(QString layername, MapAdapter *mapadapter, bool takeevents)
: Layer(layername, mapadapter, Layer::MapLayer, takeevents)
{
}
MapLayer::~MapLayer()
{
}
{
}
MapLayer::~MapLayer() { }
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef MAPLAYER_H
#define MAPLAYER_H
@ -31,36 +31,39 @@
namespace qmapcontrol
{
//! MapLayer class
/*!
//! MapLayer class
/*!
* There are two different layer types:
* - MapLayer: Displays Maps, but also Geometries. The configuration for displaying maps have to be done in the MapAdapter
* - MapLayer: Displays Maps, but also Geometries. The configuration for displaying maps
*have to be done in the MapAdapter
* - GeometryLayer: Only displays Geometry objects.
*
* MapLayers also can display Geometry objects. The difference to the GeometryLayer is the repainting. Objects that are
* added to a MapLayer are "baken" on the map. This means, when you change it´s position for example the changes are
* not visible until a new offscreen image has been drawn. If you have "static" Geometries which won´t change their
* position this is fine. But if you want to change the objects position or pen you should use a GeometryLayer. Those
* are repainted immediately on changes.
* MapLayers also can display Geometry objects. The difference to the GeometryLayer is the
*repainting. Objects that are added to a MapLayer are "baken" on the map. This means,
*when you change it´s position for example the changes are not visible until a new
*offscreen image has been drawn. If you have "static" Geometries which won´t change their
* position this is fine. But if you want to change the objects position or pen you should
*use a GeometryLayer. Those are repainted immediately on changes.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapLayer : public Layer
{
class QMAPCONTROL_EXPORT MapLayer : public Layer
{
Q_OBJECT
public:
public:
//! MapLayer constructor
/*!
* This is used to construct a map layer.
*
* @param layername The name of the Layer
* @param mapadapter The MapAdapter which does coordinate translation and Query-String-Forming
* @param takeevents Should the Layer receive MouseEvents? This is set to true by default. Setting it to false could
* be something like a "speed up hint"
* @param mapadapter The MapAdapter which does coordinate translation and
* Query-String-Forming
* @param takeevents Should the Layer receive MouseEvents? This is set to true by
* default. Setting it to false could be something like a "speed up hint"
*/
MapLayer(QString layername, MapAdapter* mapadapter, bool takeevents=true);
MapLayer(QString layername, MapAdapter *mapadapter, bool takeevents = true);
virtual ~MapLayer();
};
};
}
#endif

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "mapnetwork.h"
#include <QNetworkRequest>
@ -33,21 +33,22 @@
namespace qmapcontrol
{
MapNetwork::MapNetwork(ImageManager* parent)
: parent(parent),
http(new QNetworkAccessManager(this)),
loaded(0),
networkActive( false ),
cacheEnabled(false)
{
connect(http, SIGNAL(finished(QNetworkReply *)), this, SLOT(requestFinished(QNetworkReply *)));
}
MapNetwork::MapNetwork(ImageManager *parent)
: parent(parent)
, http(new QNetworkAccessManager(this))
, loaded(0)
, networkActive(false)
, cacheEnabled(false)
{
connect(http, SIGNAL(finished(QNetworkReply *)), this,
SLOT(requestFinished(QNetworkReply *)));
}
MapNetwork::~MapNetwork()
MapNetwork::~MapNetwork()
{
foreach (QNetworkReply *reply, replyList)
{
foreach(QNetworkReply *reply, replyList)
{
if(reply->isRunning())
if (reply->isRunning())
{
reply->abort();
}
@ -57,16 +58,16 @@ namespace qmapcontrol
http->deleteLater();
http = 0;
}
}
void MapNetwork::loadImage(const QString& host, const QString& url)
{
void MapNetwork::loadImage(const QString &host, const QString &url)
{
QString hostName = host;
QString portNumber = QString("80");
QRegExp r(".:.");
if(r.indexIn(host) >= 0)
if (r.indexIn(host) >= 0)
{
QStringList s = host.split(":");
@ -77,30 +78,33 @@ namespace qmapcontrol
QString finalUrl = QString("http://%1:%2%3").arg(hostName).arg(portNumber).arg(url);
QNetworkRequest request = QNetworkRequest(QUrl(finalUrl));
if( cacheEnabled )
if (cacheEnabled)
{
// prefer our cached version (if enabled) over fresh network query
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::PreferCache);
// Data obtained should be saved to cache for future uses
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, true);
}
request.setRawHeader("User-Agent", "Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)");
request.setRawHeader(
"User-Agent",
"Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)");
QMutexLocker lock(&vectorMutex);
replyList.append( http->get(request) );
loadingMap.insert( finalUrl, url );
replyList.append(http->get(request));
loadingMap.insert(finalUrl, url);
}
void MapNetwork::requestFinished(QNetworkReply *reply)
{
void MapNetwork::requestFinished(QNetworkReply *reply)
{
if (!reply)
{
//qDebug() << "MapNetwork::requestFinished - reply no longer valid";
// qDebug() << "MapNetwork::requestFinished - reply no longer valid";
return;
}
//qDebug() << "MapNetwork::requestFinished" << reply->url().toString();
// qDebug() << "MapNetwork::requestFinished" << reply->url().toString();
if (reply->error() == QNetworkReply::NoError)
{
QString id = reply->url().toString();
@ -110,7 +114,7 @@ namespace qmapcontrol
{
QMutexLocker lock(&vectorMutex);
idInMap = loadingMap.contains(id);
if(idInMap)
if (idInMap)
{
url = loadingMap[id];
loadingMap.remove(id);
@ -119,18 +123,22 @@ namespace qmapcontrol
if (idInMap)
{
//qDebug() << "request finished for reply: " << reply << ", belongs to: " << url << endl;
// qDebug() << "request finished for reply: " << reply << ", belongs to: " <<
// url << endl;
QByteArray ax;
if (reply->bytesAvailable()>0)
if (reply->bytesAvailable() > 0)
{
QPixmap pm;
ax = reply->readAll();
if (pm.loadFromData(ax) && pm.size().width() > 1 && pm.size().height() > 1)
if (pm.loadFromData(ax) && pm.size().width() > 1
&& pm.size().height() > 1)
{
loaded += pm.size().width()*pm.size().height()*pm.depth()/8/1024;
//qDebug() << "Network loaded: " << loaded << " width:" << pm.size().width() << " height:" <<pm.size().height();
loaded
+= pm.size().width() * pm.size().height() * pm.depth() / 8 / 1024;
// qDebug() << "Network loaded: " << loaded << " width:" <<
// pm.size().width() << " height:" <<pm.size().height();
parent->receivedImage(pm, url);
}
else
@ -143,7 +151,7 @@ namespace qmapcontrol
if (loadQueueSize() == 0)
{
//qDebug () << "all loaded";
// qDebug () << "all loaded";
parent->loadingQueueEmpty();
}
@ -152,34 +160,34 @@ namespace qmapcontrol
reply->deleteLater();
reply = 0;
}
}
int MapNetwork::loadQueueSize() const
{
int MapNetwork::loadQueueSize() const
{
QMutexLocker lock(&vectorMutex);
return loadingMap.size();
}
}
void MapNetwork::setDiskCache(QNetworkDiskCache *qCache)
{
void MapNetwork::setDiskCache(QNetworkDiskCache *qCache)
{
cacheEnabled = (qCache != 0);
if (http)
{
http->setCache(qCache);
}
}
}
void MapNetwork::abortLoading()
{
//qDebug() << "MapNetwork::abortLoading";
void MapNetwork::abortLoading()
{
// qDebug() << "MapNetwork::abortLoading";
// be sure that replyList is copied in case it's modified in another thread
QListIterator<QNetworkReply *> iter(replyList);
while(iter.hasNext())
while (iter.hasNext())
{
QNetworkReply *reply = iter.next();
if (reply)
{
if(reply->isRunning())
if (reply->isRunning())
{
reply->abort();
}
@ -190,25 +198,26 @@ namespace qmapcontrol
QMutexLocker lock(&vectorMutex);
replyList.clear();
loadingMap.clear();
}
}
bool MapNetwork::imageIsLoading(QString url)
{
bool MapNetwork::imageIsLoading(QString url)
{
QMutexLocker lock(&vectorMutex);
return loadingMap.values().contains(url);
}
}
void MapNetwork::setProxy(const QString host, const int port, const QString username, const QString password)
{
void MapNetwork::setProxy(const QString host, const int port, const QString username,
const QString password)
{
// do not set proxy on qt/extended
#ifndef Q_WS_QWS
if (http)
{
QNetworkProxy proxy = QNetworkProxy( QNetworkProxy::HttpProxy, host, port );
proxy.setUser( username );
proxy.setPassword( password );
http->setProxy( proxy );
QNetworkProxy proxy = QNetworkProxy(QNetworkProxy::HttpProxy, host, port);
proxy.setUser(username);
proxy.setPassword(password);
http->setProxy(proxy);
}
#endif
}
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef MAPNETWORK_H
#define MAPNETWORK_H
@ -43,16 +43,16 @@
*/
namespace qmapcontrol
{
class ImageManager;
class QMAPCONTROL_EXPORT MapNetwork : QObject
{
class ImageManager;
class QMAPCONTROL_EXPORT MapNetwork : QObject
{
Q_OBJECT
public:
MapNetwork(ImageManager* parent);
public:
MapNetwork(ImageManager *parent);
~MapNetwork();
void loadImage(const QString& host, const QString& url);
void loadImage(const QString &host, const QString &url);
/*!
* checks if the given url is already loading
@ -63,10 +63,12 @@ namespace qmapcontrol
/*!
* Aborts all current loading threads.
* This is useful when changing the zoom-factor, though newly needed images loads faster
* This is useful when changing the zoom-factor, though newly needed images loads
* faster
*/
void abortLoading();
void setProxy(QString host, int port, const QString username = QString(), const QString password = QString());
void setProxy(QString host, int port, const QString username = QString(),
const QString password = QString());
/*!
*
@ -78,28 +80,28 @@ namespace qmapcontrol
*
* @return next free http downloader thread
*/
QNetworkAccessManager* nextFreeHttp();
QNetworkAccessManager *nextFreeHttp();
/*!
* sets the disk cache for each network manager
* @param qCache the disk cache object to set
*/
void setDiskCache( QNetworkDiskCache* qCache );
void setDiskCache(QNetworkDiskCache *qCache);
private:
Q_DISABLE_COPY (MapNetwork)
private:
Q_DISABLE_COPY(MapNetwork)
ImageManager* parent;
QNetworkAccessManager* http;
QList<QNetworkReply*> replyList;
ImageManager *parent;
QNetworkAccessManager *http;
QList<QNetworkReply *> replyList;
QMap<QString, QString> loadingMap;
qreal loaded;
mutable QMutex vectorMutex;
bool networkActive;
bool cacheEnabled;
private slots:
private slots:
void requestFinished(QNetworkReply *reply);
};
};
}
#endif

View File

@ -1,37 +1,36 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "openaerialmapadapter.h"
namespace qmapcontrol
{
OpenAerialMapAdapter::OpenAerialMapAdapter()
: TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17)
{
}
OpenAerialMapAdapter::~OpenAerialMapAdapter()
{
}
OpenAerialMapAdapter::OpenAerialMapAdapter()
: TileMapAdapter("tile.openaerialmap.org",
"/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17)
{
}
OpenAerialMapAdapter::~OpenAerialMapAdapter() { }
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2009 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef OPENAERIALMAPADAPTER_H
#define OPENAERIALMAPADAPTER_H
@ -30,21 +30,22 @@
#include "tilemapadapter.h"
namespace qmapcontrol
{
//! MapAdapter for OpenStreetMap
/*!
* This is a conveniece class, which extends and configures a TileMapAdapter. Source of maps is http://www.openaerialmap.org/
//! MapAdapter for OpenStreetMap
/*!
* This is a conveniece class, which extends and configures a TileMapAdapter. Source of
*maps is http://www.openaerialmap.org/
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT OpenAerialMapAdapter : public TileMapAdapter
{
class QMAPCONTROL_EXPORT OpenAerialMapAdapter : public TileMapAdapter
{
Q_OBJECT
public:
public:
//! constructor
/*!
* This construct a OpenAerialMap Adapter
*/
OpenAerialMapAdapter();
virtual ~OpenAerialMapAdapter();
};
};
}
#endif

View File

@ -1,37 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "osmmapadapter.h"
namespace qmapcontrol
{
OSMMapAdapter::OSMMapAdapter()
OSMMapAdapter::OSMMapAdapter()
: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17)
{
}
OSMMapAdapter::~OSMMapAdapter()
{
}
{
}
OSMMapAdapter::~OSMMapAdapter() { }
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef OSMMAPADAPTER_H
#define OSMMAPADAPTER_H
@ -30,21 +30,21 @@
#include "tilemapadapter.h"
namespace qmapcontrol
{
//! MapAdapter for OpenStreetMap
/*!
//! MapAdapter for OpenStreetMap
/*!
* This is a conveniece class, which extends and configures a TileMapAdapter
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT OSMMapAdapter : public TileMapAdapter
{
class QMAPCONTROL_EXPORT OSMMapAdapter : public TileMapAdapter
{
Q_OBJECT
public:
public:
//! constructor
/*!
* This construct a OpenStreetmap Adapter
*/
OSMMapAdapter();
virtual ~OSMMapAdapter();
};
};
}
#endif

View File

@ -1,86 +1,98 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "point.h"
namespace qmapcontrol
{
Point::Point()
{}
Point::Point(const Point& point)
:Geometry(point.name()), X(point.longitude()), Y(point.latitude())
{
Point::Point() { }
Point::Point(const Point &point)
: Geometry(point.name())
, X(point.longitude())
, Y(point.latitude())
{
visible = point.isVisible();
mywidget = 0;
mypixmap = QPixmap();
mypen = point.mypen;
homelevel = -1;
minsize = QSize(-1,-1);
maxsize = QSize(-1,-1);
}
minsize = QSize(-1, -1);
maxsize = QSize(-1, -1);
}
Point::Point(qreal x, qreal y, QString name, enum Alignment alignment)
: Geometry(name), X(x), Y(y), myalignment(alignment)
{
Point::Point(qreal x, qreal y, QString name, enum Alignment alignment)
: Geometry(name)
, X(x)
, Y(y)
, myalignment(alignment)
{
GeometryType = "Point";
mywidget = 0;
mypixmap = QPixmap();
visible = true;
homelevel = -1;
minsize = QSize(-1,-1);
maxsize = QSize(-1,-1);
}
minsize = QSize(-1, -1);
maxsize = QSize(-1, -1);
}
Point::Point(qreal x, qreal y, QWidget* widget, QString name, enum Alignment alignment)
: Geometry(name), X(x), Y(y), mywidget(widget), myalignment(alignment)
{
Point::Point(qreal x, qreal y, QWidget *widget, QString name, enum Alignment alignment)
: Geometry(name)
, X(x)
, Y(y)
, mywidget(widget)
, myalignment(alignment)
{
// Point(x, y, name, alignment);
GeometryType = "Point";
mypixmap = QPixmap();
visible = true;
size = widget->size();
homelevel = -1;
minsize = QSize(-1,-1);
maxsize = QSize(-1,-1);
minsize = QSize(-1, -1);
maxsize = QSize(-1, -1);
if(mywidget!=0)
if (mywidget != 0)
{
mywidget->show();
}
}
Point::Point(qreal x, qreal y, QPixmap pixmap, QString name, enum Alignment alignment)
: Geometry(name), X(x), Y(y), mypixmap(pixmap), myalignment(alignment)
{
}
Point::Point(qreal x, qreal y, QPixmap pixmap, QString name, enum Alignment alignment)
: Geometry(name)
, X(x)
, Y(y)
, mypixmap(pixmap)
, myalignment(alignment)
{
GeometryType = "Point";
mywidget = 0;
visible = true;
size = pixmap.size();
homelevel = -1;
minsize = QSize(-1,-1);
maxsize = QSize(-1,-1);
}
/*
minsize = QSize(-1, -1);
maxsize = QSize(-1, -1);
}
/*
Point& Point::operator=(const Point& rhs)
{
if (this == &rhs)
@ -100,45 +112,49 @@ namespace qmapcontrol
}
}
*/
Point::~Point()
{
if(mywidget!=0)
Point::~Point()
{
if (mywidget != 0)
{
delete mywidget;
mywidget = 0;
}
}
}
void Point::setPixmap( QPixmap qPixmap )
{
void Point::setPixmap(QPixmap qPixmap)
{
mypixmap = qPixmap;
size = mypixmap.size();
//forces redraw
// forces redraw
emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
emit(positionChanged(this));
}
}
void Point::setVisible(bool visible)
{
void Point::setVisible(bool visible)
{
this->visible = visible;
if (mywidget !=0)
if (mywidget != 0)
{
mywidget->setVisible(visible);
}
}
}
QRectF Point::boundingBox()
{
qreal minlon=180;
qreal maxlon=-180;
qreal minlat=90;
qreal maxlat=-90;
QRectF Point::boundingBox()
{
qreal minlon = 180;
qreal maxlon = -180;
qreal minlat = 90;
qreal maxlat = -90;
if (longitude() < minlon) minlon = longitude();
if (longitude() > maxlon) maxlon = longitude();
if (latitude() < minlat) minlat = latitude();
if (latitude() > maxlat) maxlat = latitude();
if (longitude() < minlon)
minlon = longitude();
if (longitude() > maxlon)
maxlon = longitude();
if (latitude() < minlat)
minlat = latitude();
if (latitude() > maxlat)
maxlat = latitude();
QPointF min = QPointF(minlon, minlat);
QPointF max = QPointF(maxlon, maxlat);
@ -146,45 +162,47 @@ namespace qmapcontrol
QSizeF si = QSizeF(dist.x(), dist.y());
return QRectF(min, si);
}
}
qreal Point::longitude() const
{
qreal Point::longitude() const
{
return X;
}
qreal Point::latitude() const
{
}
qreal Point::latitude() const
{
return Y;
}
QPointF Point::coordinate() const
{
}
QPointF Point::coordinate() const
{
return QPointF(X, Y);
}
}
void Point::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset)
{
void Point::draw(QPainter *painter, const MapAdapter *mapadapter, const QRect &viewport,
const QPoint offset)
{
if (!visible)
return;
if (homelevel > 0)
{
int currentzoom = mapadapter->maxZoom() < mapadapter->minZoom() ? mapadapter->minZoom() - mapadapter->currentZoom() : mapadapter->currentZoom();
int currentzoom = mapadapter->maxZoom() < mapadapter->minZoom()
? mapadapter->minZoom() - mapadapter->currentZoom()
: mapadapter->currentZoom();
// int currentzoom = mapadapter->getZoom();
int diffzoom = homelevel-currentzoom;
int diffzoom = homelevel - currentzoom;
int viewheight = size.height();
int viewwidth = size.width();
viewheight = int(viewheight / pow(2.0, diffzoom));
viewwidth = int(viewwidth / pow(2.0, diffzoom));
if (minsize.height()!= -1 && viewheight < minsize.height())
if (minsize.height() != -1 && viewheight < minsize.height())
viewheight = minsize.height();
else if (maxsize.height() != -1 && viewheight > maxsize.height())
viewheight = maxsize.height();
if (minsize.width()!= -1 && viewwidth < minsize.width())
if (minsize.width() != -1 && viewwidth < minsize.width())
viewwidth = minsize.width();
else if (maxsize.width() != -1 && viewwidth > maxsize.width())
viewwidth = maxsize.width();
@ -196,7 +214,6 @@ namespace qmapcontrol
displaysize = size;
}
if (mypixmap.size().width() > 0)
{
const QPointF c = QPointF(X, Y);
@ -205,38 +222,38 @@ namespace qmapcontrol
if (viewport.contains(point))
{
QPoint alignedtopleft = alignedPoint(point);
painter->drawPixmap(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(), displaysize.height(), mypixmap);
painter->drawPixmap(alignedtopleft.x(), alignedtopleft.y(),
displaysize.width(), displaysize.height(), mypixmap);
}
}
else if (mywidget!=0)
else if (mywidget != 0)
{
drawWidget(mapadapter, offset);
}
}
}
void Point::drawWidget(const MapAdapter* mapadapter, const QPoint offset)
{
void Point::drawWidget(const MapAdapter *mapadapter, const QPoint offset)
{
const QPointF c = QPointF(X, Y);
QPoint point = mapadapter->coordinateToDisplay(c);
point -= offset;
QPoint alignedtopleft = alignedPoint(point);
if (mywidget!=0)
if (mywidget != 0)
{
mywidget->setGeometry(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(), displaysize.height());
}
mywidget->setGeometry(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(),
displaysize.height());
}
}
QPoint Point::alignedPoint(const QPoint point) const
{
QPoint Point::alignedPoint(const QPoint point) const
{
QPoint alignedtopleft;
if (myalignment == Middle)
{
alignedtopleft.setX(point.x()-displaysize.width()/2);
alignedtopleft.setY(point.y()-displaysize.height()/2);
alignedtopleft.setX(point.x() - displaysize.width() / 2);
alignedtopleft.setY(point.y() - displaysize.height() / 2);
}
else if (myalignment == TopLeft)
{
@ -245,38 +262,38 @@ namespace qmapcontrol
}
else if (myalignment == TopRight)
{
alignedtopleft.setX(point.x()-displaysize.width());
alignedtopleft.setX(point.x() - displaysize.width());
alignedtopleft.setY(point.y());
}
else if (myalignment == BottomLeft)
{
alignedtopleft.setX(point.x());
alignedtopleft.setY(point.y()-displaysize.height());
alignedtopleft.setY(point.y() - displaysize.height());
}
else if (myalignment == BottomRight)
{
alignedtopleft.setX(point.x()-displaysize.width());
alignedtopleft.setY(point.y()-displaysize.height());
alignedtopleft.setX(point.x() - displaysize.width());
alignedtopleft.setY(point.y() - displaysize.height());
}
else if (myalignment == BottomMiddle)
{
alignedtopleft.setX(point.x()-displaysize.width()/2);
alignedtopleft.setY(point.y()-displaysize.height());
alignedtopleft.setX(point.x() - displaysize.width() / 2);
alignedtopleft.setY(point.y() - displaysize.height());
}
else if (myalignment == TopMiddle)
{
alignedtopleft.setX(point.x()-displaysize.width()/2);
alignedtopleft.setX(point.x() - displaysize.width() / 2);
alignedtopleft.setY(point.y());
}
return alignedtopleft;
}
}
bool Point::Touches(Point* click, const MapAdapter* mapadapter)
{
bool Point::Touches(Point *click, const MapAdapter *mapadapter)
{
if (this->isVisible() == false)
return false;
if ( !click || !mapadapter )
if (!click || !mapadapter)
return false;
if (points().size() < 1)
@ -288,7 +305,7 @@ namespace qmapcontrol
qreal halfwidth = 2; // use 2 pixels by default
if (mypixmap.width() > 0)
{
halfwidth = static_cast<qreal> (mypixmap.width()) / static_cast<qreal> (2);
halfwidth = static_cast<qreal>(mypixmap.width()) / static_cast<qreal>(2);
}
QPointF pt1 = mapadapter->coordinateToDisplay(coordinate());
@ -308,24 +325,22 @@ namespace qmapcontrol
qreal upperLeftY = qMin(pt1y1, qMin(pt1y2, qMin(pt2y1, pt2y2)));
qreal lowerRightX = qMax(pt1x1, qMax(pt1x2, qMax(pt2x1, pt2x2)));
qreal lowerRightY = qMax(pt1y1, qMax(pt1y2, qMax(pt2y1, pt2y2)));
QRectF bounds(QPointF(upperLeftX, upperLeftY), QPointF(lowerRightX,
lowerRightY));
QRectF bounds(QPointF(upperLeftX, upperLeftY), QPointF(lowerRightX, lowerRightY));
if ( bounds.contains(clickPt) )
if (bounds.contains(clickPt))
{
emit(geometryClicked(this, QPoint(0, 0)));
return true;
}
return false;
}
}
void Point::setCoordinate(QPointF point)
void Point::setCoordinate(QPointF point)
{
if (X == point.x() && Y == point.y())
{
if ( X == point.x() &&
Y == point.y() )
{
//no change, prevent unessessary update/redraw
// no change, prevent unessessary update/redraw
return;
}
@ -334,39 +349,39 @@ namespace qmapcontrol
emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
emit(positionChanged(this));
}
QList<Point*> Point::points()
{
//TODO: assigning temp?!
QList<Point*> points;
}
QList<Point *> Point::points()
{
// TODO: assigning temp?!
QList<Point *> points;
points.append(this);
return points;
}
QWidget* Point::widget()
{
return mywidget;
}
QPixmap Point::pixmap()
{
return mypixmap;
}
void Point::setBaselevel(int zoomlevel)
{
homelevel = zoomlevel;
}
void Point::setMinsize(QSize minsize)
{
this->minsize = minsize;
}
void Point::setMaxsize(QSize maxsize)
{
this->maxsize = maxsize;
}
Point::Alignment Point::alignment() const
{
return myalignment;
}
}
QWidget *Point::widget()
{
return mywidget;
}
QPixmap Point::pixmap()
{
return mypixmap;
}
void Point::setBaselevel(int zoomlevel)
{
homelevel = zoomlevel;
}
void Point::setMinsize(QSize minsize)
{
this->minsize = minsize;
}
void Point::setMaxsize(QSize maxsize)
{
this->maxsize = maxsize;
}
Point::Alignment Point::alignment() const
{
return myalignment;
}
}

View File

@ -1,38 +1,38 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef POINT_H
#define POINT_H
//#include "qglobal.h"
#if QT_VERSION >= 0x050000
// Qt5 code
//#include <QtWidgets>
// Qt5 code
//#include <QtWidgets>
#else
// Qt4 code
#include <QWidget>
// Qt4 code
# include <QWidget>
#endif
#include "qmapcontrol_global.h"
@ -40,34 +40,36 @@
namespace qmapcontrol
{
//! A geometric point to draw objects into maps
/*!
//! A geometric point to draw objects into maps
/*!
* This class can be used to draw your custom QPixmap or other QWidgets into maps.
* You can instantiate a Point with any Pixmap you want. The objects cares about collision detection (for clickable objects)
* You can instantiate a Point with any Pixmap you want. The objects cares about collision
* detection (for clickable objects)
*
* When drawing a pixmap, take care you are adding the point to a GeometryLayer.
* You can also add a point to a MapLayer, but this should only be done, if the point is not changing its position or color etc.
* (GeometryLayers are assured to be repainted on any changes at the point. MapLayers only gets repainted, if a new
* offscreenImage is painter. This is a performance issue.)
* You can also add a point to a MapLayer, but this should only be done, if the point is
* not changing its position or color etc. (GeometryLayers are assured to be repainted on
* any changes at the point. MapLayers only gets repainted, if a new offscreenImage is
* painter. This is a performance issue.)
*
* Points emit click events, if the containing layer receives clickevents (the default)
*
* You can also add a widget into maps. But keep in mind, that widgets always are drawn on top of all layers.
* You also have to handle click events yourself.
* You can also add a widget into maps. But keep in mind, that widgets always are drawn on
* top of all layers. You also have to handle click events yourself.
*
* To create "zoomable objects" (objects that increases size on zooming), a base level have to be set.
* The base level is the zoom level on which the point´s pixmap gets displayed on full size.
* On lower zoom levels it gets displayed smaller and on higher zoom levels larger.
* A minimal size can be set as well as a maximum size.
* To create "zoomable objects" (objects that increases size on zooming), a base level
* have to be set. The base level is the zoom level on which the point´s pixmap gets
* displayed on full size. On lower zoom levels it gets displayed smaller and on higher
* zoom levels larger. A minimal size can be set as well as a maximum size.
* @see setBaselevel, setMinsize, setMaxsize
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Point : public Geometry
{
class QMAPCONTROL_EXPORT Point : public Geometry
{
Q_OBJECT
public:
public:
friend class Layer;
friend class LineString;
@ -78,13 +80,13 @@ namespace qmapcontrol
TopRight, /*!< Align on TopRight*/
TopMiddle, /*!< Align on TopLeft*/
BottomLeft, /*!< Align on BottomLeft*/
BottomRight,/*!< Align on BottomRight*/
BottomRight, /*!< Align on BottomRight*/
BottomMiddle, /*!< Align on BottomMiddle*/
Middle /*!< Align on Middle*/
};
Point();
explicit Point(const Point&);
explicit Point(const Point &);
//! Copy Constructor
/*!
* This constructor creates a Point with no image or widget.
@ -93,33 +95,36 @@ namespace qmapcontrol
* @param name name of the point
* @param alignment alignment of the point (Middle or TopLeft)
*/
Point(qreal x, qreal y, QString name = QString(), enum Alignment alignment=Middle);
Point(qreal x, qreal y, QString name = QString(), enum Alignment alignment = Middle);
//! Constructor
/*!
* This constructor creates a point which will display the given widget.
* You can set an alignment on which corner the widget should be aligned to the coordinate.
* You have to set the size of the widget, before adding it to
* IMPORTANT: You have to set the QMapControl as parent for the widget!
* You can set an alignment on which corner the widget should be aligned to the
* coordinate. You have to set the size of the widget, before adding it to IMPORTANT:
* You have to set the QMapControl as parent for the widget!
* @param x longitude
* @param y latitude
* @param widget the widget which should be displayed by this point
* @param name name of the point
* @param alignment allignment of the point (Middle or TopLeft)
*/
Point(qreal x, qreal y, QWidget* widget, QString name = QString(), enum Alignment alignment = Middle);
Point(qreal x, qreal y, QWidget *widget, QString name = QString(),
enum Alignment alignment = Middle);
//! Constructor
/*!
* This constructor creates a point which will display the give pixmap.
* You can set an alignment on which corner the pixmap should be aligned to the coordinate.
* You can set an alignment on which corner the pixmap should be aligned to the
* coordinate.
* @param x longitude
* @param y latitude
* @param pixmap the pixmap which should be displayed by this point
* @param name name of the point
* @param alignment allignment of the point (Middle or TopLeft)
*/
Point(qreal x, qreal y, QPixmap pixmap, QString name = QString(), enum Alignment alignment = Middle);
Point(qreal x, qreal y, QPixmap pixmap, QString name = QString(),
enum Alignment alignment = Middle);
virtual ~Point();
//! returns the bounding box of the point
@ -150,12 +155,12 @@ namespace qmapcontrol
*/
QPointF coordinate() const;
virtual QList<Point*> points();
virtual QList<Point *> points();
/*! \brief returns the widget of the point
@return the widget of the point
*/
QWidget* widget();
QWidget *widget();
//! returns the pixmap of the point
/*!
@ -165,8 +170,9 @@ namespace qmapcontrol
//! Sets the zoom level on which the points pixmap gets displayed on full size
/*!
* Use this method to set a zoom level on which the pixmap gets displayed with its real size.
* On zoomlevels below it will be displayed smaller, and on zoom levels thereover it will be displayed larger
* Use this method to set a zoom level on which the pixmap gets displayed with its
* real size. On zoomlevels below it will be displayed smaller, and on zoom levels
* thereover it will be displayed larger
* @see setMinsize, setMaxsize
* @param zoomlevel the zoomlevel on which the point will be displayed on full size
*/
@ -174,7 +180,8 @@ namespace qmapcontrol
//! sets a minimal size for the pixmap
/*!
* When the point's pixmap should change its size on zooming, this method sets the minimal size.
* When the point's pixmap should change its size on zooming, this method sets the
* minimal size.
* @see setBaselevel
* @param minsize the minimal size which the pixmap should have
*/
@ -182,7 +189,8 @@ namespace qmapcontrol
//! sets a maximal size for the pixmap
/*!
* When the point´s pixmap should change its size on zooming, this method sets the maximal size.
* When the point´s pixmap should change its size on zooming, this method sets the
* maximal size.
* @see setBaselevel
* @param maxsize the maximal size which the pixmap should have
*/
@ -190,14 +198,14 @@ namespace qmapcontrol
Point::Alignment alignment() const;
virtual void setPixmap( QPixmap qPixmap );
virtual void setPixmap(QPixmap qPixmap);
protected:
protected:
qreal X;
qreal Y;
QSize size;
QWidget* mywidget;
QWidget *mywidget;
QPixmap mypixmap;
Alignment myalignment;
int homelevel;
@ -205,10 +213,11 @@ namespace qmapcontrol
QSize minsize;
QSize maxsize;
void drawWidget(const MapAdapter* mapadapter, const QPoint offset);
// void drawPixmap(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint versch);
virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset);
void drawWidget(const MapAdapter *mapadapter, const QPoint offset);
// void drawPixmap(QPainter* painter, const MapAdapter* mapadapter, const QRect
// &viewport, const QPoint versch);
virtual void draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &viewport, const QPoint offset);
QPoint alignedPoint(const QPoint point) const;
//! returns true if the given Point touches this Point
@ -218,11 +227,11 @@ namespace qmapcontrol
* @param mapadapter the mapadapter which is used for calculations
* @return
*/
virtual bool Touches(Point* p, const MapAdapter* mapadapter);
virtual bool Touches(Point *p, const MapAdapter *mapadapter);
public slots:
public slots:
void setCoordinate(QPointF point);
virtual void setVisible(bool visible);
};
};
}
#endif

View File

@ -1,34 +1,35 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "tilemapadapter.h"
namespace qmapcontrol
{
TileMapAdapter::TileMapAdapter(const QString& host, const QString& serverPath, int tilesize, int minZoom, int maxZoom)
:MapAdapter(host, serverPath, tilesize, minZoom, maxZoom)
{
TileMapAdapter::TileMapAdapter(const QString &host, const QString &serverPath,
int tilesize, int minZoom, int maxZoom)
: MapAdapter(host, serverPath, tilesize, minZoom, maxZoom)
{
PI = acos(-1.0);
/*
@ -48,7 +49,7 @@ namespace qmapcontrol
int max = param1 > param2 ? param1 : param2;
max = param3 > max ? param3 : max;
int middle = param1+param2+param3-min-max;
int middle = param1 + param2 + param3 - min - max;
order[0][0] = min;
if (min == param1)
@ -69,7 +70,7 @@ namespace qmapcontrol
order[2][0] = max;
if (max == param1)
order[2][1] = 0;
else if(max == param2)
else if (max == param2)
order[2][1] = 1;
else
order[2][1] = 2;
@ -77,113 +78,110 @@ namespace qmapcontrol
int zoom = mMax_zoom < mMin_zoom ? mMin_zoom - mCurrent_zoom : mCurrent_zoom;
mNumberOfTiles = tilesonzoomlevel(zoom);
loc.setNumberOptions(QLocale::OmitGroupSeparator);
}
}
TileMapAdapter::~TileMapAdapter()
{
}
//TODO: pull out
void TileMapAdapter::zoom_in()
{
TileMapAdapter::~TileMapAdapter() { }
// TODO: pull out
void TileMapAdapter::zoom_in()
{
if (mMin_zoom > mMax_zoom)
{
//mCurrent_zoom = mCurrent_zoom-1;
mCurrent_zoom = mCurrent_zoom > mMax_zoom ? mCurrent_zoom-1 : mMax_zoom;
// mCurrent_zoom = mCurrent_zoom-1;
mCurrent_zoom = mCurrent_zoom > mMax_zoom ? mCurrent_zoom - 1 : mMax_zoom;
}
else if (mMin_zoom < mMax_zoom)
{
//mCurrent_zoom = mCurrent_zoom+1;
mCurrent_zoom = mCurrent_zoom < mMax_zoom ? mCurrent_zoom+1 : mMax_zoom;
// mCurrent_zoom = mCurrent_zoom+1;
mCurrent_zoom = mCurrent_zoom < mMax_zoom ? mCurrent_zoom + 1 : mMax_zoom;
}
int zoom = mMax_zoom < mMin_zoom ? mMin_zoom - mCurrent_zoom : mCurrent_zoom;
mNumberOfTiles = tilesonzoomlevel(zoom);
}
void TileMapAdapter::zoom_out()
{
}
void TileMapAdapter::zoom_out()
{
if (mMin_zoom > mMax_zoom)
{
//mCurrent_zoom = mCurrent_zoom+1;
mCurrent_zoom = mCurrent_zoom < mMin_zoom ? mCurrent_zoom+1 : mMin_zoom;
// mCurrent_zoom = mCurrent_zoom+1;
mCurrent_zoom = mCurrent_zoom < mMin_zoom ? mCurrent_zoom + 1 : mMin_zoom;
}
else if (mMin_zoom < mMax_zoom)
{
//mCurrent_zoom = mCurrent_zoom-1;
mCurrent_zoom = mCurrent_zoom > mMin_zoom ? mCurrent_zoom-1 : mMin_zoom;
// mCurrent_zoom = mCurrent_zoom-1;
mCurrent_zoom = mCurrent_zoom > mMin_zoom ? mCurrent_zoom - 1 : mMin_zoom;
}
int zoom = mMax_zoom < mMin_zoom ? mMin_zoom - mCurrent_zoom : mCurrent_zoom;
mNumberOfTiles = tilesonzoomlevel(zoom);
}
}
qreal TileMapAdapter::deg_rad(qreal x) const
{
return x * (PI/180.0);
}
qreal TileMapAdapter::rad_deg(qreal x) const
{
return x * (180/PI);
}
qreal TileMapAdapter::deg_rad(qreal x) const
{
return x * (PI / 180.0);
}
qreal TileMapAdapter::rad_deg(qreal x) const
{
return x * (180 / PI);
}
QString TileMapAdapter::query(int x, int y, int z) const
{
QString TileMapAdapter::query(int x, int y, int z) const
{
x = xoffset(x);
y = yoffset(y);
int a[3] = {z, x, y};
return QString(serverPath().replace(order[2][0],2, loc.toString(a[order[2][1]]))
.replace(order[1][0],2, loc.toString(a[order[1][1]]))
.replace(order[0][0],2, loc.toString(a[order[0][1]])));
int a[3] = { z, x, y };
return QString(serverPath()
.replace(order[2][0], 2, loc.toString(a[order[2][1]]))
.replace(order[1][0], 2, loc.toString(a[order[1][1]]))
.replace(order[0][0], 2, loc.toString(a[order[0][1]])));
}
}
QPoint TileMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
{
qreal x = (coordinate.x()+180) * (mNumberOfTiles*mTileSize)/360.; // coord to pixel!
qreal y = (1-(log(tan(PI/4+deg_rad(coordinate.y())/2)) /PI)) /2 * (mNumberOfTiles*mTileSize);
QPoint TileMapAdapter::coordinateToDisplay(const QPointF &coordinate) const
{
qreal x
= (coordinate.x() + 180) * (mNumberOfTiles * mTileSize) / 360.; // coord to pixel!
qreal y = (1 - (log(tan(PI / 4 + deg_rad(coordinate.y()) / 2)) / PI)) / 2
* (mNumberOfTiles * mTileSize);
return QPoint(int(x), int(y));
}
}
QPointF TileMapAdapter::displayToCoordinate(const QPoint& point) const
{
qreal longitude = (point.x()*(360/(mNumberOfTiles*mTileSize)))-180;
qreal latitude = rad_deg(atan(sinh((1-point.y()*(2/(mNumberOfTiles*mTileSize)))*PI)));
QPointF TileMapAdapter::displayToCoordinate(const QPoint &point) const
{
qreal longitude = (point.x() * (360 / (mNumberOfTiles * mTileSize))) - 180;
qreal latitude
= rad_deg(atan(sinh((1 - point.y() * (2 / (mNumberOfTiles * mTileSize))) * PI)));
return QPointF(longitude, latitude);
}
}
bool TileMapAdapter::isTileValid(int x, int y, int z) const
{
bool TileMapAdapter::isTileValid(int x, int y, int z) const
{
if (mMax_zoom < mMin_zoom)
{
z= mMin_zoom - z;
z = mMin_zoom - z;
}
if (x<0 || x > (1 << z)-1 ||
y<0 || y > (1 << z)-1)
if (x < 0 || x > (1 << z) - 1 || y < 0 || y > (1 << z) - 1)
{
return false;
}
return true;
}
int TileMapAdapter::tilesonzoomlevel(int zoomlevel) const
{
return int(pow(2.0, zoomlevel));
}
int TileMapAdapter::xoffset(int x) const
{
return x;
}
int TileMapAdapter::yoffset(int y) const
{
return y;
}
}
int TileMapAdapter::tilesonzoomlevel(int zoomlevel) const
{
return int(pow(2.0, zoomlevel));
}
int TileMapAdapter::xoffset(int x) const
{
return x;
}
int TileMapAdapter::yoffset(int y) const
{
return y;
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef TILEMAPADAPTER_H
#define TILEMAPADAPTER_H
@ -31,37 +31,39 @@
namespace qmapcontrol
{
//! MapAdapter for servers with image tiles
/*!
//! MapAdapter for servers with image tiles
/*!
* Use this derived MapAdapter to display maps from OpenStreetMap
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT TileMapAdapter : public MapAdapter
{
class QMAPCONTROL_EXPORT TileMapAdapter : public MapAdapter
{
Q_OBJECT
public:
public:
//! constructor
/*!
* Sample of a correct initialization of a MapAdapter:<br/>
* TileMapAdapter* ta = new TileMapAdapter("192.168.8.1", "/img/img_cache.php/%1/%2/%3.png", 256, 0,17);<br/>
* The placeholders %1, %2, %3 stands for x, y, z<br/>
* The minZoom is 0 (means the whole world is visible). The maxZoom is 17 (means it is zoomed in to the max)
* TileMapAdapter* ta = new TileMapAdapter("192.168.8.1",
* "/img/img_cache.php/%1/%2/%3.png", 256, 0,17);<br/> The placeholders %1, %2, %3
* stands for x, y, z<br/> The minZoom is 0 (means the whole world is visible). The
* maxZoom is 17 (means it is zoomed in to the max)
* @param host The servers URL
* @param serverPath The path to the tiles with placeholders
* @param tilesize the size of the tiles
* @param minZoom the minimum zoom level
* @param maxZoom the maximum zoom level
*/
TileMapAdapter(const QString& host, const QString& serverPath, int tilesize, int minZoom = 0, int maxZoom = 17);
TileMapAdapter(const QString &host, const QString &serverPath, int tilesize,
int minZoom = 0, int maxZoom = 17);
virtual ~TileMapAdapter();
virtual QPoint coordinateToDisplay(const QPointF&) const;
virtual QPointF displayToCoordinate(const QPoint&) const;
virtual QPoint coordinateToDisplay(const QPointF &) const;
virtual QPointF displayToCoordinate(const QPoint &) const;
qreal PI;
protected:
protected:
qreal rad_deg(qreal) const;
qreal deg_rad(qreal) const;
@ -72,6 +74,6 @@ namespace qmapcontrol
virtual int tilesonzoomlevel(int zoomlevel) const;
virtual int xoffset(int x) const;
virtual int yoffset(int y) const;
};
};
}
#endif

View File

@ -1,72 +1,68 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#include "wmsmapadapter.h"
#include <QStringList>
namespace qmapcontrol
{
WMSMapAdapter::WMSMapAdapter(QString host, QString serverPath, int tilesize)
WMSMapAdapter::WMSMapAdapter(QString host, QString serverPath, int tilesize)
: MapAdapter(host, serverPath, tilesize, 0, 17)
{
{
mNumberOfTiles = pow(2.0, mCurrent_zoom);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
changeHostAddress( host, serverPath );
changeHostAddress(host, serverPath);
loc = QLocale(QLocale::English);
loc.setNumberOptions( QLocale::OmitGroupSeparator );
setBoundingBox( -180, -90, 180, 90 );
loc.setNumberOptions(QLocale::OmitGroupSeparator);
setBoundingBox(-180, -90, 180, 90);
qreal res = 0.703125;
for( int z = 0; z < 17; z++ )
for (int z = 0; z < 17; z++)
{
mResolutions[z] = res;
res = res / 2;
}
}
}
WMSMapAdapter::~WMSMapAdapter() { }
WMSMapAdapter::~WMSMapAdapter()
{
}
void WMSMapAdapter::changeHostAddress( const QString qHost, const QString qServerPath )
{
void WMSMapAdapter::changeHostAddress(const QString qHost, const QString qServerPath)
{
mServerOptions.clear();
QString serverPathPrefix;
if ( qServerPath.contains("?") &&
qServerPath.split("?").size() > 1 )
if (qServerPath.contains("?") && qServerPath.split("?").size() > 1)
{
serverPathPrefix = qServerPath.split("?").at( 0 );
foreach( QString opt, qServerPath.split("?").at(1).split("&") )
serverPathPrefix = qServerPath.split("?").at(0);
foreach (QString opt, qServerPath.split("?").at(1).split("&"))
{
if (opt.contains( "="))
if (opt.contains("="))
{
mServerOptions[ opt.split("=").at(0).toUpper() ] = opt.split("=").at(1);
mServerOptions[opt.split("=").at(0).toUpper()] = opt.split("=").at(1);
}
}
}
@ -75,113 +71,114 @@ namespace qmapcontrol
serverPathPrefix = "/wms/";
}
MapAdapter::changeHostAddress(qHost,serverPathPrefix);
MapAdapter::changeHostAddress(qHost, serverPathPrefix);
//force expected parameters
// force expected parameters
if (!mServerOptions.contains("VERSION"))
{
mServerOptions["VERSION"] = "1.1.1";
}
if (!mServerOptions.contains("TRANSPARENT"))
{
mServerOptions["TRANSPARENT"]= "TRUE";
mServerOptions["TRANSPARENT"] = "TRUE";
}
//if (!mServerOptions.contains("LAYERS"))
// if (!mServerOptions.contains("LAYERS"))
//{
// mServerOptions["LAYERS"] = TBD;
//}
if (!mServerOptions.contains("SRS") &&
!mServerOptions.contains("CRS"))
if (!mServerOptions.contains("SRS") && !mServerOptions.contains("CRS"))
{
mServerOptions["SRS"] = "EPSG:4326";
//mServerOptions["SRS"] = "EPSG:900913"; //google mercator
//mServerOptions["SRS"] = "EPSG:3857"; //EPSG:3857 is a Spherical Mercator projection
// mServerOptions["SRS"] = "EPSG:900913"; //google mercator
// mServerOptions["SRS"] = "EPSG:3857"; //EPSG:3857 is a Spherical Mercator
// projection
}
if (!mServerOptions.contains("STYLES"))
{
mServerOptions["STYLES"]= QString();
mServerOptions["STYLES"] = QString();
}
if (!mServerOptions.contains("FORMAT"))
{
mServerOptions["FORMAT"] = "IMAGE/PNG";
}
mServerOptions["SRS"] = "EPSG:4326"; //mercator
mServerOptions["SERVICE"]= "WMS";
mServerOptions["TILED"]= "TRUE";
mServerOptions["REQUEST"]= "GetMap";
mServerOptions["WIDTH"]= loc.toString(tilesize());
mServerOptions["HEIGHT"]= loc.toString(tilesize());
mServerOptions.remove("BBOX"); //added at time of query string
}
mServerOptions["SRS"] = "EPSG:4326"; // mercator
mServerOptions["SERVICE"] = "WMS";
mServerOptions["TILED"] = "TRUE";
mServerOptions["REQUEST"] = "GetMap";
mServerOptions["WIDTH"] = loc.toString(tilesize());
mServerOptions["HEIGHT"] = loc.toString(tilesize());
mServerOptions.remove("BBOX"); // added at time of query string
}
QString WMSMapAdapter::serverPath() const
{
QString WMSMapAdapter::serverPath() const
{
QString urlPath;
foreach( QString key, mServerOptions.keys() )
foreach (QString key, mServerOptions.keys())
{
if (!urlPath.isEmpty())
{
urlPath.append("&");
}
urlPath.append( QString("%1=%2").arg( key ).arg( mServerOptions[key] ) );
urlPath.append(QString("%1=%2").arg(key).arg(mServerOptions[key]));
}
return QString("%1?%2").arg( MapAdapter::serverPath() ).arg( urlPath );
}
return QString("%1?%2").arg(MapAdapter::serverPath()).arg(urlPath);
}
QPoint WMSMapAdapter::coordinateToDisplay(const QPointF& coordinate) const
{
qreal x = (coordinate.x()+180) * (mNumberOfTiles*mTileSize)/360.; // coord to pixel!
qreal y = -1*(coordinate.y()-90) * (mNumberOfTiles*mTileSize)/180.; // coord to pixel!
QPoint WMSMapAdapter::coordinateToDisplay(const QPointF &coordinate) const
{
qreal x
= (coordinate.x() + 180) * (mNumberOfTiles * mTileSize) / 360.; // coord to pixel!
qreal y = -1 * (coordinate.y() - 90) * (mNumberOfTiles * mTileSize)
/ 180.; // coord to pixel!
return QPoint(int(x), int(y));
}
QPointF WMSMapAdapter::displayToCoordinate(const QPoint& point) const
{
qreal lon = (point.x()*(360./(mNumberOfTiles*mTileSize)))-180;
qreal lat = -(point.y()*(180./(mNumberOfTiles*mTileSize)))+90;
}
QPointF WMSMapAdapter::displayToCoordinate(const QPoint &point) const
{
qreal lon = (point.x() * (360. / (mNumberOfTiles * mTileSize))) - 180;
qreal lat = -(point.y() * (180. / (mNumberOfTiles * mTileSize))) + 90;
return QPointF(lon, lat);
}
void WMSMapAdapter::zoom_in()
{
mCurrent_zoom+=1;
}
void WMSMapAdapter::zoom_in()
{
mCurrent_zoom += 1;
mNumberOfTiles = pow(2.0, mCurrent_zoom);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
}
void WMSMapAdapter::zoom_out()
{
mCurrent_zoom-=1;
}
void WMSMapAdapter::zoom_out()
{
mCurrent_zoom -= 1;
mNumberOfTiles = pow(2.0, mCurrent_zoom);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
}
}
bool WMSMapAdapter::isTileValid(int /*x*/, int /*y*/, int /*z*/) const
{
bool WMSMapAdapter::isTileValid(int /*x*/, int /*y*/, int /*z*/) const
{
// if (x>0 && y>0 && z>0)
{
return true;
}
// return false;
}
QString WMSMapAdapter::query(int i, int j, int /*z*/) const
{
return getQ(-180+i*coord_per_x_tile,
90-(j+1)*coord_per_y_tile,
-180+i*coord_per_x_tile+coord_per_x_tile,
90-(j+1)*coord_per_y_tile+coord_per_y_tile);
}
}
QString WMSMapAdapter::query(int i, int j, int /*z*/) const
{
return getQ(-180 + i * coord_per_x_tile, 90 - (j + 1) * coord_per_y_tile,
-180 + i * coord_per_x_tile + coord_per_x_tile,
90 - (j + 1) * coord_per_y_tile + coord_per_y_tile);
}
QString WMSMapAdapter::getQ(qreal ux, qreal uy, qreal ox, qreal oy) const
{
QString WMSMapAdapter::getQ(qreal ux, qreal uy, qreal ox, qreal oy) const
{
qreal x1 = ux;
qreal y1 = uy;
qreal x2 = ox;
qreal y2 = oy;
//if ( mServerOptions["SRS"].toUpper() == "EPSG:4326" )
// if ( mServerOptions["SRS"].toUpper() == "EPSG:4326" )
//{
// if ( x1 < 0 )
// {
@ -204,9 +201,9 @@ namespace qmapcontrol
return QString("%1&BBOX=%2,%3,%4,%5")
.arg(serverPath())
.arg(QString::number(x1,'f',6))
.arg(QString::number(y1,'f',6))
.arg(QString::number(x2,'f',6))
.arg(QString::number(y2,'f',6));
}
.arg(QString::number(x1, 'f', 6))
.arg(QString::number(y1, 'f', 6))
.arg(QString::number(x2, 'f', 6))
.arg(QString::number(y2, 'f', 6));
}
}

View File

@ -1,27 +1,27 @@
/*
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
*
* This file is part of QMapControl,
* an open-source cross-platform map widget
*
* Copyright (C) 2007 - 2008 Kai Winter
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
*
* Contact e-mail: kaiwinter@gmx.de
* Program URL : http://qmapcontrol.sourceforge.net/
*
*/
#ifndef WMSMAPADAPTER_H
#define WMSMAPADAPTER_H
@ -31,20 +31,22 @@
namespace qmapcontrol
{
//! MapAdapter for WMS servers
/*!
//! MapAdapter for WMS servers
/*!
* Use this derived MapAdapter to display maps from WMS servers
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT WMSMapAdapter : public MapAdapter
{
public:
class QMAPCONTROL_EXPORT WMSMapAdapter : public MapAdapter
{
public:
//! constructor
/*!
* Sample of a correct initialization of a MapAdapter:<br/>
* MapAdapter* mapadapter = new WMSMapAdapter("www2.demis.nl", "/wms/wms.asp?wms=WorldMap[...]&BBOX=%1,%2,%3,%4&WIDTH=%5&HEIGHT=%5&TRANSPARENT=TRUE", 256);<br/>
* The placeholders %1, %2, %3, %4 creates the bounding box, %5 is for the tilesize
* The minZoom is 0 (means the whole world is visible). The maxZoom is 17 (means it is zoomed in to the max)
* MapAdapter* mapadapter = new WMSMapAdapter("www2.demis.nl",
* "/wms/wms.asp?wms=WorldMap[...]&BBOX=%1,%2,%3,%4&WIDTH=%5&HEIGHT=%5&TRANSPARENT=TRUE",
* 256);<br/> The placeholders %1, %2, %3, %4 creates the bounding box, %5 is for the
* tilesize The minZoom is 0 (means the whole world is visible). The maxZoom is 17
* (means it is zoomed in to the max)
* @param host The servers URL
* @param serverPath The path to the tiles with placeholders
* @param tilesize the size of the tiles
@ -53,24 +55,25 @@ namespace qmapcontrol
virtual ~WMSMapAdapter();
virtual QString serverPath() const;
virtual QPoint coordinateToDisplay(const QPointF&) const;
virtual QPointF displayToCoordinate(const QPoint&) const;
virtual void changeHostAddress( const QString qHost, const QString qServerPath = QString() );
virtual QPoint coordinateToDisplay(const QPointF &) const;
virtual QPointF displayToCoordinate(const QPoint &) const;
virtual void changeHostAddress(const QString qHost,
const QString qServerPath = QString());
protected:
protected:
virtual void zoom_in();
virtual void zoom_out();
virtual QString query(int x, int y, int z) const;
virtual bool isTileValid(int x, int y, int z) const;
private:
private:
virtual QString getQ(qreal ux, qreal uy, qreal ox, qreal oy) const;
qreal coord_per_x_tile;
qreal coord_per_y_tile;
QHash<QString,QString> mServerOptions;
QHash<int,qreal> mResolutions;
};
QHash<QString, QString> mServerOptions;
QHash<int, qreal> mResolutions;
};
}
#endif