Poul K. Sørensen
Poul K. Sørensen

Reputation: 17530

QWebView: Extremely laggy when dragging the map around, when using google maps

I used the QWebView to show a simple html page loading google maps. But when dragging the map around it's really slow at loading the images, and it doesn't seem like it caches them, as it's slow the second time also to move it around.

Anyone seen something similar and got an solution?

    #define MAP_HTML "<html><head><script type=\"text/javascript\" " \
    "src=\"http://maps.googleapis.com/maps/api/js?sensor=false\"></script>" \
    "<script  type=\"text/javascript\">" \
    "var map; function initialize(lat, lng) { "\
    "map = new google.maps.Map(document.getElementById(\"map_canvas\"), " \
    "{ zoom: 15, center: new google.maps.LatLng(lat, lng), " \
    "disableDefaultUI: true, mapTypeId: google.maps.MapTypeId.ROADMAP  });" \
    "} </script>" \
    "</head><body style=\"margin:0px; padding:0px;\" onload=\"initialize(55.786033,12.521667)\">" \
    "<div id=\"map_canvas\" style=\"width:100%; height:100%\"></div>" \
    "</body></html>"


GMapWidget::GMapWidget(QWidget *parent)
    : QWebView(parent)
    , m_accessManager(new QNetworkAccessManager(this))
    , m_initMap(false)
{
    connect(m_accessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotNetworkReply(QNetworkReply*)));

    connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
    setHtml(MAP_HTML);
//  auto t = QUrl::fromLocalFile("index.html").path();

//  load(QUrl::fromLocalFile("index.html"));
}

Upvotes: 1

Views: 671

Answers (1)

Chris Browet
Chris Browet

Reputation: 4266

You might try adding a QNetworkDiskCache to your QNetworkAccessManager to see if it fares better:

QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
diskCache->setCacheDirectory("cacheDir");
m_accessManager->setCache(diskCache);

Upvotes: 1

Related Questions