change line width and add line-width test

This commit is contained in:
Konstantin Käfer
2014-07-10 14:54:43 -07:00
parent a8963fcbe4
commit a8e71bcb7b
12 changed files with 73 additions and 21 deletions

View File

@@ -8,7 +8,6 @@ module.exports = {
"mapbox": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5",
"tileSize": 512,
"maxZoom": 14
}
},

View File

@@ -92,7 +92,7 @@ float TransformState::getPixelRatio() const {
#pragma mark - Zoom
float TransformState::getNormalizedZoom() const {
return std::log(scale * util::tileSize / 256.0f) / M_LN2;
return std::log(scale * util::tileSize / 512.0f) / M_LN2;
}
int32_t TransformState::getIntegerZoom() const {

View File

@@ -250,11 +250,6 @@ void StyleLayer::updateProperties(float z, const timestamp now) {
layers->updateProperties(z, now);
}
// Accomodate for different tile size.
if (bucket && bucket->source) {
z += std::log(bucket->source->tile_size / 256.0f) / M_LN2;
}
cleanupAppliedStyleProperties(now);
switch (type) {

View File

@@ -170,7 +170,9 @@ void StyleParser::parseSources(JSVal value) {
parseRenderProperty(itr->value, type, "type", parseSourceType);
parseRenderProperty(itr->value, url, "url");
parseRenderProperty(itr->value, tile_size, "tileSize");
if (type == SourceType::Raster) {
parseRenderProperty(itr->value, tile_size, "tileSize");
}
parseRenderProperty(itr->value, min_zoom, "minZoom");
parseRenderProperty(itr->value, max_zoom, "maxZoom");

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

View File

@@ -0,0 +1,8 @@
{
"zoom": 14,
"latitude": 52.499167,
"longitude": 13.418056,
"angle": 0,
"width": 512,
"height": 512
}

View File

@@ -0,0 +1,32 @@
{
"version": 3,
"sources": {
"mapbox": {
"type": "vector",
"url": "tiles/{z}-{x}-{y}.vector.pbf",
"tileSize": 512,
"maxZoom": 14
}
},
"layers": [
{
"id": "background",
"type": "background",
"style": {
"background-color": "white"
}
},
{
"id": "road",
"source": "mapbox",
"source-layer": "road",
"type": "line",
"style": {
"line-width": {
"fn": "stops",
"stops": [[13, 0], [13.999, 0], [14, 4], [14.1, 100]]
}
}
}
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -9,21 +9,23 @@
#include "../common/headless_view.hpp"
#include <dirent.h>
const std::string base_directory = []{
std::string fn = __FILE__;
fn.erase(fn.find_last_of("/"));
return fn;
return fn + "/fixtures/styles";
}();
class HeadlessTest : public ::testing::TestWithParam<const char *> {};
class HeadlessTest : public ::testing::TestWithParam<std::string> {};
TEST_P(HeadlessTest, render) {
const char *base = GetParam();
const std::string &base = GetParam();
const std::string style = llmr::util::read_file(base_directory + "/fixtures/styles/" + base + ".style.json");
const std::string info = llmr::util::read_file(base_directory + "/fixtures/styles/" + base + ".info.json");
const std::string expected_image = base_directory + "/fixtures/styles/" + base + ".expected.png";
const std::string actual_image = base_directory + "/fixtures/styles/" + base + ".actual.png";
const std::string style = llmr::util::read_file(base_directory + "/" + base + ".style.json");
const std::string info = llmr::util::read_file(base_directory + "/" + base + ".info.json");
const std::string expected_image = base_directory + "/" + base + ".expected.png";
const std::string actual_image = base_directory + "/" + base + ".actual.png";
// Parse settings.
rapidjson::Document doc;
@@ -58,12 +60,26 @@ TEST_P(HeadlessTest, render) {
const std::string image = llmr::util::compress_png(width, height, pixels.get(), true);
llmr::util::write_file(actual_image, image);
const std::string expected_image_data(llmr::util::read_file(expected_image));
const llmr::util::Image expected(expected_image_data, true);
ASSERT_EQ(width, expected.getWidth());
ASSERT_EQ(height, expected.getHeight());
}
INSTANTIATE_TEST_CASE_P(Headless, HeadlessTest,
::testing::Values("0", "1"));
::testing::ValuesIn([]{
std::vector<std::string> names;
const std::string ending = ".info.json";
DIR *dir = opendir(base_directory.c_str());
if (dir == nullptr) return names;
for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) {
const std::string name = dp->d_name;
if (name.length() >= ending.length() && name.compare(name.length() - ending.length(), ending.length(), ending) == 0) {
names.push_back(name.substr(0, name.length() - ending.length()));
}
}
closedir(dir);
return names;
}()));