diff --git a/server/src/tile_style.rs b/server/src/tile_style.rs index f175f24..a73b9b0 100644 --- a/server/src/tile_style.rs +++ b/server/src/tile_style.rs @@ -34,7 +34,6 @@ pub struct Style { pub z_index: i32, pub stroke: Option<(f64, Color)>, pub fill: Option, - pub label: Option, } impl Style { @@ -42,7 +41,6 @@ impl Style { z_index: 0, stroke: None, fill: None, - label: None, }; } @@ -51,7 +49,7 @@ const STYLES: &[(Selector, Style)] = &[ Style { z_index: -10, ..Style::DEFAULT }), (Selector::TagEquals("landuse", "forest"), - Style { z_index: -8, fill: Some((0.2, 0.7, 0.2, 0.8)), label: Some(20.), ..Style::DEFAULT }), + Style { z_index: -8, fill: Some((0.2, 0.7, 0.2, 0.8)), ..Style::DEFAULT }), (Selector::TagEquals("leisure", "park"), Style { z_index: -8, fill: Some((0.3, 0.7, 0.3, 0.8)), ..Style::DEFAULT }), (Selector::TagEquals("landuse", "meadow"), diff --git a/server/src/tiles.rs b/server/src/tiles.rs index b18ac8a..614a7b7 100644 --- a/server/src/tiles.rs +++ b/server/src/tiles.rs @@ -7,7 +7,7 @@ use gotham::{ hyper::{Body, Response}, state::{FromState, State}, }; -use geo::{LineString, Point, Rect}; +use geo::{LineString, Rect}; use mime::IMAGE_PNG; use http::StatusCode; use cairo::{ImageSurface, Context}; @@ -27,49 +27,12 @@ impl Grow for Rect { } } -fn bounding_box(path: &LineString) -> Option> { - let mut x1 = None; - let mut x2 = None; - let mut y1 = None; - let mut y2 = None; - for point in path.points_iter() { - #[inline] - fn update bool>(m: &mut Option, n: f64, f: F) { - match *m { - None => *m = Some(n), - Some(ref mut o) => { - if f(*o) { - *m = Some(n); - } - } - } - } - let x = point.x(); - let y = point.y(); - update(&mut x1, x, |x1| x < x1); - update(&mut y1, y, |y1| y < y1); - update(&mut x2, x, |x2| x > x2); - update(&mut y2, y, |y2| y > y2); - } - Some(Rect::new((x1?, y1?), (x2?, y2?))) -} - -fn center(rect: &Rect) -> Point { - ((rect.min() + rect.max()) / 2.).into() -} - struct Shape { style: &'static tile_style::Style, path: LineString, excludes: Rc>>, } -struct Label { - font_size: f64, - pos: Point, - text: String, -} - pub fn get_tile(state: State) -> (State, Response) { let mut times = vec![Instant::now()]; let te = TileExtractor::borrow_from(&state); @@ -85,12 +48,6 @@ pub fn get_tile(state: State) -> (State, Response) { ctx.set_line_join(cairo::LineJoin::Round); ctx.set_line_cap(cairo::LineCap::Butt); - let mut font_options = cairo::FontOptions::new().unwrap(); - font_options.set_antialias(cairo::Antialias::Good); - font_options.set_hint_style(cairo::HintStyle::Full); - font_options.set_hint_metrics(cairo::HintMetrics::On); - ctx.set_font_options(&font_options); - // background ctx.set_source_rgba(0.5, 0.5, 0.5, 1.); ctx.fill().unwrap(); @@ -102,7 +59,6 @@ pub fn get_tile(state: State) -> (State, Response) { bounds, }; let mut shapes: BTreeMap> = BTreeMap::new(); - let mut labels = vec![]; times.push(Instant::now()); let ways_result = app_state.with_db(|db| @@ -195,19 +151,6 @@ pub fn get_tile(state: State) -> (State, Response) { shapes.entry(style.z_index) .or_default() .push(shape); - - if let Some(bbox) = bounding_box(&path) { - let center = center(&bbox); - style.label.and_then(|font_size| { - tags.get("name:de") - .or(tags.get("name")) - .map(|text| labels.push(Label { - font_size, - pos: center, - text: text.to_string(), - })) - }); - } } }); } @@ -249,22 +192,6 @@ pub fn get_tile(state: State) -> (State, Response) { } } - times.push(Instant::now()); - - for Label { font_size, pos, text } in labels.into_iter() { - let (x, y) = pctx.lonlat_to_xy(pos.x(), pos.y()); - let te = if let Ok(te) = pctx.ctx.text_extents(&text) { - te - } else { - continue; - }; - - pctx.ctx.move_to(x - te.width / 2., y - te.height / 2.); - pctx.ctx.set_source_rgba(0., 0., 0., 1.); - pctx.ctx.set_font_size(font_size); - let _ = pctx.ctx.show_text(&text); - } - times.push(Instant::now()); let mut buffer = Cursor::new(vec![]); s.write_to_png(&mut buffer).unwrap();