Merge branch 'master' into linux-wrapper
Conflicts: include/llmr/style/sprite.hpp
This commit is contained in:
@@ -47,7 +47,7 @@ const unsigned char resources::style[] = {
|
||||
12, 114, 111, 97, 100, 95, 114, 101, 103, 117, 108, 97, 114, 18, 24, 10,
|
||||
10, 114, 111, 97, 100, 95, 108, 97, 114, 103, 101, 18, 10, 114, 111, 97,
|
||||
100, 95, 108, 97, 114, 103, 101, 18, 18, 10, 7, 97, 108, 99, 111, 104,
|
||||
111, 108, 18, 7, 97, 108, 99, 111, 104, 111, 108, 26, 220, 2, 10, 7,
|
||||
111, 108, 18, 7, 97, 108, 99, 111, 104, 111, 108, 26, 132, 3, 10, 7,
|
||||
100, 101, 102, 97, 117, 108, 116, 18, 27, 10, 4, 112, 97, 114, 107, 34,
|
||||
8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 159, 223, 200, 66, 4,
|
||||
112, 97, 114, 107, 18, 31, 10, 4, 119, 111, 111, 100, 34, 8, 8, 2,
|
||||
@@ -69,6 +69,9 @@ const unsigned char resources::style[] = {
|
||||
255, 102, 102, 102, 34, 52, 8, 3, 18, 48, 0, 0, 0, 0, 0, 0,
|
||||
0, 63, 0, 0, 48, 65, 0, 0, 0, 63, 0, 0, 80, 65, 0, 0,
|
||||
128, 63, 0, 0, 128, 65, 0, 0, 128, 64, 0, 0, 160, 65, 0, 0,
|
||||
128, 66, 0, 0, 240, 65, 0, 0, 128, 66
|
||||
128, 66, 0, 0, 240, 65, 0, 0, 128, 66, 34, 38, 10, 7, 97, 108,
|
||||
99, 111, 104, 111, 108, 29, 255, 153, 153, 153, 34, 8, 8, 2, 18, 4,
|
||||
0, 0, 192, 65, 66, 12, 97, 108, 99, 111, 104, 111, 108, 45, 115, 104,
|
||||
111, 112
|
||||
};
|
||||
const unsigned long resources::style_size = sizeof(resources::style);
|
||||
|
||||
@@ -34,19 +34,21 @@ Sprite::operator bool() const {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
void Sprite::load(const std::string& base_url) {
|
||||
void Sprite::load(const std::string& base_url, float pixelRatio) {
|
||||
std::shared_ptr<Sprite> sprite = shared_from_this();
|
||||
|
||||
auto complete = [sprite]() {
|
||||
std::lock_guard<std::mutex> lock(sprite->mtx);
|
||||
if (sprite->img && sprite->pos.size()) {
|
||||
sprite->loaded = true;
|
||||
platform::restart(NULL);
|
||||
platform::restart();
|
||||
fprintf(stderr, "sprite loaded\n");
|
||||
}
|
||||
};
|
||||
|
||||
platform::request_http(base_url + ".json", [sprite](const platform::Response & res) {
|
||||
std::string suffix = (pixelRatio > 1 ? "@2x" : "");
|
||||
|
||||
platform::request_http(base_url + suffix + ".json", [sprite](const platform::Response & res) {
|
||||
if (res.code == 200) {
|
||||
sprite->parseJSON(res.body);
|
||||
} else {
|
||||
@@ -54,7 +56,7 @@ void Sprite::load(const std::string& base_url) {
|
||||
}
|
||||
}, complete);
|
||||
|
||||
platform::request_http(base_url + ".png", [sprite](const platform::Response & res) {
|
||||
platform::request_http(base_url + suffix + ".png", [sprite](const platform::Response & res) {
|
||||
if (res.code == 200) {
|
||||
sprite->loadImage(res.body);
|
||||
} else {
|
||||
@@ -242,11 +244,13 @@ void Sprite::bind(bool linear) {
|
||||
|
||||
if (!texture) {
|
||||
glGenTextures(1, &texture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ Style::Style() {
|
||||
void Style::reset() {
|
||||
computed.fills.clear();
|
||||
computed.lines.clear();
|
||||
computed.points.clear();
|
||||
}
|
||||
|
||||
void Style::load(const uint8_t *const data, uint32_t bytes) {
|
||||
@@ -89,10 +90,12 @@ std::pair<std::string, ClassDescription> Style::parseClass(pbf data) {
|
||||
while (data.next()) {
|
||||
if (data.tag == 1) { // name
|
||||
name = data.string();
|
||||
} else if (data.tag == 2) { // fill_style
|
||||
} else if (data.tag == 2) { // fill style
|
||||
klass.fill.insert(parseFillClass(data.message()));
|
||||
} else if (data.tag == 3) { // stroke_style
|
||||
} else if (data.tag == 3) { // line style
|
||||
klass.line.insert(parseLineClass(data.message()));
|
||||
} else if (data.tag == 4) { // point style
|
||||
klass.point.insert(parsePointClass(data.message()));
|
||||
} else {
|
||||
data.skip();
|
||||
}
|
||||
@@ -159,6 +162,30 @@ std::pair<std::string, LineClass> Style::parseLineClass(pbf data) {
|
||||
return { name, stroke };
|
||||
}
|
||||
|
||||
std::pair<std::string, PointClass> Style::parsePointClass(pbf data) {
|
||||
PointClass point;
|
||||
std::string name;
|
||||
|
||||
while (data.next()) {
|
||||
if (data.tag == 1) { // name
|
||||
name = data.string();
|
||||
} else if (data.tag == 2) { // hidden
|
||||
point.hidden = parseProperty<bool>(data.message());
|
||||
} else if (data.tag == 3) { // color
|
||||
point.color = parseColor(data);
|
||||
} else if (data.tag == 4) { // size
|
||||
point.size = parseProperty<float>(data.message());
|
||||
} else if (data.tag == 6) { // opacity
|
||||
point.opacity = parseProperty<float>(data.message());
|
||||
} else if (data.tag == 8) { // image
|
||||
point.image = data.string();
|
||||
} else {
|
||||
data.skip();
|
||||
}
|
||||
}
|
||||
|
||||
return { name, point };
|
||||
}
|
||||
|
||||
Color Style::parseColor(pbf& data) {
|
||||
uint32_t rgba = data.fixed<uint32_t, 4>();
|
||||
@@ -240,6 +267,21 @@ void Style::cascade(float z) {
|
||||
stroke.color = layer.color;
|
||||
stroke.opacity = layer.opacity(z);
|
||||
}
|
||||
|
||||
// Cascade point classes
|
||||
for (const auto& point_pair : sheetClass.point) {
|
||||
const std::string& layer_name = point_pair.first;
|
||||
const llmr::PointClass& layer = point_pair.second;
|
||||
|
||||
// TODO: This should be restricted to point styles that have actual
|
||||
// values so as to not override with default values.
|
||||
llmr::PointProperties& point = computed.points[layer_name];
|
||||
point.hidden = layer.hidden(z);
|
||||
point.color = layer.color;
|
||||
point.size = layer.size(z);
|
||||
point.opacity = layer.opacity(z);
|
||||
point.image = layer.image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user