Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
fallback to default properties instead of not rendering when we don't…
Browse files Browse the repository at this point in the history
… have a style

refs #272
  • Loading branch information
kkaefer committed May 30, 2014
1 parent 942da9c commit 461a19d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
12 changes: 12 additions & 0 deletions include/llmr/style/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct IconClass : public GenericClass {
};

struct IconProperties : public GenericProperties {
inline IconProperties() : GenericProperties() {}
float size = 0;
Color color = {{ 1, 1, 1, 1 }};
std::string image;
Expand All @@ -147,6 +148,7 @@ struct LineClass : public GenericClass {
};

struct LineProperties : public GenericProperties {
inline LineProperties() : GenericProperties() {}
float width = 0;
float offset = 0;
Color color = {{ 0, 0, 0, 1 }};
Expand All @@ -164,6 +166,7 @@ struct FillClass : public GenericClass {
};

struct FillProperties : public GenericProperties {
inline FillProperties() : GenericProperties() {}
Winding winding = Winding::NonZero;
bool antialias = true;
Color fill_color = {{ 0, 0, 0, 1 }};
Expand All @@ -187,6 +190,7 @@ struct TextClass : public GenericClass {
};

struct TextProperties : public GenericProperties {
inline TextProperties() : GenericProperties() {}
Color color = {{ 0, 0, 0, 1 }};
Color halo = {{ 1, 1, 1, 0.75 }};
float halo_radius = 0.25f;
Expand All @@ -202,13 +206,15 @@ struct BackgroundClass : public GenericClass {
};

struct BackgroundProperties : public GenericProperties {
inline BackgroundProperties() : GenericProperties() {}
Color color = {{ 1, 1, 1, 1 }};
};

struct RasterClass : public GenericClass {
};

struct RasterProperties : public GenericProperties {
inline RasterProperties() : GenericProperties() {}
};

struct CompositeClass : public GenericClass {
Expand All @@ -219,6 +225,12 @@ struct CompositeProperties : public GenericProperties {
};


const IconProperties defaultIconProperties;
const LineProperties defaultLineProperties;
const FillProperties defaultFillProperties;
const TextProperties defaultTextProperties;
const BackgroundProperties defaultBackgroundProperties;
const RasterProperties defaultRasterProperties;
const CompositeProperties defaultCompositeProperties;

}
Expand Down
6 changes: 5 additions & 1 deletion src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,11 @@ typename Styles::const_iterator find_style(const Styles &styles, const LayerDesc
template <typename Styles>
bool is_invisible(const Styles &styles, const LayerDescription &layer_desc) {
auto it = find_style(styles, layer_desc);
if (it == styles.end()) { return true; }
if (it == styles.end()) {
// We don't have a style, so we fall back to the default style which is
// always visible.
return false;
}
return !it->second.isVisible();
}

Expand Down
5 changes: 3 additions & 2 deletions src/renderer/painter_fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons

const std::unordered_map<std::string, FillProperties> &fill_properties = map.getStyle().computed.fills;
const std::unordered_map<std::string, FillProperties>::const_iterator fill_properties_it = fill_properties.find(layer_name);
if (fill_properties_it == fill_properties.end()) return;

const FillProperties& properties = fill_properties_it->second;
const FillProperties &properties = fill_properties_it != fill_properties.end()
? fill_properties_it->second
: defaultFillProperties;
if (!properties.enabled) return;


Expand Down
5 changes: 3 additions & 2 deletions src/renderer/painter_icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ void Painter::renderIcon(IconBucket& bucket, const std::string& layer_name, cons

const std::unordered_map<std::string, IconProperties> &icon_properties = map.getStyle().computed.icons;
const std::unordered_map<std::string, IconProperties>::const_iterator icon_properties_it = icon_properties.find(layer_name);
if (icon_properties_it == icon_properties.end()) return;

const IconProperties& properties = icon_properties_it->second;
const IconProperties &properties = icon_properties_it != icon_properties.end()
? icon_properties_it->second
: defaultIconProperties;
if (!properties.enabled) return;

Color color = properties.color;
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/painter_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons

const std::unordered_map<std::string, LineProperties> &line_properties = map.getStyle().computed.lines;
const std::unordered_map<std::string, LineProperties>::const_iterator line_properties_it = line_properties.find(layer_name);
if (line_properties_it == line_properties.end()) return;

const LineProperties& properties = line_properties_it->second;
const LineProperties &properties = line_properties_it != line_properties.end()
? line_properties_it->second
: defaultLineProperties;
if (!properties.enabled) return;

float width = properties.width;
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/painter_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ void Painter::renderRaster(RasterBucket& bucket, const std::string& layer_name,

const std::unordered_map<std::string, RasterProperties> &raster_properties = map.getStyle().computed.rasters;
const std::unordered_map<std::string, RasterProperties>::const_iterator raster_properties_it = raster_properties.find(layer_name);
if (raster_properties_it == raster_properties.end()) return;

const RasterProperties& properties = raster_properties_it->second;
const RasterProperties &properties = raster_properties_it != raster_properties.end()
? raster_properties_it->second
: defaultRasterProperties;
if (!properties.enabled) return;

depthMask(false);
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/painter_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons

const std::unordered_map<std::string, TextProperties> &text_properties = map.getStyle().computed.texts;
const std::unordered_map<std::string, TextProperties>::const_iterator text_properties_it = text_properties.find(layer_name);
if (text_properties_it == text_properties.end()) return;

const TextProperties& properties = text_properties_it->second;
const TextProperties &properties = text_properties_it != text_properties.end()
? text_properties_it->second
: defaultTextProperties;
if (!properties.enabled) return;

mat4 exMatrix;
Expand Down

0 comments on commit 461a19d

Please sign in to comment.