Merge branch 'master' of github.com:mapbox/llmr-native
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,6 +6,7 @@
|
||||
/ios/build
|
||||
/config.gypi
|
||||
/config.mk
|
||||
/config/constants_local.cpp
|
||||
/build
|
||||
/bin/node_modules
|
||||
/include/llmr/shader/shaders.hpp
|
||||
|
||||
12
bin/style.js
12
bin/style.js
@@ -917,7 +917,7 @@ module.exports = {
|
||||
"poi": {
|
||||
"source": "outdoors",
|
||||
"layer": "poi_label",
|
||||
"icon": "maki",
|
||||
"icon": "{{maki}}",
|
||||
"field": "scalerank",
|
||||
"value": [1, 2],
|
||||
"size": 12,
|
||||
@@ -926,7 +926,7 @@ module.exports = {
|
||||
"poi_3": {
|
||||
"source": "outdoors",
|
||||
"layer": "poi_label",
|
||||
"icon": "maki",
|
||||
"icon": "{{maki}}",
|
||||
"field": "scalerank",
|
||||
"value": 3,
|
||||
"size": 12,
|
||||
@@ -935,7 +935,7 @@ module.exports = {
|
||||
"poi_4_4": {
|
||||
"source": "outdoors",
|
||||
"layer": "poi_label",
|
||||
"icon": "maki",
|
||||
"icon": "{{maki}}",
|
||||
"filter": [
|
||||
"and",
|
||||
{ "field": "scalerank", "value": 4 },
|
||||
@@ -947,7 +947,7 @@ module.exports = {
|
||||
"poi_4_16": {
|
||||
"source": "outdoors",
|
||||
"layer": "poi_label",
|
||||
"icon": "maki",
|
||||
"icon": "{{maki}}",
|
||||
"filter": [
|
||||
"and",
|
||||
{ "field": "scalerank", "value": 4 },
|
||||
@@ -960,7 +960,7 @@ module.exports = {
|
||||
"poi_4_all": {
|
||||
"source": "outdoors",
|
||||
"layer": "poi_label",
|
||||
"icon": "maki",
|
||||
"icon": "{{maki}}",
|
||||
"field": "scalerank",
|
||||
"value": 4,
|
||||
"size": 12,
|
||||
@@ -969,7 +969,7 @@ module.exports = {
|
||||
"poi_aerodrome": {
|
||||
"source": "outdoors",
|
||||
"layer": "poi_label",
|
||||
"icon": "maki",
|
||||
"icon": "{{maki}}",
|
||||
"field": "maki",
|
||||
"value": "airport",
|
||||
"size": 24,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include <llmr/util/constants.hpp>
|
||||
|
||||
const char *llmr::kSpriteURL = "http://mapbox-kkaefer.s3.amazonaws.com/static/outdoors-gl/sprite";
|
||||
const char *llmr::kVectorTileURL = "http://a.tiles.mapbox.com/v3/mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5/%d/%d/%d.vector.pbf";
|
||||
const char *llmr::kGlyphURL = "http://mapbox.s3.amazonaws.com/gl-glyphs-256/%s/%d-%d.pbf";
|
||||
|
||||
const float llmr::util::tileSize = 512.0f;
|
||||
|
||||
#if defined(DEBUG)
|
||||
@@ -24,4 +28,4 @@ const bool llmr::debug::missingFontStackWarning = false;
|
||||
const bool llmr::debug::missingFontFaceWarning = false;
|
||||
const bool llmr::debug::glyphWarning = false;
|
||||
const bool llmr::debug::shapingWarning = false;
|
||||
#endif
|
||||
#endif
|
||||
@@ -12,9 +12,6 @@ class loop;
|
||||
}
|
||||
|
||||
namespace llmr {
|
||||
|
||||
extern const char *kSpriteURL;
|
||||
|
||||
namespace platform {
|
||||
|
||||
class Request;
|
||||
|
||||
@@ -10,6 +10,12 @@ 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 {
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
#include "vec.hpp"
|
||||
|
||||
namespace llmr {
|
||||
|
||||
extern const char *kSpriteURL;
|
||||
extern const char *kVectorTileURL;
|
||||
extern const char *kGlyphURL;
|
||||
|
||||
namespace util {
|
||||
|
||||
extern const float tileSize;
|
||||
|
||||
49
include/llmr/util/token.hpp
Normal file
49
include/llmr/util/token.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef LLMR_UTIL_TOKEN
|
||||
#define LLMR_UTIL_TOKEN
|
||||
|
||||
#ifdef __linux__
|
||||
#include <boost/regex.hpp>
|
||||
namespace regex_impl = boost;
|
||||
#else
|
||||
#include <regex>
|
||||
namespace regex_impl = std;
|
||||
#endif
|
||||
|
||||
namespace llmr {
|
||||
namespace util {
|
||||
|
||||
namespace detail {
|
||||
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) {
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end namespace util
|
||||
} // end namespace llmr
|
||||
|
||||
#endif
|
||||
2
llmr.gyp
2
llmr.gyp
@@ -65,6 +65,7 @@
|
||||
],
|
||||
'sources': [
|
||||
'<!@(find src -name "*.cpp")',
|
||||
'<!@(test -f "config/constants_local.cpp" && echo "config/constants_local.cpp" || echo "config/constants.cpp")',
|
||||
'<!@(find src -name "*.c")',
|
||||
'<!@(find src -name "*.h")',
|
||||
'<!@(find include -name "*.hpp")',
|
||||
@@ -131,6 +132,7 @@
|
||||
],
|
||||
'sources': [
|
||||
'<!@(find src/ \( -name "*.cpp" ! -name shaders.hpp ! -name shaders_gles2.cpp ! -name shaders_gl.cpp \))',
|
||||
'<!@(test -f "config/constants_local.cpp" && echo "config/constants_local.cpp" || echo "config/constants.cpp")',
|
||||
'<!@(find src -name "*.c")',
|
||||
'<!@(find src -name "*.h")',
|
||||
'<!@(find include -name "*.hpp")',
|
||||
|
||||
@@ -170,7 +170,7 @@ void Map::setup() {
|
||||
sources.emplace("outdoors",
|
||||
std::unique_ptr<Source>(new Source(*this,
|
||||
painter,
|
||||
"http://a.tiles.mapbox.com/v3/mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5/%d/%d/%d.vector.pbf",
|
||||
kVectorTileURL,
|
||||
Source::Type::vector,
|
||||
{{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }},
|
||||
512,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <llmr/renderer/raster_bucket.hpp>
|
||||
#include <llmr/util/raster.hpp>
|
||||
#include <llmr/util/constants.hpp>
|
||||
#include <llmr/util/token.hpp>
|
||||
#include <llmr/geometry/glyph_atlas.hpp>
|
||||
#include <llmr/text/glyph_store.hpp>
|
||||
#include <llmr/text/glyph.hpp>
|
||||
@@ -68,6 +69,11 @@ void TileParser::parseStyleLayers(const std::vector<LayerDescription> &layers) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (layer_desc.bucket_name == "background") {
|
||||
// background is a special, fake bucket
|
||||
continue;
|
||||
}
|
||||
|
||||
if (layer_desc.child_layer.size()) {
|
||||
// This is a layer group.
|
||||
// TODO: create framebuffer
|
||||
@@ -79,10 +85,7 @@ void TileParser::parseStyleLayers(const std::vector<LayerDescription> &layers) {
|
||||
auto bucket_it = tile.buckets.find(layer_desc.bucket_name);
|
||||
if (bucket_it == tile.buckets.end()) {
|
||||
auto bucket_it = style->buckets.find(layer_desc.bucket_name);
|
||||
if (layer_desc.bucket_name == "background") {
|
||||
// background is a special, fake bucket
|
||||
continue;
|
||||
} else if (bucket_it != style->buckets.end()) {
|
||||
if (bucket_it != style->buckets.end()) {
|
||||
// Only create the new bucket if we have an actual specification
|
||||
// for it.
|
||||
std::unique_ptr<Bucket> bucket = createBucket(bucket_it->second);
|
||||
@@ -193,9 +196,6 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer &laye
|
||||
tile.textVertexBuffer, tile.triangleElementsBuffer, bucket_desc, placement);
|
||||
|
||||
util::utf8_to_utf32 ucs4conv;
|
||||
regex_impl::regex token_regex("\\{\\{(\\w+)\\}\\}");
|
||||
const auto tokens_end = regex_impl::sregex_token_iterator();
|
||||
|
||||
|
||||
std::vector<std::pair<std::u32string, pbf>> labels;
|
||||
|
||||
@@ -209,34 +209,8 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer &laye
|
||||
return nullptr;
|
||||
VectorTileFeature feature{feature_pbf, layer};
|
||||
|
||||
const std::string &field = bucket_desc.geometry.field;
|
||||
std::string source_string;
|
||||
source_string.reserve(field.size());
|
||||
|
||||
bool token = false;
|
||||
for (auto token_it = regex_impl::sregex_token_iterator(field.begin(), field.end(), token_regex, {-1, 1}); token_it != tokens_end; ++token_it, token = !token) {
|
||||
if (!token_it->matched) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (token) {
|
||||
auto it_prop = feature.properties.find(token_it->str());
|
||||
if (it_prop == feature.properties.end()) {
|
||||
// feature does not have the correct property
|
||||
if (debug::labelTextMissingWarning) {
|
||||
fprintf(stderr,
|
||||
"[WARNING] feature doesn't have property '%s' required for labelling\n",
|
||||
token_it->str().c_str());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
source_string += toString(it_prop->second);
|
||||
} else {
|
||||
source_string += token_it->str();
|
||||
}
|
||||
}
|
||||
|
||||
const std::u32string string = ucs4conv.convert(source_string);
|
||||
const std::u32string string = ucs4conv.convert(
|
||||
util::replaceTokens(bucket_desc.geometry.field, feature.properties));
|
||||
|
||||
// Loop through all characters of this text and collect unique codepoints.
|
||||
for (uint32_t chr : string) {
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#include <llmr/platform/platform.hpp>
|
||||
|
||||
const char *llmr::kSpriteURL = "http://mapbox-kkaefer.s3.amazonaws.com/static/outdoors-gl/sprite";
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <llmr/platform/gl.hpp>
|
||||
#include <llmr/util/constants.hpp>
|
||||
#include <llmr/util/token.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
@@ -28,16 +29,10 @@ void IconBucket::addFeature(const VectorTileFeature &feature, SpriteAtlas &sprit
|
||||
std::string field;
|
||||
|
||||
if (geometry.field.size()) {
|
||||
auto field_it = feature.properties.find(geometry.field);
|
||||
if (field_it == feature.properties.end()) {
|
||||
if (debug::tileParseWarnings) {
|
||||
fprintf(stderr, "[WARNING] feature doesn't contain field '%s'\n", geometry.field.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
field = util::replaceTokens(geometry.field, feature.properties);
|
||||
}
|
||||
|
||||
field = toString(field_it->second);
|
||||
} else {
|
||||
if (!field.size()) {
|
||||
field = "<circle>";
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <llmr/util/string.hpp>
|
||||
#include <llmr/util/utf.hpp>
|
||||
#include <llmr/util/pbf.hpp>
|
||||
#include <llmr/util/constants.hpp>
|
||||
#include <llmr/platform/platform.hpp>
|
||||
#include <uv.h>
|
||||
#include <algorithm>
|
||||
@@ -118,7 +119,7 @@ GlyphPBF::GlyphPBF(const std::string &fontStack, GlyphRange glyphRange)
|
||||
: future(promise.get_future().share())
|
||||
{
|
||||
// Load the glyph set URL
|
||||
std::string url = util::sprintf<255>("http://mapbox.s3.amazonaws.com/gl-glyphs-256/%s/%d-%d.pbf", fontStack.c_str(), glyphRange.first, glyphRange.second);
|
||||
std::string url = util::sprintf<255>(kGlyphURL, fontStack.c_str(), glyphRange.first, glyphRange.second);
|
||||
|
||||
// TODO: Find more reliable URL normalization function
|
||||
std::replace(url.begin(), url.end(), ' ', '+');
|
||||
|
||||
Reference in New Issue
Block a user