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

@ -6,7 +6,7 @@
* Also it demonstrates more possibilities for user interaction:<br/>
* - notes can be added to any coordinate (a QTextEdit is used for editing the note)<br/>
* - the user can measure distances between two points
*
*
* \image html sample_citymap.png "screenshot"
*/
@ -22,69 +22,71 @@
#include <QLabel>
#include <QTimer>
Citymap::Citymap(QWidget*)
Citymap::Citymap(QWidget *)
{
// create MapControl
mc = new MapControl(QSize(380,540));
// create MapControl
mc = new MapControl(QSize(380, 540));
mc->showScale(true);
// display the MapControl in the application
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(mc);
layout->setContentsMargins(0,0,0,0);
QWidget* w = new QWidget();
w->setLayout(layout);
setCentralWidget(w);
// display the MapControl in the application
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mc);
layout->setContentsMargins(0, 0, 0, 0);
QWidget *w = new QWidget();
w->setLayout(layout);
setCentralWidget(w);
notepixmap = new QPixmap(QApplication::applicationDirPath() + "/images/note.png");
coord1 = QPointF();
coord2 = QPointF();
mapadapter = new OSMMapAdapter();
// create a layer with the mapadapter and type MapLayer
l = new MapLayer("Custom Layer", mapadapter);
coord1 = QPointF();
coord2 = QPointF();
mapadapter = new OSMMapAdapter();
mc->addLayer(l);
notes = new GeometryLayer("Notes", mapadapter);
// create a layer with the mapadapter and type MapLayer
l = new MapLayer("Custom Layer", mapadapter);
createTours();
addSights();
addPubs();
addMuseums();
addZoomButtons();
createActions();
createMenus();
mc->addLayer(l);
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)));
mc->setView(QPointF(8.26,50));
mc->setZoom(13);
ignoreClicks = false;
addingNote = false;
noteID = 0;
notetextedit = new QTextEdit(mc);
notetextedit->setGeometry(0,0,200,100);
notepoint = new Point(0, 0, notetextedit, ".", Point::TopLeft);
notepoint->setVisible(false);
notes->addGeometry(notepoint);
notes = new GeometryLayer("Notes", mapadapter);
statusBar = new QStatusBar( this );
createTours();
addSights();
addPubs();
addMuseums();
addZoomButtons();
createActions();
createMenus();
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)));
mc->setView(QPointF(8.26, 50));
mc->setZoom(13);
ignoreClicks = false;
addingNote = false;
noteID = 0;
notetextedit = new QTextEdit(mc);
notetextedit->setGeometry(0, 0, 200, 100);
notepoint = new Point(0, 0, notetextedit, ".", Point::TopLeft);
notepoint->setVisible(false);
notes->addGeometry(notepoint);
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,214 +112,260 @@ void Citymap::cacheTiles(bool qEnabled)
void Citymap::createTours()
{
QPen* pen = new QPen(QColor(0,0,255,100));
pen->setWidth(5);
QList<Point*> points;
points << new Point(8.2606, 50.0051);
points << new Point(8.2602, 50.0050);
points << new Point(8.2598, 50.0044);
points << new Point(8.2569, 50.0057);
points << new Point(8.2595, 50.0083);
points << new Point(8.2587, 50.0086);
points << new Point(8.2589, 50.0100);
points << new Point(8.2590, 50.0105);
pub_tour = new LineString(points, "", pen);
notes->addGeometry(pub_tour);
points.clear();
points << new Point(8.25987, 50.0018);
points << new Point(8.26192, 50.0019);
points << new Point(8.26301, 50.0031);
points << new Point(8.26459, 50.0026);
points << new Point(8.26601, 50.004);
points << new Point(8.26781, 50.0033);
points << new Point(8.27052, 50.0054);
points << new Point(8.2697, 50.0059);
museum_tour = new LineString(points, "", pen);
notes->addGeometry(museum_tour);
points.clear();
points << new Point(8.26015, 50.0015);
points << new Point(8.2617, 50.0012);
points << new Point(8.26423, 50.0002);
points << new Point(8.26698, 50.0024);
points << new Point(8.27065, 50.0012);
points << new Point(8.27152, 50.0016);
points << new Point(8.27225, 50.0004);
points << new Point(8.27333, 49.9994);
points << new Point(8.26946, 49.9983);
points << new Point(8.27105, 49.9973);
points << new Point(8.27024, 49.9972);
points << new Point(8.26833, 49.9958);
sights_tour = new LineString(points, "", pen);
notes->addGeometry(sights_tour);
QPen *pen = new QPen(QColor(0, 0, 255, 100));
pen->setWidth(5);
QList<Point *> points;
points << new Point(8.2606, 50.0051);
points << new Point(8.2602, 50.0050);
points << new Point(8.2598, 50.0044);
points << new Point(8.2569, 50.0057);
points << new Point(8.2595, 50.0083);
points << new Point(8.2587, 50.0086);
points << new Point(8.2589, 50.0100);
points << new Point(8.2590, 50.0105);
pub_tour = new LineString(points, "", pen);
notes->addGeometry(pub_tour);
points.clear();
points << new Point(8.25987, 50.0018);
points << new Point(8.26192, 50.0019);
points << new Point(8.26301, 50.0031);
points << new Point(8.26459, 50.0026);
points << new Point(8.26601, 50.004);
points << new Point(8.26781, 50.0033);
points << new Point(8.27052, 50.0054);
points << new Point(8.2697, 50.0059);
museum_tour = new LineString(points, "", pen);
notes->addGeometry(museum_tour);
points.clear();
points << new Point(8.26015, 50.0015);
points << new Point(8.2617, 50.0012);
points << new Point(8.26423, 50.0002);
points << new Point(8.26698, 50.0024);
points << new Point(8.27065, 50.0012);
points << new Point(8.27152, 50.0016);
points << new Point(8.27225, 50.0004);
points << new Point(8.27333, 49.9994);
points << new Point(8.26946, 49.9983);
points << new Point(8.27105, 49.9973);
points << new Point(8.27024, 49.9972);
points << new Point(8.26833, 49.9958);
sights_tour = new LineString(points, "", pen);
notes->addGeometry(sights_tour);
}
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");
dom->setBaselevel(17);
sights->addGeometry(dom);
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");
quitin->setBaselevel(17);
sights->addGeometry(quitin);
connect(sights, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClicked(Geometry*, QPoint)));
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");
dom->setBaselevel(17);
sights->addGeometry(dom);
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");
quitin->setBaselevel(17);
sights->addGeometry(quitin);
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");
pubs->addGeometry(bagatelle);
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");
pubs->addGeometry(krokodil);
connect(pubs, SIGNAL(geometryClicked(Geometry*, QPoint)),
this, SLOT(geometryClickEventKneipe(Geometry*, QPoint)));
pubs = new GeometryLayer("Kneipe", mapadapter);
mc->addLayer(pubs);
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");
pubs->addGeometry(nirgendwo);
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)));
}
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");
rgzm->setBaselevel(17);
museum->addGeometry(rgzm);
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)));
museum = new GeometryLayer("Museen", mapadapter);
mc->addLayer(museum);
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);
museum->addGeometry(lm);
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->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>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>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.");
}
if (geometry->name() != "")
infodialog->showMaximized();
if (ignoreClicks || addingNote)
return;
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>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>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.");
}
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->setWindowTitle(geometry->name());
infodialog->setInfotext("<h1>" + geometry->name() + "</h1>");
infodialog->showNormal();
if (ignoreClicks || addingNote)
return;
InfoDialog *infodialog = new InfoDialog(this);
infodialog->setWindowTitle(geometry->name());
infodialog->setInfotext("<h1>" + geometry->name() + "</h1>");
infodialog->showNormal();
}
void Citymap::addZoomButtons()
{
// create buttons as controls for zoom
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()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
// create buttons as controls for zoom
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()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout *innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
}
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)));
togglePub = new QAction(tr("Show Pubs"), this);
togglePub->setCheckable(true);
togglePub->setChecked(true);
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)));
toggleSightTour = new QAction(tr("Show Sight Tour"), this);
toggleSightTour->setCheckable(true);
toggleSightTour->setChecked(true);
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)));
toggleMuseumTour = new QAction(tr("Show Museum Tour"), this);
toggleMuseumTour->setCheckable(true);
toggleMuseumTour->setChecked(true);
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()));
toolsDistance = new QAction(tr("Calculate Distance"), this);
connect(toolsDistance, SIGNAL(triggered(bool)),
this, SLOT(calcDistance()));
toggleSights = new QAction(tr("Show Sights"), this);
toggleSights->setCheckable(true);
toggleSights->setChecked(true);
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)));
toggleMuseum = new QAction(tr("Show Museums"), this);
toggleMuseum->setCheckable(true);
toggleMuseum->setChecked(true);
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)));
togglePubTour = new QAction(tr("Show Pub Tour"), this);
togglePubTour->setCheckable(true);
togglePubTour->setChecked(true);
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)));
addNoteAction = new QAction(tr("Add Note"), this);
connect(addNoteAction, SIGNAL(triggered(bool)), this, SLOT(addNote()));
toolsDistance = new QAction(tr("Calculate Distance"), this);
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)));
QActionGroup* mapproviderGroup = new QActionGroup(this);
connect(toolsLocalDiskCache, SIGNAL(triggered(bool)), this, SLOT(cacheTiles(bool)));
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);
@ -327,122 +375,122 @@ void Citymap::createActions()
googleActionHybrid = new QAction(tr("Google: Hybrid"), mapproviderGroup);
osmAction->setCheckable(true);
googleActionMap->setCheckable(true);
googleActionMap->setCheckable(true);
googleActionSatellite->setCheckable(true);
googleActionTerrain->setCheckable(true);
googleActionHybrid->setCheckable(true);
osmAction->setChecked(true);
connect(mapproviderGroup, SIGNAL(triggered(QAction*)),
this, SLOT(mapproviderSelected(QAction*)));
QActionGroup* mapZoomGroup = new QActionGroup(this);
connect(mapproviderGroup, SIGNAL(triggered(QAction *)), this,
SLOT(mapproviderSelected(QAction *)));
for( int i=0; i <= 17; ++i )
QActionGroup *mapZoomGroup = new QActionGroup(this);
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()
{
layerMenu = menuBar()->addMenu(tr("&Layer"));
layerMenu->addAction(toggleSights);
layerMenu->addAction(togglePub);
layerMenu->addAction(toggleMuseum);
layerMenu = menuBar()->addMenu(tr("&Layer"));
layerMenu->addAction(toggleSights);
layerMenu->addAction(togglePub);
layerMenu->addAction(toggleMuseum);
tourMenu = menuBar()->addMenu(tr("T&ours"));
tourMenu->addAction(toggleSightTour);
tourMenu->addAction(togglePubTour);
tourMenu->addAction(toggleMuseumTour);
toolsMenu = menuBar()->addMenu(tr("&Tools"));
toolsMenu->addAction(addNoteAction);
toolsMenu->addAction(toolsDistance);
tourMenu = menuBar()->addMenu(tr("T&ours"));
tourMenu->addAction(toggleSightTour);
tourMenu->addAction(togglePubTour);
tourMenu->addAction(toggleMuseumTour);
toolsMenu = menuBar()->addMenu(tr("&Tools"));
toolsMenu->addAction(addNoteAction);
toolsMenu->addAction(toolsDistance);
toolsMenu->addAction(toolsLocalDiskCache);
mapMenu = menuBar()->addMenu(tr("&Map Provider"));
mapMenu->addAction(osmAction);
mapMenu->addAction(googleActionMap);
mapMenu = menuBar()->addMenu(tr("&Map Provider"));
mapMenu->addAction(osmAction);
mapMenu->addAction(googleActionMap);
mapMenu->addAction(googleActionSatellite);
mapMenu->addAction(googleActionTerrain);
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)));
addingNote = true;
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);
currentnoteID = noteID;
p->setBaselevel(16);
p->setMinsize(QSize(12, 10));
p->setMaxsize(QSize(47, 40));
notes->addGeometry(p);
notetextedit->clear();
notepoint->setCoordinate(coord);
notepoint->setVisible(true);
mc->updateRequestNew();
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)));
Point *p = new Point(coord.x(), coord.y(), *notepixmap, QString::number(++noteID),
Point::BottomLeft);
currentnoteID = noteID;
p->setBaselevel(16);
p->setMinsize(QSize(12, 10));
p->setMaxsize(QSize(47, 40));
notes->addGeometry(p);
notetextedit->clear();
notepoint->setCoordinate(coord);
notepoint->setVisible(true);
mc->updateRequestNew();
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)));
}
void Citymap::hideNote(const QMouseEvent* evnt, const QPointF)
void Citymap::hideNote(const QMouseEvent *evnt, const QPointF)
{
if (addingNote && evnt->type() == QEvent::MouseButtonDblClick)
{
addingNote = false;
notepoint->setVisible(false);
if (addingNote && evnt->type() == QEvent::MouseButtonDblClick)
{
addingNote = false;
notepoint->setVisible(false);
mc->updateRequestNew();
// save text
notestext[currentnoteID] = notetextedit->toPlainText();
disconnect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(hideNote(const QMouseEvent*, const QPointF)));
}
mc->updateRequestNew();
// save text
notestext[currentnoteID] = notetextedit->toPlainText();
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();
notetextedit->setPlainText(notestext[currentnoteID]);
notepoint->setCoordinate(geom->points().at(0)->coordinate());
notepoint->setVisible(true);
mc->updateRequestNew();
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(hideNote(const QMouseEvent*, const QPointF)));
addingNote = true;
currentnoteID = QVariant(geom->name()).toInt();
notetextedit->setPlainText(notestext[currentnoteID]);
notepoint->setCoordinate(geom->points().at(0)->coordinate());
notepoint->setVisible(true);
mc->updateRequestNew();
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());
@ -451,93 +499,101 @@ 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)));
ignoreClicks = true;
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));
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 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;
QList<Point*> points;
points.append(new Point(coord1.x(), coord1.y()));
QPixmap* pixm = new QPixmap(100,20);
pixm->fill(Qt::transparent);
QPainter pain(pixm);
pain.setFont(QFont("Helvetiva", 6));
pain.drawText(pixm->rect(), QString().setNum(km, 'f', 3) + " km");
pain.end();
if (coord1 == QPointF() && evnt->type() == QEvent::MouseButtonPress)
{
coord1 = coord;
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 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;
QList<Point *> points;
points.append(new Point(coord1.x(), coord1.y()));
QPixmap *pixm = new QPixmap(100, 20);
pixm->fill(Qt::transparent);
QPainter pain(pixm);
pain.setFont(QFont("Helvetiva", 6));
pain.drawText(pixm->rect(), QString().setNum(km, 'f', 3) + " km");
pain.end();
points.append(new Point(coord2.x(), coord2.y(), *pixm, "", Point::BottomLeft));
l->addGeometry(new LineString(points));
mc->updateRequestNew();
coord1 = QPointF();
coord2 = QPointF();
ignoreClicks = false;
disconnect(mc, SIGNAL(mouseEventCoordinate( const QMouseEvent*, const QPointF)),
this, SLOT(calcDistanceClick(const QMouseEvent*, const QPointF)));
l->addGeometry(new LineString(points));
mc->updateRequestNew();
coord1 = QPointF();
coord2 = QPointF();
ignoreClicks = false;
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)
{
int zoom = mapadapter->adaptedZoom();
mc->setZoom(0);
mapadapter = new OSMMapAdapter();
l->setMapAdapter(mapadapter);
sights->setMapAdapter(mapadapter);
museum->setMapAdapter(mapadapter);
pubs->setMapAdapter(mapadapter);
notes->setMapAdapter(mapadapter);
mc->updateRequestNew();
mc->setZoom(zoom);
}
else if (action == googleActionMap)
{
if (action == osmAction)
{
int zoom = mapadapter->adaptedZoom();
mc->setZoom(0);
mapadapter = new GoogleMapAdapter();
l->setMapAdapter(mapadapter);
sights->setMapAdapter(mapadapter);
museum->setMapAdapter(mapadapter);
mapadapter = new OSMMapAdapter();
l->setMapAdapter(mapadapter);
sights->setMapAdapter(mapadapter);
museum->setMapAdapter(mapadapter);
pubs->setMapAdapter(mapadapter);
notes->setMapAdapter(mapadapter);
mc->updateRequestNew();
mc->setZoom(zoom);
}
notes->setMapAdapter(mapadapter);
mc->updateRequestNew();
mc->setZoom(zoom);
}
else if (action == googleActionMap)
{
int zoom = mapadapter->adaptedZoom();
mc->setZoom(0);
mapadapter = new GoogleMapAdapter();
l->setMapAdapter(mapadapter);
sights->setMapAdapter(mapadapter);
museum->setMapAdapter(mapadapter);
pubs->setMapAdapter(mapadapter);
notes->setMapAdapter(mapadapter);
mc->updateRequestNew();
mc->setZoom(zoom);
}
else if (action == googleActionSatellite)
{
int zoom = mapadapter->adaptedZoom();
@ -581,12 +637,11 @@ void Citymap::mapproviderSelected(QAction* action)
Citymap::~Citymap()
{
delete mc;
delete mapadapter;
delete notepixmap;
delete sights;
delete notes;
delete pubs;
delete museum;
delete mc;
delete mapadapter;
delete notepixmap;
delete sights;
delete notes;
delete pubs;
delete museum;
}

View File

@ -14,99 +14,99 @@
class QLabel;
using namespace qmapcontrol;
class Citymap: public QMainWindow
class Citymap : public QMainWindow
{
Q_OBJECT
public:
Citymap(QWidget* parent = 0);
Q_OBJECT
public:
Citymap(QWidget *parent = 0);
~Citymap();
~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();
void addZoomButtons();
void createTours();
void createActions();
void createMenus();
void createTours();
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;
bool ignoreClicks;
bool addingNote;
void addSights();
void addPubs();
void addMuseums();
void addSights();
void addPubs();
void addMuseums();
QPointF coord1;
QPointF coord2;
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;
int noteID;
int currentnoteID;
QHash<int, QString> notestext;
QLabel* loadingProgress;
QTimer* loadingProgressTimer;
QTextEdit *notetextedit;
Point *notepoint;
int noteID;
int currentnoteID;
QHash<int, QString> notestext;
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);
void addNote();
void writeNote(const QMouseEvent*, const QPointF);
void calcDistance();
void calcDistanceClick(const QMouseEvent*, const QPointF);
void mapControlZoomChanged(const QPointF &coordinate, int zoom ) const;
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 calcDistance();
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 resizeEvent(QResizeEvent *qEvent);
void updateProgress();
void cacheTiles(bool qEnabled);
void mapproviderSelected(QAction *);
void mapZoomSelected(QAction *);
void editNote(Geometry *geom, QPoint point);
void resizeEvent(QResizeEvent *qEvent);
void updateProgress();
void cacheTiles(bool qEnabled);
};
#endif

View File

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

View File

@ -5,17 +5,17 @@
#include <QTextEdit>
/**
@author Kai Winter <kaiwinter@gmx.de>
@author Kai Winter <kaiwinter@gmx.de>
*/
class InfoDialog : public QDialog
{
Q_OBJECT
public:
InfoDialog(QWidget* parent=0);
void setInfotext(QString text);
private:
QTextEdit* infotext;
Q_OBJECT
public:
InfoDialog(QWidget *parent = 0);
void setInfotext(QString text);
private:
QTextEdit *infotext;
};
#endif

View File

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

View File

