server tiles: remove labels again

This commit is contained in:
Astro 2021-08-28 19:40:48 +02:00
parent fe5e68736f
commit 4f01097362
2 changed files with 2 additions and 77 deletions

View File

@ -34,7 +34,6 @@ pub struct Style {
pub z_index: i32,
pub stroke: Option<(f64, Color)>,
pub fill: Option<Color>,
pub label: Option<f64>,
}
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"),

View File

@ -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<f64> {
}
}
fn bounding_box(path: &LineString<f64>) -> Option<Rect<f64>> {
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<F: FnOnce(f64) -> bool>(m: &mut Option<f64>, 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<f64>) -> Point<f64> {
((rect.min() + rect.max()) / 2.).into()
}
struct Shape {
style: &'static tile_style::Style,
path: LineString<f64>,
excludes: Rc<Vec<LineString<f64>>>,
}
struct Label {
font_size: f64,
pos: Point<f64>,
text: String,
}
pub fn get_tile(state: State) -> (State, Response<Body>) {
let mut times = vec![Instant::now()];
let te = TileExtractor::borrow_from(&state);
@ -85,12 +48,6 @@ pub fn get_tile(state: State) -> (State, Response<Body>) {
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<Body>) {
bounds,
};
let mut shapes: BTreeMap<i32, Vec<Shape>> = 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<Body>) {
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<Body>) {
}
}
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();