-
Notifications
You must be signed in to change notification settings - Fork 42
fix: Fix map.set_view_state does not set pitch and bearing #1055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a1fe3a0
503b1b5
6424f6f
46f8abf
71eadac
c7cd153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know the peculiarities of jupyter widgets, but these tests always passed, even with pitch and bearing specified. |
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some tests. This was fun to play around with. Oddly, updating pitch/bearing with |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """Mapview interaction tests.""" | ||
|
|
||
| import pytest | ||
| from IPython.display import display | ||
|
|
||
| from lonboard import Map | ||
| from lonboard.view_state import MapViewState | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_map(): | ||
| """Lonboard map for testing.""" | ||
| return Map([]) | ||
|
|
||
|
|
||
| def click_and_drag_canvas( | ||
| page_session, | ||
| start_pos, | ||
| end_pos, | ||
| button, | ||
| ): | ||
| """Simulate click and drag on the map. | ||
|
|
||
| Start and end positions are 0-100 percentages of the canvas size. | ||
| """ | ||
| canvas = page_session.locator("canvas").first | ||
| canvas.wait_for(state="visible", timeout=5000) | ||
| bbox = canvas.bounding_box() | ||
|
|
||
| # Convert relative coords to absolute pixels | ||
| start_x = bbox["x"] + (start_pos["x"] / 100) * bbox["width"] | ||
| start_y = bbox["y"] + (start_pos["y"] / 100) * bbox["height"] | ||
| end_x = bbox["x"] + (end_pos["x"] / 100) * bbox["width"] | ||
| end_y = bbox["y"] + (end_pos["y"] / 100) * bbox["height"] | ||
|
|
||
| page_session.mouse.move(start_x, start_y) | ||
| page_session.mouse.down(button=button) | ||
| page_session.mouse.move(end_x, end_y) | ||
| page_session.mouse.up(button=button) | ||
| page_session.wait_for_timeout(500) | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("solara_test") | ||
| def test_jupyter_set_view_state(page_session, sample_map): | ||
| """Test setting view state in Jupyter environment.""" | ||
| m = sample_map | ||
| set_state = { | ||
| "longitude": -100, | ||
| "latitude": 40, | ||
| "zoom": 5, | ||
| "pitch": 30, | ||
| "bearing": 45, | ||
| } | ||
| m.set_view_state(**set_state) | ||
|
|
||
| # Simulate a cell break in Jupyter, best I could do | ||
| display(m) | ||
| canvas = page_session.locator("canvas").first | ||
| canvas.wait_for(timeout=5000) | ||
| page_session.wait_for_timeout(1000) | ||
|
|
||
| assert m.view_state == MapViewState(**set_state) | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("solara_test") | ||
| def test_jupyter_manual_view_state_change(page_session, sample_map): | ||
| """Test manual view state change in Jupyter environment.""" | ||
| m = sample_map | ||
| m.set_view_state(zoom=3) | ||
| display(m) | ||
| initial_view_state = m.view_state | ||
| start_pos = {"x": 50, "y": 50} | ||
|
|
||
| # Increase lon from 0 by dragging left | ||
| end_pos = {"x": 40, "y": 50} | ||
| click_and_drag_canvas(page_session, start_pos, end_pos, button="left") | ||
| assert m.view_state.longitude > initial_view_state.longitude | ||
|
|
||
| # Increse lat from 0 by dragging down | ||
| end_pos = {"x": 50, "y": 60} | ||
| click_and_drag_canvas(page_session, start_pos, end_pos, button="left") | ||
| assert m.view_state.latitude > initial_view_state.latitude | ||
|
|
||
| # Increase pitch by dragging up w. RMB | ||
| end_pos = {"x": 50, "y": 40} | ||
| click_and_drag_canvas(page_session, start_pos, end_pos, button="right") | ||
| assert m.view_state.pitch > initial_view_state.pitch | ||
|
|
||
| # Increase bearing by dragging left w. RMB | ||
| start_pos = {"x": 40, "y": 40} | ||
| end_pos = {"x": 30, "y": 40} | ||
| click_and_drag_canvas(page_session, start_pos, end_pos, button="right") | ||
| assert m.view_state.bearing > initial_view_state.bearing |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initially wrote an isMapView() check, as suggested #1052 (comment) but turns out view was always "undefined" when I created my maps with
m = viz([])