@ -2,12 +2,13 @@
/*!
* \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.
*
*
* You can find this example here: MapAPI/Samples/GPS
* \image html sample_gps.png "screenshot"
* @see http://3rdparty.downloads.openmoko.org
@ -19,92 +20,89 @@
GPS::GPS()
{
// create MapControl
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);
// create MapControl
mc = new MapControl(QSize(480, 640));
// ImageManager::instance()->setProxy("www-cache", 8080);
// create a layer with the mapadapter and type MapLayer
Layer* l = new Layer("Custom Layer", mapadapter, Layer::MapLayer);
// create MapAdapter to get maps from
TileMapAdapter *mapadapter
= new TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17);
//current GPS Location
gpsDot = new CirclePoint(0,0, "GPS", CirclePoint::Middle, new QPen( Qt::darkBlue ));
l->addGeometry( gpsDot );
// create a layer with the mapadapter and type MapLayer
Layer *l = new Layer("Custom Layer", mapadapter, Layer::MapLayer);
// add Layer to the MapControl
mc->addLayer(l);
// current GPS Location
gpsDot = new CirclePoint(0, 0, "GPS", CirclePoint::Middle, new QPen(Qt::darkBlue));
l->addGeometry(gpsDot);
// display the MapControl in the application
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(mc);
setLayout(layout);
// add Layer to the MapControl
mc->addLayer(l);
// create buttons as controls for zoom
QPushButton* zoomin = new QPushButton("+");
QPushButton* zoomout = new QPushButton("-");
// display the MapControl in the application
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(mc);
setLayout(layout);
// create buttons as controls for zoom
QPushButton *zoomin = new QPushButton("+");
QPushButton *zoomout = new QPushButton("-");
followgps = new QPushButton("Follow");
followgps->setCheckable(true);
simulategps = new QPushButton("Simulate");
simulategps->setCheckable(true);
gpsposition = new QLabel();
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
followgps->setMaximumWidth(50);
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
followgps->setMaximumWidth(50);
simulategps->setMaximumWidth(50);
gpsposition->setFont(QFont("Arial", 10));
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
gpsposition->setFont(QFont("Arial", 10));
connect(simulategps, SIGNAL(clicked(bool)),
this, SLOT(simulategps_checked()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
innerlayout->addWidget(followgps);
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()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout *innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
innerlayout->addWidget(followgps);
innerlayout->addWidget(simulategps);
innerlayout->addWidget(gpsposition);
mc->setLayout(innerlayout);
GPS_Neo* gm = new GPS_Neo();
connect(gm, SIGNAL(new_position(float, QPointF)),
this, SLOT(updatePosition(float, QPointF)));
innerlayout->addWidget(gpsposition);
mc->setLayout(innerlayout);
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()));
if (followgps->isChecked())
{
mc->setView(coordinate);
}
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,25 +9,25 @@
#include "circlepoint.h"
using namespace qmapcontrol;
class GPS: public QWidget
class GPS : public QWidget
{
Q_OBJECT
public:
GPS();
~GPS();
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:
void updatePosition(float time, QPointF coordinate);
void resizeEvent(QResizeEvent *qEvent);
void simulategps_checked();
public slots:
void updatePosition(float time, QPointF coordinate);
void resizeEvent(QResizeEvent *qEvent);
void simulategps_checked();
};
#endif

View File

@ -1,70 +1,67 @@
#include "gps_neo.h"
GPS_Neo::GPS_Neo(QObject *parent)
: QObject(parent)
: QObject(parent)
{
running = false;
running = false;
}
GPS_Neo::~GPS_Neo()
{
}
GPS_Neo::~GPS_Neo() { }
void GPS_Neo::start()
{
if (!running)
{
running = true;
QTimer::singleShot(1000, this, SLOT(tick()));
}
if (!running)
{
running = true;
QTimer::singleShot(1000, this, SLOT(tick()));
}
}
void GPS_Neo::stop()
{
running = false;
running = false;
}
void GPS_Neo::tick()
{
QFile file("/tmp/nmeaNP");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// qDebug() << file.error();
return;
}
QByteArray line;
while (!file.atEnd())
{
line = file.readLine();
if (line.contains("GPRMC"))
{
break;
}
}
file.close();
GPS_Position pos = process_line(line);
emit(new_position(pos.time, QPointF(pos.longitude, pos.latitude)));
if (running)
{
QTimer::singleShot(1000, this, SLOT(tick()));
}
QFile file("/tmp/nmeaNP");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
// qDebug() << file.error();
return;
}
QByteArray line;
while (!file.atEnd())
{
line = file.readLine();
if (line.contains("GPRMC"))
{
break;
}
}
file.close();
GPS_Position pos = process_line(line);
emit(new_position(pos.time, QPointF(pos.longitude, pos.latitude)));
if (running)
{
QTimer::singleShot(1000, this, SLOT(tick()));
}
}
GPS_Position GPS_Neo::process_line(QByteArray line)
{
line.chop(1);
{
line.chop(1);
QList<QByteArray> elems = line.split(',');
QList<QByteArray> elems = line.split(',');
float time = QString(elems.at(1)).toFloat();
float latitude = elems.at(3).toFloat()/100;
QString latitude_dir = elems.at(4);
float longitude = elems.at(5).toFloat()/100;
QString longitude_dir = elems.at(6);
return GPS_Position(time, longitude, longitude_dir, latitude, latitude_dir);
float time = QString(elems.at(1)).toFloat();
float latitude = elems.at(3).toFloat() / 100;
QString latitude_dir = elems.at(4);
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,31 +6,32 @@
#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:
GPS_Neo(QObject *parent = 0);
~GPS_Neo();
void start();
void stop();
Q_OBJECT
public:
GPS_Neo(QObject *parent = 0);
~GPS_Neo();
void start();
void stop();
private:
QList<GPS_Position> positions;
GPS_Position process_line(QByteArray line);
bool running;
private:
QList<GPS_Position> positions;
GPS_Position process_line(QByteArray line);
bool running;
signals:
void new_position(float, QPointF);
signals:
void new_position(float, QPointF);
public slots:
void tick();
public slots:
void tick();
};
#endif

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

@ -2,12 +2,12 @@
#include "gps.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
GPS ta;
ta.resize(480, 640);
QApplication app(argc, argv);
ta.setWindowTitle("GPS Demo");
ta.show();
return app.exec();
GPS ta;
ta.resize(480, 640);
ta.setWindowTitle("GPS Demo");
ta.show();
return app.exec();
}

View File

@ -1,17 +1,18 @@
#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
* - One which draws a plain circle
* - One which uses a QPen to draw a circle
* - One which has no markers
* Then these Points were added to a LineString
*
*
* Also there is a keylistener.
*
*
* You can find this example here: MapAPI/Samples/LinesAndPoints
* \image html sample_linesandpoints.png "screenshot"
*/
@ -22,155 +23,164 @@
#include <QMessageBox>
LinesAndPoints::LinesAndPoints(QWidget *parent)
: QWidget(parent)
: QWidget(parent)
{
// the size which the QMapControl should fill
QSize size = QSize(480,640);
mc = new MapControl(size);
// create layout
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(mc);
setLayout(layout);
// create layer
MapAdapter* mapadapter = new OSMMapAdapter();
Layer* l = new MapLayer("Custom Layer", mapadapter);
mc->addLayer(l);
// create a LineString
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 with a circle
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));
// A QPen can be used to customize the
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));
// "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"));
// the size which the QMapControl should fill
QSize size = QSize(480, 640);
// A QPen also can use transparency
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);
// 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)));
// Sets the view to the interesting area
mc = new MapControl(size);
// create layout
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(mc);
setLayout(layout);
// create layer
MapAdapter *mapadapter = new OSMMapAdapter();
Layer *l = new MapLayer("Custom Layer", mapadapter);
mc->addLayer(l);
// create a LineString
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 with a circle
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));
// A QPen can be used to customize the
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));
// "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"));
// A QPen also can use transparency
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);
// 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)));
// Sets the view to the interesting area
mc->setView(QPointF(8.259959, 50.001781));
mc->setZoom(11);
addZoomButtons();
addZoomButtons();
}
void LinesAndPoints::addZoomButtons()
{
// create buttons as controls for zoom
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()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
// create buttons as controls for zoom
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()));
// add zoom buttons to the layout of the MapControl
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();
qDebug() << "number of child elements: " << pp.size();
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(), "just a point");
}
qDebug() << "parent: " << geom->parentGeometry();
qDebug() << "Element clicked: " << geom->name();
if (geom->hasClickedPoints())
{
QList<Geometry *> pp = geom->clickedPoints();
qDebug() << "number of child elements: " << pp.size();
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(), "just a point");
}
}
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'
{
mc->zoomIn();
}
else if (evnt->key() == 50)
{
mc->moveTo(QPointF(8.25, 60));
}
else if (evnt->key() == 51 || evnt->key() == 16777313) // tastatur '3'
{
mc->zoomOut();
}
else if (evnt->key() == 54) // 6
{
mc->setView(QPointF(8,50));
}
else if (evnt->key() == 16777234) // left
{
mc->scrollLeft();
}
else if (evnt->key() == 16777236) // right
{
mc->scrollRight();
}
else if (evnt->key() == 16777235 ) // up
{
mc->scrollUp();
}
else if (evnt->key() == 16777237) // down
{
mc->scrollDown();
}
else if (evnt->key() == 48 || evnt->key() == 17825797) // 0
{
emit(close());
}
else
{
qDebug() << evnt->key() << endl;
}
if (evnt->key() == 49 || evnt->key() == 17825792) // tastatur '1'
{
mc->zoomIn();
}
else if (evnt->key() == 50)
{
mc->moveTo(QPointF(8.25, 60));
}
else if (evnt->key() == 51 || evnt->key() == 16777313) // tastatur '3'
{
mc->zoomOut();
}
else if (evnt->key() == 54) // 6
{
mc->setView(QPointF(8, 50));
}
else if (evnt->key() == 16777234) // left
{
mc->scrollLeft();
}
else if (evnt->key() == 16777236) // right
{
mc->scrollRight();
}
else if (evnt->key() == 16777235) // up
{
mc->scrollUp();
}
else if (evnt->key() == 16777237) // down
{
mc->scrollDown();
}
else if (evnt->key() == 48 || evnt->key() == 17825797) // 0
{
emit(close());
}
else
{
qDebug() << evnt->key() << endl;
}
}

View File

@ -11,20 +11,20 @@ using namespace qmapcontrol;
class LinesAndPoints : public QWidget
{
Q_OBJECT
public:
LinesAndPoints(QWidget *parent = 0);
~LinesAndPoints();
public:
LinesAndPoints(QWidget *parent = 0);
~LinesAndPoints();
private:
MapControl* mc;
void addZoomButtons();
private:
MapControl *mc;
void addZoomButtons();
public slots:
void geometryClicked(Geometry* geom, QPoint coord_px);
void resizeEvent(QResizeEvent *qEvent);
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

@ -2,11 +2,11 @@
#include "linesandpoints.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
LinesAndPoints ta;
ta.resize(480,640);
ta.setWindowTitle("QMapControl Demo");
ta.show();
return app.exec();
QApplication app(argc, argv);
LinesAndPoints ta;
ta.resize(480, 640);
ta.setWindowTitle("QMapControl Demo");
ta.show();
return app.exec();
}

View File

@ -2,12 +2,12 @@
#include "mapviewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Mapviewer ta;
ta.resize(380, 565);
ta.setWindowTitle("Mapviewer");
ta.show();
return app.exec();
QApplication app(argc, argv);
Mapviewer ta;
ta.resize(380, 565);
ta.setWindowTitle("Mapviewer");
ta.show();
return app.exec();
}

View File

@ -20,52 +20,47 @@ 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();
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

@ -5,12 +5,12 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Mapviewer ta;
QApplication app(argc, argv);
Mapviewer ta;
ta.resize(380, 565);
ta.setWindowTitle("Mapviewer");
ta.show();
return app.exec();
return app.exec();
}

View File

@ -5,11 +5,11 @@
/*!
* \example mapviewer.cpp
* This application is just a simple map viewer. A Mapadapter is created (OpenStreetmaps)
* This application is just a simple map viewer. A Mapadapter is created (OpenStreetmaps)
* and added to a layer. The layer is given to the MapControl.
* Two Buttons are available to adjust the zoom level. If the window is
* resized the map widget will adjust its size.
*
*
* You can find this example here: QMapControl/Samples/Mapviewer
* \image html sample_mapviewer.png "screenshot"
*/
@ -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 )
// resize the widget
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

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

View File

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

View File

@ -2,11 +2,11 @@
#include "multidemo.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Multidemo ta;
ta.resize(480,640);
ta.setWindowTitle("QMapControl Demo");
ta.show();
return app.exec();
QApplication app(argc, argv);
Multidemo ta;
ta.resize(480, 640);
ta.setWindowTitle("QMapControl Demo");
ta.show();
return app.exec();
}

View File

@ -11,232 +11,255 @@
* - 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"
*/
Multidemo::Multidemo(QWidget *parent)
: QWidget(parent)
: QWidget(parent)
{
setupMaps();
createLayout();
gm = new GPS_Modul();
connect(gm, SIGNAL(new_position(QPointF)),
ip, SLOT(setCoordinate(QPointF)));
setupMaps();
createLayout();
gm = new GPS_Modul();
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);
// 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);
// maplayer
Layer* l = new MapLayer("Custom Layer", mapadapter);
mc->addLayer(l);
// Geometry layer
Layer* l2 = new GeometryLayer("Geom Layer", mapadapter);
mc->addLayer(l2);
// maplayer
Layer *l = new MapLayer("Custom Layer", mapadapter);
mc->addLayer(l);
// Geometry layer
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->addLayer(layer_mini);
// "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->addLayer(layer_mini);
// create points
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));
// create points
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));
// add points to linestring
pen = new QPen(QColor(0, 0, 255, 100));
pen->setWidth(5);
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);
// add points to linestring
pen = new QPen(QColor(0, 0, 255, 100));
pen->setWidth(5);
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);
// this point receives position changes from the "gps modul"
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);
// so if have to be added to the GeometryLayer l2
l2->addGeometry(ip);
QPushButton* pb = new QPushButton("test button", mc);
// widget example
Point *wpoint = new Point(-20, -20, pb, ".", Point::TopLeft);
wpoint->setBaselevel(3);
l->addGeometry(wpoint);
pb->setGeometry(0, 0, 100, 50);
// widget example
Point* wpoint = new Point(-20,-20, pb, ".", Point::TopLeft);
wpoint->setBaselevel(3);
l->addGeometry(wpoint);
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()
{
btn1 = new QPushButton("Add Point");
btn1->setCheckable(true);
btn1->setMaximumWidth(80);
btn1->setMaximumHeight(20);
btn1->setFont(QFont("Verdana", 5));
btn1 = new QPushButton("Add Point");
btn1->setCheckable(true);
btn1->setMaximumWidth(80);
btn1->setMaximumHeight(20);
btn1->setFont(QFont("Verdana", 5));
btn2 = new QPushButton("Drag Rect");
btn2->setCheckable(true);
btn2->setMaximumHeight(20);
btn2->setFont(QFont("Verdana", 5));
btn2->setMaximumWidth(80);
btn2 = new QPushButton("Drag Rect");
btn2->setCheckable(true);
btn2->setMaximumHeight(20);
btn2->setFont(QFont("Verdana", 5));
btn2->setMaximumWidth(80);
btn3 = new QPushButton("Move to Click");
btn3->setCheckable(true);
btn3->setMaximumHeight(20);
btn3->setFont(QFont("Verdana", 5));
btn3->setMaximumWidth(80);
btn3 = new QPushButton("Move to Click");
btn3->setCheckable(true);
btn3->setMaximumHeight(20);
btn3->setFont(QFont("Verdana", 5));
btn3->setMaximumWidth(80);
btn4 = new QPushButton("Follow Geom");
btn4->setCheckable(true);
btn4->setMaximumHeight(20);
btn4->setFont(QFont("Verdana", 5));
btn4->setMaximumWidth(80);
btn4 = new QPushButton("Follow Geom");
btn4->setCheckable(true);
btn4->setMaximumHeight(20);
btn4->setFont(QFont("Verdana", 5));
btn4->setMaximumWidth(80);
btn5 = new QPushButton("GPS");
btn5->setCheckable(true);
btn5->setMaximumHeight(20);
btn5->setFont(QFont("Verdana", 5));
btn5->setMaximumWidth(80);
btn1->setFocusPolicy(Qt::NoFocus);
btn2->setFocusPolicy(Qt::NoFocus);
btn3->setFocusPolicy(Qt::NoFocus);
btn4->setFocusPolicy(Qt::NoFocus);
btn5->setFocusPolicy(Qt::NoFocus);
btn5 = new QPushButton("GPS");
btn5->setCheckable(true);
btn5->setMaximumHeight(20);
btn5->setFont(QFont("Verdana", 5));
btn5->setMaximumWidth(80);
btn1->setFocusPolicy(Qt::NoFocus);
btn2->setFocusPolicy(Qt::NoFocus);
btn3->setFocusPolicy(Qt::NoFocus);
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);
layoutinner->addWidget(btn2);
layoutinner->addWidget(btn3);
layoutinner->addWidget(btn4);
layoutinner->addWidget(btn5);
layoutinner->addSpacing(70);
layout->addLayout(layoutinner);
layoutinner->addWidget(mc2);
layoutinner->addWidget(btn1);
layoutinner->addWidget(btn2);
layoutinner->addWidget(btn3);
layoutinner->addWidget(btn4);
layoutinner->addWidget(btn5);
layoutinner->addSpacing(70);
layout->addLayout(layoutinner);
QHBoxLayout* mclayout = new QHBoxLayout;
mclayout->addWidget(mc);
mclayout->setMargin(0);
setLayout(mclayout);
QHBoxLayout *mclayout = new QHBoxLayout;
mclayout->addWidget(mc);
mclayout->setMargin(0);
setLayout(mclayout);
mc->setLayout(layoutinner);
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)
{
mc->layer("Geom Layer")->addGeometry(new CirclePoint(coord.x(), coord.y(), 10, "added point"));
mc->updateRequestNew();
}
if (btn1->isChecked() && evnt->type() == QEvent::MouseButtonPress)
{
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)
{
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())));
}
if (geom->hasClickedPoints())
{
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())));
}
}
Multidemo::~Multidemo()
{
}
Multidemo::~Multidemo() { }
void Multidemo::keyPressEvent(QKeyEvent* evnt)
void Multidemo::keyPressEvent(QKeyEvent *evnt)
{
if (evnt->key() == 49 || evnt->key() == 17825792) // keyboard '1'
{
mc->zoomIn();
}
else if (evnt->key() == 50)
{
mc->moveTo(QPointF(8.25, 60));
}
else if (evnt->key() == 51 || evnt->key() == 16777313) // keyboard '3'
{
mc->zoomOut();
}
else if (evnt->key() == 52) //4
{
mc->updateRequestNew();
}
else if (evnt->key() == 16777234) // left
{
mc->scrollLeft();
}
else if (evnt->key() == 16777236) // right
{
mc->scrollRight();
}
else if (evnt->key() == 16777235 ) // up
{
mc->scrollUp();
}
else if (evnt->key() == 16777237) // down
{
mc->scrollDown();
}
else if (evnt->key() == 48 || evnt->key() == 17825797) // 0
{
emit(close());
if (evnt->key() == 49 || evnt->key() == 17825792) // keyboard '1'
{
mc->zoomIn();
}
else if (evnt->key() == 50)
{
mc->moveTo(QPointF(8.25, 60));
}
else if (evnt->key() == 51 || evnt->key() == 16777313) // keyboard '3'
{
mc->zoomOut();
}
else if (evnt->key() == 52) // 4
{
mc->updateRequestNew();
}
else if (evnt->key() == 16777234) // left
{
mc->scrollLeft();
}
else if (evnt->key() == 16777236) // right
{
mc->scrollRight();
}
else if (evnt->key() == 16777235) // up
{
mc->scrollUp();
}
else if (evnt->key() == 16777237) // down
{
mc->scrollDown();
}
else if (evnt->key() == 48 || evnt->key() == 17825797) // 0
{
emit(close());
}
}
@ -247,52 +270,51 @@ void Multidemo::resizeEvent(QResizeEvent *event)
void Multidemo::buttonToggled(bool active)
{
if (active)
mc->setMouseMode(MapControl::Dragging);
else
mc->setMouseMode(MapControl::Panning);
if (active)
mc->setMouseMode(MapControl::Dragging);
else
mc->setMouseMode(MapControl::Panning);
}
void Multidemo::toggleFollow(bool follow)
{
if (follow)
mc->followGeometry(ip);
else
mc->stopFollowing(ip);
if (follow)
mc->followGeometry(ip);
else
mc->stopFollowing(ip);
}
void Multidemo::toggleGPS(bool gps)
{
if (gps)
gm->start();
else
gm->stop();
if (gps)
gm->start();
else
gm->stop();
}
void Multidemo::draggedRect(QRectF rect)
{
QList<QPointF> coords;
coords.append(rect.topLeft());
coords.append(rect.bottomRight());
mc->setViewAndZoomIn(coords);
QList<QPointF> coords;
coords.append(rect.topLeft());
coords.append(rect.bottomRight());
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)
{
mc2->setView(mc->currentCoordinate());
}
if (evnt->type() == QEvent::MouseButtonPress && btn3->isChecked())
{
mc->moveTo(coordinate);
}
// 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)
{
mc2->moveTo(coordinate);
mc->setView(coordinate);
}
if (evnt->type() == QEvent::MouseButtonPress)
{
mc2->moveTo(coordinate);
mc->setView(coordinate);
}
}

View File

@ -13,48 +13,47 @@
using namespace qmapcontrol;
class Multidemo : public QWidget
{
Q_OBJECT
public:
Multidemo(QWidget *parent = 0);
Q_OBJECT
public:
Multidemo(QWidget *parent = 0);
~Multidemo();
~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;
void setupMaps();
void createLayout();
Layer *l;
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);
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 draggedRect(QRectF);
void mouseEventCoordinate(const QMouseEvent *, const QPointF);
protected:
void keyPressEvent(QKeyEvent* evnt);
virtual void resizeEvent ( QResizeEvent * event );
signals:
void setX(int);
void setY(int);
void zoomIn();
void zoomOut();
protected:
void keyPressEvent(QKeyEvent *evnt);
virtual void resizeEvent(QResizeEvent *event);
signals:
void setX(int);
void setY(int);
void zoomIn();
void zoomOut();
};
#endif

View File

@ -3,13 +3,12 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Phonebook pb;
pb.resize(480, 500);
pb.setWindowTitle("Phonebook Demo");
pb.show();
return app.exec();
}
QApplication app(argc, argv);
Phonebook pb;
pb.resize(480, 500);
pb.setWindowTitle("Phonebook Demo");
pb.show();
return app.exec();
}

