Important: Please read the Qt Code of Conduct -

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 :
    <div id="map"></div>
    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);

    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;

    << "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 );
    << QString("map.setCenter (lonLat, %1);").arg(QString::number(zoomLevelDefault,10));

    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,


  • 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