map_gui/render/
area.rs

1use geom::{Bounds, Pt2D, Tessellation};
2use map_model::{Area, AreaID, AreaType, Map};
3use widgetry::{Color, EventCtx, Fill, GeomBatch, GfxCtx, Line, Text};
4
5use crate::colors::ColorScheme;
6use crate::render::{DrawOptions, Renderable};
7use crate::{AppLike, ID};
8
9pub struct DrawArea {
10    pub id: AreaID,
11}
12
13impl DrawArea {
14    pub fn new(
15        ctx: &EventCtx,
16        area: &Area,
17        cs: &ColorScheme,
18        all_areas: &mut GeomBatch,
19    ) -> DrawArea {
20        all_areas.push(DrawArea::fill(area.area_type, cs), area.polygon.clone());
21        if false {
22            // TODO Need to auto-size better -- ensure it's completely contained in the polygon,
23            // probably
24            if let Some(name) = area.osm_tags.get("name") {
25                all_areas.append(
26                    Text::from(Line(name).fg(Color::BLACK))
27                        .render_autocropped(ctx)
28                        .scale(1.0)
29                        .centered_on(area.polygon.polylabel())
30                        .set_z_offset(-0.1),
31                );
32            }
33        }
34
35        DrawArea { id: area.id }
36    }
37
38    pub fn fill(area_type: AreaType, cs: &ColorScheme) -> Fill {
39        match area_type {
40            AreaType::Park => cs.grass.clone(),
41            AreaType::Water => cs.water.clone(),
42            AreaType::Island => cs.map_background.clone(),
43            AreaType::StudyArea => cs.study_area.clone(),
44        }
45    }
46}
47
48impl Renderable for DrawArea {
49    fn get_id(&self) -> ID {
50        ID::Area(self.id)
51    }
52
53    fn draw(&self, _: &mut GfxCtx, _: &dyn AppLike, _: &DrawOptions) {}
54
55    fn get_outline(&self, map: &Map) -> Tessellation {
56        // Since areas are so big, don't just draw the outline
57        Tessellation::from(map.get_a(self.id).polygon.clone())
58    }
59
60    fn get_bounds(&self, map: &Map) -> Bounds {
61        map.get_a(self.id).polygon.get_bounds()
62    }
63
64    fn contains_pt(&self, pt: Pt2D, map: &Map) -> bool {
65        map.get_a(self.id).polygon.contains_pt(pt)
66    }
67}