Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Map set min/max longitude latitude



  • Hi all,
    I'm trying to limit the visible area on a map. Is there a way to set a min/max for longitude/latitude for the gesture area?
    Couldn't find anything working to restrict the area.
    thx,
    patrik



  • Hello :)

    You can accomplish this using this parameter,
    "fieldOfView : real

    This property holds the field of view of the camera used to look at the map, in degrees. If the plugin property of the map is not set, or the plugin does not support mapping, the value is 45 degrees.

    Note that changing this value implicitly changes also the distance between the camera and the map, so that, at a tilting angle of 0 degrees, the resulting image is identical for any value used for this property.

    For more information about this parameter, consult the Wikipedia articles about Field of view and Angle of view."
    https://doc.qt.io/qt-5/qml-qtlocation-map.html#fieldOfView-prop



  • Hi MEMekaniske,
    seems not to work. Can put there any value but I can move the map with no boundaries...
    thx,
    patrik



  • @patrikd hey!

    Ok, so you want there to be no drag/flick etc enabled?

    Took this from the Qt docs, you can disable gestures using the following example and only allow the ones that you want to be enabled.
    Or since you don't want any movement you can just remove gesture feature and remove focus from the map object.

    Example Usage
    The following example enables the pinch and pan gestures on the map, but not flicking. So the map scrolling will halt immediately on releasing the mouse button / touch.
    
    Map {
        gesture.enabled: true
        gesture.acceptedGestures: MapGestureArea.PinchGesture | MapGestureArea.PanGesture
    }
    
    "
    MapGestureArea.NoGesture        Don't support any additional gestures (value: 0x0000).
    MapGestureArea.PinchGesture	Support the map pinch gesture (value: 0x0001).
    MapGestureArea.PanGesture	Support the map pan gesture (value: 0x0002).
    MapGestureArea.FlickGesture	Support the map flick gesture (value: 0x0004).
    MapGestureArea.RotationGesture	Support the map rotation gesture (value: 0x0008).
    MapGestureArea.TiltGesture	Support the map tilt gesture (value: 0x0010).
    

    Or if you want there to be a limmit on zooming in and out, you can use the following.

    maximumZoomLevel : real
    minimumZoomLevel : real
    


  • Hi MEMakaniske,
    thx for your advice but still not the result. My target is this functionality:
    https://docs.mapbox.com/ios/maps/examples/constraining-gestures/

    But I can't find a way to restrict my map view. The min/max zoom doesn't help on this
    and it seems like restricting the gestures doesn't help. I can still move my map out of the view.
    best,
    patrik



  • Ok, now I understand.

    I was wrong in the previous revision of this reply, that was for getting address lists etc from a shape of set by coordinates.
    You need the GeoShape module
    https://doc.qt.io/qt-5/qml-geoshape.html

    I'll give this a shot myself in the morning! hope you get it working right with geoshape!



  • @patrikd

    I have been trying to search the docs for any way to do this easily and with gestures.
    But I am only able to do this easily with MouseArea.

    I think you would need to use the map plugin you reffered in the link, which is also available in Qt if you'd want to do this with as few lines of code as possible.

    https://doc.qt.io/qt-5/location-plugin-mapboxgl.html


Log in to reply