View File

@ -1,131 +1,122 @@
#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);
friends = new GeometryLayer("Friends", mapadapter);
friendpoint = new CirclePoint(0.,0., 10);
friends->addGeometry(friendpoint);
mc->addLayer(map);
mc->addLayer(friends);
QListWidget* list = new QListWidget();
QStringList strlist;
strlist << "Kai" << "2";
list->addItems(strlist);
connect(list, SIGNAL(itemClicked( QListWidgetItem* )),
this, SLOT(selectedName(QListWidgetItem*)));
QSlider* slider = new QSlider(Qt::Horizontal);
slider->setMinimum(0);
slider->setMaximum(17);
connect(slider, SIGNAL(valueChanged(int)),
mc, SLOT(setZoom(int)));
mc->setMinimumWidth(480);
QVBoxLayout* maplayout = new QVBoxLayout;
maplayout->addWidget(mc);
maplayout->addWidget(slider);
QHBoxLayout* layout = new QHBoxLayout;
layout->addWidget(list);
layout->addLayout(maplayout);
mc = new MapControl(QSize(480, 540));
MapAdapter *mapadapter = new OSMMapAdapter();
Layer *map = new MapLayer("Karte", mapadapter);
friends = new GeometryLayer("Friends", mapadapter);
QWidget* w = new QWidget;
w->setLayout(layout);
setCentralWidget(w);
createActions();
createMenus();
friendpoint = new CirclePoint(0., 0., 10);
friends->addGeometry(friendpoint);
mc->addLayer(map);
mc->addLayer(friends);
QListWidget *list = new QListWidget();
QStringList strlist;
strlist << "Kai"
<< "2";
list->addItems(strlist);
connect(list, SIGNAL(itemClicked(QListWidgetItem *)), this,
SLOT(selectedName(QListWidgetItem *)));
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setMinimum(0);
slider->setMaximum(17);
connect(slider, SIGNAL(valueChanged(int)), mc, SLOT(setZoom(int)));
mc->setMinimumWidth(480);
QVBoxLayout *maplayout = new QVBoxLayout;
maplayout->addWidget(mc);
maplayout->addWidget(slider);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(list);
layout->addLayout(maplayout);
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")
{
friendpoint->setCoordinate(QPointF(8.26, 50));
friendpoint->setName("Kai");
mc->setView(friendpoint);
}
else if (item->text() == "2")
{
friendpoint->setCoordinate(QPointF(6.43, 40));
mc->setView(friendpoint);
}
if (item->text() == "Kai")
{
friendpoint->setCoordinate(QPointF(8.26, 50));
friendpoint->setName("Kai");
mc->setView(friendpoint);
}
else if (item->text() == "2")
{
friendpoint->setCoordinate(QPointF(6.43, 40));
mc->setView(friendpoint);
}
}
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 = menuBar()->addMenu(tr("&File"));
// 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 = menuBar()->addMenu(tr("&Edit"));
// editMenu->addAction(cutAct);
// editMenu->addAction(copyAct);
// editMenu->addAction(pasteAct);
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("&Help"));
// helpMenu->addAction(aboutAct);
// helpMenu->addAction(aboutQtAct);
}
Phonebook::~Phonebook()
{
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("&Help"));
// helpMenu->addAction(aboutAct);
// helpMenu->addAction(aboutQtAct);
}
Phonebook::~Phonebook() { }

View File

@ -4,38 +4,38 @@
#include <QtGui>
#include "../../../qmapcontrol.h"
using namespace qmapcontrol;
class Phonebook: public QMainWindow
class Phonebook : public QMainWindow
{
Q_OBJECT
public:
Phonebook(QWidget* parent = 0);
~Phonebook();
Q_OBJECT
public:
Phonebook(QWidget *parent = 0);
~Phonebook();
private:
MapControl* mc;
Layer* friends;
Point* friendpoint;
void createActions();
void createMenus();
QMenu *fileMenu;
QMenu *editMenu;
QMenu *helpMenu;
QToolBar *fileToolBar;
QToolBar *editToolBar;
QAction *newAct;
QAction *openAct;
QAction *saveAct;
QAction *saveAsAct;
QAction *exitAct;
QAction *cutAct;
QAction *copyAct;
QAction *pasteAct;
QAction *aboutAct;
QAction *aboutQtAct;
public slots:
void selectedName(QListWidgetItem* item);
MapControl *mc;
Layer *friends;
Point *friendpoint;
void createActions();
void createMenus();
QMenu *fileMenu;
QMenu *editMenu;
QMenu *helpMenu;
QToolBar *fileToolBar;
QToolBar *editToolBar;
QAction *newAct;
QAction *openAct;
QAction *saveAct;
QAction *saveAsAct;
QAction *exitAct;
QAction *cutAct;
QAction *copyAct;
QAction *pasteAct;
QAction *aboutAct;
QAction *aboutQtAct;
public slots:
void selectedName(QListWidgetItem *item);
};
#endif

View File

@ -1,95 +1,96 @@
/*
*
* 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)
: Point(x, y, name, alignment)
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() { }
void ArrowPoint::setHeading(qreal heading)
{
h = heading;
drawArrow();
}
qreal ArrowPoint::getHeading() const
{
return h;
}
void ArrowPoint::setPen(QPen *pen)
{
mypen = pen;
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
painter.setRenderHints(QPainter::Antialiasing | QPainter::Qt4CompatiblePainting);
//#endif
if (mypen)
{
size = QSize(sideLength, sideLength);
h = heading;
mypen = pen;
mypixmap = QPixmap(sideLength, sideLength);
drawArrow();
painter.setPen(*mypen);
painter.setBrush(QBrush(mypen->color()));
}
else
{
painter.setBrush(QBrush(painter.pen().color()));
}
ArrowPoint::~ArrowPoint()
{
}
void ArrowPoint::setHeading(qreal heading)
{
h = heading;
drawArrow();
}
painter.setWindow(-(size.width() / 2), -(size.height() / 2), size.width(),
size.height());
QTransform transform;
transform.rotate(-h);
transform.scale(0.4, 0.75);
painter.setWorldTransform(transform);
qreal ArrowPoint::getHeading() const
{
return h;
}
void ArrowPoint::setPen(QPen* pen)
{
mypen = pen;
drawArrow();
}
QPolygon arrow;
arrow << QPoint(0, -(size.height() / 2));
arrow << QPoint(-(size.width() / 2), +(size.height() / 2));
arrow << QPoint(0, 0);
arrow << QPoint(+(size.width() / 2), +(size.height() / 2));
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
painter.setRenderHints(QPainter::Antialiasing | QPainter::Qt4CompatiblePainting);
//#endif
if(mypen)
{
painter.setPen(*mypen);
painter.setBrush(QBrush(mypen->color()));
}
else
{
painter.setBrush(QBrush(painter.pen().color()));
}
painter.setWindow(-(size.width() / 2), -(size.height() / 2), size.width(), size.height());
QTransform transform;
transform.rotate(-h);
transform.scale(0.4, 0.75);
painter.setWorldTransform(transform);
QPolygon arrow;
arrow << QPoint(0, -(size.height() / 2));
arrow << QPoint(-(size.width() / 2), +(size.height() / 2));
arrow << QPoint(0, 0);
arrow << QPoint(+(size.width() / 2), +(size.height() / 2));
painter.drawPolygon(arrow);
}
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,54 +35,57 @@
namespace qmapcontrol
{
//! 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
//! 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:
//!
/*!
*
* @author Jeffery MacEachern <j.maceachern@gmail.com>
* @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 name name of the arrow point
* @param alignment alignment (Middle or TopLeft)
* @param pen QPen for drawing
*/
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 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);
virtual ~ArrowPoint();
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
/*!
* A QPen can be used to modify the look of the drawn arrow
* @param pen the QPen which should be used for drawing
* @see http://doc.trolltech.com/4.3/qpen.html
*/
virtual void setPen(QPen* pen);
//! sets the QPen which is used for drawing the arrow
/*!
* A QPen can be used to modify the look of the drawn arrow
* @param pen the QPen which should be used for drawing
* @see http://doc.trolltech.com/4.3/qpen.html
*/
virtual void setPen(QPen *pen);
//! sets the heading of the arrow and redraws it in the new orientation
/*!
* @param heading new heading
*/
void setHeading(qreal heading);
//! sets the heading of the arrow and redraws it in the new orientation
/*!
* @param heading new heading
*/
void setHeading(qreal heading);
//! gets the current heading of the arrow
qreal getHeading() const;
private:
void drawArrow();
//! gets the current heading of the arrow
qreal getHeading() const;
// Heading
qreal h;
private:
void drawArrow();
// Brush to fill the arrow with - solid colour, same as pen
QBrush mybrush;
};
// Heading
qreal h;
// 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,120 +38,129 @@
namespace qmapcontrol
{
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;
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())
myKey.prepend("&key=");
if (myMapType.isEmpty())
myMapType.append("Road");
}
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);
x += mTileSize / 2;
y += mTileSize / 2;
return QPoint(int(x), int(y));
}
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);
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 t = atan(exp(YCoord));
qreal res = (2. * t) - (M_PI / 2.);
return res;
}
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()
{
if (mCurrent_zoom >= maxZoom())
return;
mCurrent_zoom += 1;
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
}
void bingApiMapadapter::zoom_out()
{
if (mCurrent_zoom <= minZoom())
return;
mCurrent_zoom -= 1;
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 location = "/REST/v1/Imagery/Map/";
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));
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");
return location;
}
void bingApiMapadapter::setKey(QString apiKey)
{
if (apiKey.isEmpty())
return;
myKey.clear();
myKey.append("&key=" + apiKey);
}
void bingApiMapadapter::setMapType(QString mapType) /* Aerial, AerialWithLabels, Road */
{
if (mapType.isEmpty())
return;
myMapType.clear();
myMapType.append(mapType);
}
if (!myKey.isEmpty())
myKey.prepend("&key=");
if (myMapType.isEmpty())
myMapType.append("Road");
}
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);
x += mTileSize / 2;
y += mTileSize / 2;
return QPoint(int(x), int(y));
}
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);
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 t = atan(exp(YCoord));
qreal res = (2. * t) - (M_PI / 2.);
return res;
}
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()
{
if (mCurrent_zoom >= maxZoom())
return;
mCurrent_zoom += 1;
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
}
void bingApiMapadapter::zoom_out()
{
if (mCurrent_zoom <= minZoom())
return;
mCurrent_zoom -= 1;
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 location = "/REST/v1/Imagery/Map/";
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));
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");
return location;
}
void bingApiMapadapter::setKey(QString apiKey)
{
if (apiKey.isEmpty())
return;
myKey.clear();
myKey.append("&key=" + apiKey);
}
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,34 +39,34 @@
namespace qmapcontrol
{
class QMAPCONTROL_EXPORT bingApiMapadapter : public TileMapAdapter
{
Q_OBJECT
public:
bingApiMapadapter(QString mapType = "Road", QString apiKey = "");
virtual ~bingApiMapadapter();
class QMAPCONTROL_EXPORT bingApiMapadapter : public TileMapAdapter
{
Q_OBJECT
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 */
void setKey(QString apiKey);
void setMapType(QString mapType); /* Aerial, AerialWithLabels, Road */
protected:
virtual void zoom_in();
virtual void zoom_out();
protected:
virtual void zoom_in();
virtual void zoom_out();
private:
virtual QString getQ(qreal longitude, qreal latitude, int zoom) const;
qreal getMercatorLatitude(qreal YCoord) const;
qreal getMercatorYCoord(qreal lati) const;
private:
virtual QString getQ(qreal longitude, qreal latitude, int zoom) const;
qreal getMercatorLatitude(qreal YCoord) const;
qreal getMercatorYCoord(qreal lati) const;
qreal coord_per_x_tile;
qreal coord_per_y_tile;
int srvNum;
QString myKey;
QString myMapType;
};
qreal coord_per_x_tile;
qreal coord_per_y_tile;
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)
: Point(x, y, name, alignment)
{
size = QSize(radius, radius);
mypen = pen;
mypixmap = QPixmap(radius+1, radius+1);
drawCircle();
}
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);
drawCircle();
}
CirclePoint::~CirclePoint()
{
}
void CirclePoint::setPen(QPen* pen)
{
mypen = pen;
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
painter.setRenderHints(QPainter::Antialiasing | QPainter::Qt4CompatiblePainting);
//#endif
if (mypen != 0)
{
painter.setPen(*mypen);
}
painter.drawEllipse(0,0, size.width(), size.height());
}
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);
drawCircle();
}
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);
drawCircle();
}
CirclePoint::~CirclePoint() { }
void CirclePoint::setPen(QPen *pen)
{
mypen = pen;
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
painter.setRenderHints(QPainter::Antialiasing | QPainter::Qt4CompatiblePainting);
//#endif
if (mypen != 0)
{
painter.setPen(*mypen);
}
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,50 +31,52 @@
namespace qmapcontrol
{
//! 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
//! 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:
//!
/*!
*
* @author Kai Winter <kaiwinter@gmx.de>
* @param x longitude
* @param y latitude
* @param name name of the circle point
* @param alignment alignment (Middle or TopLeft)
* @param pen QPen for drawing
*/
class QMAPCONTROL_EXPORT CirclePoint : public Point
{
public:
//!
/*!
*
* @param x longitude
* @param y latitude
* @param name name of the circle point
* @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);
//!
/*!
*
* @param x longitude
* @param y latitude
* @param radius the radius of the circle
* @param name name of the circle point
* @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);
virtual ~CirclePoint();
//!
/*!
*
* @param x longitude
* @param y latitude
* @param radius the radius of the circle
* @param name name of the circle point
* @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);
virtual ~CirclePoint();
//! sets the QPen which is used for drawing the circle
/*!
* A QPen can be used to modify the look of the drawn circle
* @param pen the QPen which should be used for drawing
* @see http://doc.trolltech.com/4.3/qpen.html
*/
virtual void setPen(QPen* pen);
//! sets the QPen which is used for drawing the circle
/*!
* A QPen can be used to modify the look of the drawn circle
* @param pen the QPen which should be used for drawing
* @see http://doc.trolltech.com/4.3/qpen.html
*/
virtual void setPen(QPen *pen);
private:
void drawCircle();
};
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)
: Geometry(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,35 +32,38 @@
namespace qmapcontrol
{
//! 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."
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Curve : public Geometry
{
Q_OBJECT
public:
virtual ~Curve();
//! 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."
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Curve : public Geometry
{
Q_OBJECT
public:
virtual ~Curve();
double Length;
double Length;
// virtual Geometry Clone();
// virtual QRectF GetBoundingBox();
// virtual Geometry Clone();
// virtual QRectF GetBoundingBox();
// virtual Point EndPoint() = 0;
// virtual Point StartPoint() = 0;
// virtual Point Value() = 0;
// virtual Point EndPoint() = 0;
// virtual Point StartPoint() = 0;
// virtual Point Value() = 0;
protected:
Curve(QString name = QString());
virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &screensize, const QPoint offset) = 0;
};
protected:
Curve(QString name = QString());
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)
{
Q_UNUSED(tileSize)
PI = acos(-1.0);
EmptyMapAdapter::EmptyMapAdapter(int tileSize, int minZoom, int maxZoom)
: MapAdapter("", "", 256, minZoom, maxZoom)
{
Q_UNUSED(tileSize)
PI = acos(-1.0);
mNumberOfTiles = tilesonzoomlevel(minZoom);
}
EmptyMapAdapter::~EmptyMapAdapter()
{
}
void EmptyMapAdapter::zoom_in()
{
if (mCurrent_zoom < mMax_zoom)
{
mCurrent_zoom = mCurrent_zoom + 1;
}
mNumberOfTiles = tilesonzoomlevel(mCurrent_zoom);
}
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::rad_deg(qreal x) const
{
return x * (180/PI);
}
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);
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)));
return QPointF(longitude, latitude);
}
bool EmptyMapAdapter::isTileValid(int x, int y, int z) const
{
if (mMax_zoom < mMin_zoom)
{
z= mMin_zoom - z;
}
bool result = true;
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;
}
mNumberOfTiles = tilesonzoomlevel(minZoom);
}
EmptyMapAdapter::~EmptyMapAdapter() { }
void EmptyMapAdapter::zoom_in()
{
if (mCurrent_zoom < mMax_zoom)
{
mCurrent_zoom = mCurrent_zoom + 1;
}
mNumberOfTiles = tilesonzoomlevel(mCurrent_zoom);
}
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::rad_deg(qreal x) const
{
return x * (180 / PI);
}
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);
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)));
return QPointF(longitude, latitude);
}
bool EmptyMapAdapter::isTileValid(int x, int y, int z) const
{
if (mMax_zoom < mMin_zoom)
{
z = mMin_zoom - z;
}
bool result = true;
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;
}
}

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,44 +31,45 @@
namespace qmapcontrol
{
//! MapAdapter which do not load map tiles.
//! 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
{
Q_OBJECT
public:
//! Constructor.
/*!
* 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>
* @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
*/
class QMAPCONTROL_EXPORT EmptyMapAdapter : public MapAdapter
{
Q_OBJECT
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 minZoom the minimum zoom level
* @param maxZoom the maximum zoom level
*/
EmptyMapAdapter(int tileSize = 256, int minZoom = 0, int maxZoom = 17);
EmptyMapAdapter(int tileSize = 256, int minZoom = 0, int maxZoom = 17);
virtual ~EmptyMapAdapter();
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;
qreal PI;
protected:
qreal rad_deg(qreal) const;
qreal deg_rad(qreal) const;
protected:
qreal rad_deg(qreal) const;
qreal deg_rad(qreal) const;
virtual bool isTileValid(int x, int y, int z) const;
virtual void zoom_in();
virtual void zoom_out();
virtual QString query(int x, int y, int z) const;
virtual int tilesonzoomlevel(int zoomlevel) const;
virtual int xoffset(int x) const;
virtual int yoffset(int y) const;
};
virtual bool isTileValid(int x, int y, int z) const;
virtual void zoom_in();
virtual void zoom_out();
virtual QString query(int x, int y, int z) const;
virtual int tilesonzoomlevel(int zoomlevel) const;
virtual int xoffset(int x) const;
virtual int yoffset(int y) const;
};
}
#endif

View File

