QT openstreetmap can refresh the map properly



  • 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,



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.