Use an offline interactive map in QML

不问归期 提交于 2020-12-29 10:01:31

问题


I'd like to inject a chunk of map that I got from OpenStreetMap under the form of an osm file.

From what I've read in the documentation, the Open Street Map Plugin doesn't seem to have any parameter taking a source file as a map. It only works with a server. Problem is I won't have an Internet connection when running my application. I need to use a map internally.

Ditto for Mapbox and HERE plugins.

Is there any other way to do this?

Here is the boilerplate to create a Map:

Plugin {
    id: somePlugin
    // code here to choose the plugin as necessary
}

Map {
    id: map

    plugin: somePlugin

    center {
        latitude: -27
        longitude: 153
    }
    zoomLevel: map.minimumZoomLevel

    gesture.enabled: true
}

回答1:


Update April 2017: QtLocation now supports offline OSM tiles. See http://doc.qt.io/qt-5/location-plugin-osm.html

As you note, QtLocation currently does not give you the offline option. Also, for basemaps it currently only supports image tiles (not the XML vector OSM data you are talking about).

You have a few alternatives:

In QML: you can use the ArcGIS Runtime SDK for Qt. Starting from version 10.26 it supports adding custom map layers with offline tiles. You will need to get PNG/JPG tiles of your OSM data first. Here is an example layer that supports OSM slippymap tiles.

In C++: you will find a few options to display vector data that might require or not conversion from the OSM format and more work on your side:

  • http://wiki.openstreetmap.org/wiki/Libosmscout
  • https://www.mapbox.com/blog/qmapboxgl/
  • QGis is made in Qt, as are many other opensource geographic projects, so they might be helpful

Also, don't forget to vote for the issues mentioned above in Qt Bugtracker!




回答2:


You can generate or download tiles for offline usage. For generating tiles take a look at TileMill or Maperitive. Downloading tiles can be achieved via Marble and various other tools, but please respect the tile server's usage policy! Downloading high zoom tiles causes high load on the tile server because these tiles are usually not cached and need to be rendered on the fly.



来源:https://stackoverflow.com/questions/36647616/use-an-offline-interactive-map-in-qml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!