【QT学习】qml中地图Map去掉mapbox标签

(1)背景:在使用qml加载mapboxgl插件来显示地图的时候,会出现左下角的地图标签,如何去掉

 

在Map中有一个要素:copyrightsVisible代表版权,置成false即可。

Map {
    id:map
    anchors.fill: parent
    color: "black"
    copyrightsVisible:false
   plugin: Plugin {
        name: "mapboxgl"
    }
}

(2)背景:如何设置地图的样式:

 (2.1)可以使用qt自带的样式:通过mainMap.activeMapType设置当前地图正在显示的地图底图:例如

Map
{
    id:map
    zoomLevel: 12
    center: QtPositioning.coordinate(60.170448, 24.942046) // Helsinki
    copyrightsVisible:false
    plugin: Plugin { name: "mapboxgl" }
    
    Component.onCompleted:
    {
        map.activeMapType = map.supportedMapTypes[7];//设置当前地图底图是数组的第8个元素
    }
}

上述代码表示设置底图是第8个元素,一般地图支持的类型,即通过打印map.supportedMapTypes有:

{
"0":{"objectName":"","style":1,"name":"mapbox://styles/mapbox/streets-v10","description":"Streets","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"1":{"objectName":"","style":1,"name":"mapbox://styles/mapbox/basic-v9","description":"Basic","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"2":{"objectName":"","style":1,"name":"mapbox://styles/mapbox/bright-v9","description":"Bright","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"3":{"objectName":"","style":4,"name":"mapbox://styles/mapbox/outdoors-v10","description":"Outdoors","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"4":{"objectName":"","style":2,"name":"mapbox://styles/mapbox/satellite-v9","description":"Satellite","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"5":{"objectName":"","style":5,"name":"mapbox://styles/mapbox/satellite-streets-v10","description":"Satellite Streets","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"6":{"objectName":"","style":7,"name":"mapbox://styles/mapbox/light-v9","description":"Light","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"7":{"objectName":"","style":7,"name":"mapbox://styles/mapbox/dark-v9","description":"Dark","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"8":{"objectName":"","style":6,"name":"mapbox://styles/mapbox/navigation-preview-day-v2","description":"Navigation Preview Day","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"9":{"objectName":"","style":6,"name":"mapbox://styles/mapbox/navigation-preview-night-v2","description":"Navigation Preview Night","mobile":false,"night":true,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"10":{"objectName":"","style":9,"name":"mapbox://styles/mapbox/navigation-guidance-day-v2","description":"Navigation Guidance Day","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},
"11":{"objectName":"","style":9,"name":"mapbox://styles/mapbox/navigation-guidance-night-v2","description":"Navigation Guidance Night","mobile":false,"night":true,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}}
}

所以map.supportedMapTypes[7]代表的是

"7":{"objectName":"","style":7,"name":"mapbox://styles/mapbox/dark-v9","description":"Dark","mobile":false,"night":false,"cameraCapabilities":{"objectName":"","minimumZoomLevel":1,"maximumZoomLevel":21,"minimumTilt":0,"maximumTilt":60,"minimumFieldOfView":36.87,"maximumFieldOfView":36.87},"metadata":{"isHTTPS":true}},

(2.2)可以自定义样式:通过设置参数PluginParameter自定义一个json或者在线的style。

Map
{
    id:map
    zoomLevel: 12
    center: QtPositioning.coordinate(60.170448, 24.942046) // Helsinki
    copyrightsVisible:false
    plugin: Plugin { 
        name: "mapboxgl" 
        PluginParameter {
            name: "mapboxgl.mapping.additional_style_urls"
            value: "http://XXXXXXXXXXXstyle.json"
        }
        PluginParameter {
            name: "mapboxgl.mapping.additional_style_urls"
            value: "mapbox://styles/mapbox/dark-v9"
        }
    }
    
    Component.onCompleted:
    {
        map.activeMapType = map.supportedMapTypes[0];//设置当前地图底图是数组的第8个元素
    }
}

一般情况下添加的新的style均插在原来的最开始位置。

你可能感兴趣的:(map,QT,#,qml)