summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@codesorcery.net>2014-05-31 11:32:42 -0700
committerJustin R. Miller <incanus@codesorcery.net>2014-05-31 11:32:42 -0700
commita81a336638000f1986f1bde56e909a07b2a6ae36 (patch)
tree19ca5424367a3c89e76009a77fe54413d8c3ea51
parent6fd1525335bb753bb0efdfc3cfb58e1b6c4c1539 (diff)
downloadqtlocation-mapboxgl-a81a336638000f1986f1bde56e909a07b2a6ae36.tar.gz
programmatic styling API
-rw-r--r--.gitignore7
-rw-r--r--README.md6
-rwxr-xr-xbin/build-style.js36
-rw-r--r--bin/style.js206
-rw-r--r--common/glfw_view.cpp2
-rw-r--r--include/llmr/map/map.hpp14
-rw-r--r--include/llmr/style/style.hpp4
-rw-r--r--ios/MBXViewController.mm6
m---------ios/MVKMapKit0
-rw-r--r--ios/img/toggleStyle.png (renamed from ios/img/toggleRaster.png)bin4966 -> 4966 bytes
-rw-r--r--ios/llmr-app.gyp9
-rw-r--r--linux/llmr-app.gyp1
-rw-r--r--llmr.gyp13
-rw-r--r--macosx/llmr-app.gyp1
-rw-r--r--macosx/main.mm10
-rwxr-xr-xsetup-libraries.sh1
-rw-r--r--src/map/map.cpp65
-rw-r--r--src/map/tile_parser.cpp12
-rw-r--r--src/style/style.cpp16
19 files changed, 296 insertions, 113 deletions
diff --git a/.gitignore b/.gitignore
index 0b4742764e..5295ff95ff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,9 @@
/ios/build
/config.gypi
/config.mk
-/build \ No newline at end of file
+/build
+/bin/node_modules
+/include/llmr/shader/shaders.hpp
+/src/shader/shaders_gl.cpp
+/src/shader/shaders_gles2.cpp
+/bin/style.bin.js
diff --git a/README.md b/README.md
index 47c6a8d1d9..bffa8167e3 100644
--- a/README.md
+++ b/README.md
@@ -6,11 +6,13 @@ implemented in C++11, currently targeting iOS, OS X, and Ubuntu Linux.
# Depends
- Modern C++ compiler that supports `-std=c++11`
+ - Boost headers
- `libpng`
- `libuv`
- - `libcurl` (depends on OpenSSL; Linux only)
- `glfw3`
- - Boost
+ - `libcurl` (depends on OpenSSL; Linux only)
+ - `libboost_regex` (Linux only)
+ - Homebrew (for build on OS X)
- Python (for build only)
- Node.js (for build only)
diff --git a/bin/build-style.js b/bin/build-style.js
index 932287b899..c69fcb8b40 100755
--- a/bin/build-style.js
+++ b/bin/build-style.js
@@ -7,36 +7,6 @@ var mkdirp = require('./mkdirp');
var name = 'style';
var data = JSON.stringify(require(path.join(process.cwd(), process.argv[2])));
-
-var length = data.length;
-
-var header = '// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n\n';
-header += '#ifndef LLMR_STYLE_RESOURCES\n';
-header += '#define LLMR_STYLE_RESOURCES\n';
-header += '\n';
-header += 'namespace llmr {\n';
-header += 'namespace resources {\n';
-header += '\n';
-header += 'extern const unsigned char ' + name + '[];\n';
-header += 'extern const unsigned long ' + name + '_size;\n';
-header += '\n';
-header += '}\n';
-header += '}\n';
-header += '\n';
-header += '#endif\n';
-
-var header_path = path.join(process.argv[3], 'include/llmr/style/resources.hpp');
-mkdirp.sync(path.dirname(header_path));
-fs.writeFileSync(header_path, header);
-
-var code = '// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED.\n';
-code += '#include <llmr/style/resources.hpp>\n';
-code += '\n';
-code += 'using namespace llmr;\n';
-code += '\n';
-code += 'const unsigned char resources::' + name + '[] = R"JSON(' + data + ')JSON";\n';
-code += 'const unsigned long resources::' + name + '_size = sizeof(resources::' + name + ');\n';
-
-var file_path = path.join(process.argv[3], 'src/style/resources.cpp');
-mkdirp.sync(path.dirname(file_path));
-fs.writeFileSync(file_path, code);
+var out_path = path.join(process.argv[3], 'bin/style.min.js');
+mkdirp.sync(path.dirname(out_path));
+fs.writeFileSync(out_path, data);
diff --git a/bin/style.js b/bin/style.js
index 0a389f6be1..ffa326525a 100644
--- a/bin/style.js
+++ b/bin/style.js
@@ -661,15 +661,61 @@ module.exports = {
"layer": "country_label_line",
"type": "line"
},
- "marine_label_line": {
+ "marine_label_line_1": {
"source": "outdoors",
"layer": "marine_label",
"feature_type": "line",
"type": "text",
+ "field": "labelrank",
+ "value": 1,
+ "text_field": "{{name_en}}",
+ "path": "curve",
+ "font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
+ "fontSize": 30,
+ "letterSpacing": 0.4,
+ "maxAngleDelta": 0.5
+ },
+ "marine_label_line_2": {
+ "source": "outdoors",
+ "layer": "marine_label",
+ "feature_type": "line",
+ "field": "labelrank",
+ "value": 2,
+ "type": "text",
+ "text_field": "{{name_en}}",
+ "path": "curve",
+ "font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
+ "fontSize": 24,
+ "letterSpacing": 0.2,
+ "maxAngleDelta": 0.5
+ },
+ "marine_label_line_3": {
+ "source": "outdoors",
+ "layer": "marine_label",
+ "feature_type": "line",
+ "type": "text",
+ "field": "labelrank",
+ "value": 3,
"text_field": "{{name_en}}",
"path": "curve",
"font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
- "fontSize": 16
+ "fontSize": 18,
+ "letterSpacing": 0.1,
+ "maxAngleDelta": 0.5
+ },
+ "marine_label_line_other": {
+ "source": "outdoors",
+ "layer": "marine_label",
+ "feature_type": "line",
+ "type": "text",
+ "field": "labelrank",
+ "value": [4, 5, 6],
+ "text_field": "{{name_en}}",
+ "path": "curve",
+ "font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
+ "fontSize": 16,
+ "letterSpacing": 0.1,
+ "maxAngleDelta": 0.5
},
"marine_label_point_1": {
"source": "outdoors",
@@ -698,9 +744,24 @@ module.exports = {
"font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
"fontSize": 24,
"maxWidth": 8,
- "letterSpacing": 0.4,
+ "letterSpacing": 0.2,
"lineHeight": 1.5,
},
+ "marine_label_point_3": {
+ "source": "outdoors",
+ "layer": "marine_label",
+ "feature_type": "point",
+ "type": "text",
+ "text_field": "{{name_en}}",
+ "path": "horizontal",
+ "field": "labelrank",
+ "value": 3,
+ "font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
+ "fontSize": 18,
+ "maxWidth": 8,
+ "letterSpacing": 0.1,
+ "lineHeight": 1.3,
+ },
"marine_label_point_other": {
"source": "outdoors",
"layer": "marine_label",
@@ -709,9 +770,12 @@ module.exports = {
"text_field": "{{name_en}}",
"path": "horizontal",
"field": "labelrank",
- "value": [3,4,5,6],
+ "value": [4,5,6],
"font": "Open Sans Semibold Italic, Arial Unicode MS Bold",
- "fontSize": 18
+ "fontSize": 16,
+ "maxWidth": 8,
+ "letterSpacing": 0.1,
+ "lineHeight": 1.2,
},
"state_label": {
"source": "outdoors",
@@ -1363,8 +1427,20 @@ module.exports = {
"bucket": "country_label"
},
{
- "name": "marine_label_line",
- "bucket": "marine_label_line"
+ "name": "marine_label_line_1",
+ "bucket": "marine_label_line_1"
+ },
+ {
+ "name": "marine_label_line_2",
+ "bucket": "marine_label_line_2"
+ },
+ {
+ "name": "marine_label_line_3",
+ "bucket": "marine_label_line_3"
+ },
+ {
+ "name": "marine_label_line_other",
+ "bucket": "marine_label_line_other"
},
{
"name": "marine_label_point_1",
@@ -1375,6 +1451,10 @@ module.exports = {
"bucket": "marine_label_point_2"
},
{
+ "name": "marine_label_point_3",
+ "bucket": "marine_label_point_3"
+ },
+ {
"name": "marine_label_point_other",
"bucket": "marine_label_point_other"
},
@@ -2309,12 +2389,50 @@ module.exports = {
"width": 0.5,
"opacity": 0.5
},
- "marine_label_line": {
+ "marine_label_line_1": {
+ "color": "marine_text",
+ "size": ["stops",
+ {"z": 3, "val": 20},
+ {"z": 4, "val": 25},
+ {"z": 5, "val": 30},
+ {"z": 22, "val": 30}
+ ],
+ "stroke": "water"
+ },
+ "marine_label_line_2": {
+ "color": "marine_text",
+ "size": ["stops",
+ {"z": 3, "val": 13},
+ {"z": 4, "val": 14},
+ {"z": 5, "val": 20},
+ {"z": 6, "val": 24},
+ {"z": 22, "val": 24}
+ ],
+ "stroke": "water"
+ },
+ "marine_label_line_3": {
+ "color": "marine_text",
+ "size": ["stops",
+ {"z": 3, "val": 12},
+ {"z": 4, "val": 13},
+ {"z": 5, "val": 15},
+ {"z": 6, "val": 18},
+ {"z": 22, "val": 18}
+ ],
+ "stroke": "water"
+ },
+ "marine_label_line_other": {
"color": "marine_text",
+ "size": ["stops",
+ {"z": 4, "val": 12},
+ {"z": 5, "val": 14},
+ {"z": 6, "val": 16},
+ {"z": 22, "val": 16}
+ ],
"stroke": "water"
},
"marine_label_point_1": {
- "color": "#a9c4c7",
+ "color": "marine_text",
"size": ["stops",
{"z": 3, "val": 20},
{"z": 4, "val": 25},
@@ -2324,7 +2442,7 @@ module.exports = {
"stroke": "water"
},
"marine_label_point_2": {
- "color": "#a9c4c7",
+ "color": "marine_text",
"size": ["stops",
{"z": 3, "val": 13},
{"z": 4, "val": 14},
@@ -2334,8 +2452,8 @@ module.exports = {
],
"stroke": "water"
},
- "marine_label_point_other": {
- "color": "#a9c4c7",
+ "marine_label_point_3": {
+ "color": "marine_text",
"size": ["stops",
{"z": 3, "val": 12},
{"z": 4, "val": 13},
@@ -2345,6 +2463,16 @@ module.exports = {
],
"stroke": "water"
},
+ "marine_label_point_other": {
+ "color": "marine_text",
+ "size": ["stops",
+ {"z": 4, "val": 12},
+ {"z": 5, "val": 14},
+ {"z": 6, "val": 16},
+ {"z": 22, "val": 16}
+ ],
+ "stroke": "water"
+ },
"state_label": {
"color": "#333",
"strokeWidth": 0.4,
@@ -2500,7 +2628,7 @@ module.exports = {
}
},
{
- "name": "satellite",
+ "name": "night",
"layers": {
"background": {
"color": "land_night"
@@ -3067,8 +3195,46 @@ module.exports = {
"width": 0.5,
"opacity": 0.5
},
- "marine_label_line": {
+ "marine_label_line_1": {
"color": "water_dark_night",
+ "size": ["stops",
+ {"z": 3, "val": 20},
+ {"z": 4, "val": 25},
+ {"z": 5, "val": 30},
+ {"z": 22, "val": 30}
+ ],
+ "stroke": "water_night"
+ },
+ "marine_label_line_2": {
+ "color": "water_dark_night",
+ "size": ["stops",
+ {"z": 3, "val": 13},
+ {"z": 4, "val": 14},
+ {"z": 5, "val": 20},
+ {"z": 6, "val": 24},
+ {"z": 22, "val": 24}
+ ],
+ "stroke": "water_night"
+ },
+ "marine_label_line_3": {
+ "color": "water_dark_night",
+ "size": ["stops",
+ {"z": 3, "val": 12},
+ {"z": 4, "val": 13},
+ {"z": 5, "val": 15},
+ {"z": 6, "val": 18},
+ {"z": 22, "val": 18}
+ ],
+ "stroke": "water_night"
+ },
+ "marine_label_line_other": {
+ "color": "water_dark_night",
+ "size": ["stops",
+ {"z": 4, "val": 12},
+ {"z": 5, "val": 14},
+ {"z": 6, "val": 16},
+ {"z": 22, "val": 16}
+ ],
"stroke": "water_night"
},
"marine_label_point_1": {
@@ -3092,7 +3258,7 @@ module.exports = {
],
"stroke": "water_night"
},
- "marine_label_point_other": {
+ "marine_label_point_3": {
"color": "water_dark_night",
"size": ["stops",
{"z": 3, "val": 12},
@@ -3103,6 +3269,16 @@ module.exports = {
],
"stroke": "water_night"
},
+ "marine_label_point_other": {
+ "color": "water_dark_night",
+ "size": ["stops",
+ {"z": 4, "val": 12},
+ {"z": 5, "val": 14},
+ {"z": 6, "val": 16},
+ {"z": 22, "val": 16}
+ ],
+ "stroke": "water_night"
+ },
"state_label": {
"color": "#fff",
"strokeWidth": 0.4,
diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp
index 3cc50b591e..5c623d7259 100644
--- a/common/glfw_view.cpp
+++ b/common/glfw_view.cpp
@@ -74,7 +74,7 @@ void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, in
break;
case GLFW_KEY_R:
if (!mods)
- view->map->toggleRaster();
+ view->map->toggleStyle();
break;
case GLFW_KEY_N:
if (!mods)
diff --git a/include/llmr/map/map.hpp b/include/llmr/map/map.hpp
index 8874172c3e..d5d11dde8f 100644
--- a/include/llmr/map/map.hpp
+++ b/include/llmr/map/map.hpp
@@ -52,6 +52,14 @@ public:
void resize(uint16_t width, uint16_t height, float ratio = 1);
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fb_width, uint16_t fb_height);
+ // Styling
+ void toggleStyle();
+ void setAppliedClasses(std::set<std::string> appliedClasses);
+ std::set<std::string> getAppliedClasses() const;
+ void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0);
+ void setStyleJSON(std::string newStyleJSON);
+ std::string getStyleJSON() const;
+
// Transition
void cancelTransitions();
@@ -92,9 +100,6 @@ public:
void toggleDebug();
bool getDebug() const;
- // TEMPORARY DEBUG API
- void toggleRaster();
-
public:
inline const TransformState &getState() const { return state; }
inline std::shared_ptr<const Style> getStyle() const { return style; }
@@ -115,7 +120,6 @@ private:
// Setup
void setup();
- void loadStyle(const uint8_t *const data, uint32_t bytes);
void updateTiles();
void updateRenderState();
@@ -161,6 +165,8 @@ private:
Sources sources;
+ std::string styleJSON = "";
+
bool debug = false;
time animationTime = 0;
diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp
index 97abf586ed..58202393dc 100644
--- a/include/llmr/style/style.hpp
+++ b/include/llmr/style/style.hpp
@@ -30,7 +30,7 @@ public:
void reset();
- void loadJSON(const uint8_t *const data, size_t bytes);
+ void loadJSON(const uint8_t *const data);
size_t layerCount() const;
void cascade(float z);
@@ -39,7 +39,7 @@ public:
void updateTransitions(time now);
void cancelTransitions();
- void setDefaultTransitionDuration(uint64_t duration = 0);
+ void setDefaultTransitionDuration(uint64_t duration_milliseconds = 0);
public:
std::shared_ptr<Sprite> sprite;
diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm
index 25fca05996..213fdceeb1 100644
--- a/ios/MBXViewController.mm
+++ b/ios/MBXViewController.mm
@@ -85,7 +85,7 @@ llmr::Settings_NSUserDefaults *settings = nullptr;
singleTap.numberOfTapsRequired = 1;
[self.mapView addGestureRecognizer:singleTap];
- NSArray *selectorNames = @[ @"unrotate", @"resetPosition", @"toggleDebug", @"toggleRaster", @"locateUser" ];
+ NSArray *selectorNames = @[ @"unrotate", @"resetPosition", @"toggleDebug", @"toggleStyle", @"locateUser" ];
CGFloat buttonSize = 40;
CGFloat bufferSize = 20;
CGFloat alpha = 0.75;
@@ -166,9 +166,9 @@ llmr::Settings_NSUserDefaults *settings = nullptr;
self.debug = ! self.debug;
}
-- (void)toggleRaster
+- (void)toggleStyle
{
- [self.mapView toggleRaster];
+ [self.mapView toggleStyle];
}
- (void)locateUser
diff --git a/ios/MVKMapKit b/ios/MVKMapKit
-Subproject 7c7bb2310216a8d18108db40b09db08732df1f8
+Subproject fe12687eb95b925b37a260596f309931a745d82
diff --git a/ios/img/toggleRaster.png b/ios/img/toggleStyle.png
index 59a6f330fb..59a6f330fb 100644
--- a/ios/img/toggleRaster.png
+++ b/ios/img/toggleStyle.png
Binary files differ
diff --git a/ios/llmr-app.gyp b/ios/llmr-app.gyp
index 5d7e1f8e3d..89acc2d749 100644
--- a/ios/llmr-app.gyp
+++ b/ios/llmr-app.gyp
@@ -14,8 +14,10 @@
"./MBXAppDelegate.m",
"./MBXViewController.h",
"./MBXViewController.mm",
- "./MVKMapKit/MVKMapKit/MVKMapView.h",
- "./MVKMapKit/MVKMapKit/MVKMapView.mm",
+ '<!@(find MVKMapKit/MVKMapKit -type f -name "MVKMapView.*")',
+ '<!@(find MVKMapKit/MVKMapKit -type f -name "MVKStyleFunctionValue.*")',
+ '<!@(find MVKMapKit/MVKMapKit -type f -name "MVKTypes.*")',
+ '<!@(find MVKMapKit/MVKMapKit -type f -name "*+MVKAdditions.*")',
"../common/settings_nsuserdefaults.hpp",
"../common/settings_nsuserdefaults.mm",
"../common/foundation_request.h",
@@ -25,7 +27,8 @@
'mac_bundle': 1,
'mac_bundle_resources': [
'<!@(find img -type f)',
- '<!@(find MVKMapKit/MVKMapKit/Resources -type f)'
+ '<!@(find MVKMapKit/MVKMapKit/Resources -type f)',
+ '<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js'
],
'link_settings': {
'libraries': [
diff --git a/linux/llmr-app.gyp b/linux/llmr-app.gyp
index 75fd0dfe3d..93b08364ed 100644
--- a/linux/llmr-app.gyp
+++ b/linux/llmr-app.gyp
@@ -44,6 +44,7 @@
'libraries': [
'<@(glfw3_libraries)',
'<@(curl_libraries)',
+ '-lboost_regex'
],
},
}],
diff --git a/llmr.gyp b/llmr.gyp
index a32a598f53..d165a24d3b 100644
--- a/llmr.gyp
+++ b/llmr.gyp
@@ -44,20 +44,15 @@
'bin/style.js',
],
'outputs': [
- '<(SHARED_INTERMEDIATE_DIR)/include/llmr/style/resources.hpp',
- '<(SHARED_INTERMEDIATE_DIR)/src/style/resources.cpp'
+ '<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js'
],
'action': ['<@(node)', 'bin/build-style.js', '<@(_inputs)', '<(SHARED_INTERMEDIATE_DIR)']
}
],
'direct_dependent_settings': {
'sources': [
- '<(SHARED_INTERMEDIATE_DIR)/include/llmr/style/resources.hpp',
- '<(SHARED_INTERMEDIATE_DIR)/src/style/resources.cpp'
+ '<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js'
],
- 'include_dirs':[
- '<(SHARED_INTERMEDIATE_DIR)/include/',
- ]
}
},
{
@@ -135,7 +130,7 @@
'shaders',
],
'sources': [
- '<!@(find src/ \( -name "*.cpp" ! -name resources.cpp ! -name shaders.hpp ! -name resources.hpp ! -name shaders_gles2.cpp ! -name shaders_gl.cpp \))',
+ '<!@(find src/ \( -name "*.cpp" ! -name shaders.hpp ! -name shaders_gles2.cpp ! -name shaders_gl.cpp \))',
'<!@(find src -name "*.c")',
'<!@(find src -name "*.h")',
'<!@(find include -name "*.hpp")',
@@ -190,7 +185,7 @@
}, {
'libraries': [
'<@(png_libraries)',
- '<@(uv_libraries)',
+ '<@(uv_libraries)'
]
}]
]
diff --git a/macosx/llmr-app.gyp b/macosx/llmr-app.gyp
index 83bcd0f039..02319da94b 100644
--- a/macosx/llmr-app.gyp
+++ b/macosx/llmr-app.gyp
@@ -21,6 +21,7 @@
'mac_bundle': 1,
'mac_bundle_resources': [
'Icon.icns',
+ '<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js'
],
'xcode_settings': {
'SDKROOT': 'macosx',
diff --git a/macosx/main.mm b/macosx/main.mm
index 174b0f1b1f..4c5da2f329 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -1,6 +1,8 @@
#include "../common/settings_nsuserdefaults.hpp"
#include "../common/glfw_view.hpp"
+#import <Foundation/Foundation.h>
+
int main() {
GLFWView view;
llmr::Map map(view);
@@ -10,7 +12,13 @@ int main() {
map.setLonLatZoom(settings.longitude, settings.latitude, settings.zoom);
map.setAngle(settings.angle);
map.setDebug(settings.debug);
- map.toggleRaster();
+
+ // Load style
+ NSString *path = [[NSBundle mainBundle] pathForResource:@"style.min" ofType:@"js"];
+ NSString *json = [NSString stringWithContentsOfFile:path
+ encoding:[NSString defaultCStringEncoding]
+ error:nil];
+ map.setStyleJSON((std::string)[json cStringUsingEncoding:[NSString defaultCStringEncoding]]);
// fprintf(stderr, "lon: %f, lat: %f, zoom: %f, angle: %f, debug: %d\n", settings.l)
diff --git a/setup-libraries.sh b/setup-libraries.sh
index f37a67cb0e..e0b03637e4 100755
--- a/setup-libraries.sh
+++ b/setup-libraries.sh
@@ -95,6 +95,7 @@ source Linux.sh
if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64/lib/libssl.a ] ; then ./scripts/build_openssl.sh ; fi
if [ ! -f out/build-cpp11-libstdcpp-gcc-x86_64/lib/libcurl.a ] ; then ./scripts/build_curl.sh ; fi
if [ ! -d out/build-cpp11-libstdcpp-gcc-x86_64/include/boost ] ; then ./scripts/build_boost.sh `pwd`/../../src/ `pwd`/../../include/ `pwd`/../../linux/ `pwd`/../../common/ ; fi
+ if [ ! -d out/build-cpp11-libstdcpp-gcc-x86_64/lib/libboost_regex.a ] ; then ./scripts/build_boost.sh --with-regex ; fi
cd ../../
./configure \
diff --git a/src/map/map.cpp b/src/map/map.cpp
index c4c736d1a8..305b523c1e 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -174,25 +174,20 @@ void Map::setup() {
14,
true)));
- sources.emplace("satellite",
- std::unique_ptr<Source>(new Source(*this,
- painter,
- "https://a.tiles.mapbox.com/v3/justin.hh0gkdfm/%d/%d/%d%s.png256",
- Source::Type::raster,
- {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 }},
- 256,
- 0,
- 21,
- false)));
-
- loadStyle(resources::style, resources::style_size);
+ setStyleJSON(styleJSON);
}
-void Map::loadStyle(const uint8_t *const data, uint32_t bytes) {
- style->loadJSON(data, bytes);
+void Map::setStyleJSON(std::string newStyleJSON) {
+ styleJSON.swap(newStyleJSON);
+ style->cancelTransitions();
+ style->loadJSON((const uint8_t *)styleJSON.c_str());
update();
}
+std::string Map::getStyleJSON() const {
+ return styleJSON;
+}
+
#pragma mark - Size
// Note: This function is called from another thread. Make sure you only call threadsafe functions!
@@ -388,25 +383,45 @@ bool Map::getDebug() const {
return debug;
}
-void Map::toggleRaster() {
- style->setDefaultTransitionDuration(300);
+void Map::toggleStyle() {
+ setDefaultTransitionDuration(300);
style->cancelTransitions();
- auto it = sources.find("satellite");
- if (it != sources.end()) {
- Source &satellite_source = *it->second;
- if (satellite_source.enabled) {
- satellite_source.enabled = false;
- style->appliedClasses.erase("satellite");
- } else {
- satellite_source.enabled = true;
- style->appliedClasses.insert("satellite");
+ if (style->appliedClasses.size() == 1) {
+ for (auto source_it = style->classes.begin(); source_it != style->classes.end(); source_it++) {
+ if (source_it->first != "default") {
+ style->appliedClasses.insert(source_it->first);
+ break;
+ }
+ }
+ } else {
+ for (auto source_it = style->classes.begin(); source_it != style->classes.end(); source_it++) {
+ if (source_it->first != "default") {
+ style->appliedClasses.erase(source_it->first);
+ break;
+ }
}
}
update();
}
+void Map::setAppliedClasses(std::set<std::string> appliedClasses) {
+ style->cancelTransitions();
+
+ style->appliedClasses.swap(appliedClasses);
+
+ update();
+}
+
+std::set<std::string> Map::getAppliedClasses() const {
+ return style->appliedClasses;
+}
+
+void Map::setDefaultTransitionDuration(uint64_t duration_milliseconds) {
+ style->setDefaultTransitionDuration(duration_milliseconds);
+}
+
void Map::updateTiles() {
for (auto &pair : sources) {
const std::unique_ptr<Source> &source = pair.second;
diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp
index ecd15adbbb..ad0fb2d715 100644
--- a/src/map/tile_parser.cpp
+++ b/src/map/tile_parser.cpp
@@ -16,7 +16,13 @@
#include <llmr/util/std.hpp>
#include <llmr/util/utf.hpp>
+#ifdef __linux__
+#include <boost/regex.hpp>
+namespace regex_impl = boost;
+#else
#include <regex>
+namespace regex_impl = std;
+#endif
using namespace llmr;
@@ -184,8 +190,8 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer &laye
tile.textVertexBuffer, tile.triangleElementsBuffer, bucket_desc, placement);
util::utf8_to_utf32 ucs4conv;
- std::regex token_regex("\\{\\{(\\w+)\\}\\}");
- const auto tokens_end = std::sregex_token_iterator();
+ regex_impl::regex token_regex("\\{\\{(\\w+)\\}\\}");
+ const auto tokens_end = regex_impl::sregex_token_iterator();
std::vector<std::pair<std::u32string, pbf>> labels;
@@ -205,7 +211,7 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer &laye
source_string.reserve(field.size());
bool token = false;
- for (auto token_it = std::sregex_token_iterator(field.begin(), field.end(), token_regex, {-1, 1}); token_it != tokens_end; ++token_it, token = !token) {
+ 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;
}
diff --git a/src/style/style.cpp b/src/style/style.cpp
index f1694694c0..9ae0b273f4 100644
--- a/src/style/style.cpp
+++ b/src/style/style.cpp
@@ -965,20 +965,14 @@ size_t Style::layerCount() const {
return count;
}
-void Style::setDefaultTransitionDuration(uint64_t duration) {
- default_transition_duration = duration;
+void Style::setDefaultTransitionDuration(uint64_t duration_milliseconds) {
+ default_transition_duration = duration_milliseconds;
}
-void Style::loadJSON(const uint8_t *const data, size_t bytes) {
- rapidjson::Document doc;
-
- if (bytes <= 0) {
- return;
- }
+void Style::loadJSON(const uint8_t *const data) {
+ uv::writelock lock(mtx);
- if (data[bytes - 1] != 0) {
- throw exception("style JSON string is not 0-terminated");
- }
+ rapidjson::Document doc;
doc.Parse<0>((const char *const)data);