@ -1,66 +1,70 @@
/*
*
* 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;
mypixmap = QPixmap(filename);
size = mypixmap.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)
{
mypixmap = pixmap;
size = mypixmap.size();
}
void FixedImageOverlay::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &, const QPoint)
{
if (!visible)
return;
const QPointF c = QPointF(X, Y);
QPoint topleft = mapadapter->coordinateToDisplay(c);
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()
{
}
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;
}
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)
{
if (!visible)
return;
const QPointF c = QPointF(X, Y);
QPoint topleft = mapadapter->coordinateToDisplay(c);
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() { }
}

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:
//! Creates an image overlay which loads and displays the given image file
/*!
* 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>
* 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 filename the file which should be loaded and displayed
* @param name the name of the image point
*/
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 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 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());
//! 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 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());
virtual void draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset);
virtual ~FixedImageOverlay();
virtual void draw(QPainter *painter, const MapAdapter *mapadapter,
const QRect &viewport, const QPoint offset);
virtual ~FixedImageOverlay();
private:
qreal x_lowerright;
qreal y_lowerright;
};
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 Geometry::name() const
{
return myname;
}
Geometry* Geometry::parentGeometry() const
{
return myparentGeometry;
}
void Geometry::setParentGeometry(Geometry* geom)
{
myparentGeometry = geom;
}
bool Geometry::hasPoints() const
{
return false;
}
bool Geometry::hasClickedPoints() const
{
return false;
}
QList<Geometry*>& Geometry::clickedPoints()
{
return touchedPoints;
}
bool Geometry::isVisible() const
{
return 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;
}
Geometry::Geometry(QString name)
: GeometryType("Geometry")
, myparentGeometry(0)
, mypen(0)
, visible(true)
, myname(name)
{
}
Geometry::~Geometry() { }
QString Geometry::name() const
{
return myname;
}
Geometry *Geometry::parentGeometry() const
{
return myparentGeometry;
}
void Geometry::setParentGeometry(Geometry *geom)
{
myparentGeometry = geom;
}
bool Geometry::hasPoints() const
{
return false;
}
bool Geometry::hasClickedPoints() const
{
return false;
}
QList<Geometry *> &Geometry::clickedPoints()
{
return touchedPoints;
}
bool Geometry::isVisible() const
{
return 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;
}
}

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,124 +34,129 @@
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.
*
* This class and the derived classes Point, Curve and LineString are leant on the Simple
* Feature Specification of the Open Geospatial Consortium.
* @see www.opengeospatial.com
*
* @author Kai Winter <kaiwinter@gmx.de>
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.
* @see www.opengeospatial.com
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Geometry : public QObject
{
friend class LineString;
Q_OBJECT
public:
explicit Geometry(QString name = QString());
virtual ~Geometry();
QString GeometryType;
//!
/*! returns true if the given Geometry is equal to this Geometry
* not implemented yet!
* @param geom The Geometry to be tested
* @return true if the given Geometry is equal to this
*/
class QMAPCONTROL_EXPORT Geometry : public QObject
{
friend class LineString;
Q_OBJECT
public:
explicit Geometry(QString name = QString());
virtual ~Geometry();
bool Equals(Geometry *geom);
QString GeometryType;
//! returns a String representation of this Geometry
/*!
* not implemented yet!
* @return a String representation of this Geometry
*/
QString toString();
//!
/*! returns true if the given Geometry is equal to this Geometry
* not implemented yet!
* @param geom The Geometry to be tested
* @return true if the given Geometry is equal to this
*/
bool Equals(Geometry* geom);
//! returns the name of this Geometry
/*!
* @return the name of this Geometry
*/
QString name() const;
//! returns a String representation of this Geometry
/*!
* not implemented yet!
* @return a String representation of this Geometry
*/
QString toString();
//! 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
* @return the parent Geometry of this Geometry
*/
Geometry *parentGeometry() const;
//! returns the name of this Geometry
/*!
* @return the name of this Geometry
*/
QString name() const;
//! returns true if this Geometry is visible
/*!
* @return true if this Geometry is visible
*/
bool isVisible() const;
//! 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
* @return the parent Geometry of this Geometry
*/
Geometry* parentGeometry() const;
//! sets the name of the geometry
/*!
* @param name the new name of the geometry
*/
void setName(QString name);
//! returns true if this Geometry is visible
/*!
* @return true if this Geometry is visible
*/
bool isVisible() const;
//! 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.
* @return the QPen which is used for drawing
*/
QPen *pen() const;
//! sets the name of the geometry
/*!
* @param name the new name of the geometry
*/
void setName(QString name);
//! 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 bool hasPoints() const;
virtual bool hasClickedPoints() const;
virtual void setPen(QPen *pen);
virtual QList<Geometry *> &clickedPoints();
virtual QList<Point *> points() = 0;
//! 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.
* @return the QPen which is used for drawing
*/
QPen* pen() const;
private:
Q_DISABLE_COPY(Geometry)
//! 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 bool hasPoints() const;
virtual bool hasClickedPoints() const;
virtual void setPen(QPen* pen);
virtual QList<Geometry*>& clickedPoints();
virtual QList<Point*> points()=0;
Geometry *myparentGeometry;
QList<Geometry *> touchedPoints;
private:
Q_DISABLE_COPY( Geometry )
protected:
QPen *mypen;
bool visible;
QString myname;
void setParentGeometry(Geometry *geom);
Geometry* myparentGeometry;
QList<Geometry*> touchedPoints;
signals:
void updateRequest(Geometry *geom);
void updateRequest(QRectF rect);
//! This signal is emitted when a Geometry is clicked
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The objects emits a signal if it gets clicked
* @param geometry The clicked Geometry
* @param point -unused-
*/
void geometryClicked(Geometry *geometry, QPoint point);
protected:
QPen* mypen;
bool visible;
QString myname;
void setParentGeometry(Geometry* geom);
//! A Geometry emits this signal, when its position gets changed
/*!
* @param geom the Geometry
*/
void positionChanged(Geometry *geom);
signals:
void updateRequest(Geometry* geom);
void updateRequest(QRectF rect);
//! This signal is emitted when a Geometry is clicked
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The objects emits a signal if it gets clicked
* @param geometry The clicked Geometry
* @param point -unused-
*/
void geometryClicked(Geometry* geometry, QPoint point);
//! A Geometry emits this signal, when its position gets changed
/*!
* @param geom the Geometry
*/
void positionChanged(Geometry* geom);
public slots:
//! if visible is true, the layer is made visible
/*!
* @param visible if the layer should be visible
*/
virtual void setVisible(bool visible);
};
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)
: Layer(layername, mapadapter, Layer::GeometryLayer, takeevents)
{
}
GeometryLayer::~GeometryLayer()
{
}
GeometryLayer::GeometryLayer(QString layername, MapAdapter *mapadapter, bool takeevents)
: Layer(layername, mapadapter, Layer::GeometryLayer, takeevents)
{
}
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
/*!
* There are two different layer types:
* - 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT GeometryLayer : public Layer
{
Q_OBJECT
//! 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
* - 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT GeometryLayer : public Layer
{
Q_OBJECT
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"
*/
GeometryLayer(QString layername, MapAdapter* mapadapter, bool takeevents=true);
virtual ~GeometryLayer();
};
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"
*/
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,228 +39,248 @@
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;
mCoord_per_y_tile = 180. / mNumberOfTiles;
bool usingBusinessAPI = (mApiType == GoogleMapsForBusinessesAPI);
if (!mApiKey.isEmpty() && !usingBusinessAPI)
{
mMapLayerType = typeToString(qMapType);
mNumberOfTiles = pow(2., mCurrent_zoom + 0.0);
mCoord_per_x_tile = 360. / mNumberOfTiles;
mCoord_per_y_tile = 180. / mNumberOfTiles;
bool usingBusinessAPI = (mApiType == GoogleMapsForBusinessesAPI);
if ( !mApiKey.isEmpty() && !usingBusinessAPI )
{
mApiKey.prepend("&key=");
}
if ( !mApiClientID.isEmpty() && usingBusinessAPI )
{
mApiClientID.prepend("&client=");
}
if ( !mMapLayerType.isEmpty() )
{
mMapLayerType.prepend("&maptype=");
}
mApiKey.prepend("&key=");
}
googleApiMapadapter::~googleApiMapadapter()
if (!mApiClientID.isEmpty() && usingBusinessAPI)
{
mApiClientID.prepend("&client=");
}
QString googleApiMapadapter::getHost() const
if (!mMapLayerType.isEmpty())
{
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);
x += mTileSize / 2;
y += mTileSize / 2;
return QPoint(int(x), int(y));
}
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 t = atan(exp(YCoord));
qreal res = (2. * t) - (PI / 2.);
return res;
}
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()
{
if (mCurrent_zoom >= maxZoom())
return;
mCurrent_zoom += 1;
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
mCoord_per_x_tile = 360. / mNumberOfTiles;
mCoord_per_y_tile = 180. / mNumberOfTiles;
}
void googleApiMapadapter::zoom_out()
{
if (mCurrent_zoom <= minZoom())
return;
mCurrent_zoom -= 1;
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
{
if ((x >= 0 && x < mNumberOfTiles) && (y >= 0 && y < mNumberOfTiles) && z >= 0)
return true;
return false;
}
QString googleApiMapadapter::typeToString(layerType qLayerType)
{
switch (qLayerType)
{
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.);
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 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");
if (! mMapLayerType.isEmpty())
{
location.append(mMapLayerType);
}
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");
}
else
{
location.append(mApiClientID);
}
}
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");
}
else
{
// 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
//
// 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=
QString urlSignature = "&signature=";
QString computedHash = signURL( location, mApiKey );
urlSignature.append( computedHash );
location.append( urlSignature );
}
}
return location;
}
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("-", "+");
usablePrivateKey.replace("_", "/");
QByteArray privateKeyBytes;
privateKeyBytes.append(qPrintable(usablePrivateKey));
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(qPrintable(qURL));
QString rawSignature = hash.hash(privateKeyBytes, QCryptographicHash::Sha1);
// convert the bytes to string and make url-safe by replacing '+' and '/' characters
QByteArray base64signature;
base64signature.append(rawSignature.toUtf8());
// base 64 encode the binary signature
QString result = base64signature.toBase64();
// convert the signature to 'web safe' base 64
result.replace("+", "-");
result.replace("/", "_");
return result;
}
void googleApiMapadapter::setKey(QString qApiKey)
{
if (qApiKey.isEmpty())
return;
mApiKey.clear();
mApiKey.append("&key=");
mApiKey.append(qApiKey);
}
void googleApiMapadapter::setMapLayerType(layerType qMapType)
{
mMapLayerType.clear();
mMapLayerType.append("&maptype=");
mMapLayerType.append(typeToString(qMapType));
mMapLayerType.prepend("&maptype=");
}
}
googleApiMapadapter::~googleApiMapadapter() { }
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);
x += mTileSize / 2;
y += mTileSize / 2;
return QPoint(int(x), int(y));
}
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 t = atan(exp(YCoord));
qreal res = (2. * t) - (PI / 2.);
return res;
}
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()
{
if (mCurrent_zoom >= maxZoom())
return;
mCurrent_zoom += 1;
mNumberOfTiles = pow(2, mCurrent_zoom + 0.0);
mCoord_per_x_tile = 360. / mNumberOfTiles;
mCoord_per_y_tile = 180. / mNumberOfTiles;
}
void googleApiMapadapter::zoom_out()
{
if (mCurrent_zoom <= minZoom())
return;
mCurrent_zoom -= 1;
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
{
if ((x >= 0 && x < mNumberOfTiles) && (y >= 0 && y < mNumberOfTiles) && z >= 0)
return true;
return false;
}
QString googleApiMapadapter::typeToString(layerType qLayerType)
{
switch (qLayerType)
{
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.);
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 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");
if (!mMapLayerType.isEmpty())
{
location.append(mMapLayerType);
}
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");
}
else
{
location.append(mApiClientID);
}
}
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");
}
else
{
// 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
//
// 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=
QString urlSignature = "&signature=";
QString computedHash = signURL(location, mApiKey);
urlSignature.append(computedHash);
location.append(urlSignature);
}
}
return location;
}
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("-", "+");
usablePrivateKey.replace("_", "/");
QByteArray privateKeyBytes;
privateKeyBytes.append(qPrintable(usablePrivateKey));
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(qPrintable(qURL));
QString rawSignature = hash.hash(privateKeyBytes, QCryptographicHash::Sha1);
// convert the bytes to string and make url-safe by replacing '+' and '/' characters
QByteArray base64signature;
base64signature.append(rawSignature.toUtf8());
// base 64 encode the binary signature
QString result = base64signature.toBase64();
// convert the signature to 'web safe' base 64
result.replace("+", "-");
result.replace("/", "_");
return result;
}
void googleApiMapadapter::setKey(QString qApiKey)
{
if (qApiKey.isEmpty())
return;
mApiKey.clear();
mApiKey.append("&key=");
mApiKey.append(qApiKey);
}
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,57 +39,60 @@
namespace qmapcontrol
{
class QMAPCONTROL_EXPORT googleApiMapadapter : public TileMapAdapter
class QMAPCONTROL_EXPORT googleApiMapadapter : public TileMapAdapter
{
Q_OBJECT
public:
enum layerType
{
Q_OBJECT
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
};
enum apiType
{
GoogleMapsAPI = 0,
GoogleMapsForBusinessesAPI
};
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;
QString getHost() const;
void setKey(QString apiKey);
void setMapLayerType(layerType qMapType = layerType_ROADMAP);
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;
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;
qreal mCoord_per_x_tile;
qreal mCoord_per_y_tile;
QString mApiKey;
QString mApiClientID;
apiType mApiType;
QString mMapLayerType;
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
{
GoogleMapsAPI = 0,
GoogleMapsForBusinessesAPI
};
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;
QString getHost() const;
void setKey(QString apiKey);
void setMapLayerType(layerType qMapType = layerType_ROADMAP);
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;
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;
qreal mCoord_per_x_tile;
qreal mCoord_per_y_tile;
QString mApiKey;
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)
{
switch (qLayerType)
{
case satellite: return "s";
case terrain: return "t";
case hybrid: return "h";
case roadmap:
default:
return "m";
}
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,31 +31,32 @@
namespace qmapcontrol
{
//! 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
{
Q_OBJECT
//! 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
{
Q_OBJECT
public:
enum googleLayerType
{
roadmap = 0,
satellite,
terrain,
hybrid
};
//! constructor
/*!
* This construct a Google Adapter
*/
GoogleMapAdapter( googleLayerType qLayerType = roadmap );
virtual ~GoogleMapAdapter();
private:
QString typeToString( googleLayerType qLayerType );
public:
enum googleLayerType
{
roadmap = 0,
satellite,
terrain,
hybrid
};
//! constructor
/*!
* This construct a Google Adapter
*/
GoogleMapAdapter(googleLayerType qLayerType = roadmap);
virtual ~GoogleMapAdapter();
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
/*!
* 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.
* @author Kai Winter
*/
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*/
//! 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.
* @author Kai Winter
*/
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:
QString longitude_dir;
QString latitude_dir;
};
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,150 +34,153 @@ 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))
{
emptyPixmap.fill(Qt::transparent);
//initialize loading image
loadingPixmap.fill( Qt::transparent );
QPainter paint(&loadingPixmap);
QBrush brush( Qt::lightGray, Qt::Dense5Pattern );
paint.fillRect(loadingPixmap.rect(), brush );
paint.end();
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);
if (QPixmapCache::cacheLimit() <= kDefaultPixmapCacheSizeKB)
{
QPixmapCache::setCacheLimit(kDefaultPixmapCacheSizeKB);
}
// initialize loading image
loadingPixmap.fill(Qt::transparent);
QPainter paint(&loadingPixmap);
QBrush brush(Qt::lightGray, Qt::Dense5Pattern);
paint.fillRect(loadingPixmap.rect(), brush);
paint.end();
if (QPixmapCache::cacheLimit() <= kDefaultPixmapCacheSizeKB)
{
QPixmapCache::setCacheLimit(kDefaultPixmapCacheSizeKB);
}
}
ImageManager::~ImageManager()
{
delete net;
net = 0;
}
QPixmap ImageManager::getImage(const QString &host, const QString &url)
{
// qDebug() << "ImageManager::getImage";
QPixmap pm;
if (net->imageIsLoading(url))
{
// currently loading an image
return loadingPixmap;
}
else if (QPixmapCache::find(url, &pm))
{
// image found in cache, use this version
return pm;
}
// 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
return pm;
}
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";
}
else
{
// 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
prefetch.append(url);
#endif
return getImage(host, url);
}
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
if (failedFetches.contains(url))
{
failedFetches.remove(url);
}
ImageManager::~ImageManager()
if (!prefetch.contains(url))
{
delete net;
net = 0;
emit imageReceived();
}
QPixmap ImageManager::getImage(const QString& host, const QString& url)
else
{
//qDebug() << "ImageManager::getImage";
QPixmap pm;
if ( net->imageIsLoading(url) )
{
//currently loading an image
return loadingPixmap;
}
else if ( QPixmapCache::find(url, &pm) )
{
//image found in cache, use this version
return pm;
}
//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
return pm;
}
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";
}
else
{
//load from net, add empty image
net->loadImage(host, url);
}
return emptyPixmap;
#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
prefetch.remove(prefetch.indexOf(url));
#endif
}
}
QPixmap ImageManager::prefetchImage(const QString& host, const QString& url)
void ImageManager::loadingQueueEmpty()
{
emit loadingFinished();
}
void ImageManager::abortLoading()
{
net->abortLoading();
}
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())
{
// 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
return getImage(host, url);
}
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
if (failedFetches.contains(url))
QDir cacheDir = path;
if (!cacheDir.exists())
{
failedFetches.remove(url);
}
if (!prefetch.contains(url))
{
emit imageReceived();
}
else
{
#if defined Q_WS_QWS || defined Q_WS_MAEMO_5 || defined Q_WS_S60
prefetch.remove(prefetch.indexOf(url));
#endif
cacheDir.mkpath(cacheDir.absolutePath());
}
diskCache->setCacheDirectory(cacheDir.absolutePath());
diskCache->setMaximumCacheSize(qDiskSizeMB * 1024 * 1024); // Megabytes to bytes
net->setDiskCache(diskCache);
}
void ImageManager::loadingQueueEmpty()
else
{
emit loadingFinished();
net->setDiskCache(0);
}
}
void ImageManager::abortLoading()
{
net->abortLoading();
}
int ImageManager::loadQueueSize() const
{
return net->loadQueueSize();
}
void ImageManager::setProxy(QString host, int port, const QString username, const QString password)
{
net->setProxy(host, port, username, password);
}
void qmapcontrol::ImageManager::fetchFailed(const QString &url)
{
qDebug() << "ImageManager::fetchFailed" << url;
void ImageManager::setCacheDir(const QDir& path, const int qDiskSizeMB)
{
if ( !path.absolutePath().isEmpty() )
{
QDir cacheDir = path;
if (!cacheDir.exists())
{
cacheDir.mkpath( cacheDir.absolutePath() );
}
diskCache->setCacheDirectory( cacheDir.absolutePath() );
diskCache->setMaximumCacheSize( qDiskSizeMB *1024*1024 ); //Megabytes to bytes
net->setDiskCache(diskCache);
}
else
{
net->setDiskCache(0);
}
}
int ImageManager::loadQueueSize() const
{
return net->loadQueueSize();
}
void qmapcontrol::ImageManager::fetchFailed(const QString &url)
{
qDebug() << "ImageManager::fetchFailed" << url;
//store current time for this failed image to prevent loading it again until
failedFetches.insert(url, QDateTime::currentDateTime());
}
// 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,85 +39,87 @@
namespace qmapcontrol
{
class MapNetwork;
/**
@author Kai Winter <kaiwinter@gmx.de>
class MapNetwork;
/**
@author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT ImageManager : public QObject
{
Q_OBJECT
public:
ImageManager(QObject *parent = 0);
virtual ~ImageManager();
//! returns a QPixmap of the asked image
/*!
* If this component doesn<EFBFBD>t have the image a network query gets started to load it.
* @param host the host of the image
* @param path the path to the image
* @return the pixmap of the asked image
*/
class QMAPCONTROL_EXPORT ImageManager : public QObject
{
Q_OBJECT
QPixmap getImage(const QString &host, const QString &path);
public:
ImageManager(QObject* parent = 0);
virtual ~ImageManager();
QPixmap prefetchImage(const QString &host, const QString &path);
//! returns a QPixmap of the asked image
/*!
* If this component doesn<EFBFBD>t have the image a network query gets started to load it.
* @param host the host of the image
* @param path the path to the image
* @return the pixmap of the asked image
*/
QPixmap getImage(const QString& host, const QString& path);
void receivedImage(const QPixmap pixmap, const QString &url);
void fetchFailed(const QString &url);
QPixmap prefetchImage(const QString& host, const QString& path);
/*!
* 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.
*/
void loadingQueueEmpty();
void receivedImage(const QPixmap pixmap, const QString& url);
void fetchFailed(const QString &url);
/*!
* Aborts all current loading threads.
* This is useful when changing the zoom-factor, though newly needed images loads
* faster
*/
void abortLoading();
/*!
* 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.
*/
void loadingQueueEmpty();
//! sets the proxy for HTTP connections
/*!
* This method sets the proxy for HTTP connections.
* This is not provided by the current Qtopia version!
* @param host the proxy<EFBFBD>s hostname or ip
* @param port the proxy<EFBFBD>s port
* @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());
/*!
* Aborts all current loading threads.
* This is useful when changing the zoom-factor, though newly needed images loads faster
*/
void abortLoading();
//! sets the cache directory for persistently saving map tiles
/*!
*
* @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);
//! sets the proxy for HTTP connections
/*!
* This method sets the proxy for HTTP connections.
* This is not provided by the current Qtopia version!
* @param host the proxy<EFBFBD>s hostname or ip
* @param port the proxy<EFBFBD>s port
* @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());
/*!
* @return Number of images pending in the load queue
*/
int loadQueueSize() const;
//! sets the cache directory for persistently saving map tiles
/*!
*
* @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);
private:
Q_DISABLE_COPY(ImageManager)
/*!
* @return Number of images pending in the load queue
*/
int loadQueueSize() const;
QPixmap emptyPixmap;
QPixmap loadingPixmap;
private:
Q_DISABLE_COPY( ImageManager )
MapNetwork *net;
QNetworkDiskCache *diskCache;
QVector<QString> prefetch;
QPixmap emptyPixmap;
QPixmap loadingPixmap;
QHash<QString, QDateTime> failedFetches;
MapNetwork* net;
QNetworkDiskCache* diskCache;
QVector<QString> prefetch;
QHash<QString,QDateTime> failedFetches;
signals:
void imageReceived();
void loadingFinished();
};
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)
: Point(x, y, name, alignment)
{
//qDebug() << "loading image: " << filename;
mypixmap = QPixmap(filename);
size = mypixmap.size();
//qDebug() << "image size: " << size;
}
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(qreal x, qreal y, QString filename, QString name,
Alignment alignment)
: Point(x, y, name, alignment)
{
// qDebug() << "loading image: " << filename;
mypixmap = QPixmap(filename);
size = mypixmap.size();
// qDebug() << "image size: " << size;
}
ImagePoint::ImagePoint(qreal x, qreal y, QPixmap pixmap, QString name,
Alignment alignment)
: Point(x, y, name, alignment)
{
mypixmap = pixmap;
size = mypixmap.size();
}
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,40 +32,43 @@
namespace qmapcontrol
{
//! 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>
//! 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:
//! 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.
* @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)
*/
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.
* @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
/*!
* Use this contructor to display the given image.
* You have to load that image yourself, but can use it for multiple points.
* @param x longitude
* @param y latitude
* @param pixmap pointer to the image pixmap
* @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);
virtual ~ImagePoint();
};
//! Creates a point which displays the given image
/*!
* Use this contructor to display the given image.
* You have to load that image yourself, but can use it for multiple points.
* @param x longitude
* @param y latitude
* @param pixmap pointer to the image pixmap
* @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);
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)
: Point(x, y, name, Point::Middle)
{
size = QSize(sideLength, sideLength);
}
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)
: Point(x, y, name, Point::Middle)
{
int sideLength = 10;
size = QSize(sideLength, sideLength);
}
InvisiblePoint::~InvisiblePoint()
{
}
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)
: Point(x, y, name, Point::Middle)
{
size = QSize(width, height);
}
InvisiblePoint::InvisiblePoint(qreal x, qreal y, QString name)
: Point(x, y, name, Point::Middle)
{
int sideLength = 10;
size = QSize(sideLength, sideLength);
}
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,46 +32,47 @@
namespace qmapcontrol
{
//! 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.
//! 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:
//!
/*!
*
* @author Frederic Bourgeois <bourgeoislab@gmail.com>
* @param x longitude
* @param y latitude
* @param name name of the invisible point
*/
class QMAPCONTROL_EXPORT InvisiblePoint : public Point
{
public:
//!
/*!
*
* @param x longitude
* @param y latitude
* @param name name of the invisible point
*/
InvisiblePoint(qreal x, qreal y, QString name = QString());
InvisiblePoint(qreal x, qreal y, QString name = QString());
//!
/*!
*
* @param x longitude
* @param y latitude
* @param width width
* @param height height
* @param name name of the invisible point
*/
InvisiblePoint(qreal x, qreal y, int width = 10, int height = 10, QString name = QString());
//!
/*!
*
* @param x longitude
* @param y latitude
* @param width width
* @param height height
* @param name name of the invisible point
*/
InvisiblePoint(qreal x, qreal y, int width = 10, int height = 10,
QString name = QString());
//!
/*!
*
* @param x longitude
* @param y latitude
* @param sideLength side length of the bounding box (square)
* @param name name of the invisible point
*/
InvisiblePoint(qreal x, qreal y, int sideLength = 10, QString name = QString());
virtual ~InvisiblePoint();
};
//!
/*!
*
* @param x longitude
* @param y latitude
* @param sideLength side length of the bounding box (square)
* @param name name of the invisible point
*/
InvisiblePoint(qreal x, qreal y, int sideLength = 10, QString name = QString());
virtual ~InvisiblePoint();
};
}
#endif

