• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Open-S2 / open-vector-tile / #67

03 May 2025 04:21AM UTC coverage: 98.815% (+0.1%) from 98.678%
#67

push

Mr Martian
migrate to stable

9510 of 9624 relevant lines covered (98.82%)

68.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/rust/mapbox/vector_tile.rs
1
use crate::{
2
    base::BaseVectorTile,
3
    mapbox::{MapboxVectorLayer, write_layer},
4
};
5
use alloc::{collections::BTreeMap, rc::Rc, string::String, vec::Vec};
6
use core::cell::RefCell;
7
use pbf::{ProtoRead, Protobuf};
8

9
/// The vector tile struct that covers both "open" and "mapbox" specifications
10
#[derive(Debug)]
11
pub struct MapboxVectorTile {
12
    /// the layers in the vector tile
13
    pub layers: BTreeMap<String, MapboxVectorLayer>,
14
    /// the protobuf for the vector tile
15
    pbf: Rc<RefCell<Protobuf>>,
16
}
17
impl MapboxVectorTile {
18
    /// Create a new vector tile
19
    pub fn new(data: Vec<u8>, end: Option<usize>) -> Self {
12✔
20
        let pbf = Rc::new(RefCell::new(data.into()));
12✔
21
        let mut vt = MapboxVectorTile { pbf: pbf.clone(), layers: BTreeMap::new() };
12✔
22

12✔
23
        let mut tmp_pbf = pbf.borrow_mut();
12✔
24
        tmp_pbf.read_fields(&mut vt, end);
12✔
25

12✔
26
        vt
12✔
27
    }
12✔
28

29
    /// Get a layer given the name
30
    pub fn layer(&mut self, name: &str) -> Option<&mut MapboxVectorLayer> {
18✔
31
        self.layers.get_mut(name)
18✔
32
    }
18✔
33
}
34
impl ProtoRead for MapboxVectorTile {
35
    fn read(&mut self, tag: u64, pb: &mut Protobuf) {
18✔
36
        match tag {
18✔
37
            1 | 3 => {
18✔
38
                let mut layer = MapboxVectorLayer::new(self.pbf.clone(), tag == 1);
18✔
39
                pb.read_message(&mut layer);
18✔
40
                self.layers.insert(layer.name.clone(), layer);
18✔
41
            }
18✔
42
            _ => panic!("unknown tag: {}", tag),
×
43
        }
44
    }
18✔
45
}
46

47
/// writer for converting a BaseVectorTile to encoded bytes of the Open Vector Flat Tile format or Mapbox Vector Tile
48
pub fn write_tile(tile: &mut BaseVectorTile, mapbox_support: bool) -> Vec<u8> {
3✔
49
    let mut pbf = Protobuf::new();
3✔
50

51
    // first write layers
52
    for layer in tile.layers.values() {
9✔
53
        pbf.write_bytes_field(
9✔
54
            if mapbox_support { 3 } else { 1 },
9✔
55
            &write_layer(layer, mapbox_support),
9✔
56
        );
57
    }
58

59
    pbf.take()
3✔
60
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc