diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 0895096f6..38d5277a8 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -86,6 +86,7 @@ public class MapSnapshotter {
private int width;
private int height;
private String styleUrl = Style.MAPBOX_STREETS;
+ private String styleJson;
private LatLngBounds region;
private CameraPosition cameraPosition;
private boolean showLogo = true;
@@ -111,6 +112,15 @@ public class MapSnapshotter {
return this;
}
+ /**
+ * @param styleJson The style json to use
+ * @return the mutated {@link Options}
+ */
+ public Options withStyleJson(String styleJson) {
+ this.styleJson = styleJson;
+ return this;
+ }
+
/**
* @param region the region to show in the snapshot.
* This is applied after the camera position
@@ -208,7 +218,7 @@ public class MapSnapshotter {
String programCacheDir = context.getCacheDir().getAbsolutePath();
nativeInitialize(this, fileSource, options.pixelRatio, options.width,
- options.height, options.styleUrl, options.region, options.cameraPosition,
+ options.height, options.styleUrl, options.styleJson, options.region, options.cameraPosition,
options.showLogo, programCacheDir);
}
@@ -462,7 +472,7 @@ public class MapSnapshotter {
protected native void nativeInitialize(MapSnapshotter mapSnapshotter,
FileSource fileSource, float pixelRatio,
- int width, int height, String styleUrl,
+ int width, int height, String styleUrl, String styleJson,
LatLngBounds region, CameraPosition position,
boolean showLogo, String programCacheDir);
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index fb1d0ef8a..b78fba0aa 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -344,6 +344,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
+
+
+
+
Timber.e(error));
+ }
+ });
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mapSnapshotter.cancel();
+ }
+
+ @Override
+ public void onSnapshotReady(MapSnapshot snapshot) {
+ Timber.i("Snapshot ready");
+ ImageView imageView = (ImageView) findViewById(R.id.snapshot_image);
+ imageView.setImageBitmap(snapshot.getBitmap());
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index 17d6ad57c..b515a4d3a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -57,6 +57,7 @@
Show a static bitmap taken with the MapSnapshotter
Show how to reuse a MapSnapshotter instance
Show how to add a marker to a Snapshot
+ Show how to load a local style with a Snapshot
Use Android SDK Animators to animate camera position changes
Use Android SDK Views as symbols
Use TextureView to render the map
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index 3f011bd3e..114ff38a0 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -57,6 +57,7 @@
Map Snapshotter
Map Snapshotter Reuse
Map Snapshot with marker
+ Map Snapshot with local style
Animator animation
SymbolGenerator
TextureView debug
diff --git a/platform/android/scripts/exclude-activity-gen.json b/platform/android/scripts/exclude-activity-gen.json
index 157808aa5..d7d9c1655 100644
--- a/platform/android/scripts/exclude-activity-gen.json
+++ b/platform/android/scripts/exclude-activity-gen.json
@@ -2,6 +2,7 @@
"BaseLocationActivity",
"MapSnapshotterMarkerActivity",
"MapSnapshotterReuseActivity",
+ "MapSnapshotterLocalStyleActivity",
"LatLngBoundsActivity",
"BottomSheetActivity",
"MapSnapshotterActivity",
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index a006953d3..ca1307dd1 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -20,6 +20,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
jni::jint width,
jni::jint height,
jni::String styleURL,
+ jni::String styleJSON,
jni::Object region,
jni::Object position,
jni::jboolean _showLogo,
@@ -42,12 +43,19 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
if (region) {
bounds = LatLngBounds::getLatLngBounds(_env, region);
}
+
+ std::pair style;
+ if (styleJSON) {
+ style = std::make_pair(true, jni::Make(_env, styleJSON));
+ } else {
+ style = std::make_pair(false, jni::Make(_env, styleURL));
+ }
showLogo = _showLogo;
// Create the core snapshotter
snapshotter = std::make_unique(fileSource,
*threadPool,
- jni::Make(_env, styleURL),
+ style,
size,
pixelRatio,
cameraOptions,
@@ -141,7 +149,7 @@ void MapSnapshotter::registerNative(jni::JNIEnv& env) {
// Register the peer
jni::RegisterNativePeer(env, MapSnapshotter::javaClass, "nativePtr",
- std::make_unique, jni::Object, jni::jfloat, jni::jint, jni::jint, jni::String, jni::Object, jni::Object, jni::jboolean, jni::String>,
+ std::make_unique, jni::Object, jni::jfloat, jni::jint, jni::jint, jni::String, jni::String, jni::Object, jni::Object, jni::jboolean, jni::String>,
"nativeInitialize",
"finalize",
METHOD(&MapSnapshotter::setStyleUrl, "setStyleUrl"),
diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp
index 4cdf4bcf2..33d32e01a 100644
--- a/platform/android/src/snapshotter/map_snapshotter.hpp
+++ b/platform/android/src/snapshotter/map_snapshotter.hpp
@@ -34,6 +34,7 @@ public:
jni::jint width,
jni::jint height,
jni::String styleURL,
+ jni::String styleJSON,
jni::Object region,
jni::Object position,
jni::jboolean showLogo,
diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm
index 923c8fb2a..76d99a041 100644
--- a/platform/darwin/src/MGLMapSnapshotter.mm
+++ b/platform/darwin/src/MGLMapSnapshotter.mm
@@ -428,6 +428,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
_mbglThreadPool = mbgl::sharedThreadPool();
std::string styleURL = std::string([options.styleURL.absoluteString UTF8String]);
+ std::pair style = std::make_pair(false, styleURL);
// Size; taking into account the minimum texture size for OpenGL ES
// For non retina screens the ratio is 1:1 MGLSnapshotterMinimumPixelSize
@@ -454,7 +455,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
}
// Create the snapshotter
- _mbglMapSnapshotter = std::make_unique(*mbglFileSource, *_mbglThreadPool, styleURL, size, pixelRatio, cameraOptions, coordinateBounds);
+ _mbglMapSnapshotter = std::make_unique(*mbglFileSource, *_mbglThreadPool, style, size, pixelRatio, cameraOptions, coordinateBounds);
}
@end
diff --git a/platform/default/mbgl/map/map_snapshotter.cpp b/platform/default/mbgl/map/map_snapshotter.cpp
index 9341c23cf..da3a250e0 100644
--- a/platform/default/mbgl/map/map_snapshotter.cpp
+++ b/platform/default/mbgl/map/map_snapshotter.cpp
@@ -15,7 +15,7 @@ class MapSnapshotter::Impl {
public:
Impl(FileSource&,
Scheduler&,
- const std::string& styleURL,
+ const std::pair style,
const Size&,
const float pixelRatio,
const CameraOptions&,
@@ -43,7 +43,7 @@ private:
MapSnapshotter::Impl::Impl(FileSource& fileSource,
Scheduler& scheduler,
- const std::string& styleURL,
+ const std::pair style,
const Size& size,
const float pixelRatio,
const CameraOptions& cameraOptions,
@@ -52,8 +52,11 @@ MapSnapshotter::Impl::Impl(FileSource& fileSource,
: frontend(size, pixelRatio, fileSource, scheduler, programCacheDir)
, map(frontend, MapObserver::nullObserver(), size, pixelRatio, fileSource, scheduler, MapMode::Static) {
- map.getStyle().loadURL(styleURL);
-
+ if (style.first) {
+ map.getStyle().loadJSON(style.second);
+ } else{
+ map.getStyle().loadURL(style.second);
+ }
map.jumpTo(cameraOptions);
// Set region, if specified
@@ -134,13 +137,13 @@ LatLngBounds MapSnapshotter::Impl::getRegion() const {
MapSnapshotter::MapSnapshotter(FileSource& fileSource,
Scheduler& scheduler,
- const std::string& styleURL,
+ const std::pair style,
const Size& size,
const float pixelRatio,
const CameraOptions& cameraOptions,
const optional region,
const optional programCacheDir)
- : impl(std::make_unique>("Map Snapshotter", fileSource, scheduler, styleURL, size, pixelRatio, cameraOptions, region, programCacheDir)) {
+ : impl(std::make_unique>("Map Snapshotter", fileSource, scheduler, style, size, pixelRatio, cameraOptions, region, programCacheDir)) {
}
MapSnapshotter::~MapSnapshotter() = default;
diff --git a/platform/default/mbgl/map/map_snapshotter.hpp b/platform/default/mbgl/map/map_snapshotter.hpp
index 985396e5a..a71da121c 100644
--- a/platform/default/mbgl/map/map_snapshotter.hpp
+++ b/platform/default/mbgl/map/map_snapshotter.hpp
@@ -27,7 +27,7 @@ class MapSnapshotter {
public:
MapSnapshotter(FileSource& fileSource,
Scheduler& scheduler,
- const std::string& styleURL,
+ const std::pair style,
const Size&,
const float pixelRatio,
const CameraOptions&,