View File

@ -1,386 +1,412 @@
/*
*
* 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()
: 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(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 )
{
mapAdapter->deleteLater();
mapAdapter = 0;
}
}
void Layer::setSize(QSize size)
{
this->size = size;
screenmiddle = QPoint(size.width()/2, size.height()/2);
emit(updateRequest());
}
QString Layer::layername() const
{
return mylayername;
}
MapAdapter* Layer::mapadapter()
{
return mapAdapter;
}
void Layer::setVisible(bool visible)
{
this->visible = visible;
emit(updateRequest());
}
QList<Geometry*>& Layer::getGeometries()
{
return geometries;
}
bool Layer::containsGeometry( Geometry* geometry )
{
return 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 ) )
{
return;
}
geometries.removeAll(geometry);
geometries.append(geometry);
emit(updateRequest());
}
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)));
}
void Layer::removeGeometry(Geometry* geometry, bool qDeleteObject)
{
if ( !geometry )
{
return;
}
QRectF boundingBox = geometry->boundingBox();
foreach( Geometry* geo, geometries )
{
if ( geo && geo == geometry )
{
disconnect(geometry);
geometries.removeAll( geometry );
if (qDeleteObject)
{
delete geo;
geo = 0;
}
}
}
emit(updateRequest(boundingBox));
}
void Layer::clearGeometries( bool qDeleteObject )
{
foreach(Geometry *geometry, geometries)
{
disconnect(geometry);
if ( qDeleteObject )
{
delete geometry;
geometry = 0;
}
}
geometries.clear();
}
bool Layer::isVisible() const
{
return visible;
}
void Layer::zoomIn() const
{
mapAdapter->zoom_in();
}
void Layer::zoomOut() const
{
mapAdapter->zoom_out();
}
void Layer::mouseEvent(const QMouseEvent* evnt, const QPoint mapmiddle_px)
{
if (takesMouseEvents())
{
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)
{
Geometry *geo = *iter;
if (geo && geo->isVisible() && geo->Touches(tmppoint, mapAdapter))
{
emit(geometryClicked(geo, QPoint(evnt->x(), evnt->y())));
}
}
delete tmppoint;
}
}
}
bool Layer::takesMouseEvents() const
{
return takeevents;
}
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
{
QPoint offset;
if (mylayertype == MapLayer)
{
offset = mapmiddle_px;
}
else
{
offset = mapmiddle_px-screenmiddle;
}
painter->translate(-mapmiddle_px+screenmiddle);
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);
}
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;
// 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 space_above = screenmiddle.y() - cross_y;
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_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;
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);
// for the EmptyMapAdapter no tiles should be loaded and painted.
if (mapAdapter->host().isEmpty())
{
return;
}
//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())) );
}
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)
{
// check if image is valid
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())));
}
}
}
}
bool enabledPrefetch = false;
if ( enabledPrefetch )
{
// 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)
{
if (mapAdapter->isTileValid(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()))
{
m_ImageManager->prefetchImage(mapAdapter->host(), mapAdapter->query(i, prefetch_tile_bottom, mapAdapter->currentZoom()));
}
}
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()));
}
if (mapAdapter->isTileValid(prefetch_tile_right, i, mapAdapter->currentZoom()))
{
m_ImageManager->prefetchImage(mapAdapter->host(), mapAdapter->query(prefetch_tile_right, i, mapAdapter->currentZoom()));
}
}
}
}
QRect Layer::offscreenViewport() const
{
return myoffscreenViewport;
}
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)
{
QPoint topleft_relative = QPoint(mapmiddle_px-screenmiddle);
point->drawWidget(mapAdapter, topleft_relative);
}
}
}
}
Layer::LayerType Layer::layertype() const
{
return mylayertype;
}
void Layer::setMapAdapter(MapAdapter* mapadapter)
{
mapAdapter = mapadapter;
emit(updateRequest());
}
void Layer::setImageManager(ImageManager *qImageManager)
{
m_ImageManager = qImageManager;
mapAdapter->deleteLater();
mapAdapter = 0;
}
}
void Layer::setSize(QSize size)
{
this->size = size;
screenmiddle = QPoint(size.width() / 2, size.height() / 2);
emit(updateRequest());
}
QString Layer::layername() const
{
return mylayername;
}
MapAdapter *Layer::mapadapter()
{
return mapAdapter;
}
void Layer::setVisible(bool visible)
{
this->visible = visible;
emit(updateRequest());
}
QList<Geometry *> &Layer::getGeometries()
{
return geometries;
}
bool Layer::containsGeometry(Geometry *geometry)
{
return 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))
{
return;
}
geometries.removeAll(geometry);
geometries.append(geometry);
emit(updateRequest());
}
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)));
}
void Layer::removeGeometry(Geometry *geometry, bool qDeleteObject)
{
if (!geometry)
{
return;
}
QRectF boundingBox = geometry->boundingBox();
foreach (Geometry *geo, geometries)
{
if (geo && geo == geometry)
{
disconnect(geometry);
geometries.removeAll(geometry);
if (qDeleteObject)
{
delete geo;
geo = 0;
}
}
}
emit(updateRequest(boundingBox));
}
void Layer::clearGeometries(bool qDeleteObject)
{
foreach (Geometry *geometry, geometries)
{
disconnect(geometry);
if (qDeleteObject)
{
delete geometry;
geometry = 0;
}
}
geometries.clear();
}
bool Layer::isVisible() const
{
return visible;
}
void Layer::zoomIn() const
{
mapAdapter->zoom_in();
}
void Layer::zoomOut() const
{
mapAdapter->zoom_out();
}
void Layer::mouseEvent(const QMouseEvent *evnt, const QPoint mapmiddle_px)
{
if (takesMouseEvents())
{
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)
{
Geometry *geo = *iter;
if (geo && geo->isVisible() && geo->Touches(tmppoint, mapAdapter))
{
emit(geometryClicked(geo, QPoint(evnt->x(), evnt->y())));
}
}
delete tmppoint;
}
}
}
bool Layer::takesMouseEvents() const
{
return takeevents;
}
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
{
QPoint offset;
if (mylayertype == MapLayer)
{
offset = mapmiddle_px;
}
else
{
offset = mapmiddle_px - screenmiddle;
}
painter->translate(-mapmiddle_px + screenmiddle);
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);
}
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;
// 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 space_above = screenmiddle.y() - cross_y;
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_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;
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);
// for the EmptyMapAdapter no tiles should be loaded and painted.
if (mapAdapter->host().isEmpty())
{
return;
}
// 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())));
}
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)
{
// check if image is valid
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())));
}
}
}
}
bool enabledPrefetch = false;
if (enabledPrefetch)
{
// 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)
{
if (mapAdapter->isTileValid(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()))
{
m_ImageManager->prefetchImage(
mapAdapter->host(),
mapAdapter->query(i, prefetch_tile_bottom,
mapAdapter->currentZoom()));
}
}
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()));
}
if (mapAdapter->isTileValid(prefetch_tile_right, i,
mapAdapter->currentZoom()))
{
m_ImageManager->prefetchImage(
mapAdapter->host(),
mapAdapter->query(prefetch_tile_right, i, mapAdapter->currentZoom()));
}
}
}
}
QRect Layer::offscreenViewport() const
{
return myoffscreenViewport;
}
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)
{
QPoint topleft_relative = QPoint(mapmiddle_px - screenmiddle);
point->drawWidget(mapAdapter, topleft_relative);
}
}
}
}
Layer::LayerType Layer::layertype() const
{
return mylayertype;
}
void Layer::setMapAdapter(MapAdapter *mapadapter)
{
mapAdapter = mapadapter;
emit(updateRequest());
}
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,179 +43,186 @@
namespace qmapcontrol
{
//! 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
* - 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Layer : public QObject
//! 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
* - 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT Layer : public QObject
{
Q_OBJECT
public:
friend class LayerManager;
//! sets the type of a layer, see Layer class doc for further information
enum LayerType
{
Q_OBJECT
public:
friend class LayerManager;
//! sets the type of a layer, see Layer class doc for further information
enum LayerType
{
MapLayer, /*!< uses the MapAdapter to display maps, only gets refreshed when a new offscreen image is needed */
GeometryLayer /*!< gets refreshed everytime when a geometry changes */
};
//! Layer default constructor
/*!
* This is used to construct a layer.
*/
Layer();
//! Layer constructor
/*!
* 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 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"
*/
Layer(QString layername, MapAdapter* mapadapter, enum LayerType layertype, bool takeevents=true);
virtual ~Layer();
//! returns the layer's name
/*!
* @return the name of this layer
*/
QString layername() const;
//! returns the layer´s MapAdapter
/*!
* This method returns the MapAdapter of this Layer, which can be useful
* to do coordinate transformations.
* @return the MapAdapter which us used by this Layer
*/
MapAdapter* mapadapter();
//! adds a Geometry object to this Layer
/*!
* Please notice the different LayerTypes (MapLayer and GeometryLayer) and the differences
* @param geometry the new Geometry
*/
void addGeometry(Geometry* geometry);
//! removes the Geometry object from this Layer
/*!
* This method removes a Geometry object from this Layer.
* 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);
//! removes all Geometry objects from this Layer
/*!
* This method removes all Geometry objects from this Layer.
* 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);
//! 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();
//! returns true if Layer contains geometry
/*!
* This method returns if a Geometry objects is on this Layer.
*/
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 );
//! 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 );
//! return true if the layer is visible
/*!
* @return if the layer is visible
*/
bool isVisible() const;
//! returns the LayerType of the Layer
/*!
* There are two LayerTypes: MapLayer and GeometryLayer
* @return the LayerType of this Layer
*/
Layer::LayerType layertype() const;
void setMapAdapter(MapAdapter* mapadapter);
void setImageManager(ImageManager* qImageManager);
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 setSize(QSize size);
QRect offscreenViewport() const;
bool takesMouseEvents() const;
void mouseEvent(const QMouseEvent*, const QPoint mapmiddle_px);
void zoomIn() const;
void zoomOut() const;
void _draw(QPainter* painter, const QPoint mapmiddle_px) const;
bool visible;
QString mylayername;
LayerType mylayertype;
QSize size;
QPoint screenmiddle;
QList<Geometry*> geometries;
MapAdapter* mapAdapter;
bool takeevents;
mutable QRect myoffscreenViewport;
ImageManager* m_ImageManager;
signals:
//! This signal is emitted when a Geometry is clicked
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The layer emits a signal for every clicked geometry
* @param geometry The clicked Geometry
* @param point The coordinate (in widget coordinates) of the click
*/
void geometryClicked(Geometry* geometry, QPoint point);
void updateRequest(QRectF rect);
void updateRequest();
public slots:
//! if visible is true, the layer is made visible
/*!
* @param visible if the layer should be visible
*/
void setVisible(bool visible);
MapLayer, /*!< uses the MapAdapter to display maps, only gets refreshed when a new offscreen image is needed */
GeometryLayer /*!< gets refreshed everytime when a geometry changes */
};
//! Layer default constructor
/*!
* This is used to construct a layer.
*/
Layer();
//! Layer constructor
/*!
* 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 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"
*/
Layer(QString layername, MapAdapter *mapadapter, enum LayerType layertype,
bool takeevents = true);
virtual ~Layer();
//! returns the layer's name
/*!
* @return the name of this layer
*/
QString layername() const;
//! returns the layer´s MapAdapter
/*!
* This method returns the MapAdapter of this Layer, which can be useful
* to do coordinate transformations.
* @return the MapAdapter which us used by this Layer
*/
MapAdapter *mapadapter();
//! adds a Geometry object to this Layer
/*!
* Please notice the different LayerTypes (MapLayer and GeometryLayer) and the
* differences
* @param geometry the new Geometry
*/
void addGeometry(Geometry *geometry);
//! removes the Geometry object from this Layer
/*!
* This method removes a Geometry object from this Layer.
* 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);
//! removes all Geometry objects from this Layer
/*!
* This method removes all Geometry objects from this Layer.
* 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);
//! 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();
//! returns true if Layer contains geometry
/*!
* This method returns if a Geometry objects is on this Layer.
*/
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);
//! 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);
//! return true if the layer is visible
/*!
* @return if the layer is visible
*/
bool isVisible() const;
//! returns the LayerType of the Layer
/*!
* There are two LayerTypes: MapLayer and GeometryLayer
* @return the LayerType of this Layer
*/
Layer::LayerType layertype() const;
void setMapAdapter(MapAdapter *mapadapter);
void setImageManager(ImageManager *qImageManager);
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 setSize(QSize size);
QRect offscreenViewport() const;
bool takesMouseEvents() const;
void mouseEvent(const QMouseEvent *, const QPoint mapmiddle_px);
void zoomIn() const;
void zoomOut() const;
void _draw(QPainter *painter, const QPoint mapmiddle_px) const;
bool visible;
QString mylayername;
LayerType mylayertype;
QSize size;
QPoint screenmiddle;
QList<Geometry *> geometries;
MapAdapter *mapAdapter;
bool takeevents;
mutable QRect myoffscreenViewport;
ImageManager *m_ImageManager;
signals:
//! This signal is emitted when a Geometry is clicked
/*!
* A Geometry is clickable, if the containing layer is clickable.
* The layer emits a signal for every clicked geometry
* @param geometry The clicked Geometry
* @param point The coordinate (in widget coordinates) of the click
*/
void geometryClicked(Geometry *geometry, QPoint point);
void updateRequest(QRectF rect);
void updateRequest();
public slots:
//! if visible is true, the layer is made visible
/*!
* @param visible if the layer should be visible
*/
void setVisible(bool visible);
};
}
#endif

File diff suppressed because it is too large Load Diff

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,221 +37,221 @@
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.
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT LayerManager : public QObject
{
Q_OBJECT
public:
LayerManager(MapControl *, QSize);
~LayerManager();
//! returns the coordinate of the center of the map
/*!
* 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.
* @author Kai Winter <kaiwinter@gmx.de>
* @return returns the coordinate of the middle of the screen
*/
class QMAPCONTROL_EXPORT LayerManager : public QObject
{
Q_OBJECT
QPointF currentCoordinate() const;
public:
LayerManager(MapControl*, QSize);
~LayerManager();
//! returns the current offscreen image
/*!
* @return the current offscreen image
*/
QPixmap getImage() const;
//! returns the coordinate of the center of the map
/*!
* @return returns the coordinate of the middle of the screen
*/
QPointF currentCoordinate() const;
//! 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 &) const;
//! returns the current offscreen image
/*!
* @return the current offscreen image
*/
QPixmap getImage() const;
//! returns the base layer
/*!
* This will return the base layer of the LayerManager.
* The base layer is the one which is used to do internal coordinate calculations.
* @return the base layer
*/
Layer *layer() const;
//! 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&) const;
//! returns the names of all layers
/*!
* @return returns a QList with the names of all layers
*/
QList<QString> layers() const;
//! returns the base layer
/*!
* This will return the base layer of the LayerManager.
* The base layer is the one which is used to do internal coordinate calculations.
* @return the base layer
*/
Layer* layer() const;
//! sets the middle of the map to the given coordinate
/*!
* @param coordinate the coordinate which the view´s middle should be set to
*/
void setView(const QPointF &coordinate);
//! returns the names of all layers
/*!
* @return returns a QList with the names of all layers
*/
QList<QString> layers() const;
//! sets the view, so all coordinates are visible
/*!
* @param coordinates the Coorinates which should be visible
*/
void setView(const QList<QPointF> coordinates);
//! sets the middle of the map to the given coordinate
/*!
* @param coordinate the coordinate which the view´s middle should be set to
*/
void setView(const QPointF& coordinate);
//! 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.
* @param coordinates the Coorinates which should be visible
*/
void setViewAndZoomIn(const QList<QPointF> coordinates);
//! sets the view, so all coordinates are visible
/*!
* @param coordinates the Coorinates which should be visible
*/
void setView(const QList<QPointF> coordinates);
//! zooms in one step
void zoomIn();
//! 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.
* @param coordinates the Coorinates which should be visible
*/
void setViewAndZoomIn (const QList<QPointF> coordinates);
//! zooms out one step
void zoomOut();
//! zooms in one step
void zoomIn();
//! return min Zoom Level
int minZoom();
//! zooms out one step
void zoomOut();
//! return max Zoom Level
int maxZoom();
//! return min Zoom Level
int minZoom();
//! sets the given zoomlevel
/*!
* @param zoomlevel the zoomlevel
*/
void setZoom(int zoomlevel);
//! return max Zoom Level
int maxZoom();
//! The Viewport of the display
/*!
* Returns the visible viewport in world coordinates
* @return the visible viewport in world coordinates
*/
QRectF getViewport() const;
//! sets the given zoomlevel
/*!
* @param zoomlevel the zoomlevel
*/
void setZoom(int zoomlevel);
//! scrolls the view
/*!
* 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);
//! The Viewport of the display
/*!
* Returns the visible viewport in world coordinates
* @return the visible viewport in world coordinates
*/
QRectF getViewport() const;
//! forwards mouseevents to the layers
/*!
* This method is invoked by the MapControl which receives Mouse Events.
* These events are forwarded to the layers, so they can check for clicked geometries.
* @param evnt the mouse event
*/
void mouseEvent(const QMouseEvent *evnt);
//! scrolls the view
/*!
* 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);
//! returns the middle of the map in projection coordinates
/*!
*
* @return the middle of the map in projection coordinates
*/
QPoint getMapmiddle_px() const;
//! forwards mouseevents to the layers
/*!
* This method is invoked by the MapControl which receives Mouse Events.
* 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 forceRedraw();
void removeZoomImage();
//! returns the middle of the map in projection coordinates
/*!
*
* @return the middle of the map in projection coordinates
*/
QPoint getMapmiddle_px() const;
//! adds a layer
/*!
* 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 forceRedraw();
void removeZoomImage();
//! removes a layer
/*!
* Removes a layer and redraws existing layers
* @param layer the layer which should be removed
*/
void removeLayer(Layer *layer);
//! adds a layer
/*!
* If multiple layers are added, they are painted in the added order.
* @param layer the layer which should be added
*/
void addLayer(Layer* layer);
//! returns the current zoom level
/*!
* @return returns the current zoom level
*/
int currentZoom() const;
//! removes a layer
/*!
* Removes a layer and redraws existing layers
* @param layer the layer which should be removed
*/
void removeLayer( Layer* layer );
void drawGeoms(QPainter *painter);
void drawImage(QPainter *painter);
//! returns the current zoom level
/*!
* @return returns the current zoom level
*/
int currentZoom() const;
//! Set whether to enable a view bounding box
/*!
*
* @param usebounds enable/disable use of bounding box
*/
void setUseBoundingBox(bool usebounds);
void drawGeoms(QPainter* painter);
void drawImage(QPainter* painter);
//! Check if bounding box is being used
/*!
*
* @return if bounding box is being used
*/
bool isBoundingBoxEnabled();
//! Set constraints for bounding box
/*!
*
* @param rect specified bounds for view to stay within
*/
void setBoundingBox(QRectF &rect);
//! Set whether to enable a view bounding box
/*!
*
* @param usebounds enable/disable use of bounding box
*/
void setUseBoundingBox( bool usebounds );
//! Get current bounding box
/*!
*
* @return bounding box
*/
QRectF getBoundingBox();
//! Check if bounding box is being used
/*!
*
* @return if bounding box is being used
*/
bool isBoundingBoxEnabled();
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);
inline bool checkOffscreen() const;
inline bool containsAll(QList<QPointF> coordinates) const;
inline void moveWidgets();
inline void setMiddle(QList<QPointF> coordinates);
//! Set constraints for bounding box
/*!
*
* @param rect specified bounds for view to stay within
*/
void setBoundingBox( QRectF &rect );
MapControl *mapcontrol;
QPoint screenmiddle; // middle of the screen
QPoint scroll; // scrollvalue of the offscreen image
QPoint zoomImageScroll; // scrollvalue of the zoom image
//! Get current bounding box
/*!
*
* @return bounding box
*/
QRectF getBoundingBox();
QSize size; // widget size
QSize offSize; // size of the offscreen image
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);
inline bool checkOffscreen() const;
inline bool containsAll(QList<QPointF> coordinates) const;
inline void moveWidgets();
inline void setMiddle(QList<QPointF> coordinates);
QPixmap composedOffscreenImage;
QPixmap zoomImage;
MapControl* mapcontrol;
QPoint screenmiddle; // middle of the screen
QPoint scroll; // scrollvalue of the offscreen image
QPoint zoomImageScroll; // scrollvalue of the zoom image
QList<Layer *> mylayers;
QSize size; // widget size
QSize offSize; // size of the offscreen image
QPoint mapmiddle_px; // projection-display coordinates
QPointF mapmiddle; // world coordinate
QPixmap composedOffscreenImage;
QPixmap zoomImage;
QPoint whilenewscroll;
QList<Layer*> mylayers;
QRectF boundingBox; // limit viewing area if desired
bool useBoundingBox;
QPoint mapmiddle_px; // projection-display coordinates
QPointF mapmiddle; // world coordinate
QPoint whilenewscroll;
QRectF boundingBox; // limit viewing area if desired
bool useBoundingBox;
public slots:
void updateRequest(QRectF rect);
void updateRequest();
void resize(QSize newSize);
};
public slots:
void updateRequest(QRectF rect);
void updateRequest();
void resize(QSize newSize);
};
}
#endif

