summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/style.json102
-rw-r--r--include/llmr/style/filter_expression.hpp2
-rw-r--r--include/llmr/style/value.hpp6
-rw-r--r--include/llmr/util/token.hpp27
-rw-r--r--src/map/source.cpp14
-rw-r--r--src/map/vector_tile.cpp2
-rw-r--r--src/style/filter_expression.cpp14
-rw-r--r--src/text/glyph_store.cpp11
-rw-r--r--test/fixtures/styles/0.style.json2
-rw-r--r--test/fixtures/styles/1.style.json2
10 files changed, 91 insertions, 91 deletions
diff --git a/bin/style.json b/bin/style.json
index 4044e45626..a26a37f2fa 100755
--- a/bin/style.json
+++ b/bin/style.json
@@ -1,7 +1,7 @@
{
"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",
@@ -1734,10 +1734,10 @@
"id": "country_label",
"source": "mapbox",
"source-layer": "country_label",
- "filter": { "$type": "point" },
+ "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,
@@ -1759,10 +1759,10 @@
"id": "marine_label_line_1",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "line", "labelrank": 1 },
+ "filter": { "$type": "LineString", "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,
@@ -1789,10 +1789,10 @@
"id": "marine_label_line_2",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "line", "labelrank": 2 },
+ "filter": { "$type": "LineString", "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,
@@ -1818,10 +1818,10 @@
"id": "marine_label_line_3",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "line", "labelrank": 3 },
+ "filter": { "$type": "LineString", "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,
@@ -1847,10 +1847,10 @@
"id": "marine_label_line_other",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "line", "labelrank": [4, 5, 6] },
+ "filter": { "$type": "LineString", "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,
@@ -1876,10 +1876,10 @@
"id": "marine_label_point_1",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "point", "labelrank": 1 },
+ "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,
@@ -1907,10 +1907,10 @@
"id": "marine_label_point_2",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "point", "labelrank": 2 },
+ "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,
@@ -1938,10 +1938,10 @@
"id": "marine_label_point_3",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "point", "labelrank": 3 },
+ "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,
@@ -1969,10 +1969,10 @@
"id": "marine_label_point_other",
"source": "mapbox",
"source-layer": "marine_label",
- "filter": { "$type": "point", "labelrank": [4, 5, 6] },
+ "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,
@@ -2000,10 +2000,10 @@
"id": "state_label",
"source": "mapbox",
"source-layer": "state_label",
- "filter": { "$type": "point" },
+ "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,
@@ -2031,10 +2031,10 @@
"id": "place_label_city",
"source": "mapbox",
"source-layer": "place_label",
- "filter": { "type": "city", "$type": "point" },
+ "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,
@@ -2062,10 +2062,10 @@
"id": "place_label_town",
"source": "mapbox",
"source-layer": "place_label",
- "filter": { "type": "town", "$type": "point" },
+ "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,
@@ -2093,10 +2093,10 @@
"id": "place_label_village",
"source": "mapbox",
"source-layer": "place_label",
- "filter": { "type": "village", "$type": "point" },
+ "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,
@@ -2124,10 +2124,10 @@
"id": "place_label_other",
"source": "mapbox",
"source-layer": "place_label",
- "filter": { "type": ["hamlet", "suburb", "neighbourhood"], "$type": "point" },
+ "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,
@@ -2154,10 +2154,10 @@
"id": "road_label_1",
"source": "mapbox",
"source-layer": "road_label",
- "filter": { "class": ["motorway", "main"], "$type": "line" },
+ "filter": { "class": ["motorway", "main"], "$type": "LineString" },
"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",
@@ -2180,10 +2180,10 @@
"id": "road_label_2",
"source": "mapbox",
"source-layer": "road_label",
- "filter": { "class": ["street", "street_limited"], "$type": "line" },
+ "filter": { "class": ["street", "street_limited"], "$type": "LineString" },
"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",
@@ -2206,10 +2206,10 @@
"id": "road_label_3",
"source": "mapbox",
"source-layer": "road_label",
- "filter": { "class": ["service", "driveway", "path"], "$type": "line" },
+ "filter": { "class": ["service", "driveway", "path"], "$type": "LineString" },
"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",
@@ -2232,11 +2232,11 @@
"id": "contour_label",
"source": "mapbox",
"source-layer": "contour",
- "filter": { "index": [5, 10], "$type": "line" },
+ "filter": { "index": [5, 10], "$type": "LineString" },
"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
@@ -2257,10 +2257,10 @@
"id": "water_label",
"source": "mapbox",
"source-layer": "water_label",
- "filter": { "$type": "point" },
+ "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,
@@ -2278,10 +2278,10 @@
"id": "waterway_label",
"source": "mapbox",
"source-layer": "waterway_label",
- "filter": { "$type": "line" },
+ "filter": { "$type": "LineString" },
"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,
@@ -2303,7 +2303,7 @@
"filter": { "scalerank": [1, 2] },
"render": {
"type": "icon",
- "icon-image": "{{maki}}-12",
+ "icon-image": "{maki}-12",
"icon-size": 12
},
"style.night": {}
@@ -2311,10 +2311,10 @@
"id": "poi_label_1-2",
"source": "mapbox",
"source-layer": "poi_label",
- "filter": { "scalerank": [1, 2], "$type": "point" },
+ "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",
@@ -2341,7 +2341,7 @@
"filter": { "scalerank": 3 },
"render": {
"type": "icon",
- "icon-image": "{{maki}}-12",
+ "icon-image": "{maki}-12",
"icon-size": 12
},
"style": {
@@ -2360,10 +2360,10 @@
"id": "poi_label_3",
"source": "mapbox",
"source-layer": "poi_label",
- "filter": { "scalerank": 3, "$type": "point" },
+ "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",
@@ -2398,7 +2398,7 @@
"filter": { "scalerank": 4 },
"render": {
"type": "icon",
- "icon-image": "{{maki}}-12",
+ "icon-image": "{maki}-12",
"icon-size": 12
},
"style": {
@@ -2417,10 +2417,10 @@
"id": "poi_label_4",
"source": "mapbox",
"source-layer": "poi_label",
- "filter": { "scalerank": 4, "$type": "point" },
+ "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",
@@ -2455,7 +2455,7 @@
"filter": { "maki": "airport" },
"render": {
"type": "icon",
- "icon-image": "{{maki}}-12",
+ "icon-image": "{maki}-12",
"icon-size": 12
},
"style": {
diff --git a/include/llmr/style/filter_expression.hpp b/include/llmr/style/filter_expression.hpp
index 696aa04aeb..5c7a400d80 100644
--- a/include/llmr/style/filter_expression.hpp
+++ b/include/llmr/style/filter_expression.hpp
@@ -85,7 +85,7 @@ public:
enum class GeometryType : uint8_t {
Any,
Point,
- Line,
+ LineString,
Polygon
};
diff --git a/include/llmr/style/value.hpp b/include/llmr/style/value.hpp
index bdcba4cad3..fac316d3d5 100644
--- a/include/llmr/style/value.hpp
+++ b/include/llmr/style/value.hpp
@@ -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 {
diff --git a/include/llmr/util/token.hpp b/include/llmr/util/token.hpp
index db5b5fa0c3..6795b97d12 100644
--- a/include/llmr/util/token.hpp
+++ b/include/llmr/util/token.hpp
@@ -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
diff --git a/src/map/source.cpp b/src/map/source.cpp
index c3c5e89fd4..8d1593f76c 100644
--- a/src/map/source.cpp
+++ b/src/map/source.cpp
@@ -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");
diff --git a/src/map/vector_tile.cpp b/src/map/vector_tile.cpp
index fb42726681..a32db7fb35 100644
--- a/src/map/vector_tile.cpp
+++ b/src/map/vector_tile.cpp
@@ -272,7 +272,7 @@ void FilteredVectorTileLayer::iterator::operator++() {
} else if (feature_pbf.tag == 3) { // geometry type
switch (FeatureType(feature_pbf.varint())) {
case FeatureType::Point: extractor.setType(FilterExpression::GeometryType::Point); break;
- case FeatureType::LineString: extractor.setType(FilterExpression::GeometryType::Line); break;
+ case FeatureType::LineString: extractor.setType(FilterExpression::GeometryType::LineString); break;
case FeatureType::Polygon: extractor.setType(FilterExpression::GeometryType::Polygon); break;
default: break;
}
diff --git a/src/style/filter_expression.cpp b/src/style/filter_expression.cpp
index 1a85b742e5..58483accac 100644
--- a/src/style/filter_expression.cpp
+++ b/src/style/filter_expression.cpp
@@ -175,10 +175,10 @@ std::ostream& operator <<(std::ostream &s, FilterExpression::Operator op) {
std::ostream& operator <<(std::ostream &s, FilterExpression::GeometryType type) {
switch (type) {
- case FilterExpression::GeometryType::Point: s << "point"; break;
- case FilterExpression::GeometryType::Line: s << "line"; break;
- case FilterExpression::GeometryType::Polygon: s << "polygon"; break;
- case FilterExpression::GeometryType::Any: s << "any"; break;
+ case FilterExpression::GeometryType::Point: s << "Point"; break;
+ case FilterExpression::GeometryType::LineString: s << "LineString"; break;
+ case FilterExpression::GeometryType::Polygon: s << "Polygon"; break;
+ case FilterExpression::GeometryType::Any: s << "<Any>"; break;
}
return s;
}
@@ -265,9 +265,9 @@ void FilterExpression::setGeometryType(GeometryType g) {
}
FilterExpression::GeometryType parseGeometryType(const std::string &geometry) {
- if (geometry == "point") return FilterExpression::GeometryType::Point;
- if (geometry == "line") return FilterExpression::GeometryType::Line;
- if (geometry == "polygon") return FilterExpression::GeometryType::Polygon;
+ if (geometry == "Point") return FilterExpression::GeometryType::Point;
+ if (geometry == "LineString") return FilterExpression::GeometryType::LineString;
+ if (geometry == "Polygon") return FilterExpression::GeometryType::Polygon;
return FilterExpression::GeometryType::Any;
}
diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp
index b79010670d..f83d810899 100644
--- a/src/text/glyph_store.cpp
+++ b/src/text/glyph_store.cpp
@@ -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(), ' ', '+');
diff --git a/test/fixtures/styles/0.style.json b/test/fixtures/styles/0.style.json
index 06d7a1db1a..d5994b82cc 100644
--- a/test/fixtures/styles/0.style.json
+++ b/test/fixtures/styles/0.style.json
@@ -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
}
diff --git a/test/fixtures/styles/1.style.json b/test/fixtures/styles/1.style.json
index d35c4bc0f4..0d0286b277 100644
--- a/test/fixtures/styles/1.style.json
+++ b/test/fixtures/styles/1.style.json
@@ -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
}