replace {{token}} with {token}, and %d/%d/%d with {z}/{x}/{y}

refs https://github.com/mapbox/mapbox-gl-style-spec/pull/87
This commit is contained in:
Konstantin Käfer
2014-07-09 16:27:23 -07:00
parent f2ee02d3ca
commit 22c8afced5
7 changed files with 59 additions and 59 deletions

View File

@@ -3,7 +3,7 @@
module.exports = {
"version": 3,
"sprite": "https://www.mapbox.com/mapbox-gl-styles/sprites/outdoors",
"glyphs": "https://mapbox.s3.amazonaws.com/gl-glyphs-256/{{fontstack}}/{{range}}.pbf",
"glyphs": "https://mapbox.s3.amazonaws.com/gl-glyphs-256/{fontstack}/{range}.pbf",
"sources": {
"mapbox": {
"type": "vector",
@@ -1739,7 +1739,7 @@ module.exports = {
"filter": { "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
"text-max-size": 24,
@@ -1764,7 +1764,7 @@ module.exports = {
"filter": { "$type": "line", "labelrank": 1 },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 30,
@@ -1794,7 +1794,7 @@ module.exports = {
"filter": { "$type": "line", "labelrank": 2 },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 24,
@@ -1823,7 +1823,7 @@ module.exports = {
"filter": { "$type": "line", "labelrank": 3 },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 18,
@@ -1852,7 +1852,7 @@ module.exports = {
"filter": { "$type": "line", "labelrank": [4, 5, 6] },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 16,
@@ -1881,7 +1881,7 @@ module.exports = {
"filter": { "$type": "point", "labelrank": 1 },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 30,
@@ -1912,7 +1912,7 @@ module.exports = {
"filter": { "$type": "point", "labelrank": 2 },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 24,
@@ -1943,7 +1943,7 @@ module.exports = {
"filter": { "$type": "point", "labelrank": 3 },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 18,
@@ -1974,7 +1974,7 @@ module.exports = {
"filter": { "$type": "point", "labelrank": [4, 5, 6] },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 16,
@@ -2005,7 +2005,7 @@ module.exports = {
"filter": { "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Regular, Arial Unicode MS Regular",
"text-max-size": 16,
@@ -2036,7 +2036,7 @@ module.exports = {
"filter": { "type": "city", "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
"text-max-size": 20,
@@ -2067,7 +2067,7 @@ module.exports = {
"filter": { "type": "town", "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
"text-max-size": 24,
@@ -2098,7 +2098,7 @@ module.exports = {
"filter": { "type": "village", "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
"text-max-size": 22,
@@ -2129,7 +2129,7 @@ module.exports = {
"filter": { "type": ["hamlet", "suburb", "neighbourhood"], "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
"text-max-size": 18,
@@ -2159,7 +2159,7 @@ module.exports = {
"filter": { "class": ["motorway", "main"], "$type": "line" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-padding": 2,
"text-font": "Open Sans Regular, Arial Unicode MS Regular",
@@ -2185,7 +2185,7 @@ module.exports = {
"filter": { "class": ["street", "street_limited"], "$type": "line" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-padding": 2,
"text-font": "Open Sans Regular, Arial Unicode MS Regular",
@@ -2211,7 +2211,7 @@ module.exports = {
"filter": { "class": ["service", "driveway", "path"], "$type": "line" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-padding": 2,
"text-font": "Open Sans Regular, Arial Unicode MS Regular",
@@ -2238,7 +2238,7 @@ module.exports = {
"render": {
"type": "text",
"text-path": "curve",
"text-field": "{{ele}} m",
"text-field": "{ele} m",
"text-font": "Open Sans Regular, Arial Unicode MS Regular",
"text-max-size": 10,
"text-max-angle": 0.5
@@ -2262,7 +2262,7 @@ module.exports = {
"filter": { "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 12,
@@ -2283,7 +2283,7 @@ module.exports = {
"filter": { "$type": "line" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "curve",
"text-font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"text-max-size": 12,
@@ -2305,7 +2305,7 @@ module.exports = {
"filter": { "scalerank": [1, 2] },
"render": {
"type": "icon",
"icon-image": "{{maki}}-12",
"icon-image": "{maki}-12",
"icon-size": 12
},
"style.night": {}
@@ -2316,7 +2316,7 @@ module.exports = {
"filter": { "scalerank": [1, 2], "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-padding": 2,
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
@@ -2343,7 +2343,7 @@ module.exports = {
"filter": { "scalerank": 3 },
"render": {
"type": "icon",
"icon-image": "{{maki}}-12",
"icon-image": "{maki}-12",
"icon-size": 12
},
"style": {
@@ -2365,7 +2365,7 @@ module.exports = {
"filter": { "scalerank": 3, "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-padding": 2,
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
@@ -2400,7 +2400,7 @@ module.exports = {
"filter": { "scalerank": 4 },
"render": {
"type": "icon",
"icon-image": "{{maki}}-12",
"icon-image": "{maki}-12",
"icon-size": 12
},
"style": {
@@ -2422,7 +2422,7 @@ module.exports = {
"filter": { "scalerank": 4, "$type": "point" },
"render": {
"type": "text",
"text-field": "{{name_en}}",
"text-field": "{name_en}",
"text-path": "horizontal",
"text-padding": 2,
"text-font": "Open Sans Semibold, Arial Unicode MS Bold",
@@ -2457,7 +2457,7 @@ module.exports = {
"filter": { "maki": "airport" },
"render": {
"type": "icon",
"icon-image": "{{maki}}-12",
"icon-image": "{maki}-12",
"icon-size": 12
},
"style": {

View File

@@ -10,12 +10,6 @@ typedef util::variant<bool, int64_t, uint64_t, double, std::string> Value;
std::string toString(const Value &value);
inline std::string& operator+=(std::string& out, const Value& value) {
out += toString(value);
return out;
}
Value parseValue(pbf data);
namespace util {

View File

@@ -9,40 +9,43 @@ namespace regex_impl = boost;
namespace regex_impl = std;
#endif
#include <map>
namespace llmr {
namespace util {
namespace detail {
const regex_impl::regex tokenRegex("\\{\\{(\\w+)\\}\\}");
const regex_impl::regex tokenRegex("\\{(\\w+)\\}");
const regex_impl::sregex_token_iterator tokensEnd = regex_impl::sregex_token_iterator();
}
template <typename Tokens>
std::string replaceTokens(const std::string &source, const Tokens &tokens) {
template <typename Lookup>
std::string replaceTokens(const std::string &source, const Lookup &lookup) {
std::string result;
result.reserve(source.size());
bool token = false;
for (auto token_it = regex_impl::sregex_token_iterator(source.begin(), source.end(),
detail::tokenRegex, {-1, 1});
token_it != detail::tokensEnd; ++token_it, token = !token) {
token_it != detail::tokensEnd; ++token_it, token = !token) {
if (!token_it->matched) {
continue;
}
if (token) {
const auto it_prop = tokens.find(token_it->str());
if (it_prop != tokens.end()) {
result += it_prop->second;
}
} else {
result += token_it->str();
}
result += token ? lookup(token_it->str()) : token_it->str();
}
return result;
}
template <typename T>
inline std::string replaceTokens(const std::string &source, const std::map<std::string, T> &properties) {
return replaceTokens(source, [&properties](const std::string &token) -> std::string {
const auto it_prop = properties.find(token);
return it_prop != properties.end() ? toString(it_prop->second) : "";
});
}
} // end namespace util
} // end namespace llmr

View File

@@ -7,6 +7,7 @@
#include <llmr/util/string.hpp>
#include <llmr/util/texturepool.hpp>
#include <llmr/util/vec.hpp>
#include <llmr/util/token.hpp>
#include <llmr/util/std.hpp>
#include <llmr/geometry/glyph_atlas.hpp>
#include <llmr/style/style_layer.hpp>
@@ -28,7 +29,7 @@ Source::Source(SourceType type, const std::string &url,
std::string Source::normalizeSourceURL(const std::string &url) {
const std::string t = "mapbox://";
if (url.compare(0, t.length(), t) == 0) {
return std::string("http://api.tiles.mapbox.com/v3/") + url.substr(t.length()) + "/%d/%d/%d.vector.pbf";
return std::string("http://api.tiles.mapbox.com/v3/") + url.substr(t.length()) + "/{z}/{x}/{y}.vector.pbf";
} else {
return url;
}
@@ -142,14 +143,17 @@ TileData::State Source::addTile(Map &map, const Tile::ID& id) {
if (!new_tile.data) {
// If we don't find working tile data, we're just going to load it.
std::string formed_url;
const std::string formed_url = util::replaceTokens(url, [&](const std::string &token) -> std::string {
if (token == "z") return std::to_string(normalized_id.z);
if (token == "x") return std::to_string(normalized_id.x);
if (token == "y") return std::to_string(normalized_id.y);
if (token == "ratio") return (map.getState().getPixelRatio() > 1.0 ? "@2x" : "");
return "";
});
if (type == SourceType::Vector) {
formed_url = util::sprintf<256>(url, normalized_id.z, normalized_id.x, normalized_id.y);
new_tile.data = std::make_shared<VectorTileData>(normalized_id, map, formed_url);
} else if (type == SourceType::Raster) {
formed_url = util::sprintf<256>(url, normalized_id.z, normalized_id.x, normalized_id.y, (map.getState().getPixelRatio() > 1.0 ? "@2x" : ""));
new_tile.data = std::make_shared<RasterTileData>(normalized_id, map, formed_url);
} else {
throw std::runtime_error("source type not implemented");

View File

@@ -120,12 +120,11 @@ GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, Gl
: future(promise.get_future().share())
{
// Load the glyph set URL
const std::map<std::string, std::string> tokens {{
{ "fontstack", fontStack },
{ "range", std::to_string(glyphRange.first) + "-" + std::to_string(glyphRange.second) }
}};
std::string url = util::replaceTokens(glyphURL, tokens);
std::string url = util::replaceTokens(glyphURL, [&](const std::string &name) -> std::string {
if (name == "fontstack") return fontStack;
if (name == "range") return std::to_string(glyphRange.first) + "-" + std::to_string(glyphRange.second);
return "";
});
// TODO: Find more reliable URL normalization function
std::replace(url.begin(), url.end(), ' ', '+');

View File

@@ -3,7 +3,7 @@
"sources": {
"mapbox": {
"type": "vector",
"url": "tiles/%d-%d-%d.vector.pbf",
"url": "tiles/{z}-{x}-{y}.vector.pbf",
"tileSize": 512,
"maxZoom": 14
}

View File

@@ -3,7 +3,7 @@
"sources": {
"mapbox": {
"type": "vector",
"url": "tiles/%d-%d-%d.vector.pbf",
"url": "tiles/{z}-{x}-{y}.vector.pbf",
"tileSize": 512,
"maxZoom": 14
}