View File

@ -1,224 +1,229 @@
/*
*
* 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()
: Curve()
{
GeometryType = "LineString";
}
LineString::LineString()
: Curve()
{
GeometryType = "LineString";
}
LineString::LineString(QList<Point*> const points, QString name, QPen* pen)
:Curve(name)
{
mypen = pen;
LineString();
setPoints(points);
}
LineString::LineString(QList<Point *> const points, QString name, QPen *pen)
: Curve(name)
{
mypen = pen;
LineString();
setPoints(points);
}
LineString::~LineString()
{
removePoints();
}
LineString::~LineString()
{
removePoints();
}
void LineString::removePoints()
void LineString::removePoints()
{
QListIterator<Point *> iter(childPoints);
while (iter.hasNext())
{
QListIterator<Point*> iter(childPoints);
while(iter.hasNext())
Point *pt = iter.next();
if (pt && pt->parentGeometry() == this)
{
Point *pt = iter.next();
if (pt && pt->parentGeometry() == this)
{
delete pt;
pt = 0;
}
}
childPoints.clear();
}
void LineString::addPoint(Point* point)
{
point->setParentGeometry(this);
childPoints.append(point);
}
QList<Point*> LineString::points()
{
return childPoints;
}
void LineString::setPoints(QList<Point*> points)
{
removePoints();
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)
{
if (!visible)
return;
QPolygon p = QPolygon();
QPointF c;
for (int i=0; i<childPoints.size(); i++)
{
c = childPoints[i]->coordinate();
p.append(mapadapter->coordinateToDisplay(c));
}
if (mypen != 0)
{
painter->save();
painter->setPen(*mypen);
}
painter->drawPolyline(p);
if (mypen != 0)
{
painter->restore();
}
for (int i=0; i<childPoints.size(); i++)
{
childPoints[i]->draw(painter, mapadapter, screensize, offset);
delete pt;
pt = 0;
}
}
childPoints.clear();
}
int LineString::numberOfPoints() const
void LineString::addPoint(Point *point)
{
point->setParentGeometry(this);
childPoints.append(point);
}
QList<Point *> LineString::points()
{
return childPoints;
}
void LineString::setPoints(QList<Point *> points)
{
removePoints();
for (int i = 0; i < points.size(); i++)
{
return childPoints.count();
points.at(i)->setParentGeometry(this);
}
childPoints = points;
}
bool LineString::Touches(Point* geom, const MapAdapter* mapadapter)
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++)
{
touchedPoints.clear();
if (points().size() < 2)
{
// really shouldn't end up here since we always add atleast points to create a line
return false;
}
bool touches = false;
QPointF clickPt = mapadapter->coordinateToDisplay(geom->coordinate());
qreal halfwidth = 2; // use 2 pixels by default
if (mypen && mypen->width() > 0)
{
halfwidth = static_cast<qreal> (mypen->width())/ static_cast<qreal> (2);
}
QPointF pt1 = mapadapter->coordinateToDisplay(points().at(0)->coordinate());
qreal pt1x1 = pt1.x() - halfwidth;
qreal pt1x2 = pt1.x() + halfwidth;
qreal pt1y1 = pt1.y() - halfwidth;
qreal pt1y2 = pt1.y() + halfwidth;
for (int i = 1; i < childPoints.size(); ++i)
{
QPointF pt2 = mapadapter->coordinateToDisplay(childPoints.at(i)->coordinate());
qreal pt2x1 = pt2.x() - halfwidth;
qreal pt2x2 = pt2.x() + halfwidth;
qreal pt2y1 = pt2.y() - halfwidth;
qreal pt2y2 = pt2.y() + halfwidth;
// build lazy bounding box
qreal upperLeftX = qMin(pt1x1, qMin(pt1x2, qMin(pt2x1, pt2x2)));
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));
if (bounds.contains(clickPt))
{
touchedPoints.append(childPoints.at(i));
touches = true;
}
pt1x1 = pt2x1;
pt1x2 = pt2x2;
pt1y1 = pt2y1;
pt1y2 = pt2y2;
}
if (touches)
{
emit(geometryClicked(this, QPoint(0,0)));
}
return touches;
c = childPoints[i]->coordinate();
p.append(mapadapter->coordinateToDisplay(c));
}
bool LineString::Touches(Geometry* /*geom*/, const MapAdapter* /*mapadapter*/)
if (mypen != 0)
{
touchedPoints.clear();
painter->save();
painter->setPen(*mypen);
}
painter->drawPolyline(p);
if (mypen != 0)
{
painter->restore();
}
for (int i = 0; i < childPoints.size(); i++)
{
childPoints[i]->draw(painter, mapadapter, screensize, offset);
}
}
int LineString::numberOfPoints() const
{
return childPoints.count();
}
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
return false;
}
QList<Geometry*>& LineString::clickedPoints()
bool touches = false;
QPointF clickPt = mapadapter->coordinateToDisplay(geom->coordinate());
qreal halfwidth = 2; // use 2 pixels by default
if (mypen && mypen->width() > 0)
{
return Geometry::clickedPoints();
halfwidth = static_cast<qreal>(mypen->width()) / static_cast<qreal>(2);
}
bool LineString::hasPoints() const
QPointF pt1 = mapadapter->coordinateToDisplay(points().at(0)->coordinate());
qreal pt1x1 = pt1.x() - halfwidth;
qreal pt1x2 = pt1.x() + halfwidth;
qreal pt1y1 = pt1.y() - halfwidth;
qreal pt1y2 = pt1.y() + halfwidth;
for (int i = 1; i < childPoints.size(); ++i)
{
return childPoints.size() > 0 ? true : false;
}
QPointF pt2 = mapadapter->coordinateToDisplay(childPoints.at(i)->coordinate());
qreal pt2x1 = pt2.x() - halfwidth;
qreal pt2x2 = pt2.x() + halfwidth;
qreal pt2y1 = pt2.y() - halfwidth;
qreal pt2y2 = pt2.y() + halfwidth;
bool LineString::hasClickedPoints() const
{
return touchedPoints.size() > 0 ? true : false;
}
// build lazy bounding box
qreal upperLeftX = qMin(pt1x1, qMin(pt1x2, qMin(pt2x1, pt2x2)));
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 LineString::boundingBox()
{
qreal minlon=180;
qreal maxlon=-180;
qreal minlat=90;
qreal maxlat=-90;
for (int i=0; i<childPoints.size(); ++i)
QRectF bounds(QPointF(upperLeftX, upperLeftY), QPointF(lowerRightX, lowerRightY));
if (bounds.contains(clickPt))
{
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();
touchedPoints.append(childPoints.at(i));
touches = true;
}
QPointF min = QPointF(minlon, minlat);
QPointF max = QPointF(maxlon, maxlat);
QPointF dist = max - min;
QSizeF si = QSizeF(dist.x(), dist.y());
return QRectF(min, si);
pt1x1 = pt2x1;
pt1x2 = pt2x2;
pt1y1 = pt2y1;
pt1y2 = pt2y2;
}
if (touches)
{
emit(geometryClicked(this, QPoint(0, 0)));
}
return touches;
}
bool LineString::Touches(Geometry * /*geom*/, const MapAdapter * /*mapadapter*/)
{
touchedPoints.clear();
return false;
}
QList<Geometry *> &LineString::clickedPoints()
{
return Geometry::clickedPoints();
}
bool LineString::hasPoints() const
{
return childPoints.size() > 0 ? true : false;
}
bool LineString::hasClickedPoints() const
{
return touchedPoints.size() > 0 ? true : false;
}
QRectF LineString::boundingBox()
{
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();
}
QPointF min = QPointF(minlon, minlat);
QPointF max = QPointF(maxlon, maxlat);
QPointF dist = max - min;
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,97 +31,100 @@
namespace qmapcontrol
{
//! A collection of Point objects to describe a line
//! 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
{
Q_OBJECT
public:
LineString();
//! constructor
/*!
* 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>
* The constructor of a LineString takes a list of Points to form a line.
* @param points a list of points
* @param name the name of the LineString
* @param pen a QPen can be used to modify the look of the line.
* @see http://doc.trolltech.com/4.3/qpen.html
*/
class QMAPCONTROL_EXPORT LineString : public Curve
{
Q_OBJECT
LineString(QList<Point *> const points, QString name = QString(), QPen *pen = 0);
virtual ~LineString();
public:
LineString();
//! constructor
/*!
* The constructor of a LineString takes a list of Points to form a line.
* @param points a list of points
* @param name the name of the LineString
* @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 );
virtual ~LineString();
//! returns the points of the LineString
/*!
* @return a list with the points of the LineString
*/
QList<Point *> points();
//! returns the points of the LineString
/*!
* @return a list with the points of the LineString
*/
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);
//! adds a point at the end of the LineString
/*!
* @param point the point which should be added to the LineString
*/
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);
//! 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);
//! returns the number of Points the LineString consists of
/*!
* @return the number of the LineString´s Points
*/
int numberOfPoints() const;
//! returns the number of Points the LineString consists of
/*!
* @return the number of the LineString´s Points
*/
int numberOfPoints() const;
//! returns the bounding box (rect) that contains all points
/*!
* @return the rect that contains all points
*/
virtual QRectF boundingBox();
//! returns the bounding box (rect) that contains all points
/*!
* @return the rect that contains all points
*/
virtual QRectF boundingBox();
//! returns true if the LineString has Childs
/*!
* This is equal to: numberOfPoints() > 0
* @return true it the LineString has Childs (=Points)
* @see clickedPoints()
*/
virtual bool hasPoints() const;
//! returns true if the LineString has Childs
/*!
* This is equal to: numberOfPoints() > 0
* @return true it the LineString has Childs (=Points)
* @see clickedPoints()
*/
virtual bool hasPoints() const;
//! returns true if the LineString has clicked Points
/*!
* @return true if childs of a LineString were clicked
* @see clickedPoints()
*/
virtual bool hasClickedPoints() const;
//! returns true if the LineString has clicked Points
/*!
* @return true if childs of a LineString were clicked
* @see clickedPoints()
*/
virtual bool hasClickedPoints() const;
//! 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.
* @return the clicked Points of the LineString
*/
virtual QList<Geometry *> &clickedPoints();
//! 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.
* @return the clicked Points of the LineString
*/
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:
//! removes cleans up memory of child points that were reparented with setPoints()
/*!
* @see setPoints()
*/
void removePoints();
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)
{
mCurrent_zoom = qMinZoom;
changeHostAddress( qHost, qServerPath );
}
MapAdapter::~MapAdapter()
{
}
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;
}
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);
}
MapAdapter::~MapAdapter() { }
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;
}
}

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,141 +38,148 @@
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)
*
* 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.
*
* @see TileMapAdapter, @see WMSMapAdapter
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapAdapter : public QObject
{
friend class Layer;
Q_OBJECT
public:
virtual ~MapAdapter();
//! returns the host of this MapAdapter
/*!
* 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)
*
* 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.
*
* @see TileMapAdapter, @see WMSMapAdapter
*
* @author Kai Winter <kaiwinter@gmx.de>
* @return the host of this MapAdapter
*/
class QMAPCONTROL_EXPORT MapAdapter : public QObject
{
friend class Layer;
QString host() const;
Q_OBJECT
//! returns the server path part of this MapAdapter
/*!
* @return the serverpath of this MapAdapter
*/
virtual QString serverPath() const;
public:
virtual ~MapAdapter();
//! change or update server host address post init
/*!
* @param host the host address
* @param serverPath the server path
*/
virtual void changeHostAddress(const QString qHost,
const QString qServerPath = QString());
//! returns the host of this MapAdapter
/*!
* @return the host of this MapAdapter
*/
QString host() const;
//! returns the server path part of this MapAdapter
/*!
* @return the serverpath of this MapAdapter
*/
virtual QString serverPath() const;
//! returns the size of the tiles
/*!
* @return the size of the tiles
*/
int tilesize() const;
//! change or update server host address post init
/*!
* @param host the host address
* @param serverPath the server path
*/
virtual void changeHostAddress( const QString qHost, const QString qServerPath = QString() );
//! returns the min zoom value
/*!
* @return the min zoom value
*/
int minZoom() const;
//! returns the size of the tiles
/*!
* @return the size of the tiles
*/
int tilesize() const;
//! returns the max zoom value
/*!
* @return the max zoom value
*/
int maxZoom() const;
//! returns the min zoom value
/*!
* @return the min zoom value
*/
int minZoom() const;
//! returns the current zoom
/*!
* @return the current zoom
*/
int currentZoom() const;
//! returns the max zoom value
/*!
* @return the max zoom value
*/
int maxZoom() const;
virtual int adaptedZoom() const;
//! returns the current zoom
/*!
* @return the current zoom
*/
int currentZoom() 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.
* @param coordinate the world coordinate
* @return the display coordinate (in widget coordinates)
*/
virtual QPoint coordinateToDisplay(const QPointF &coordinate) const = 0;
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.
* @param coordinate the world coordinate
* @return the display coordinate (in widget coordinates)
*/
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.
* @param point the display coordinate
* @return the world coordinate
*/
virtual QPointF displayToCoordinate(const QPoint &point) 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.
* @param point the display coordinate
* @return the world coordinate
*/
virtual QPointF displayToCoordinate(const QPoint& point) const = 0;
QRectF getBoundingbox() const { return mBoundingBox; }
void setBoundingBox(qreal qMinX, qreal qMinY, qreal qMaxX, qreal qMaxY);
QRectF getBoundingbox() const { return mBoundingBox; }
void setBoundingBox(qreal qMinX, qreal qMinY, qreal qMaxX, qreal qMaxY );
//! returns the tilesize for the mapadapter
/*!
* returns the tilesize for the mapadapter
* @return the tile size
*/
int tileSize();
//! returns the tilesize for the mapadapter
/*!
* returns the tilesize for the mapadapter
* @return the tile size
*/
int tileSize();
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;
virtual QString query(int x, int y, int z) const = 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;
virtual QString query(int x, int y, int z) const = 0;
QSize mSize;
QString mServerHost;
QString mServerPath;
QSize mSize;
QString mServerHost;
QString mServerPath;
int mTileSize;
int mMin_zoom;
int mMax_zoom;
int mCurrent_zoom;
int mTileSize;
int mMin_zoom;
int mMax_zoom;
int mCurrent_zoom;
int param1;
int param2;
int param3;
int param4;
int param5;
int param6;
int param1;
int param2;
int param3;
int param4;
int param5;
int param6;
QString sub1;
QString sub2;
QString sub3;
QString sub4;
QString sub5;
QString sub6;
QString sub1;
QString sub2;
QString sub3;
QString sub4;
QString sub5;
QString sub6;
int order[3][2];
int order[3][2];
int mMiddle_x;
int mMiddle_y;
int mMiddle_x;
int mMiddle_y;
qreal mNumberOfTiles;
QLocale loc;
QRectF mBoundingBox;
};
qreal mNumberOfTiles;
QLocale loc;
QRectF mBoundingBox;
};
}
#endif

