Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How yo use openseamap in QML?
QtWS25 Last Chance

How yo use openseamap in QML?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 779 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aurentiaco
    wrote on 5 Feb 2024, 09:24 last edited by
    #1

    Hello I am developing a qml map in Qt 5.15.2 and I need to use openseamap as a map. For that I am using openstreetmap plugin and want to add layer of openseamap in it. Does anybody have any idea of how can I do that. Or is there any other ways to do that. I want to make a marine map application actually. This is my qml code so far and also I want to use that map offline too and when it connects the internet I want to update the map.

    import QtLocation 5.15
    import QtPositioning 5.3
    import QtQuick 2.15
    import QtQuick.Controls 2.2
    
    
    Rectangle {
        width: 1024
        height: 768
    
        function handleZoom(){
            if(map.zoomLevel < 14){
                centerAnimation.start();
            }else{
                zoomOutAnimation.start();
            }
        }
    
        function zoomIn(){
            handleZoom();
        }
    
        function zoomOut(){
            zoomOutAnimation.start();
        }
    
        Map {
            id: map
            anchors.fill: parent
    
            plugin: Plugin {
                name: "osm"
            }
    
            zoomLevel: 14
            minimumZoomLevel: 0
            maximumZoomLevel: 18
            tilt: 0
    
            PropertyAnimation {
                id: centerAnimation
                target: map
                properties: "center"
                from: map.center
                to: QtPositioning.coordinate(_latitude, _longitude)
                duration: 1000
                easing.type: Easing.InOutQuad
    
                onStopped: {
                    zoomInAnimation.start(500);
                }
            }
            NumberAnimation {
                id: zoomOutAnimation
                target: map
                properties: "zoomLevel"
                from: map.zoomLevel
                to: 14  // You can adjust the zoom-out level
                duration: 500  // Duration of the animation in milliseconds
    
                onStopped: {
                    centerAnimation.start(200)
                }
            }
            NumberAnimation {
                id: zoomInAnimation
                target: map
                properties: "zoomLevel"
                from: map.zoomLevel
                to: 17  // You can adjust the zoom-out level
                duration: 500  // Duration of the animation in milliseconds
            }
            MapQuickItem {
                anchorPoint.x: marker.width / 2
                anchorPoint.y: marker.height
    
                sourceItem: Item {
                    width: 30
                    height: 30
    
                    Rectangle {
                        id: marker
                        width: 10
                        height: 10
                        color: "red"
                        radius: 3
                    }
                }
    
                coordinate: QtPositioning.coordinate(_latitude, _longitude)
            }
            Button {
                text: "Center"
                onClicked: {
                    zoomIn();
                }
                // Make the button round
                width: 70
                height: 70
    
    
                // Apply circular background
                background: Rectangle {
                    width: parent.width
                    height: parent.height
                    radius: 35
                    color: "lightblue" // Set your desired background color
                }
    
                anchors {
                    bottom: parent.bottom
                    right: parent.right
                    bottomMargin: 30
                    rightMargin: 30
                }
            }
    
            ComboBox {
                id: styleComboBox
                model: ListModel {
                    id: styleModel
                }
                onActivated: {
                    map.activeMapType = map.supportedMapTypes[index];
                }
                Component.onCompleted: {
                    for (var i = 0; i < map.supportedMapTypes.length; i++) {
                        styleModel.append({ text: map.supportedMapTypes[i].description });
                    }
                }
    
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.topMargin: 10
                anchors.rightMargin: 10
            }
        }
    }
    
    
    J 1 Reply Last reply 6 Feb 2024, 02:10
    0
    • R Offline
      R Offline
      Ronel_qtmaster
      wrote on 5 Feb 2024, 20:38 last edited by
      #2

      @Aurentiaco i will advice you to use here map or mapbox instead since direct access to osm map has been removed in newer versions of Qt

      J 1 Reply Last reply 6 Feb 2024, 02:10
      0
      • A Aurentiaco
        5 Feb 2024, 09:24

        Hello I am developing a qml map in Qt 5.15.2 and I need to use openseamap as a map. For that I am using openstreetmap plugin and want to add layer of openseamap in it. Does anybody have any idea of how can I do that. Or is there any other ways to do that. I want to make a marine map application actually. This is my qml code so far and also I want to use that map offline too and when it connects the internet I want to update the map.

        import QtLocation 5.15
        import QtPositioning 5.3
        import QtQuick 2.15
        import QtQuick.Controls 2.2
        
        
        Rectangle {
            width: 1024
            height: 768
        
            function handleZoom(){
                if(map.zoomLevel < 14){
                    centerAnimation.start();
                }else{
                    zoomOutAnimation.start();
                }
            }
        
            function zoomIn(){
                handleZoom();
            }
        
            function zoomOut(){
                zoomOutAnimation.start();
            }
        
            Map {
                id: map
                anchors.fill: parent
        
                plugin: Plugin {
                    name: "osm"
                }
        
                zoomLevel: 14
                minimumZoomLevel: 0
                maximumZoomLevel: 18
                tilt: 0
        
                PropertyAnimation {
                    id: centerAnimation
                    target: map
                    properties: "center"
                    from: map.center
                    to: QtPositioning.coordinate(_latitude, _longitude)
                    duration: 1000
                    easing.type: Easing.InOutQuad
        
                    onStopped: {
                        zoomInAnimation.start(500);
                    }
                }
                NumberAnimation {
                    id: zoomOutAnimation
                    target: map
                    properties: "zoomLevel"
                    from: map.zoomLevel
                    to: 14  // You can adjust the zoom-out level
                    duration: 500  // Duration of the animation in milliseconds
        
                    onStopped: {
                        centerAnimation.start(200)
                    }
                }
                NumberAnimation {
                    id: zoomInAnimation
                    target: map
                    properties: "zoomLevel"
                    from: map.zoomLevel
                    to: 17  // You can adjust the zoom-out level
                    duration: 500  // Duration of the animation in milliseconds
                }
                MapQuickItem {
                    anchorPoint.x: marker.width / 2
                    anchorPoint.y: marker.height
        
                    sourceItem: Item {
                        width: 30
                        height: 30
        
                        Rectangle {
                            id: marker
                            width: 10
                            height: 10
                            color: "red"
                            radius: 3
                        }
                    }
        
                    coordinate: QtPositioning.coordinate(_latitude, _longitude)
                }
                Button {
                    text: "Center"
                    onClicked: {
                        zoomIn();
                    }
                    // Make the button round
                    width: 70
                    height: 70
        
        
                    // Apply circular background
                    background: Rectangle {
                        width: parent.width
                        height: parent.height
                        radius: 35
                        color: "lightblue" // Set your desired background color
                    }
        
                    anchors {
                        bottom: parent.bottom
                        right: parent.right
                        bottomMargin: 30
                        rightMargin: 30
                    }
                }
        
                ComboBox {
                    id: styleComboBox
                    model: ListModel {
                        id: styleModel
                    }
                    onActivated: {
                        map.activeMapType = map.supportedMapTypes[index];
                    }
                    Component.onCompleted: {
                        for (var i = 0; i < map.supportedMapTypes.length; i++) {
                            styleModel.append({ text: map.supportedMapTypes[i].description });
                        }
                    }
        
                    anchors.top: parent.top
                    anchors.right: parent.right
                    anchors.topMargin: 10
                    anchors.rightMargin: 10
                }
            }
        }
        
        
        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 6 Feb 2024, 02:10 last edited by
        #3

        @Aurentiaco said in How yo use openseamap in QML?:

        I need to use openseamap as a map. For that I am using openstreetmap plugin and want to add layer of openseamap in it

        You'll need two separate maps -- One to download and display the street tiles, and one to download and display the seamark tiles:

        Map {
            id: streetMap
            anchors.fill: parent
            plugin: Plugin { name: "osm" }
            center: seamarkMap.center // Sync the 2 maps' centers
            zoomLevel: seamarkMap.zoomLevel // Sync the 2 maps' zoomLevels
            z: -1 // Place this underneath the seamarks
        }
        
        Map {
            id: seamarkMap
            anchors.fill: parent
            color: "transparent" // Allow the street tiles to be seen though the transparent parts of the seamap tiles
            plugin: Plugin {
                name: "osm"
                PluginParameter {
                    name: "osm.mapping.custom.host"
                    value: "https://tiles.openseamap.org/seamark/"
                }
            }
            activeMapType: supportedMapTypes[supportedMapTypes.length-1]
            center: QtPositioning.coordinate(59.91, 10.75) // Oslo
            zoomLevel: 14
        }
        

        I want to use that map offline too and when it connects the internet I want to update the map.

        See https://forum.qt.io/topic/95390/qt-offline-maps-using-osm-tiles for information on how to use OSM maps offline. However, note that these are permanently offline.

        You'll need to write extra code to switch between online and offline mode, and to update your own local tiles.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        1
        • R Ronel_qtmaster
          5 Feb 2024, 20:38

          @Aurentiaco i will advice you to use here map or mapbox instead since direct access to osm map has been removed in newer versions of Qt

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 6 Feb 2024, 02:10 last edited by
          #4

          @Ronel_qtmaster said in How yo use openseamap in QML?:

          i will advice you to use here map or mapbox instead since direct access to osm map has been removed in newer versions of Qt

          That's not true. OSM is retained in Qt 6, while all other providers (like Mapbox) have been removed: https://www.qt.io/blog/the-road-to-qt-location

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          1

          1/4

          5 Feb 2024, 09:24

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved