Skip to content

Commit 0de294e

Browse files
authored
Initial demotiles support (#333)
1 parent 5844ac3 commit 0de294e

File tree

3,283 files changed

+5064
-4233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,283 files changed

+5064
-4233
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Cargo.lock
1515
dist/
1616

1717
maplibre-gl-js/
18+
render-tests/**/diff.png
19+
render-tests/**/actual.png
20+
maplibre-native-shaders/
1821

1922
# Cache by reqwest-middleware-cache
2023
*reqwest*cache*

Cargo.toml.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "test_column"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
geozero = "0.11"

maplibre/src/background/queue_system.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ pub fn queue_system(
3434
// We just iterate through the style layers and issue a single quad draw for each background layer.
3535
for layer in &style.layers {
3636
if layer.type_ == "background" {
37-
let c = match &layer.paint {
38-
Some(LayerPaint::Background(paint)) => paint
39-
.background_color
40-
.as_ref()
41-
.map(|c| c.to_array())
37+
let c: [f32; 4] = match &layer.paint {
38+
Some(paint @ LayerPaint::Background(_)) => paint
39+
.get_color()
40+
.map(|c| c.into())
4241
.unwrap_or([0.0, 0.0, 0.0, 1.0]),
4342
_ => [0.0, 0.0, 0.0, 1.0],
4443
};
@@ -50,6 +49,7 @@ pub fn queue_system(
5049
draw_function: Box::new(DrawState::<LayerItem, DrawBackground>::new())
5150
as Box<dyn crate::render::render_phase::Draw<LayerItem>>,
5251
index: layer.index,
52+
is_line: false,
5353
style_layer: layer.id.clone(),
5454
source_shape: crate::render::tile_view_pattern::TileShape::default(),
5555

maplibre/src/coords.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ impl Zoom {
201201
pub fn new(zoom: f64) -> Self {
202202
Zoom(zoom)
203203
}
204+
205+
pub fn level(&self) -> f32 {
206+
self.0 as f32
207+
}
204208
}
205209

206210
impl Zoom {

maplibre/src/geojson/mod.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,19 @@ impl<T> ProjectingTessellator<T> {
6767

6868
impl<T: GeomProcessor> GeomProcessor for ProjectingTessellator<T> {
6969
fn xy(&mut self, x: f64, y: f64, idx: usize) -> geozero::error::Result<()> {
70+
if x.is_nan() || y.is_nan() {
71+
println!(
72+
"ProjectingTessellator received NaN Input! x={}, y={}, idx={}",
73+
x, y, idx
74+
);
75+
}
7076
let (tx, ty) = self.project(x, y);
77+
if !tx.is_finite() || !ty.is_finite() {
78+
println!(
79+
"ProjectingTessellator output non-finite! lon={}, lat={} -> tx={}, ty={}",
80+
x, y, tx, ty
81+
);
82+
}
7183
self.inner.xy(tx, ty, idx)
7284
}
7385

@@ -210,12 +222,22 @@ pub fn process_geojson_features<T: VectorTransferables, C: Context>(
210222
};
211223

212224
match paint {
213-
LayerPaint::Fill(_) | LayerPaint::Line(_) => {
214-
let mut projecting = ProjectingTessellator::new(
215-
coords,
216-
request.project,
217-
ZeroTessellator::<IndexDataType>::default(),
218-
);
225+
LayerPaint::Fill(_) | LayerPaint::Line(_) | LayerPaint::Background(_) => {
226+
let mut tessellator = ZeroTessellator::<IndexDataType>::default();
227+
match paint {
228+
LayerPaint::Fill(p) => tessellator.style_property = p.fill_color.clone(),
229+
LayerPaint::Line(p) => {
230+
tessellator.style_property = p.line_color.clone();
231+
tessellator.is_line_layer = true;
232+
}
233+
LayerPaint::Background(p) => {
234+
tessellator.style_property = p.background_color.clone()
235+
}
236+
_ => {}
237+
}
238+
239+
let mut projecting =
240+
ProjectingTessellator::new(coords, request.project, tessellator);
219241

220242
let mut geojson_src = geozero::geojson::GeoJson(json_str.as_str());
221243
if let Err(e) = geojson_src.process(&mut projecting) {
@@ -249,7 +271,9 @@ pub fn process_geojson_features<T: VectorTransferables, C: Context>(
249271
coords,
250272
inner.buffer.into(),
251273
inner.feature_indices,
274+
inner.feature_colors,
252275
synthetic_layer,
276+
style_layer.id.clone(),
253277
))
254278
.map_err(ProcessGeoJsonError::SendError)?;
255279
}
@@ -291,6 +315,7 @@ pub fn process_geojson_features<T: VectorTransferables, C: Context>(
291315
inner.quad_buffer.into(),
292316
inner.features,
293317
synthetic_layer,
318+
style_layer.id.clone(),
294319
))
295320
.map_err(ProcessGeoJsonError::SendError)?;
296321
}

maplibre/src/headless/map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ impl HeadlessMap {
9090
VectorLayerBucket::AvailableLayer(AvailableVectorLayerBucket {
9191
coords: layer.coords,
9292
source_layer: layer.layer_data.name,
93+
style_layer_id: layer.style_layer_id,
9394
buffer: layer.buffer,
9495
feature_indices: layer.feature_indices,
96+
feature_colors: layer.feature_colors,
9597
})
9698
})
9799
.collect::<Vec<_>>(),

maplibre/src/io/source_type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl TessellateSource {
3131
impl Default for TessellateSource {
3232
fn default() -> Self {
3333
Self::new("https://maps.tuerantuer.org/europe_germany", "pbf")
34+
// Self::new("https://demotiles.maplibre.org/tiles", "pbf")
3435
}
3536
}
3637

maplibre/src/raster/queue_system.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn queue_system(MapContext { world, .. }: &mut MapContext) -> SystemResult {
3636
LayerItem {
3737
draw_function: Box::new(DrawState::<LayerItem, DrawRasterTiles>::new()),
3838
index: 0,
39+
is_line: false,
3940
style_layer: "raster".to_string(),
4041
tile: Tile {
4142
coords: source_shape.coords(),

maplibre/src/render/main_pass.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ impl Node for MainPassNode {
115115

116116
if let Some(layer_items) = world.resources.get::<RenderPhase<LayerItem>>() {
117117
log::trace!("RenderPhase<LayerItem>::size() = {}", layer_items.size());
118+
119+
// Draw layers in style index order (painter's algorithm).
120+
// This preserves the MapLibre GL JS rendering model where e.g.
121+
// coastline (line) → countries-fill (fill) → countries-boundary (line)
122+
// ensures fill covers inland portions of coastline.
118123
for item in layer_items {
119124
item.draw_function.draw(&mut tracked_pass, world, item);
120125
}

maplibre/src/render/render_phase/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ impl<I: PhaseItem> RenderPhase<I> {
4949
pub struct LayerItem {
5050
pub draw_function: Box<dyn Draw<LayerItem>>,
5151
pub index: u32,
52+
/// Whether this item uses the line pipeline (true) or fill pipeline (false).
53+
pub is_line: bool,
5254

5355
pub style_layer: String,
5456

0 commit comments

Comments
 (0)