File diff suppressed because it is too large Load Diff

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,398 +40,405 @@
//! 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
/*!
* 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapControl : public QFrame
//! 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapControl : public QFrame
{
Q_OBJECT
public:
//! Declares what actions mouse movements have on the map
enum MouseMode
{
Q_OBJECT
public:
//! Declares what actions mouse movements have on the map
enum MouseMode
{
Panning, /*!< The map is moved */
Dragging, /*!< A rectangular can be drawn */
None /*!< Mouse move events have no efect to the map */
};
//! The QWidget constructor of MapControl for use with QtDesigner
/*!
* @param qParent QWidget parent
* @param windowFlags QWidget Window flags
*/
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.
* @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
* @param showCrossHairs true if crosshairs should be shown at the centre of the map
* @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();
//! adds a layer
/*!
* If multiple layers are added, they are painted in the added order.
* @param layer the layer which should be added
*/
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 );
//! 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;
//! returns the names of all layers
/*!
* @return returns a QList with the names of all layers
*/
QList<QString> layers() const;
//! returns the number of existing layers
/*!
* @return returns the number of existing layers
*/
int numberOfLayers() const;
//! returns the coordinate of the center of the map
/*!
* @return returns the coordinate of the middle of the screen
*/
QPointF currentCoordinate() const;
//! returns the current zoom level
/*!
* @return returns the current zoom level
*/
int currentZoom() const;
//! update screen
void updateView() const;
//! enable mouse wheel events
/*!
* @parm enable mouse event
*/
void enableMouseWheelEvents( bool enabled = true );
//! returns mouse wheel allowed
/*!
* @return mouse wheel events enabled
*/
bool mouseWheelEventsEnabled();
//! sets the middle of the map to the given coordinate
/*!
* @param coordinate the coordinate which the view´s middle should be set to
*/
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;
//! 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.
* @param coordinates the Coorinates which should be visible
*/
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;
//! 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;
//TODO:
// void followGeometry(const QList<Geometry*>) const;
//! Stops the following of a Geometry
/*!
* if the view is set to follow a Geometry this method stops the trace.
* See followGeometry().
* @param geometry the Geometry which should not followed anymore
*/
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 );
//! 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 second MouseMode (the default) is Panning, which allows to drag the map around.
* @param mousemode the MouseMode
*/
void setMouseMode ( MouseMode mousemode );
//! returns the current MouseMode
/*!
* For a explanation for the MouseModes see setMouseMode()
* @return the current MouseMode
*/
MapControl::MouseMode mouseMode();
//! Enable persistent caching of map tiles
/*!
* Call this method to allow the QMapControl widget to save map tiles
* persistent (also over application restarts).
* 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
*/
void enablePersistentCache ( const QDir& path= QDir::homePath() + "/QMapControl.cache", const int qDiskSizeMB = 250 );
//! Sets the proxy for HTTP connections
/*!
* This method sets the proxy for HTTP connections.
* This is not provided by the current Qtopia version!
* @param host the proxy´s hostname or ip
* @param port the proxy´s port
* @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());
//! Displays the scale within the widget
/*!
*
* @param show true if the scale should be displayed
*/
void showScale ( 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 );
//! Check if bounding box is being used
/*!
*
* @return if bounding box is being used
*/
bool isBoundingBoxEnabled();
//! Set constraints for bounding box
/*!
*
* @param rect specified bounds for view to stay within
*/
void setBoundingBox( QRectF &rect );
//! Get current bounding box
/*!
*
* @return bounding box
*/
QRectF getBoundingBox();
//! Get viewport rect
/*!
*
* @return view port rect
*/
QRectF getViewport();
//! returns if a geometry is visible on viewport
/*!
*
* @param geometry the Geometry object to check
* @return true if geometry is visible
*/
bool isGeometryVisible( Geometry * geometry);
//! returns loading images queue size
/*!
*
* @return int pending loading images (queue size)
*/
int loadingQueueSize();
//! returns the imagemanager pointer
/*!
*
* @return imagemanager pointer
*/
ImageManager* getImageManager();
private:
void __init();
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)
QSize size; // size of the widget
bool mouse_wheel_events;
bool mousepressed;
MouseMode mymousemode;
bool scaleVisible;
bool crosshairsVisible;
bool m_loadingFlag;
QMutex moveMutex; // used for method moveTo()
QPointF target; // used for method moveTo()
int steps; // used for method moveTo()
QPixmap *m_doubleBuffer;
QPointF clickToWorldCoordinate ( QPoint click );
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 );
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.
* @param evnt the QMouseEvent that occured
* @param coordinate the corresponding world 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
* @param QRectF the dragged Rect
*/
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 );
//! 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;
public slots:
//! zooms in one step
void zoomIn();
//! zooms out one step
void zoomOut();
//! sets the given zoomlevel
/*!
* @param zoomlevel the zoomlevel
*/
void setZoom ( int zoomlevel );
//! scrolls the view to the left
void scrollLeft ( int pixel=10 );
//! scrolls the view to the right
void scrollRight ( int pixel=10 );
//! scrolls the view up
void scrollUp ( int pixel=10 );
//! scrolls the view down
void scrollDown ( int pixel=10 );
//! scrolls the view by the given point
void scroll ( const QPoint scroll );
//! updates the map for the given rect
/*!
* @param rect the area which should be repainted
*/
void updateRequest ( QRect rect );
//! updates the hole map by creating a new offscreen image
/*!
*
*/
void updateRequestNew();
//! Resizes the map to the given size
/*!
* @param newSize The new size
*/
void resize(const QSize newSize);
private slots:
void tick();
void loadingFinished();
void positionChanged ( Geometry* geom );
Panning, /*!< The map is moved */
Dragging, /*!< A rectangular can be drawn */
None /*!< Mouse move events have no efect to the map */
};
//! The QWidget constructor of MapControl for use with QtDesigner
/*!
* @param qParent QWidget parent
* @param windowFlags QWidget Window flags
*/
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.
* @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
* @param showCrossHairs true if crosshairs should be shown at the centre of the map
* @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();
//! adds a layer
/*!
* If multiple layers are added, they are painted in the added order.
* @param layer the layer which should be added
*/
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);
//! 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;
//! returns the names of all layers
/*!
* @return returns a QList with the names of all layers
*/
QList<QString> layers() const;
//! returns the number of existing layers
/*!
* @return returns the number of existing layers
*/
int numberOfLayers() const;
//! returns the coordinate of the center of the map
/*!
* @return returns the coordinate of the middle of the screen
*/
QPointF currentCoordinate() const;
//! returns the current zoom level
/*!
* @return returns the current zoom level
*/
int currentZoom() const;
//! update screen
void updateView() const;
//! enable mouse wheel events
/*!
* @parm enable mouse event
*/
void enableMouseWheelEvents(bool enabled = true);
//! returns mouse wheel allowed
/*!
* @return mouse wheel events enabled
*/
bool mouseWheelEventsEnabled();
//! sets the middle of the map to the given coordinate
/*!
* @param coordinate the coordinate which the view´s middle should be set to
*/
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;
//! 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.
* @param coordinates the Coorinates which should be visible
*/
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;
//! 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;
// TODO:
// void followGeometry(const QList<Geometry*>) const;
//! Stops the following of a Geometry
/*!
* if the view is set to follow a Geometry this method stops the trace.
* See followGeometry().
* @param geometry the Geometry which should not followed anymore
*/
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);
//! 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 second MouseMode (the default) is Panning, which allows to drag the map around.
* @param mousemode the MouseMode
*/
void setMouseMode(MouseMode mousemode);
//! returns the current MouseMode
/*!
* For a explanation for the MouseModes see setMouseMode()
* @return the current MouseMode
*/
MapControl::MouseMode mouseMode();
//! Enable persistent caching of map tiles
/*!
* Call this method to allow the QMapControl widget to save map tiles
* persistent (also over application restarts).
* 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
*/
void enablePersistentCache(const QDir &path = QDir::homePath() + "/QMapControl.cache",
const int qDiskSizeMB = 250);
//! Sets the proxy for HTTP connections
/*!
* This method sets the proxy for HTTP connections.
* This is not provided by the current Qtopia version!
* @param host the proxy´s hostname or ip
* @param port the proxy´s port
* @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());
//! Displays the scale within the widget
/*!
*
* @param show true if the scale should be displayed
*/
void showScale(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);
//! Check if bounding box is being used
/*!
*
* @return if bounding box is being used
*/
bool isBoundingBoxEnabled();
//! Set constraints for bounding box
/*!
*
* @param rect specified bounds for view to stay within
*/
void setBoundingBox(QRectF &rect);
//! Get current bounding box
/*!
*
* @return bounding box
*/
QRectF getBoundingBox();
//! Get viewport rect
/*!
*
* @return view port rect
*/
QRectF getViewport();
//! returns if a geometry is visible on viewport
/*!
*
* @param geometry the Geometry object to check
* @return true if geometry is visible
*/
bool isGeometryVisible(Geometry *geometry);
//! returns loading images queue size
/*!
*
* @return int pending loading images (queue size)
*/
int loadingQueueSize();
//! returns the imagemanager pointer
/*!
*
* @return imagemanager pointer
*/
ImageManager *getImageManager();
private:
void __init();
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)
QSize size; // size of the widget
bool mouse_wheel_events;
bool mousepressed;
MouseMode mymousemode;
bool scaleVisible;
bool crosshairsVisible;
bool m_loadingFlag;
QMutex moveMutex; // used for method moveTo()
QPointF target; // used for method moveTo()
int steps; // used for method moveTo()
QPixmap *m_doubleBuffer;
QPointF clickToWorldCoordinate(QPoint click);
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);
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.
* @param evnt the QMouseEvent that occured
* @param coordinate the corresponding world 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
* @param QRectF the dragged Rect
*/
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);
//! 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;
public slots:
//! zooms in one step
void zoomIn();
//! zooms out one step
void zoomOut();
//! sets the given zoomlevel
/*!
* @param zoomlevel the zoomlevel
*/
void setZoom(int zoomlevel);
//! scrolls the view to the left
void scrollLeft(int pixel = 10);
//! scrolls the view to the right
void scrollRight(int pixel = 10);
//! scrolls the view up
void scrollUp(int pixel = 10);
//! scrolls the view down
void scrollDown(int pixel = 10);
//! scrolls the view by the given point
void scroll(const QPoint scroll);
//! updates the map for the given rect
/*!
* @param rect the area which should be repainted
*/
void updateRequest(QRect rect);
//! updates the hole map by creating a new offscreen image
/*!
*
*/
void updateRequestNew();
//! Resizes the map to the given size
/*!
* @param newSize The new size
*/
void resize(const QSize newSize);
private slots:
void tick();
void loadingFinished();
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)
: Layer(layername, mapadapter, Layer::MapLayer, takeevents)
{
}
MapLayer::~MapLayer()
{
}
MapLayer::MapLayer(QString layername, MapAdapter *mapadapter, bool takeevents)
: Layer(layername, mapadapter, Layer::MapLayer, takeevents)
{
}
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
/*!
* There are two different layer types:
* - 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapLayer : public Layer
{
Q_OBJECT
//! 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
* - 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.
*
* @author Kai Winter <kaiwinter@gmx.de>
*/
class QMAPCONTROL_EXPORT MapLayer : public Layer
{
Q_OBJECT
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"
*/
MapLayer(QString layername, MapAdapter* mapadapter, bool takeevents=true);
virtual ~MapLayer();
};
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"
*/
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,182 +33,191 @@
namespace qmapcontrol
{
MapNetwork::MapNetwork(ImageManager* parent)
: parent(parent),
http(new QNetworkAccessManager(this)),
loaded(0),
networkActive( false ),
cacheEnabled(false)
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()
{
foreach (QNetworkReply *reply, replyList)
{
connect(http, SIGNAL(finished(QNetworkReply *)), this, SLOT(requestFinished(QNetworkReply *)));
if (reply->isRunning())
{
reply->abort();
}
reply->deleteLater();
reply = 0;
}
MapNetwork::~MapNetwork()
http->deleteLater();
http = 0;
}
void MapNetwork::loadImage(const QString &host, const QString &url)
{
QString hostName = host;
QString portNumber = QString("80");
QRegExp r(".:.");
if (r.indexIn(host) >= 0)
{
foreach(QNetworkReply *reply, replyList)
QStringList s = host.split(":");
hostName = s.at(0);
portNumber = s.at(1);
}
QString finalUrl = QString("http://%1:%2%3").arg(hostName).arg(portNumber).arg(url);
QNetworkRequest request = QNetworkRequest(QUrl(finalUrl));
if (cacheEnabled)
{
// prefer our cached version (if enabled) over fresh network query
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::PreferCache);
// Data obtained should be saved to cache for future uses
request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, true);
}
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);
}
void MapNetwork::requestFinished(QNetworkReply *reply)
{
if (!reply)
{
// qDebug() << "MapNetwork::requestFinished - reply no longer valid";
return;
}
// qDebug() << "MapNetwork::requestFinished" << reply->url().toString();
if (reply->error() == QNetworkReply::NoError)
{
QString id = reply->url().toString();
// check if id is in map?
bool idInMap = false;
QString url;
{
if(reply->isRunning())
QMutexLocker lock(&vectorMutex);
idInMap = loadingMap.contains(id);
if (idInMap)
{
url = loadingMap[id];
loadingMap.remove(id);
}
}
if (idInMap)
{
// qDebug() << "request finished for reply: " << reply << ", belongs to: " <<
// url << endl;
QByteArray ax;
if (reply->bytesAvailable() > 0)
{
QPixmap pm;
ax = reply->readAll();
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();
parent->receivedImage(pm, url);
}
else
{
parent->fetchFailed(url);
}
}
}
}
if (loadQueueSize() == 0)
{
// qDebug () << "all loaded";
parent->loadingQueueEmpty();
}
QMutexLocker lock(&vectorMutex);
replyList.removeAll(reply);
reply->deleteLater();
reply = 0;
}
int MapNetwork::loadQueueSize() const
{
QMutexLocker lock(&vectorMutex);
return loadingMap.size();
}
void MapNetwork::setDiskCache(QNetworkDiskCache *qCache)
{
cacheEnabled = (qCache != 0);
if (http)
{
http->setCache(qCache);
}
}
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())
{
QNetworkReply *reply = iter.next();
if (reply)
{
if (reply->isRunning())
{
reply->abort();
}
reply->deleteLater();
reply = 0;
}
http->deleteLater();
http = 0;
}
void MapNetwork::loadImage(const QString& host, const QString& url)
{
QString hostName = host;
QString portNumber = QString("80");
QRegExp r(".:.");
if(r.indexIn(host) >= 0)
{
QStringList s = host.split(":");
hostName = s.at(0);
portNumber = s.at(1);
}
QString finalUrl = QString("http://%1:%2%3").arg(hostName).arg(portNumber).arg(url);
QNetworkRequest request = QNetworkRequest(QUrl(finalUrl));
if( cacheEnabled )
{
// prefer our cached version (if enabled) over fresh network query
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
// Data obtained should be saved to cache for future uses
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
}
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 );
QMutexLocker lock(&vectorMutex);
replyList.clear();
loadingMap.clear();
}
void MapNetwork::requestFinished(QNetworkReply *reply)
{
if (!reply)
{
//qDebug() << "MapNetwork::requestFinished - reply no longer valid";
return;
}
bool MapNetwork::imageIsLoading(QString url)
{
QMutexLocker lock(&vectorMutex);
return loadingMap.values().contains(url);
}
//qDebug() << "MapNetwork::requestFinished" << reply->url().toString();
if (reply->error() == QNetworkReply::NoError)
{
QString id = reply->url().toString();
// check if id is in map?
bool idInMap = false;
QString url;
{
QMutexLocker lock(&vectorMutex);
idInMap = loadingMap.contains(id);
if(idInMap)
{
url = loadingMap[id];
loadingMap.remove(id);
}
}
if (idInMap)
{
//qDebug() << "request finished for reply: " << reply << ", belongs to: " << url << endl;
QByteArray ax;
if (reply->bytesAvailable()>0)
{
QPixmap pm;
ax = reply->readAll();
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();
parent->receivedImage(pm, url);
}
else
{
parent->fetchFailed(url);
}
}
}
}
if (loadQueueSize() == 0)
{
//qDebug () << "all loaded";
parent->loadingQueueEmpty();
}
QMutexLocker lock(&vectorMutex);
replyList.removeAll(reply);
reply->deleteLater();
reply = 0;
}
int MapNetwork::loadQueueSize() const
{
QMutexLocker lock(&vectorMutex);
return loadingMap.size();
}
void MapNetwork::setDiskCache(QNetworkDiskCache *qCache)
{
cacheEnabled = (qCache != 0);
if (http)
{
http->setCache(qCache);
}
}
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())
{
QNetworkReply *reply = iter.next();
if (reply)
{
if(reply->isRunning())
{
reply->abort();
}
reply->deleteLater();
reply = 0;
}
}
QMutexLocker lock(&vectorMutex);
replyList.clear();
loadingMap.clear();
}
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)
{
// do not set proxy on qt/extended
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 );
}
#endif
if (http)
{
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,63 +43,65 @@
*/
namespace qmapcontrol
{
class ImageManager;
class QMAPCONTROL_EXPORT MapNetwork : QObject
{
Q_OBJECT
class ImageManager;
class QMAPCONTROL_EXPORT MapNetwork : QObject
{
Q_OBJECT
public:
MapNetwork(ImageManager* parent);
~MapNetwork();
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
* @param url the url of the image
* @return boolean, if the image is already loading
*/
bool imageIsLoading(QString url);
/*!
* checks if the given url is already loading
* @param url the url of the image
* @return boolean, if the image is already loading
*/
bool imageIsLoading(QString url);
/*!
* Aborts all current loading threads.
* 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());
/*!
* Aborts all current loading threads.
* 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());
/*!
*
* @return number of elements in the load queue
*/
int loadQueueSize() const;
/*!
*
* @return number of elements in the load queue
*/
int loadQueueSize() const;
/*!
*
* @return next free http downloader thread
*/
QNetworkAccessManager* nextFreeHttp();
/*!
*
* @return next free http downloader thread
*/
QNetworkAccessManager *nextFreeHttp();
/*!
* sets the disk cache for each network manager
* @param qCache the disk cache object to set
*/
void setDiskCache( QNetworkDiskCache* qCache );
/*!
* sets the disk cache for each network manager
* @param qCache the disk cache object to set
*/
void setDiskCache(QNetworkDiskCache *qCache);
private:
Q_DISABLE_COPY (MapNetwork)
private:
Q_DISABLE_COPY(MapNetwork)
ImageManager* parent;
QNetworkAccessManager* http;
QList<QNetworkReply*> replyList;
QMap<QString, QString> loadingMap;
qreal loaded;
mutable QMutex vectorMutex;
bool networkActive;
bool cacheEnabled;
ImageManager *parent;
QNetworkAccessManager *http;
QList<QNetworkReply *> replyList;
QMap<QString, QString> loadingMap;
qreal loaded;
mutable QMutex vectorMutex;
bool networkActive;
bool cacheEnabled;
private slots:
void requestFinished(QNetworkReply *reply);
};
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
//! 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
{
Q_OBJECT
public:
//! constructor
/*!
* 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>
* This construct a OpenAerialMap Adapter
*/
class QMAPCONTROL_EXPORT OpenAerialMapAdapter : public TileMapAdapter
{
Q_OBJECT
public:
//! constructor
/*!
* This construct a OpenAerialMap Adapter
*/
OpenAerialMapAdapter();
virtual ~OpenAerialMapAdapter();
};
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()
: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17)
{
}
OSMMapAdapter::~OSMMapAdapter()
{
}
OSMMapAdapter::OSMMapAdapter()
: TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17)
{
}
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
{
Q_OBJECT
public:
//! constructor
/*!
* This is a conveniece class, which extends and configures a TileMapAdapter
* @author Kai Winter <kaiwinter@gmx.de>
* This construct a OpenStreetmap Adapter
*/
class QMAPCONTROL_EXPORT OSMMapAdapter : public TileMapAdapter
{
Q_OBJECT
public:
//! constructor
/*!
* This construct a OpenStreetmap Adapter
*/
OSMMapAdapter();
virtual ~OSMMapAdapter();
};
OSMMapAdapter();
virtual ~OSMMapAdapter();
};
}
#endif

View File

@ -1,372 +1,387 @@
/*
*
* 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())
{
visible = point.isVisible();
mywidget = 0;
mypixmap = QPixmap();
mypen = point.mypen;
homelevel = -1;
minsize = QSize(-1,-1);
maxsize = QSize(-1,-1);
}
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);
}
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);
}
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);
}
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);
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);
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)
if (mywidget != 0)
{
GeometryType = "Point";
mywidget = 0;
visible = true;
size = pixmap.size();
homelevel = -1;
minsize = QSize(-1,-1);
maxsize = QSize(-1,-1);
mywidget->show();
}
/*
Point& Point::operator=(const Point& rhs)
{
if (this == &rhs)
return *this;
else
{
X = rhs.X;
Y = rhs.Y;
size = rhs.size;
}
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);
}
/*
Point& Point::operator=(const Point& rhs)
{
if (this == &rhs)
return *this;
else
{
X = rhs.X;
Y = rhs.Y;
size = rhs.size;
mywidget = rhs.mywidget;
mypixmap = rhs.mypixmap;
alignment = rhs.alignment;
homelevel = rhs.homelevel;
minsize = rhs.minsize;
maxsize = rhs.maxsize;
mywidget = rhs.mywidget;
mypixmap = rhs.mypixmap;
alignment = rhs.alignment;
homelevel = rhs.homelevel;
minsize = rhs.minsize;
maxsize = rhs.maxsize;
}
}
*/
Point::~Point()
Point::~Point()
{
if (mywidget != 0)
{
if(mywidget!=0)
{
delete mywidget;
mywidget = 0;
}
delete mywidget;
mywidget = 0;
}
}
void Point::setPixmap(QPixmap qPixmap)
{
mypixmap = qPixmap;
size = mypixmap.size();
// forces redraw
emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
emit(positionChanged(this));
}
void Point::setVisible(bool visible)
{
this->visible = visible;
if (mywidget != 0)
{
mywidget->setVisible(visible);
}
}
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();
QPointF min = QPointF(minlon, minlat);
QPointF max = QPointF(maxlon, maxlat);
QPointF dist = max - min;
QSizeF si = QSizeF(dist.x(), dist.y());
return QRectF(min, si);
}
qreal Point::longitude() const
{
return X;
}
qreal Point::latitude() const
{
return Y;
}
QPointF Point::coordinate() const
{
return QPointF(X, Y);
}
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->getZoom();
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())
viewheight = minsize.height();
else if (maxsize.height() != -1 && viewheight > maxsize.height())
viewheight = maxsize.height();
if (minsize.width() != -1 && viewwidth < minsize.width())
viewwidth = minsize.width();
else if (maxsize.width() != -1 && viewwidth > maxsize.width())
viewwidth = maxsize.width();
displaysize = QSize(viewwidth, viewheight);
}
else
{
displaysize = size;
}
void Point::setPixmap( QPixmap qPixmap )
{
mypixmap = qPixmap;
size = mypixmap.size();
//forces redraw
emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
emit(positionChanged(this));
}
void Point::setVisible(bool visible)
{
this->visible = visible;
if (mywidget !=0)
{
mywidget->setVisible(visible);
}
}
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();
QPointF min = QPointF(minlon, minlat);
QPointF max = QPointF(maxlon, maxlat);
QPointF dist = max - min;
QSizeF si = QSizeF(dist.x(), dist.y());
return QRectF(min, si);
}
qreal Point::longitude() const
{
return X;
}
qreal Point::latitude() const
{
return Y;
}
QPointF Point::coordinate() const
{
return QPointF(X, Y);
}
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->getZoom();
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())
viewheight = minsize.height();
else if (maxsize.height() != -1 && viewheight > maxsize.height())
viewheight = maxsize.height();
if (minsize.width()!= -1 && viewwidth < minsize.width())
viewwidth = minsize.width();
else if (maxsize.width() != -1 && viewwidth > maxsize.width())
viewwidth = maxsize.width();
displaysize = QSize(viewwidth, viewheight);
}
else
{
displaysize = size;
}
if (mypixmap.size().width() > 0)
{
const QPointF c = QPointF(X, Y);
QPoint point = mapadapter->coordinateToDisplay(c);
if (viewport.contains(point))
{
QPoint alignedtopleft = alignedPoint(point);
painter->drawPixmap(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(), displaysize.height(), mypixmap);
}
}
else if (mywidget!=0)
{
drawWidget(mapadapter, offset);
}
}
void Point::drawWidget(const MapAdapter* mapadapter, const QPoint offset)
if (mypixmap.size().width() > 0)
{
const QPointF c = QPointF(X, Y);
QPoint point = mapadapter->coordinateToDisplay(c);
point -= offset;
QPoint alignedtopleft = alignedPoint(point);
if (mywidget!=0)
if (viewport.contains(point))
{
mywidget->setGeometry(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(), displaysize.height());
QPoint alignedtopleft = alignedPoint(point);
painter->drawPixmap(alignedtopleft.x(), alignedtopleft.y(),
displaysize.width(), displaysize.height(), mypixmap);
}
}
QPoint Point::alignedPoint(const QPoint point) const
else if (mywidget != 0)
{
QPoint alignedtopleft;
if (myalignment == Middle)
{
alignedtopleft.setX(point.x()-displaysize.width()/2);
alignedtopleft.setY(point.y()-displaysize.height()/2);
}
else if (myalignment == TopLeft)
{
alignedtopleft.setX(point.x());
alignedtopleft.setY(point.y());
}
else if (myalignment == TopRight)
{
alignedtopleft.setX(point.x()-displaysize.width());
alignedtopleft.setY(point.y());
}
else if (myalignment == BottomLeft)
{
alignedtopleft.setX(point.x());
alignedtopleft.setY(point.y()-displaysize.height());
}
else if (myalignment == BottomRight)
{
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());
}
else if (myalignment == TopMiddle)
{
alignedtopleft.setX(point.x()-displaysize.width()/2);
alignedtopleft.setY(point.y());
}
return alignedtopleft;
drawWidget(mapadapter, offset);
}
}
bool Point::Touches(Point* click, const MapAdapter* mapadapter)
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 (this->isVisible() == false)
return false;
mywidget->setGeometry(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(),
displaysize.height());
}
}
if ( !click || !mapadapter )
return false;
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);
}
else if (myalignment == TopLeft)
{
alignedtopleft.setX(point.x());
alignedtopleft.setY(point.y());
}
else if (myalignment == TopRight)
{
alignedtopleft.setX(point.x() - displaysize.width());
alignedtopleft.setY(point.y());
}
else if (myalignment == BottomLeft)
{
alignedtopleft.setX(point.x());
alignedtopleft.setY(point.y() - displaysize.height());
}
else if (myalignment == BottomRight)
{
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());
}
else if (myalignment == TopMiddle)
{
alignedtopleft.setX(point.x() - displaysize.width() / 2);
alignedtopleft.setY(point.y());
}
return alignedtopleft;
}
if (points().size() < 1)
{
return false;
}
bool Point::Touches(Point *click, const MapAdapter *mapadapter)
{
if (this->isVisible() == false)
return false;
QPointF clickPt = mapadapter->coordinateToDisplay(click->coordinate());
qreal halfwidth = 2; // use 2 pixels by default
if (mypixmap.width() > 0)
{
halfwidth = static_cast<qreal> (mypixmap.width()) / static_cast<qreal> (2);
}
QPointF pt1 = mapadapter->coordinateToDisplay(coordinate());
qreal pt1x1 = pt1.x() - halfwidth;
qreal pt1x2 = pt1.x() + halfwidth;
qreal pt1y1 = pt1.y() - halfwidth;
qreal pt1y2 = pt1.y() + halfwidth;
QPointF pt2 = mapadapter->coordinateToDisplay(coordinate());
qreal pt2x1 = pt2.x() - halfwidth;
qreal pt2x2 = pt2.x() + halfwidth;
qreal pt2y1 = pt2.y() - halfwidth;
qreal pt2y2 = pt2.y() + halfwidth;
// build lazy bounding box
qreal upperLeftX = qMin(pt1x1, qMin(pt1x2, qMin(pt2x1, pt2x2)));
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));
if ( bounds.contains(clickPt) )
{
emit(geometryClicked(this, QPoint(0, 0)));
return true;
}
if (!click || !mapadapter)
return false;
if (points().size() < 1)
{
return false;
}
void Point::setCoordinate(QPointF point)
QPointF clickPt = mapadapter->coordinateToDisplay(click->coordinate());
qreal halfwidth = 2; // use 2 pixels by default
if (mypixmap.width() > 0)
{
if ( X == point.x() &&
Y == point.y() )
{
//no change, prevent unessessary update/redraw
return;
}
X = point.x();
Y = point.y();
emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
emit(positionChanged(this));
}
QList<Point*> Point::points()
{
//TODO: assigning temp?!
QList<Point*> points;
points.append(this);
return points;
halfwidth = static_cast<qreal>(mypixmap.width()) / static_cast<qreal>(2);
}
QWidget* Point::widget()
QPointF pt1 = mapadapter->coordinateToDisplay(coordinate());
qreal pt1x1 = pt1.x() - halfwidth;
qreal pt1x2 = pt1.x() + halfwidth;
qreal pt1y1 = pt1.y() - halfwidth;
qreal pt1y2 = pt1.y() + halfwidth;
QPointF pt2 = mapadapter->coordinateToDisplay(coordinate());
qreal pt2x1 = pt2.x() - halfwidth;
qreal pt2x2 = pt2.x() + halfwidth;
qreal pt2y1 = pt2.y() - halfwidth;
qreal pt2y2 = pt2.y() + halfwidth;
// build lazy bounding box
qreal upperLeftX = qMin(pt1x1, qMin(pt1x2, qMin(pt2x1, pt2x2)));
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));
if (bounds.contains(clickPt))
{
return mywidget;
emit(geometryClicked(this, QPoint(0, 0)));
return true;
}
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;
}
return false;
}
void Point::setCoordinate(QPointF point)
{
if (X == point.x() && Y == point.y())
{
// no change, prevent unessessary update/redraw
return;
}
X = point.x();
Y = point.y();
emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
emit(positionChanged(this));
}
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;
}
}

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,189 +40,198 @@
namespace qmapcontrol
{
//! 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)
*
* 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.)
*
* 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.
*
* 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
//! 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)
*
* 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.)
*
* 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.
*
* 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
{
Q_OBJECT
public:
friend class Layer;
friend class LineString;
//! sets where the point should be aligned
enum Alignment
{
Q_OBJECT
public:
friend class Layer;
friend class LineString;
//! sets where the point should be aligned
enum Alignment
{
TopLeft, /*!< Align on TopLeft*/
TopRight, /*!< Align on TopRight*/
TopMiddle, /*!< Align on TopLeft*/
BottomLeft, /*!< Align on BottomLeft*/
BottomRight,/*!< Align on BottomRight*/
BottomMiddle, /*!< Align on BottomMiddle*/
Middle /*!< Align on Middle*/
};
Point();
explicit Point(const Point&);
//! Copy Constructor
/*!
* This constructor creates a Point with no image or widget.
* @param x longitude
* @param y latitude
* @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);
//! 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!
* @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);
//! 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.
* @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);
virtual ~Point();
//! returns the bounding box of the point
/*!
* The Bounding contains the coordinate of the point and its size.
* The size is set, if the point contains a pixmap or a widget
* @return the bounding box of the point
*/
virtual QRectF boundingBox();
//! returns the longitude of the point
/*!
* @return the longitude of the point
*/
qreal longitude() const;
//! returns the latitude of the point
/*!
* @return the latitude of the point
*/
qreal latitude() const;
//! returns the coordinate of the point
/*!
* The x component of the returned QPointF is the longitude value,
* the y component the latitude
* @return the coordinate of a point
*/
QPointF coordinate() const;
virtual QList<Point*> points();
/*! \brief returns the widget of the point
@return the widget of the point
*/
QWidget* widget();
//! returns the pixmap of the point
/*!
* @return the pixmap of the point
*/
QPixmap pixmap();
//! 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
* @see setMinsize, setMaxsize
* @param zoomlevel the zoomlevel on which the point will be displayed on full size
*/
void setBaselevel(int zoomlevel);
//! sets a minimal size for the pixmap
/*!
* 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
*/
void setMinsize(QSize minsize);
//! sets a maximal size for the pixmap
/*!
* 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
*/
void setMaxsize(QSize maxsize);
Point::Alignment alignment() const;
virtual void setPixmap( QPixmap qPixmap );
protected:
qreal X;
qreal Y;
QSize size;
QWidget* mywidget;
QPixmap mypixmap;
Alignment myalignment;
int homelevel;
QSize displaysize;
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);
QPoint alignedPoint(const QPoint point) const;
//! returns true if the given Point touches this Point
/*!
* The collision detection checks for the bounding rectangulars.
* @param geom the other point which should be tested on collision
* @param mapadapter the mapadapter which is used for calculations
* @return
*/
virtual bool Touches(Point* p, const MapAdapter* mapadapter);
public slots:
void setCoordinate(QPointF point);
virtual void setVisible(bool visible);
TopLeft, /*!< Align on TopLeft*/
TopRight, /*!< Align on TopRight*/
TopMiddle, /*!< Align on TopLeft*/
BottomLeft, /*!< Align on BottomLeft*/
BottomRight, /*!< Align on BottomRight*/
BottomMiddle, /*!< Align on BottomMiddle*/
Middle /*!< Align on Middle*/
};
Point();
explicit Point(const Point &);
//! Copy Constructor
/*!
* This constructor creates a Point with no image or widget.
* @param x longitude
* @param y latitude
* @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);
//! 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!
* @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);
//! 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.
* @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);
virtual ~Point();
//! returns the bounding box of the point
/*!
* The Bounding contains the coordinate of the point and its size.
* The size is set, if the point contains a pixmap or a widget
* @return the bounding box of the point
*/
virtual QRectF boundingBox();
//! returns the longitude of the point
/*!
* @return the longitude of the point
*/
qreal longitude() const;
//! returns the latitude of the point
/*!
* @return the latitude of the point
*/
qreal latitude() const;
//! returns the coordinate of the point
/*!
* The x component of the returned QPointF is the longitude value,
* the y component the latitude
* @return the coordinate of a point
*/
QPointF coordinate() const;
virtual QList<Point *> points();
/*! \brief returns the widget of the point
@return the widget of the point
*/
QWidget *widget();
//! returns the pixmap of the point
/*!
* @return the pixmap of the point
*/
QPixmap pixmap();
//! 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
* @see setMinsize, setMaxsize
* @param zoomlevel the zoomlevel on which the point will be displayed on full size
*/
void setBaselevel(int zoomlevel);
//! sets a minimal size for the pixmap
/*!
* 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
*/
void setMinsize(QSize minsize);
//! sets a maximal size for the pixmap
/*!
* 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
*/
void setMaxsize(QSize maxsize);
Point::Alignment alignment() const;
virtual void setPixmap(QPixmap qPixmap);
protected:
qreal X;
qreal Y;
QSize size;
QWidget *mywidget;
QPixmap mypixmap;
Alignment myalignment;
int homelevel;
QSize displaysize;
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);
QPoint alignedPoint(const QPoint point) const;
//! returns true if the given Point touches this Point
/*!
* The collision detection checks for the bounding rectangulars.
* @param geom the other point which should be tested on collision
* @param mapadapter the mapadapter which is used for calculations
* @return
*/
virtual bool Touches(Point *p, const MapAdapter *mapadapter);
public slots:
void setCoordinate(QPointF point);
virtual void setVisible(bool visible);
};
}
#endif

