MapViewDemo.cpp Example File
custommapview/src/MapViewDemo.cpp
#include "MapViewDemo.hpp"
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Application>
#include <bb/cascades/Container>
#include <bb/cascades/maps/MapView>
#include <bb/cascades/QmlDocument>
#include <bb/platform/geo/Point.hpp>
#include <QPoint>
using namespace bb::cascades;
using namespace bb::cascades::maps;
using namespace bb::platform::geo;
MapViewDemo::MapViewDemo(bb::cascades::Application *app) :
QObject(app)
{
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_mapViewTest", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
app->setScene(root);
}
QVariantList MapViewDemo::worldToPixelInvokable(QObject* mapObject, double latitude, double longitude) const
{
MapView* mapview = qobject_cast<MapView*>(mapObject);
const Point worldCoordinates = Point(latitude, longitude);
const QPoint pixels = mapview->worldToWindow(worldCoordinates);
return QVariantList() << pixels.x() << pixels.y();
}
void MapViewDemo::updateMarkers(QObject* mapObject, QObject* containerObject) const
{
MapView* mapview = qobject_cast<MapView*>(mapObject);
Container* container = qobject_cast<Container*>(containerObject);
for (int i = 0; i < container->count(); i++) {
const QPoint xy = worldToPixel(mapview,
container->at(i)->property("lat").value<double>(),
container->at(i)->property("lon").value<double>());
container->at(i)->setProperty("x", xy.x());
container->at(i)->setProperty("y", xy.y());
}
}
QPoint MapViewDemo::worldToPixel(QObject* mapObject, double latitude, double longitude) const
{
MapView* mapview = qobject_cast<MapView*>(mapObject);
const Point worldCoordinates = Point(latitude, longitude);
return mapview->worldToWindow(worldCoordinates);
}