Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QT openstreetmap can refresh the map properly
QtWS25 Last Chance

QT openstreetmap can refresh the map properly

Scheduled Pinned Locked Moved Qt WebKit
3 Posts 1 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fred1983
    wrote on last edited by
    #1

    Hello,

    I want to display a map with OpenStreetMap on my user interface created with QT.
    I use a QwebView and load the oms.htm on the initialization (see the code below).

    oms.htm :
    @<html>
    <body>
    [removed][removed]
    <div id="map"></div>
    [removed]
    map = new OpenLayers.Map("map");
    map.addLayer(new OpenLayers.Layer.OSM());
    var lonLat = new OpenLayers.LonLat( -0.644722 ,44.843056 ).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
    var zoom=16;
    map.setCenter (lonLat, zoom);
    [removed]
    </body>
    </html>@

    When a user enter a location in a TextEdit, I use nominatim. I can extract latitude and longitude from the xml reply.
    Then, I want to display the map centered on the new location with the code below :

    @QStringList scriptStr;

    scriptStr
    << "map = new OpenLayers.Map(("map"));"
    << "map.addLayer(new OpenLayers.Layer.OSM());"
    << QString("var lonLat = new OpenLayers.LonLat( %1 ,%2 ).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());")
    .arg( longitude )
    .arg( latitude );
    scriptStr
    << QString("map.setCenter (lonLat, %1);").arg(QString::number(zoomLevelDefault,10));
    ui->webView->page()->mainFrame()->evaluateJavaScript(scriptStr.join("\n"));@

    This code displays the new location under the previous map in the Qwebview.
    I know that I should use "map = new OpenLayers.Map(document.getElementById("map"));" instead of "map = new OpenLayers.Map(("map"));" but it doesn't display anything.

    Thanks if anyone could help me,

    Regards,

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fred1983
      wrote on last edited by
      #2

      Any ideas ?
      It seems to correct... to me at least.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fred1983
        wrote on last edited by
        #3

        I fixed the problem by deleting the instruction which creates a new map "map = new OpenLayers.Map(("map"));" in the stringlist.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved