Skip to content

Mapview get Screen Coords not accurate #68

Open
@PeterQFR

Description

Describe the bug
When a mapview is not fullscreen, the function MapView.get_window_xy_from() does not return the correct pixels coordinates

To Reproduce
Code example showing the issue:
Given the kv:

<MapWidget>
    map: agent_init_map
    done_button: donebtn
    cancel_button: cancelbtn

    BoxLayout:
        orientation: 'vertical'

        size: 640, 480
        MapView:
            size_hint_y: 0.9
            id: agent_init_map
            zoom: 11
            lat: -27.5399
            lon: 152.8045
        BoxLayout:
            size_hint_y: 0.1
            orientation: 'horizontal'
            Button:
                id: cancelbtn
                text: "Cancel"
            
            Button:
                id: donebtn
                text: "Startup"

And given a call to the mapview.get_window_xy_from in code like thus:

    def getWPScreenCoords(self, waypoint):
        #print(f'waypoint {waypoint}')
        x1, y1 = self.mapview.get_window_xy_from(
                        waypoint['lat'],
                        waypoint['lon'],
                        self.mapview.zoom)
        #print(f'coords {(x1, y1)}')
        return x1, y1

will return incorrect coordinates.

Expected behavior
A clear and concise description of what you expected to happen.
This will only work as expected if the MapView is full screen ie in a FloatLayout and there is no size hint less than 1.0.
In the BoxLayout example, the only way to make it work correctly is to change the function as below to remove the size of the lower buttons from the y coordinate:

    def getWPScreenCoords(self, waypoint):
        #print(f'waypoint {waypoint}')
        x1, y1 = self.mapview.get_window_xy_from(
                        waypoint['lat'],
                        waypoint['lon'],
                        self.mapview.zoom)
        #print(f'coords {(x1, y1)}')
        return x1, y1 - self.mapview.size[1]*(1.-float(self.mapview.size_hint_y))

Logs/output
If applicable, add screenshots to help explain your problem.

Platform (please complete the following information):

  • OS: Linux Ubuntu 22.04
  • Python version. 3.8.10
  • Kivy v2.2.1
  • kivy-Garden.mapview v1.0.6

Additional context
Add any other context about the problem here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions