Skip to content
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

Recreate OSM viewer with Bevy #1038

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Toggle visibility of details layer based on zoom
matthieu-foucault committed Dec 22, 2022
commit 8b1428924c9b9a4542c9134365a35aa77c7e1ca1
8 changes: 6 additions & 2 deletions apps/osm_viewer_bevy/src/main.rs
Original file line number Diff line number Diff line change
@@ -4,8 +4,11 @@ use bevy_pancam::{PanCam, PanCamPlugin};
use colors::ColorScheme;
use map_model::Map;
use map_renderer::{
details_layer::DetailsLayerBundle, intersection::IntersectionBundle, lane::LaneBundle,
map_layer::MapLayerBundle, road::RoadBundle,
details_layer::{toggle_details_visibility, DetailsLayerBundle},
intersection::IntersectionBundle,
lane::LaneBundle,
map_layer::MapLayerBundle,
road::RoadBundle,
};

mod colors;
@@ -22,6 +25,7 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugin(PanCamPlugin::default())
.add_startup_system(setup)
.add_system(toggle_details_visibility)
.run();
}

12 changes: 12 additions & 0 deletions apps/osm_viewer_bevy/src/map_renderer/details_layer.rs
Original file line number Diff line number Diff line change
@@ -2,14 +2,19 @@ use std::f32::consts::PI;

use bevy::prelude::*;

#[derive(Component)]
pub struct DetailsLayer;

#[derive(Bundle)]
pub struct DetailsLayerBundle {
details_layer: DetailsLayer,
spatial_bundle: SpatialBundle,
}

impl Default for DetailsLayerBundle {
fn default() -> Self {
DetailsLayerBundle {
details_layer: DetailsLayer,
spatial_bundle: SpatialBundle {
transform: Transform::from_rotation(Quat::from_rotation_x(PI))
.with_translation(Vec3::new(0., 0., -1.)),
@@ -18,3 +23,10 @@ impl Default for DetailsLayerBundle {
}
}
}

pub fn toggle_details_visibility(
camera_projection: Query<&OrthographicProjection, With<Camera2d>>,
mut details_visibility: Query<&mut Visibility, With<DetailsLayer>>,
) {
details_visibility.single_mut().is_visible = camera_projection.single().scale < 0.75;
}