summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore7
-rwxr-xr-xbin/build-style.js36
-rw-r--r--bin/style.js2
-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--llmr.gyp11
-rw-r--r--macosx/llmr-app.gyp1
-rw-r--r--macosx/main.mm10
-rw-r--r--src/map/map.cpp65
-rw-r--r--src/style/style.cpp16
15 files changed, 90 insertions, 93 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/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 ada7625cb0..ffa326525a 100644
--- a/bin/style.js
+++ b/bin/style.js
@@ -2628,7 +2628,7 @@ module.exports = {
}
},
{
- "name": "satellite",
+ "name": "night",
"layers": {
"background": {
"color": "land_night"
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 113cec55d080fc407d0c3d37f4aa36323749c1e
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/llmr.gyp b/llmr.gyp
index 73d24f9678..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")',
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/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/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);