1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//! # Open Vector Tile
//!
//! ## Description
//!
//! The `open-vector-tile` Rust crate provides functionalities to read and write
//! Open Vector Tile Spec messages. This crate uses `no_std` and is intended to be available for
//! embedded systems and WASM applications.
//!
//! Types of layers include:
//! - Vector data - vector points, lines, and polygons with 3D coordinates, properties, and/or m-values
//! - Image data - raster data that is RGB(A) encoded
//! - Grid data: data that has a max-min range, works much like an image but has floating/double precision point values for each point on the grid
//!
//! ### Reading
//!
//! ```rust,ignore
//! use open_vector_tile::{VectorTile, VectorLayerMethods};
//!
//! let data: Vec<u8> = vec![];
//! let mut tile = VectorTile::new(data, None);
//!
//! // VECTOR API
//!
//! let landuse = tile.layer("landuse").unwrap();
//!
//! // grab the first feature
//! let firstFeature = landuse.feature(0).unwrap();
//! // grab the geometry
//! let geometry = firstFeature.load_geometry();
//!
//! // OR specifically ask for a geometry type
//! let points = firstFeature.load_points();
//! let lines = firstFeature.load_lines();
//!
//! // If you want to take advantage of the pre-tessellated and indexed geometries
//! // and you're loading the data for a renderer, you can grab the pre-tessellated geometry
//! let (geometry_flat, indices) = firstFeature.load_geometry_flat();
//!
//! // IMAGE API
//!
//! let satellite = tile.images.get("satellite").unwrap();
//! // grab the image data
//! let data = &satellite.image;
//!
//! // GRID API
//!
//! let elevation = tile.grids.get("elevation").unwrap();
//! // grab the grid data
//! let data = &elevation.data;
//! ```
//!
//! ### Writing
//!
//! ```rust
//! // NOTE: Be sure to include the `serde_json` crate
//! extern crate alloc;
//! use open_vector_tile::{
//! base::{
//! BaseVectorFeature, BaseVectorLayer, BaseVectorLines3DFeature, BaseVectorLinesFeature,
//! BaseVectorPoints3DFeature, BaseVectorPointsFeature, BaseVectorPolys3DFeature,
//! BaseVectorPolysFeature, BaseVectorTile,
//! },
//! open::{
//! Extent, FeatureType, GridData, ImageData, ImageType,
//! },
//! write_tile, Point, Point3D, VectorGeometry, VectorLayerMethods,
//! VectorLine3DWithOffset, VectorLineWithOffset, VectorTile,
//! };
//! use s2json::{BBox, BBox3D, BBOX, ValuePrimitiveType, ValueType, PrimitiveValue, Value};
//!
//!
//! // WRITE VECTOR DATA //-//-//-//-//-//-//-//-//-//-//
//!
//! let mut tile = BaseVectorTile::default();
//!
//! // setup the property shapes
//!
//! let example_value_str = r#"{
//! "a": -20,
//! "b": 1,
//! "c": 2.2
//! }"#;
//! let example_value = serde_json::from_str::<Value>(example_value_str).unwrap();
//! let example_value_str_2 = r#"{
//! "a": -2,
//! "b": 1,
//! "c": 2.2
//! }"#;
//! let example_value2 = serde_json::from_str::<Value>(example_value_str_2).unwrap();
//!
//! let empty_value = Value::from([
//! ("a".to_string(), ValueType::Primitive(PrimitiveValue::I64(0))),
//! ("b".to_string(), ValueType::Primitive(PrimitiveValue::U64(0))),
//! ("c".to_string(), ValueType::Primitive(PrimitiveValue::F32(0.0))),
//! ]);
//!
//! // WRITE THE POINTS
//!
//! let mut points_layer =
//! BaseVectorLayer::new("points".to_string(), 4096.into(), vec![], None, None);
//!
//! let feature = BaseVectorPointsFeature::new(
//! None,
//! vec![Point::new_with_m(0, 0, example_value2.clone())],
//! example_value.clone(),
//! None,
//! );
//! let feature2 = BaseVectorPointsFeature::new(
//! Some(1),
//! vec![Point::new_with_m(0, 0, example_value.clone()), Point::new(1, 1)],
//! example_value2.clone(),
//! Some(BBox::new(-1.1, 0.0, 1.0, 1.0)),
//! );
//!
//! // add_features
//! points_layer.add_feature(BaseVectorFeature::BaseVectorPointsFeature(feature));
//! points_layer.add_feature(BaseVectorFeature::BaseVectorPointsFeature(feature2));
//!
//! tile.add_layer(points_layer);
//!
//! // Lastly build the tile:
//! let open_tile_bytes = write_tile(Some(&mut tile), None, None);
//!
//!
//! // WRITE IMAGE DATA //-//-//-//-//-//-//-//-//-//-//
//!
//! let image =
//! ImageData::new("test".to_string(), ImageType::AVIF, 2, 3, Vec::from([1, 2, 3, 10]));
//!
//! let open_tile_bytes = write_tile(None, Some(vec![&image]), None);
//!
//!
//! // WRITE GRID DATA //-//-//-//-//-//-//-//-//-//-//
//!
//! let elevation_data = GridData::new(
//! "elevation".to_owned(),
//! 8_192.into(),
//! 512.0,
//! 0.0,
//! 0.0,
//! vec![-1.0, 2.0, 3.0, 4.0],
//! );
//! let open_tile_bytes = write_tile(None, None, Some(vec![&elevation_data]));
//! ```
extern crate alloc;
extern crate pbf;
/// Base Vector containers for Tiles, Layers, and Features
/// Geometry utilities
/// Mapbox specification for Layers and Features
/// Open specification for Layers and Features
/// Utilities/functions that are useful across all specifications
/// The vector feature struct that covers both "open" and "mapbox" specifications
/// The vector tile struct that covers both "open" and "mapbox" specifications
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
use ;
use ;
// SAFETY: This application is single threaded, so using AssumeSingleThreaded is allowed.
static ALLOCATOR: =
unsafe ;
// #[cfg(any(target_arch = "wasm32", feature = "wasm"))]
// mod wasm_specific {
// #[panic_handler]
// fn panic(_info: &core::panic::PanicInfo) -> ! {
// loop {}
// }
// }
/// Expose the function "create_vector_tile" to JavaScript
/// Creates a new VectorTile instance given input buffer
pub extern "C"
/// Expose the function "free_vector_tile" to JavaScript
/// Frees the VectorTile instance from memory
pub extern "C"
/// Free memory allocated regardless of the type
pub extern "C"