Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use arrays for center and bounds in tilejson #57

Merged
merged 2 commits into from
Dec 11, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/tilejson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ std::string make_tilejson(const mapnik::Map &map,

for (auto const &row : params) {
out << "\"" << row.first << "\":";
mapnik::util::apply_visitor(json_converter(out), row.second);
if (row.first == "center" || row.first == "bounds") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better if there were a static const std::unordered_set<std::string> array_keys declared above and the test were:

if (array_keys.count(row.first) > 0) { ... }

out << "[" << row.second << "]";
} else {
mapnik::util::apply_visitor(json_converter(out), row.second);
}
out << ",";
}

Expand Down
16 changes: 16 additions & 0 deletions test/tilejson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ void test_tilejson_generate_numeric() {
}
}

// Some params need to be arrays of integers
for (auto &param : {"center", "bounds"}) {
// The same check as above for presense
sregex is_present = as_xpr('"') >> param >> '"' >> *space >> as_xpr(':');
if (regex_search(json.begin(), json.end(), is_present)) {
sregex is_array = as_xpr('"') >> param >> '"' >> *space >> as_xpr(':')
>> *space >> as_xpr('[');

if (!regex_search(json.begin(), json.end(), is_array)) {
throw std::runtime_error(
(boost::format("Parameter \"%1%\" should be an array of numbers, but is not "
"in TileJSON: %2%") % param % json).str());
}
}
}

} catch (const std::exception &e) {
std::throw_with_nested(
std::runtime_error(
Expand Down
3 changes: 2 additions & 1 deletion test/tilejson_params.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over">
<Parameters>
<Parameter name="metatile">1</Parameter>
<Parameter name="center">-75.6038,40.0799,11</Parameter>
<Parameter name="center">-75,40,11</Parameter>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any significance to making the center values all integers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - just a shorter output in the tests

<Parameter name="bounds">-180,-85,180,85</Parameter>
<Parameter name="maxzoom">16</Parameter>
<Parameter name="minzoom">0</Parameter>
<Parameter name="name"><![CDATA[MQ Carto Vector]]></Parameter>
Expand Down