Skip to content

Commit 2c4c87a

Browse files
committed
store the tile id an object belongs to as well as an optional title for an object
1 parent 83348eb commit 2c4c87a

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/lib/object.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::math::TileId;
2+
13
use super::css::Selector;
24

35
use lyon::math::Point;
@@ -25,16 +27,26 @@ pub struct Object {
2527
tags: HashMap<String, String>,
2628
/// The object type.
2729
_object_type: ObjectType,
30+
pub title: Option<String>,
31+
pub tile_id: TileId,
2832
}
2933

3034
impl Object {
3135
/// Creates a new object with no tags.
32-
pub fn new(selector: Selector, points: Vec<Point>, object_type: ObjectType) -> Self {
36+
pub fn new(
37+
selector: Selector,
38+
points: Vec<Point>,
39+
object_type: ObjectType,
40+
tile_id: TileId,
41+
title: Option<String>,
42+
) -> Self {
3343
Self {
3444
selector,
3545
points,
3646
tags: HashMap::new(),
3747
_object_type: object_type,
48+
title,
49+
tile_id,
3850
}
3951
}
4052

@@ -44,12 +56,16 @@ impl Object {
4456
points: Vec<Point>,
4557
tags: HashMap<String, String>,
4658
object_type: ObjectType,
59+
tile_id: TileId,
60+
title: Option<String>,
4761
) -> Self {
4862
Self {
4963
selector,
5064
points,
5165
tags,
5266
_object_type: object_type,
67+
title,
68+
tile_id,
5369
}
5470
}
5571

src/lib/vector_tile/tile.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::*;
2-
use egui::TextBuffer;
32
use feature::collection::LayerInfo;
43
use glyphon::{
54
Attrs, Buffer, Color, Family, FontSystem, Metrics, Shaping, TextArea, TextBounds, Weight,
@@ -9,8 +8,8 @@ use lyon::{
98
tessellation::{geometry_builder::VertexBuffers, FillOptions, FillTessellator},
109
};
1110
use quick_protobuf::{BytesReader, MessageRead};
11+
use std::collections::HashMap;
1212
use std::sync::{Arc, RwLock};
13-
use std::{collections::HashMap, thread::spawn};
1413
use std::{fmt::Display, ops::Range};
1514
use vector_tile::vector_tile::mod_Tile::{Feature, GeomType, Layer, Value};
1615

@@ -168,12 +167,14 @@ impl Tile {
168167

169168
let paths = geometry_commands_to_paths(feature.type_pb, &feature.geometry);
170169

170+
let mut title = None;
171171
if let Some(tag) = tags.get("name:en") {
172172
let point = paths[0][ControlPointId(0)];
173173
text.push((
174174
(point.x / extent as f32, point.y / extent as f32),
175175
tag.clone(),
176176
));
177+
title = Some(tag.clone());
177178
}
178179

179180
// If we have a valid object at hand, insert it into the object list
@@ -191,6 +192,8 @@ impl Tile {
191192
paths[0].points().to_vec(),
192193
tags,
193194
ot,
195+
*tile_id,
196+
title,
194197
));
195198
}
196199

@@ -341,7 +344,13 @@ impl Tile {
341344
.tessellate_path(&path, &FillOptions::tolerance(0.0001), builder)
342345
.expect("This is a bug. Please report it.");
343346

344-
let object = Object::new(selector, path.points().to_vec(), ObjectType::Polygon);
347+
let object = Object::new(
348+
selector,
349+
path.points().to_vec(),
350+
ObjectType::Polygon,
351+
TileId::new(0, 0, 0),
352+
Some("background".to_string()),
353+
);
345354

346355
(
347356
current_feature_id,

0 commit comments

Comments
 (0)