Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions galileo-maplibre/src/layer/vector_tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,6 @@ fn fill_rule(fill: &FillLayer, tile_schema: &TileSchema) -> Option<StyleRule> {

/// Converts a [`LineLayer`] to a [`StyleRule`], or logs and returns `None` if unsupported.
fn line_rule(line: &LineLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
if line.paint.line_dasharray.is_some() {
log::debug!(
"{UNSUPPORTED} Line dasharray is not supported yet; skipping layer {}",
line.id
);
return None;
}

log_unsupported_field!(line.paint.line_blur);
log_unsupported_field!(line.paint.line_gap_width);
log_unsupported_field!(line.paint.line_gradient);
Expand Down Expand Up @@ -306,12 +298,14 @@ fn line_rule(line: &LineLayer, tile_schema: &TileSchema) -> Option<StyleRule> {
.minzoom
.and_then(|lod| tile_schema.lod_resolution(lod.round() as u32));
let filter = line.filter.as_ref().and_then(|v| v.to_galileo_expr());
let dasharray = line.paint.line_dasharray.clone();

Some(StyleRule {
layer_name: Some(source_layer),
symbol: VectorTileSymbol::Line(VectorTileLineSymbol {
width,
stroke_color: color,
dasharray,
}),
min_resolution,
max_resolution,
Expand Down
2 changes: 1 addition & 1 deletion galileo-maplibre/src/style/layer/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct LinePaint {

/// Dash pattern for the line. Supports expressions.
#[serde(rename = "line-dasharray", skip_serializing_if = "Option::is_none")]
pub line_dasharray: Option<Value>,
pub line_dasharray: Option<Vec<f32>>,

/// Gap width for a casing effect. Supports expressions.
#[serde(rename = "line-gap-width", skip_serializing_if = "Option::is_none")]
Expand Down
1 change: 1 addition & 0 deletions galileo/src/layer/feature_layer/symbol/contour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl<F> Symbol<F> for SimpleContourSymbol {
width: self.width,
offset: 0.0,
line_cap: LineCap::Butt,
dasharray: None,
};

match geometry {
Expand Down
1 change: 1 addition & 0 deletions galileo/src/layer/feature_layer/symbol/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl SimplePolygonSymbol {
width: self.stroke_width,
offset: self.stroke_offset,
line_cap: LineCap::Butt,
dasharray: None,
};

for contour in polygon.iter_contours() {
Expand Down
1 change: 1 addition & 0 deletions galileo/src/layer/vector_tile_layer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ impl VectorTileLayerBuilder {
symbol: VectorTileSymbol::Line(VectorTileLineSymbol {
width: 1.0.into(),
stroke_color: Color::BLACK.into(),
dasharray: None,
}),
},
StyleRule {
Expand Down
8 changes: 7 additions & 1 deletion galileo/src/layer/vector_tile_layer/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,21 @@ pub struct VectorTileLineSymbol {
pub width: NumExpr,
/// Color of the line in pixels.
pub stroke_color: ColorExpr,
/// Parameters of dash array for the line.
///
/// Sets length of "dash - gap - dash - ..." of widths of the line. If the specification contains not even number of
/// values, the whole pattern is repeated twice when applied.
pub dasharray: Option<Vec<f32>>,
}

impl VectorTileLineSymbol {
pub(crate) fn to_paint(&self, feature: &MvtFeature, view: ExprView) -> Option<LinePaint> {
pub(crate) fn to_paint(&self, feature: &MvtFeature, view: ExprView) -> Option<LinePaint<'_>> {
Some(LinePaint {
color: self.stroke_color.eval(feature, view)?,
width: self.width.eval(feature, view)?,
offset: 0.0,
line_cap: LineCap::Butt,
dasharray: self.dasharray.as_deref(),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ impl VtProcessor {
))
}

fn get_line_symbol(
rule: &StyleRule,
fn get_line_symbol<'a>(
rule: &'a StyleRule,
feature: &MvtFeature,
view: ExprView,
) -> Option<LinePaint> {
) -> Option<LinePaint<'a>> {
rule.symbol.line().and_then(|s| s.to_paint(feature, view))
}

Expand Down
25 changes: 23 additions & 2 deletions galileo/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use render_bundle::RenderBundle;
use serde::{Deserialize, Serialize};

use crate::Color;
use crate::render::render_bundle::world_set::{DashArray, LineParameters};

#[cfg(feature = "wgpu")]
mod wgpu;
Expand Down Expand Up @@ -101,8 +102,8 @@ pub struct PolygonPaint {
}

/// Parameter to draw a line primitive with.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct LinePaint {
#[derive(Debug, Clone)]
pub struct LinePaint<'a> {
/// Color of the line.
pub color: Color,
/// Width of the line in pixels.
Expand All @@ -112,6 +113,26 @@ pub struct LinePaint {
pub offset: f64,
/// Type of the cap of the line.
pub line_cap: LineCap,
/// Parameters of dash array for the line.
///
/// Sets length of "dash - gap - dash - ..." of widths of the line. If the specification contains not even number of
/// values, the whole pattern is repeated twice when applied.
pub dasharray: Option<&'a [f32]>,
}

impl LinePaint<'_> {
pub(crate) fn line_parameters(&self) -> LineParameters {
LineParameters {
color: self.color,
width: self.width as f32,
offset: self.offset as f32,
cap: self.line_cap,
}
}

pub(crate) fn dasharray(&self) -> Option<DashArray<'_>> {
self.dasharray.as_ref().map(|v| DashArray(v))
}
}

/// Cap (end point) style of the line.
Expand Down
34 changes: 19 additions & 15 deletions galileo/src/render/point_paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::render::text::TextStyle;
use crate::render::{LineCap, LinePaint};

/// Specifies the way a point should be drawn to the map.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone)]
pub struct PointPaint<'a> {
pub(crate) shape: PointShape<'a>,
pub(crate) offset: Vector2<f32>,
Expand All @@ -36,13 +36,15 @@ impl<'a> PointPaint<'a> {
pub fn sector(color: Color, diameter: f32, start_angle: f32, end_angle: f32) -> Self {
Self {
offset: Vector2::default(),
shape: PointShape::Sector(SectorParameters {
fill: color.into(),
radius: diameter / 2.0,
start_angle,
end_angle,
shape: PointShape::Sector {
parameters: SectorParameters {
fill: color.into(),
radius: diameter / 2.0,
start_angle,
end_angle,
},
outline: None,
}),
},
}
}

Expand Down Expand Up @@ -112,6 +114,7 @@ impl<'a> PointPaint<'a> {
width: width as f64,
offset: 0.0,
line_cap: LineCap::Round,
dasharray: None,
})
}
_ => {}
Expand All @@ -133,27 +136,29 @@ impl<'a> PointPaint<'a> {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
#[derive(Debug, Clone)]
pub(crate) enum PointShape<'a> {
Dot {
color: Color,
},
Circle {
fill: CircleFill,
radius: f32,
outline: Option<LinePaint>,
outline: Option<LinePaint<'a>>,
},
Sector {
parameters: SectorParameters,
outline: Option<LinePaint<'a>>,
},
Sector(SectorParameters),
Square {
fill: Color,
size: f32,
outline: Option<LinePaint>,
outline: Option<LinePaint<'a>>,
},
FreeShape {
fill: Color,
scale: f32,
outline: Option<LinePaint>,
outline: Option<LinePaint<'a>>,
shape: Cow<'a, ClosedContour<Point2<f32>>>,
},
Label {
Expand All @@ -176,13 +181,12 @@ pub enum MarkerStyle {
},
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, Serialize, Deserialize)]
pub(crate) struct SectorParameters {
pub fill: CircleFill,
pub radius: f32,
pub start_angle: f32,
pub end_angle: f32,
pub outline: Option<LinePaint>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions galileo/src/render/render_bundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl RenderBundle {
pub fn add_line<N, P, C>(&mut self, line: &C, paint: &LinePaint, min_resolution: f64)
where
N: AsPrimitive<f32>,
P: CartesianPoint3d<Num = N>,
P: CartesianPoint3d<Num = N> + Copy,
C: Contour<Point = P>,
{
self.world_set.add_line(line, paint, min_resolution);
Expand All @@ -82,7 +82,7 @@ impl RenderBundle {
min_resolution: f64,
) where
N: AsPrimitive<f32>,
P: CartesianPoint3d<Num = N>,
P: CartesianPoint3d<Num = N> + Copy,
Poly: Polygon,
Poly::Contour: Contour<Point = P>,
{
Expand Down
Loading
Loading