summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/cpp/JNI.cpp6
-rw-r--r--android/cpp/NativeMapView.cpp43
-rw-r--r--android/cpp/NativeMapView.hpp5
-rw-r--r--android/java/lib/src/main/AndroidManifest.xml2
-rw-r--r--android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java19
-rw-r--r--android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java6
6 files changed, 45 insertions, 36 deletions
diff --git a/android/cpp/JNI.cpp b/android/cpp/JNI.cpp
index b8bc34c093..44ecea0b4a 100644
--- a/android/cpp/JNI.cpp
+++ b/android/cpp/JNI.cpp
@@ -140,9 +140,9 @@ using namespace mbgl::android;
// TODO: wrap C++ exceptions?
// TODO: wrap other sorts of exceptions? eg coffee catch
-jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring default_style_json) {
+jlong JNICALL nativeCreate(JNIEnv* env, jobject obj, jstring style_url, jstring api_key) {
LOG_VERBOSE("nativeCreate");
- NativeMapView* native_map_view = new NativeMapView(env, obj, std_string_from_jstring(env, default_style_json));
+ NativeMapView* native_map_view = new NativeMapView(env, obj, std_string_from_jstring(env, style_url), std_string_from_jstring(env, api_key));
if (native_map_view == nullptr) {
throw_error(env, "Unable to create NativeMapView.");
return 0;
@@ -684,7 +684,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
// NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the array correctly (too large)
std::array<JNINativeMethod, 50> methods = {{ // Can remove the extra brace in C++14
- { "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
+ { "nativeCreate", "(Ljava/lang/String;Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
{ "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) },
{ "nativeInitializeDisplay", "(J)V", reinterpret_cast<void*>(&nativeInitializeDisplay) },
{ "nativeTerminateDisplay", "(J)V", reinterpret_cast<void*>(&nativeTerminateDisplay) },
diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp
index 1ca474af6f..080b18d3be 100644
--- a/android/cpp/NativeMapView.cpp
+++ b/android/cpp/NativeMapView.cpp
@@ -31,8 +31,8 @@ void log_gl_string(GLenum name, const char* label) {
}
NativeMapView::NativeMapView(JNIEnv* env, jobject obj_,
- std::string default_style_json_) :
- default_style_json(default_style_json_) {
+ std::string style_url_, std::string api_key_) :
+ style_url(style_url_), api_key(api_key_) {
LOG_VERBOSE("NativeMapView::NativeMapView");
LOG_ASSERT(env != nullptr);
@@ -54,9 +54,8 @@ NativeMapView::NativeMapView(JNIEnv* env, jobject obj_,
view = new MBGLView(this);
map = new mbgl::Map(*view);
- // FIXME need way to load this from Java
- map->setAccessToken("pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ");
- map->setStyleURL("https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json");
+ map->setAccessToken(api_key);
+ map->setStyleURL(style_url);
}
NativeMapView::~NativeMapView() {
@@ -114,18 +113,17 @@ bool NativeMapView::initializeDisplay() {
log_egl_string(display, EGL_CLIENT_APIS, "Client APIs");
log_egl_string(display, EGL_EXTENSIONS, "Client Extensions");
- // TODO should try 565, then 8888?
+ // Try 565 first (faster)
bool use565 = true;
-
- const EGLint config_attribs[] = {
+ EGLint config_attribs[] = {
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
- EGL_BUFFER_SIZE, use565 ? 16 : 32, // Ensure we get 32bit color buffer on Tegra, 24 bit will be sorted first without it (slow software mode)
- EGL_RED_SIZE, use565 ? 5 : 8,
- EGL_GREEN_SIZE, use565 ? 6 : 8,
- EGL_BLUE_SIZE, use565 ? 5 : 8,
+ EGL_BUFFER_SIZE, 16,
+ EGL_RED_SIZE, 5,
+ EGL_GREEN_SIZE, 6,
+ EGL_BLUE_SIZE, 5,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 8,
EGL_NONE
@@ -137,9 +135,24 @@ bool NativeMapView::initializeDisplay() {
return false;
}
if (num_configs < 1) {
- LOG_ERROR("eglChooseConfig() returned no configs");
- terminateDisplay();
- return false;
+ LOG_WARN("eglChooseConfig() returned no configs for 565");
+
+ // Now try 8888
+ use565 = false;
+ config_attribs[9] = 32; // EGL_BUFFER_SIZE // Ensure we get 32bit color buffer on Tegra, 24 bit will be sorted first without it (slow software mode)
+ config_attribs[11] = 8; // EGL_RED_SIZE
+ config_attribs[13] = 8; // EGL_GREEN_SIZE
+ config_attribs[15] = 8; // EGL_BLUE_SIZE
+ if (!eglChooseConfig(display, config_attribs, nullptr, 0, &num_configs)) {
+ LOG_ERROR("eglChooseConfig(NULL) returned error %d", eglGetError());
+ terminateDisplay();
+ return false;
+ }
+ if (num_configs < 1) {
+ LOG_ERROR("eglChooseConfig() returned no configs for 8888");
+ terminateDisplay();
+ return false;
+ }
}
// TODO make_unique missing in Android NDK?
diff --git a/android/cpp/NativeMapView.hpp b/android/cpp/NativeMapView.hpp
index 046cd7c8fe..a3081e2ed6 100644
--- a/android/cpp/NativeMapView.hpp
+++ b/android/cpp/NativeMapView.hpp
@@ -41,7 +41,7 @@ class NativeMapView {
friend class MBGLView;
public:
- NativeMapView(JNIEnv* env, jobject obj, std::string default_style_json);
+ NativeMapView(JNIEnv* env, jobject obj, std::string style_url, std::string api_key);
~NativeMapView();
mbgl::Map* getMap() const {
@@ -82,7 +82,8 @@ private:
EGLConfig config = nullptr;
EGLint format = -1;
- std::string default_style_json;
+ std::string style_url;
+ std::string api_key;
};
class MBGLView: public mbgl::View {
diff --git a/android/java/lib/src/main/AndroidManifest.xml b/android/java/lib/src/main/AndroidManifest.xml
index 6a2e41b795..4a88441790 100644
--- a/android/java/lib/src/main/AndroidManifest.xml
+++ b/android/java/lib/src/main/AndroidManifest.xml
@@ -5,8 +5,6 @@
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
- <!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> -->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
index 51f627f63d..f76750c5c2 100644
--- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
+++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java
@@ -57,7 +57,10 @@ public class MapView extends SurfaceView {
private NativeMapView mNativeMapView;
// Used to style the map
- private String mDefaultStyleJSON;
+ private String mStyleUrl;
+
+ // Used to load map tiles
+ private String mApiKey;
// Touch gesture detectors
private GestureDetector mGestureDetector;
@@ -115,18 +118,12 @@ public class MapView extends SurfaceView {
return;
}
- // Load the map style
- try {
- mDefaultStyleJSON = IOUtils.toString(context.getResources()
- // .openRawResource(R.raw.style_leith), Charsets.UTF_8);
- .openRawResource(R.raw.style), Charsets.UTF_8);
- } catch (IOException e) {
- throw new RuntimeException(
- "Couldn't load default style JSON resource", e);
- }
+ // Load the map style and API key
+ mStyleUrl = "https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json";
+ mApiKey = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ";
// Create the NativeMapView
- mNativeMapView = new NativeMapView(this, mDefaultStyleJSON);
+ mNativeMapView = new NativeMapView(this, mStyleUrl, mApiKey);
// Load the attributes
TypedArray typedArray = context.obtainStyledAttributes(attrs,
diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java
index bd72846d99..5aa692e2af 100644
--- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java
+++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java
@@ -37,11 +37,11 @@ class NativeMapView {
// Constructors
//
- public NativeMapView(MapView mapView, String defaultStyleJSON) {
+ public NativeMapView(MapView mapView, String styleUrl, String apiKey) {
mMapView = mapView;
// Create the NativeMapView
- mNativeMapViewPtr = nativeCreate(defaultStyleJSON);
+ mNativeMapViewPtr = nativeCreate(styleUrl, apiKey);
}
//
@@ -359,7 +359,7 @@ class NativeMapView {
super.finalize();
}
- private native long nativeCreate(String defaultStyleJSON);
+ private native long nativeCreate(String styleUrl, String apiKey);
private native void nativeDestroy(long nativeMapViewPtr);