cascade styles

This commit is contained in:
Konstantin Käfer
2014-01-27 17:21:48 +01:00
parent e2dbcc95b5
commit 1538ebaf22
16 changed files with 408 additions and 113 deletions

View File

@@ -39,7 +39,7 @@ public:
// Getters
void matrixFor(float matrix[16], const vec3<int32_t>& id) const;
int32_t getZoom() const;
float getZoom() const;
double getScale() const;
double getAngle() const;
void getLonLat(double& lon, double& lat) const;

View File

@@ -8,25 +8,13 @@
namespace llmr {
class WidthDescription {
class ClassDescription {
public:
std::string scaling;
std::vector<float> value;
std::map<std::string, FillClass> fill;
std::map<std::string, StrokeClass> stroke;
};
class LayerStyleDescription {
public:
Color color = {{ 0, 0, 0, 0 }};
bool antialias = false;
WidthDescription width;
};
typedef std::map<std::string, LayerStyleDescription> ClassDescription;
std::ostream& operator<<(std::ostream&, const ClassDescription& layer);
}
#endif

View File

@@ -2,12 +2,13 @@
#define LLMR_STYLE_PROPERTIES
#include <array>
#include <vector>
namespace llmr {
typedef std::array<float, 4> Color;
enum Winding {
enum class Winding {
EvenOdd = 1,
NonZero = 2
};
@@ -22,19 +23,71 @@ enum Winding {
// };
enum class Property {
Null = 1,
Constant = 2,
Stops = 3
};
namespace functions {
float null(float z, const std::vector<float>&);
bool null(float z, const std::vector<bool>&);
float constant(float z, const std::vector<float>& values);
bool constant(float z, const std::vector<bool>& values);
}
template <typename T>
struct FunctionProperty {
typedef T (*fn)(float z, const std::vector<T>& values);
fn function;
std::vector<T> values;
inline FunctionProperty() : function(&functions::null) {}
inline FunctionProperty(T value) : function(&functions::constant), values(1, value) {}
inline T operator()(float z) const { return function(z, values); }
};
// StrokeClass is the information we parse from the stylesheet
struct StrokeClass {
FunctionProperty<bool> hidden;
FunctionProperty<float> width;
FunctionProperty<float> offset;
Color color = {{ 0, 0, 0, 1 }};
};
// StrokeProperties is the one we resolve this to.
struct StrokeProperties {
bool enabled = false;
Color line_color = {{ 0, 0, 0, 1 }};
float line_width = 1;
bool hidden = false;
float width = 0;
float offset = 0;
Color color = {{ 0, 0, 0, 1 }};
};
struct FillClass {
FunctionProperty<bool> hidden;
Winding winding = Winding::NonZero;
FunctionProperty<bool> antialias = true;
Color fill_color = {{ 0, 0, 0, 1 }};
Color stroke_color = {{ 0, 0, 0, std::numeric_limits<float>::infinity() }};
FunctionProperty<float> opacity = 1;
};
struct FillProperties {
bool enabled = false;
Winding winding = NonZero;
bool antialiasing = true;
bool hidden = false;
Winding winding = Winding::NonZero;
bool antialias = true;
Color fill_color = {{ 0, 0, 0, 1 }};
Color stroke_color = {{ 0, 0, 0, 1 }};
float stroke_width = 1;
float opacity = 1.0;
};
}

View File

@@ -21,14 +21,16 @@ public:
void reset();
void load(const uint8_t *const data, uint32_t bytes);
void cascade();
void cascade(float z);
private:
static std::pair<std::string, BucketDescription> loadBucket(pbf data);
static LayerDescription loadLayer(pbf data);
static std::pair<std::string, ClassDescription> loadClass(pbf data);
static std::pair<std::string, LayerStyleDescription> loadLayerStyle(pbf data);
static WidthDescription loadWidth(pbf data);
static std::pair<std::string, BucketDescription> parseBucket(pbf data);
static LayerDescription parseLayer(pbf data);
static std::pair<std::string, ClassDescription> parseClass(pbf data);
static std::pair<std::string, FillClass> parseFillClass(pbf data);
static std::pair<std::string, StrokeClass> parseStrokeClass(pbf data);
template <typename T> static FunctionProperty<T> parseProperty(pbf data);
static Color parseColor(pbf& data);
public:
// This is static information parsed from the stylesheet.