View File

@ -1,7 +1,7 @@
#include <QtGlobal>
#ifdef QMAPCONTROL_LIBRARY
# define QMAPCONTROL_EXPORT Q_DECL_EXPORT
# define QMAPCONTROL_EXPORT Q_DECL_EXPORT
#else
# define QMAPCONTROL_EXPORT Q_DECL_IMPORT
# define QMAPCONTROL_EXPORT Q_DECL_IMPORT
#endif

View File

@ -1,189 +1,187 @@
/*
*
* 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)
{
PI = acos(-1.0);
TileMapAdapter::TileMapAdapter(const QString &host, const QString &serverPath,
int tilesize, int minZoom, int maxZoom)
: MapAdapter(host, serverPath, tilesize, minZoom, maxZoom)
{
PI = acos(-1.0);
/*
Initialize the "substring replace engine". First the string replacement
in getQuery was made by QString().arg() but this was very slow. So this
splits the servers path into substrings and when calling getQuery the
substrings get merged with the parameters of the URL.
Pretty complicated, but fast.
*/
param1 = serverPath.indexOf("%1");
param2 = serverPath.indexOf("%2");
param3 = serverPath.indexOf("%3");
/*
Initialize the "substring replace engine". First the string replacement
in getQuery was made by QString().arg() but this was very slow. So this
splits the servers path into substrings and when calling getQuery the
substrings get merged with the parameters of the URL.
Pretty complicated, but fast.
*/
param1 = serverPath.indexOf("%1");
param2 = serverPath.indexOf("%2");
param3 = serverPath.indexOf("%3");
int min = param1 < param2 ? param1 : param2;
min = param3 < min ? param3 : min;
int min = param1 < param2 ? param1 : param2;
min = param3 < min ? param3 : min;
int max = param1 > param2 ? param1 : param2;
max = param3 > max ? param3 : max;
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)
order[0][1] = 0;
else if (min == param2)
order[0][1] = 1;
else
order[0][1] = 2;
order[0][0] = min;
if (min == param1)
order[0][1] = 0;
else if (min == param2)
order[0][1] = 1;
else
order[0][1] = 2;
order[1][0] = middle;
if (middle == param1)
order[1][1] = 0;
else if (middle == param2)
order[1][1] = 1;
else
order[1][1] = 2;
order[1][0] = middle;
if (middle == param1)
order[1][1] = 0;
else if (middle == param2)
order[1][1] = 1;
else
order[1][1] = 2;
order[2][0] = max;
if (max == param1)
order[2][1] = 0;
else if(max == param2)
order[2][1] = 1;
else
order[2][1] = 2;
order[2][0] = max;
if (max == param1)
order[2][1] = 0;
else if (max == param2)
order[2][1] = 1;
else
order[2][1] = 2;
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()
{
if (mMin_zoom > 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;
}
int zoom = mMax_zoom < mMin_zoom ? mMin_zoom - mCurrent_zoom : mCurrent_zoom;
mNumberOfTiles = tilesonzoomlevel(zoom);
}
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;
}
else if (mMin_zoom < mMax_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);
}
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]])));
}
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)));
return QPointF(longitude, latitude);
}
bool TileMapAdapter::isTileValid(int x, int y, int z) const
{
if (mMax_zoom < mMin_zoom)
{
z= mMin_zoom - z;
}
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 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()
{
if (mMin_zoom > 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;
}
int zoom = mMax_zoom < mMin_zoom ? mMin_zoom - mCurrent_zoom : mCurrent_zoom;
mNumberOfTiles = tilesonzoomlevel(zoom);
}
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;
}
else if (mMin_zoom < mMax_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);
}
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]])));
}
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)));
return QPointF(longitude, latitude);
}
bool TileMapAdapter::isTileValid(int x, int y, int z) const
{
if (mMax_zoom < mMin_zoom)
{
z = mMin_zoom - z;
}
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;
}
}

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,47 +31,49 @@
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
{
Q_OBJECT
public:
//! constructor
/*!
* Use this derived MapAdapter to display maps from OpenStreetMap
* @author Kai Winter <kaiwinter@gmx.de>
* 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)
* @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
*/
class QMAPCONTROL_EXPORT TileMapAdapter : public MapAdapter
{
Q_OBJECT
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)
* @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 ~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;
qreal PI;
protected:
qreal rad_deg(qreal) const;
qreal deg_rad(qreal) const;
protected:
qreal rad_deg(qreal) const;
qreal deg_rad(qreal) const;
virtual bool isTileValid(int x, int y, int z) const;
virtual void zoom_in();
virtual void zoom_out();
virtual QString query(int x, int y, int z) const;
virtual int tilesonzoomlevel(int zoomlevel) const;
virtual int xoffset(int x) const;
virtual int yoffset(int y) const;
};
virtual bool isTileValid(int x, int y, int z) const;
virtual void zoom_in();
virtual void zoom_out();
virtual QString query(int x, int y, int z) const;
virtual int tilesonzoomlevel(int zoomlevel) const;
virtual int xoffset(int x) const;
virtual int yoffset(int y) const;
};
}
#endif

View File

@ -1,212 +1,209 @@
/*
*
* 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)
: MapAdapter(host, serverPath, tilesize, 0, 17)
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);
loc = QLocale(QLocale::English);
loc.setNumberOptions(QLocale::OmitGroupSeparator);
setBoundingBox(-180, -90, 180, 90);
qreal res = 0.703125;
for (int z = 0; z < 17; z++)
{
mNumberOfTiles = pow(2.0, mCurrent_zoom);
coord_per_x_tile = 360. / mNumberOfTiles;
coord_per_y_tile = 180. / mNumberOfTiles;
changeHostAddress( host, serverPath );
loc = QLocale(QLocale::English);
loc.setNumberOptions( QLocale::OmitGroupSeparator );
setBoundingBox( -180, -90, 180, 90 );
qreal res = 0.703125;
for( int z = 0; z < 17; z++ )
{
mResolutions[z] = res;
res = res / 2;
}
}
WMSMapAdapter::~WMSMapAdapter()
{
}
void WMSMapAdapter::changeHostAddress( const QString qHost, const QString qServerPath )
{
mServerOptions.clear();
QString serverPathPrefix;
if ( qServerPath.contains("?") &&
qServerPath.split("?").size() > 1 )
{
serverPathPrefix = qServerPath.split("?").at( 0 );
foreach( QString opt, qServerPath.split("?").at(1).split("&") )
{
if (opt.contains( "="))
{
mServerOptions[ opt.split("=").at(0).toUpper() ] = opt.split("=").at(1);
}
}
}
else
{
serverPathPrefix = "/wms/";
}
MapAdapter::changeHostAddress(qHost,serverPathPrefix);
//force expected parameters
if (!mServerOptions.contains("VERSION"))
{
mServerOptions["VERSION"] = "1.1.1";
}
if (!mServerOptions.contains("TRANSPARENT"))
{
mServerOptions["TRANSPARENT"]= "TRUE";
}
//if (!mServerOptions.contains("LAYERS"))
//{
// mServerOptions["LAYERS"] = TBD;
//}
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
}
if (!mServerOptions.contains("STYLES"))
{
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
}
QString WMSMapAdapter::serverPath() const
{
QString urlPath;
foreach( QString key, mServerOptions.keys() )
{
if (!urlPath.isEmpty())
{
urlPath.append("&");
}
urlPath.append( QString("%1=%2").arg( key ).arg( mServerOptions[key] ) );
}
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!
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;
return QPointF(lon, lat);
}
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;
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
{
// 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::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 ( x1 < 0 )
// {
// x1 += 180;
// }
// if ( x1 > 360 )
// {
// x1 -= 180;
// }
// if ( x2 < 0 )
// {
// x2 += 180;
// }
// if ( x2 > 360 )
// {
// x2 -= 180;
// }
//}
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));
mResolutions[z] = res;
res = res / 2;
}
}
WMSMapAdapter::~WMSMapAdapter() { }
void WMSMapAdapter::changeHostAddress(const QString qHost, const QString qServerPath)
{
mServerOptions.clear();
QString serverPathPrefix;
if (qServerPath.contains("?") && qServerPath.split("?").size() > 1)
{
serverPathPrefix = qServerPath.split("?").at(0);
foreach (QString opt, qServerPath.split("?").at(1).split("&"))
{
if (opt.contains("="))
{
mServerOptions[opt.split("=").at(0).toUpper()] = opt.split("=").at(1);
}
}
}
else
{
serverPathPrefix = "/wms/";
}
MapAdapter::changeHostAddress(qHost, serverPathPrefix);
// force expected parameters
if (!mServerOptions.contains("VERSION"))
{
mServerOptions["VERSION"] = "1.1.1";
}
if (!mServerOptions.contains("TRANSPARENT"))
{
mServerOptions["TRANSPARENT"] = "TRUE";
}
// if (!mServerOptions.contains("LAYERS"))
//{
// mServerOptions["LAYERS"] = TBD;
//}
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
}
if (!mServerOptions.contains("STYLES"))
{
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
}
QString WMSMapAdapter::serverPath() const
{
QString urlPath;
foreach (QString key, mServerOptions.keys())
{
if (!urlPath.isEmpty())
{
urlPath.append("&");
}
urlPath.append(QString("%1=%2").arg(key).arg(mServerOptions[key]));
}
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!
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;
return QPointF(lon, lat);
}
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;
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
{
// 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::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 ( x1 < 0 )
// {
// x1 += 180;
// }
// if ( x1 > 360 )
// {
// x1 -= 180;
// }
// if ( x2 < 0 )
// {
// x2 += 180;
// }
// if ( x2 > 360 )
// {
// x2 -= 180;
// }
//}
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));
}
}

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,46 +31,49 @@
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:
//! constructor
/*!
* Use this derived MapAdapter to display maps from WMS servers
* @author Kai Winter <kaiwinter@gmx.de>
* 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)
* @param host The servers URL
* @param serverPath The path to the tiles with placeholders
* @param tilesize the size of the tiles
*/
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)
* @param host The servers URL
* @param serverPath The path to the tiles with placeholders
* @param tilesize the size of the tiles
*/
WMSMapAdapter(QString host, QString serverPath, int tilesize = 256);
virtual ~WMSMapAdapter();
WMSMapAdapter(QString host, QString serverPath, int tilesize = 256);
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 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());
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;
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:
virtual QString getQ(qreal ux, qreal uy, qreal ox, qreal oy) const;
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;
};
qreal coord_per_x_tile;
qreal coord_per_y_tile;
QHash<QString, QString> mServerOptions;
QHash<int, qreal> mResolutions;
};
}
#endif