5
votes

I have my own local Z/X/Y map tile server and want to use it as a map background in a QML application. Looking at sample code it appears that this is done by:-

 Plugin {
    id: osmPlugin
    name: "osm"
 }

So I need to write my own plugin. But the documentation seems sparse and I cannot find the source code for the osm version or installation instructions.

Is this relatively easy to do, or can it be done without writing a new plugin?

3

3 Answers

4
votes

You can set the osm.mapping.host like this:

    Plugin {
        id: osmPlugin
        name: "osm"


        PluginParameter { name: "osm.mapping.host"; value: "https://tile.openstreetmap.org/" }
        PluginParameter { name: "osm.geocoding.host"; value: "https://nominatim.openstreetmap.org" }
        PluginParameter { name: "osm.routing.host"; value: "https://router.project-osrm.org/viaroute" }
        PluginParameter { name: "osm.places.host"; value: "https://nominatim.openstreetmap.org/search" }
        PluginParameter { name: "osm.mapping.copyright"; value: "" }
        PluginParameter { name: "osm.mapping.highdpi_tiles"; value: true }
    }

But don't forget to set Custom Map type using the following code:

    Map {
        id: map
        height: parent.width
        width: parent.width
        plugin: osmPlugin

        Component.onCompleted: {
            for( var i_type in supportedMapTypes ) {
                if( supportedMapTypes[i_type].name.localeCompare( "Custom URL Map" ) === 0 ) {
                    activeMapType = supportedMapTypes[i_type]
                }
            }
        }
    }
1
votes

If the documentation doesn't cover something or not in enough detail, it is always good to remember that Qt's source is publically available.

For example the OSM plugin is here

The Woboq code browser is also really nice for that if you know the name of the class or file you are looking for

1
votes

Ok I have figured out a way to do this without writing a plugin.

The OSM plugin uses a tileserver to retrieve tiles. The url is set with the plugin option osm.mapping.custom.host setting this to a local url allows me to use my own tiles as long as they conform to the osm structure.