Skip to content

Improve the blueprint API for the map view #8027

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

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace rerun.blueprint.archetypes;
/// Configuration for the background map of the map view.
table MapBackground (
"attr.rerun.scope": "blueprint",
"attr.python.aliases": "blueprint_components.MapProviderLike",
"attr.docs.unreleased"
) {
// --- Optional ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace rerun.blueprint.archetypes;
//TODO(ab): Turn this archetype into `MapArea` and include a `center: LatLon` componnent or similar
table MapZoom (
"attr.rerun.scope": "blueprint",
"attr.python.aliases": "datatypes.Float64Like",
"attr.docs.unreleased"
) {
// --- Optional ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ namespace rerun.blueprint.views;

/// A 2D map view to display geospatial primitives.
///
/// \example views/map title="Use a blueprint to create a map view."
//TODO(ab): add a screenshot
/// \example views/map title="Use a blueprint to create a map view." image="https://static.rerun.io/map-view/8b2cc15e3f3313e2181667f6c29816ebe75e16e6/1200w.png"
table MapView (
"attr.rerun.view_identifier": "Map",
"attr.docs.unreleased"
Expand Down
8 changes: 8 additions & 0 deletions docs/content/reference/types/views/map_view.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions docs/snippets/all/views/map.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
"""Use a blueprint to show a map."""
"""Use a blueprint to customize a map view."""

import rerun as rr
import rerun.blueprint as rrb

rr.init("rerun_example_map_view", spawn=True)

rr.log("points", rr.GeoPoints(lat_lon=[[47.6344, 19.1397], [47.6334, 19.1399]]))
rr.log("points", rr.GeoPoints(lat_lon=[[47.6344, 19.1397], [47.6334, 19.1399]], radii=rr.Radius.ui_points(20.0)))

# Create a map view to display the chart.
# TODO(#7903): cleanup the blueprint API for the map view
blueprint = rrb.Blueprint(
rrb.MapView(
origin="points",
name="MapView",
zoom=rrb.archetypes.MapZoom(16.0),
background=rrb.archetypes.MapBackground(rrb.components.MapProvider.OpenStreetMap),
zoom=16.0,
background=rrb.MapProvider.OpenStreetMap,
),
collapse_panels=True,
)
Expand Down
1 change: 1 addition & 0 deletions rerun_py/rerun_sdk/rerun/blueprint/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions rerun_py/rerun_sdk/rerun/blueprint/views/map_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions rerun_py/tests/unit/blueprint_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from __future__ import annotations

from typing import Any

import rerun.blueprint as rrb


def assert_blueprint_contents_are_equal(*contents: rrb.SpaceView | rrb.Container) -> None:
"""
Check for equivalence between blueprint contents (views and containers).

This is done by checking equality between all fields, _except_ the `id` field, which is always unique.
"""

def strip_id_field(d: dict[str, Any]) -> dict[str, Any]:
return {k: v for k, v in d.items() if k != "id"}

for i, (c1, c2) in enumerate(zip(contents, contents[1:])):
assert strip_id_field(c1.__dict__) == strip_id_field(c2.__dict__), f"View {i} and {i + 1} are not equal"
24 changes: 24 additions & 0 deletions rerun_py/tests/unit/test_map_view_blueprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

import rerun.blueprint as rrb

from .blueprint_utils import assert_blueprint_contents_are_equal


def test_map_view_blueprint() -> None:
"""Various ways to create a `MapView` blueprint."""

bp1 = rrb.MapView(origin="point", name="MapView", zoom=16, background="openstreetmap")
bp2 = rrb.MapView(origin="point", name="MapView", zoom=rrb.components.ZoomLevel(16), background="openstreetmap")
bp3 = rrb.MapView(
origin="point", name="MapView", zoom=rrb.archetypes.MapZoom(16), background=rrb.MapProvider.OpenStreetMap
)
bp4 = rrb.MapView(
origin="point",
name="MapView",
zoom=rrb.archetypes.MapZoom(rrb.components.ZoomLevel(16)),
background=rrb.archetypes.MapBackground(rrb.MapProvider.OpenStreetMap),
)

# assert bp1 == bp2 == bp3 == bp4
assert_blueprint_contents_are_equal(bp1, bp2, bp3, bp4)
Loading